<commit_before>Datajam = (typeof Datajam == "undefined") ? {} : Datajam;

Datajam.Event = Backbone.Model.extend({
  id: Datajam.eventId,
  url: '/event/' + Datajam.eventId + '.json'
});

Datajam.Check = Backbone.Model.extend({
  url: '/onair/signed_in'
});

Datajam.ContentArea = Backbone.Model.extend({

});

Datajam.ContentUpdate = Backbone.Model.extend({
  save: function() {
    var contentArea = this.get('contentArea');
    var payload = { event_id: Datajam.event.get('_id'),
                    content_area_id: contentArea.get('_id'),
                    html: $('#textarea-' + contentArea.get('_id')).val() };
    $.post('/onair/update', payload, function(response) {
      $('#modal-' + contentArea.get('_id')).modal('hide');
    }, 'json');
  }
});

Datajam.DataCardUpdate = Backbone.Model.extend({
  save: function() {
    var contentArea = this.get('contentArea');
    var payload = { event_id: Datajam.event.get('_id'),
                    content_area_id: contentArea.get('_id'),
                    data: { current_card_id: $('#select-' + contentArea.get('_id') + ' option:selected').val() } };
    console.log(payload);
    $.post('/onair/update', payload, function(response) {
      $('#modal-' + contentArea.get('_id')).modal('hide');
    }, 'json');
  }
});

Datajam.OnairToolbar = Backbone.View.extend({
  render: function() {
    var topbarTemplate = Handlebars.compile($("script#onair_topbar_template").html());
    $('body').prepend(topbarTemplate(this.model.toJSON()));
    $('body').addClass('topbarred');
    return this;
  }
});

Datajam.ContentAreaView = Backbone.View.extend({
  render: function() {
    $('#content_area_' + this.model.get('_id')).html(this.model.get('html'));
  }
});

Datajam.ContentUpdateModal = Backbone.View.extend({
  events: {
    'click .modal-update': 'save'
  },
  render: function() {
    var tmpl = Datajam.ModalTemplates[this.model.get('contentArea').get('area_type')];

    // Assign to this.el and add to body.
    this.el = $(tmpl(this.model.get('contentArea').toJSON()));
    $('body').append(this.el);

    // Rebind events since this.el was assigned.
    this.delegateEvents();

    return this;
  },
  save: function() {
    this.model.save();
  }
});

Datajam.DataCardModal = Backbone.View.extend({
  events: {
    'click .modal-update': 'save'
  },
  render: function() {
    // Generate the template.
    var tmpl = Handlebars.compile($("script#data_card_modal_template").html());

    // Assign to this.el and add to body.
    this.el = $(tmpl(this.model.get('contentArea').toJSON()));
    $('body').append(this.el);

    // Rebind events since this.el was assigned.
    this.delegateEvents();

    return this;
  },
  save: function() {
    this.model.save();
  }
});

Datajam.notificationBox = function() {
  var eventReminder = $("#event_reminder");
  var scheduledTime = Datajam.event.get("unix_scheduled_at");
  var currentTime = new Date().getTime()/1000;
  var hideNotificationBox = (scheduledTime - currentTime) <= 0;

  if(hideNotificationBox && eventReminder.is(":visible")) {
    eventReminder.hide();
  }
};

Datajam.pollForUpdates = function() {
  Datajam.notificationBox();
  $.getJSON('/event/' + Datajam.eventId + '/updates.json', function(updates) {

    if (updates['content_updates'] && updates['content_updates'].length > 0) {

      if (Datajam.updates.length == 0) {
        Datajam.updates = updates['content_updates'];
      }

      // Update the DOM if there are new updates.
      var lastUpdate = Datajam.updates[Datajam.updates.length - 1];
      if (lastUpdate) {
        _.each(updates['content_updates'], function(contentUpdate) {
          if (contentUpdate['updated_at'] > lastUpdate['updated_at']) {
            $('#content_area_' + contentUpdate['content_area_id']).html(contentUpdate['html']);
            Datajam.updates.push(contentUpdate);
          }
        });
      }
    }
    setTimeout(function() { Datajam.pollForUpdates(); }, 3000);
  });
};

$(function() {

  // Compile the modal template(s).
  var tmpls = {}
  $("script.modalTemplate").each(function(){
    var tmpl = $(this)
      , areaType = tmpl.attr('id').replace('_modal_template', '');
    tmpls[areaType] = Handlebars.compile(tmpl.html());
  });

  $("#remind_event").bind('ajax:success', function(event, data, status, xhr) {<commit_msg>preventDefault on modal events<commit_after>Datajam = (typeof Datajam == "undefined") ? {} : Datajam;

Datajam.Event = Backbone.Model.extend({
  id: Datajam.eventId,
  url: '/event/' + Datajam.eventId + '.json'
});

Datajam.Check = Backbone.Model.extend({
  url: '/onair/signed_in'
});

Datajam.ContentArea = Backbone.Model.extend({

});

Datajam.ContentUpdate = Backbone.Model.extend({
  save: function() {
    var contentArea = this.get('contentArea');
    var payload = { event_id: Datajam.event.get('_id'),
                    content_area_id: contentArea.get('_id'),
                    html: $('#textarea-' + contentArea.get('_id')).val() };
    $.post('/onair/update', payload, function(response) {
      $('#modal-' + contentArea.get('_id')).modal('hide');
    }, 'json');
  }
});

Datajam.DataCardUpdate = Backbone.Model.extend({
  save: function() {
    var contentArea = this.get('contentArea');
    var payload = { event_id: Datajam.event.get('_id'),
                    content_area_id: contentArea.get('_id'),
                    data: { current_card_id: $('#select-' + contentArea.get('_id') + ' option:selected').val() } };
    console.log(payload);
    $.post('/onair/update', payload, function(response) {
      $('#modal-' + contentArea.get('_id')).modal('hide');
    }, 'json');
  }
});

Datajam.OnairToolbar = Backbone.View.extend({
  render: function() {
    var topbarTemplate = Handlebars.compile($("script#onair_topbar_template").html());
    $('body').prepend(topbarTemplate(this.model.toJSON()));
    $('body').addClass('topbarred');
    return this;
  }
});

Datajam.ContentAreaView = Backbone.View.extend({
  render: function() {
    $('#content_area_' + this.model.get('_id')).html(this.model.get('html'));
  }
});

Datajam.ContentUpdateModal = Backbone.View.extend({
  events: {
    'click .modal-update': 'save'
  },
  render: function() {
    var tmpl = Datajam.ModalTemplates[this.model.get('contentArea').get('area_type')];

    // Assign to this.el and add to body.
    this.el = $(tmpl(this.model.get('contentArea').toJSON()));
    $('body').append(this.el);

    // Rebind events since this.el was assigned.
    this.delegateEvents();

    return this;
  },
  save: function(e) {
    e.preventDefault();
    this.model.save();
  }
});

Datajam.DataCardModal = Backbone.View.extend({
  events: {
    'click .modal-update': 'save'
  },
  render: function() {
    // Generate the template.
    var tmpl = Handlebars.compile($("script#data_card_modal_template").html());

    // Assign to this.el and add to body.
    this.el = $(tmpl(this.model.get('contentArea').toJSON()));
    $('body').append(this.el);

    // Rebind events since this.el was assigned.
    this.delegateEvents();

    return this;
  },
  save: function(e) {
    e.preventDefault();
    this.model.save();
  }
});

Datajam.notificationBox = function() {
  var eventReminder = $("#event_reminder");
  var scheduledTime = Datajam.event.get("unix_scheduled_at");
  var currentTime = new Date().getTime()/1000;
  var hideNotificationBox = (scheduledTime - currentTime) <= 0;

  if(hideNotificationBox && eventReminder.is(":visible")) {
    eventReminder.hide();
  }
};

Datajam.pollForUpdates = function() {
  Datajam.notificationBox();
  $.getJSON('/event/' + Datajam.eventId + '/updates.json', function(updates) {

    if (updates['content_updates'] && updates['content_updates'].length > 0) {

      if (Datajam.updates.length == 0) {
        Datajam.updates = updates['content_updates'];
      }

      // Update the DOM if there are new updates.
      var lastUpdate = Datajam.updates[Datajam.updates.length - 1];
      if (lastUpdate) {
        _.each(updates['content_updates'], function(contentUpdate) {
          if (contentUpdate['updated_at'] > lastUpdate['updated_at']) {
            $('#content_area_' + contentUpdate['content_area_id']).html(contentUpdate['html']);
            Datajam.updates.push(contentUpdate);
          }
        });
      }
    }
    setTimeout(function() { Datajam.pollForUpdates(); }, 3000);
  });
};

$(function() {

  // Compile the modal template(s).
  var tmpls = {};
  $("script.modalTemplate").each(function(){
    var tmpl = $(this)
      , areaType = tmpl.attr('id').replace('_modal_template', '');
    tmpls[areaType] = Handlebars.compile(tmpl.html());
  });

  $("#remind_event").bind('ajax:success', function(event, data, status, xhr) {
{'fraction_non_alphanumeric': 0.18619342981851597, 'fraction_numerical': 0.0027567195037904893, 'mean_word_length': 3.419796954314721, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2924136', 'n_tokens_mistral': 2902, 'n_tokens_neox': 2808, 'n_words': 471}