<commit_before>
jQuery ->
  $("#event_title").focus();
  table = $('#events').dataTable
    "dom": '<"eventToolbar dataTables_filter">frtip',
    order: [[3, 'asc']],
    columnDefs: [
                  { orderable: false, targets: -1 },
                  { orderData: 2, targets: 3 },
                  { orderData: 4, targets: 5 },
                  { visible: false, targets: [2,4,8] }
                ]

  $('div.eventToolbar').html('<label>Current:<input type="checkbox" id="js-events-current-checkbox" name="event-filter"></label>
  <label>Past:<input type="checkbox" id="js-events-past-checkbox" name="event-filter"></label>
  <label>Templates:<input type="checkbox" id="js-events-template-checkbox" name="event-filter"></label>')

  filterCheckboxes = (element, criteria) ->
    $.fn.dataTable.ext.search.push((settings, data, dataIndex) ->
      checkboxState = element.checked
      itemStatus  = data[7]
      endTime = new Date(data[5])
      isTemplate = data[8]

      if criteria.type is "current"
        if (checkboxState is false) or (checkboxState is true and
            endTime > criteria.dateTime)
          return true
        return false
      else if criteria.type is "past"
        if (checkboxState is false) or (checkboxState is true and
            endTime < criteria.dateTime)
          return true
        return false
      else if criteria.type is "template"
        if (checkboxState is false) or (checkboxState is true and
            isTemplate is "True")
          return true
        return false
      )
    table.fnDraw()

  $('#js-events-current-checkbox').click ->
    $("#js-events-past-checkbox").prop('checked', false)
    criteria = {
      type: "current",
      dateTime: new Date()
    }
    filterCheckboxes(this, criteria)

  $('#js-events-past-checkbox').click ->
    $("#js-events-current-checkbox").prop('checked', false)
    criteria = {
      type: "past",
      dateTime: new Date()
    }
    filterCheckboxes(this, criteria)

  $('#js-events-template-checkbox').click ->
    criteria = {
      type: "template",
      status: ["Active", "Inactive"]
    }
    filterCheckboxes(this, criteria)

  $("#event_category").change ->
    temp = $("#event_category option:selected").text();
    if temp is "Training"
      $(".training-controls").show()
    else
      $(".training-controls").hide()
  $("#event_status").change ->
    status = $("#event_status option:selected").text();
    start_time = $("#event_start_time").text();
    if status is "Completed"
      $("#XXevent_start_time").hide()

  $('a[data-toggle="tab"]').on 'shown.bs.tab', (e) ->
    $.fn.dataTable.tables(
      visible: true
      api: true).columns.adjust()
    return

  $('#event_start_time').change -><commit_msg>refactored dataTables() logic within events.js.coffee<commit_after>
jQuery ->
  $("#event_title").focus();
  $table = $('#events').dataTable
    "dom": '<"eventToolbar dataTables_filter">frtip',
    order: [[3, 'asc']],
    columnDefs: [
                  { orderable: false, targets: -1 },
                  { orderData: 2, targets: 3 },
                  { orderData: 4, targets: 5 },
                  { visible: false, targets: [2,4,8] }
                ]
# sets checkbox elements within #events dataTable()
  $('div.eventToolbar').html('<label>Current:<input type="checkbox" id="js-events-current-checkbox" name="event-filter"></label>
  <label>Past:<input type="checkbox" id="js-events-past-checkbox" name="event-filter"></label>
  <label>Templates:<input type="checkbox" id="js-events-template-checkbox" name="event-filter"></label>')

# logic handling checkbox filtering with dataTables()
  filterCheckboxes = (element, criteria) ->
    $.fn.dataTable.ext.search.push((settings, data) ->
      checkboxState = element.checked
      endTime = new Date(data[5])
      isTemplate = data[8]

      if criteria.type is "current" and (checkboxState is false or (checkboxState is true and endTime > criteria.dateTime))
        return true
      else if criteria.type is "past" and (checkboxState is false or (checkboxState is true and endTime < criteria.dateTime))
        return true
      else if criteria.type is "template" and (checkboxState is false or (checkboxState is true and isTemplate is "True"))
        return true
      else
        return false
      )
    $table.fnDraw()

  # events handling checkboxes
  $('#js-events-current-checkbox').change ->
    $("#js-events-past-checkbox").prop('checked', false)
    criteria = {
      type: "current",
      dateTime: new Date()
    }
    filterCheckboxes(this, criteria)

  $('#js-events-past-checkbox').change ->
    $("#js-events-current-checkbox").prop('checked', false)
    criteria = {
      type: "past",
      dateTime: new Date()
    }
    filterCheckboxes(this, criteria)

  $('#js-events-template-checkbox').change ->
    criteria = {
      type: "template",
    }
    filterCheckboxes(this, criteria)

  $("#event_category").change ->
    temp = $("#event_category option:selected").text();
    if temp is "Training"
      $(".training-controls").show()
    else
      $(".training-controls").hide()
  $("#event_status").change ->
    status = $("#event_status option:selected").text();
    start_time = $("#event_start_time").text();
    if status is "Completed"
      $("#XXevent_start_time").hide()

  $('a[data-toggle="tab"]').on 'shown.bs.tab', (e) ->
    $.fn.dataTable.tables(
      visible: true
      api: true).columns.adjust()
    return

  $('#event_start_time').change ->
{'fraction_non_alphanumeric': 0.16318371797201525, 'fraction_numerical': 0.004179538433581683, 'mean_word_length': 2.8516445066480056, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 45, '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': '6631974', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1610, 'n_words': 368}