<commit_before>load = ->
  parent = $ "#ban-control-super"
  return unless parent.length > 0

  parent.find('#_ban').on "change", (event) ->
    $t = $ this
    if $t.is(":checked")
      $("#ban-controls").show()
    else
      $("#ban-controls").hide()
  parent.find('#_permaban').on "change", (event) ->
    $t = $ this
    if $t.is(":checked")
      $("#ban-controls-time").hide()
    else
      $("#ban-controls-time").show()

  parent.find("#until").datetimepicker
    defaultDate: parent.find("#until").val()
    sideBySide: true
    icons:
      time: "fa fa-clock-o"
      date: "fa fa-calendar"
      up: "fa fa-chevron-up"
      down: "fa fa-chevron-down"
      previous: "fa fa-chevron-left"
      next: "fa fa-chevron-right"
      today: "fa fa-home"
      clear: "fa fa-trash-o"
      close: "fa fa-times"

  parent.parent()[0].addEventListener "submit", (event) ->
    event.preventDefault();

    $("#modal-ban").modal "hide"

    checktostr = (selector) ->
      if $(selector)[0].checked
        "1"
      else
        "0"

    data = {
      ban: checktostr "#_ban"
      permaban: checktostr "#_permaban"
      until: $("#until")[0].value.trim()
      reason: $("#reason")[0].value.trim()
      user: $("#_user")[0].value
    }

    $.ajax
      url: '/ajax/mod/ban'
      type: 'POST'
      data: data
      success: (data, status, jqxhr) ->
        showNotification data.message, data.success
      error: (jqxhr, status, error) ->
        console.log jqxhr, status, error
        showNotification translate('frontend.error.message'), false
      complete: (jqxhr, status) ->

$(document).on "DOMContentLoaded", ->
  load()

$(document).on "page:load", ->
  load()<commit_msg>Fix exception being thrown upon attempting to ban a user (#82)<commit_after>load = ->
  return unless document.getElementById('ban-control-super') != null
  modalEl = $("#modal-ban")
  modalEl.modal "hide"
  modalForm = modalEl.find("form")[0]
  banCheckbox = modalForm.querySelector('[name="ban"][type="checkbox"]')
  permabanCheckbox = modalForm.querySelector('[name="permaban"][type="checkbox"]')

  banCheckbox.addEventListener "change", (event) ->
    $t = $ this
    if $t.is(":checked")
      $("#ban-controls").show()
    else
      $("#ban-controls").hide()
  permabanCheckbox.addEventListener "change", (event) ->
    $t = $ this
    if $t.is(":checked")
      $("#ban-controls-time").hide()
    else
      $("#ban-controls-time").show()

  untilInput = $ modalForm.elements["until"]
  untilInput.datetimepicker
    defaultDate: untilInput.val()
    sideBySide: true
    icons:
      time: "fa fa-clock-o"
      date: "fa fa-calendar"
      up: "fa fa-chevron-up"
      down: "fa fa-chevron-down"
      previous: "fa fa-chevron-left"
      next: "fa fa-chevron-right"
      today: "fa fa-home"
      clear: "fa fa-trash-o"
      close: "fa fa-times"

  modalForm.addEventListener "submit", (event) ->
    event.preventDefault();

    checktostr = (el) ->
      if el.checked
        "1"
      else
        "0"

    data = {
      ban: checktostr banCheckbox
      permaban: checktostr permabanCheckbox
      until: modalForm.elements["until"].value.trim()
      reason: modalForm.elements["reason"].value.trim()
      user: modalForm.elements["user"].value
    }

    $.ajax
      url: '/ajax/mod/ban'
      type: 'POST'
      data: data
      success: (data, status, jqxhr) ->
        showNotification data.message, data.success
      error: (jqxhr, status, error) ->
        console.log jqxhr, status, error
        showNotification translate('frontend.error.message'), false
      complete: (jqxhr, status) ->

$(document).on "DOMContentLoaded", ->
  load()

$(document).on "page:load", ->
  load()
{'fraction_non_alphanumeric': 0.17471016446481533, 'fraction_numerical': 0.00350498786734969, 'mean_word_length': 2.6587771203155817, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 24, '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': '3738338', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1219, 'n_words': 257}