<commit_before>get_thumb_index = (target) ->
  target.parents '.thumb-index'

select_all = (event) ->
  target = $(event.target)
  thumb_index = get_thumb_index(target)
  thumb_index.find('input:checkbox.selector:not(:checked)').prop('checked', true).trigger('change')

select_none = (event) ->
  target = $(event.target)
  thumb_index = get_thumb_index(target)
  thumb_index.find('input:checkbox.selector:checked').prop('checked', false).trigger('change')

selected_count = (parent) ->
  parent.find('input:checkbox.selector:checked').length

close_button = ->
  $('<button />').addClass('close').attr('data-dismiss', 'alert').append('&times;')

add_alert = (container, message) ->
  container.prepend($('<div />').addClass('alert alert-error').append(
    close_button).append(message))

add_to_set = (event) ->
  set_name = $('#add-to-set-name').val()

  unless set_name is ''
    target = $(event.target)
    thumb_index = get_thumb_index(target)
    ids = thumb_index.find('input:checkbox.selector:checked').map(-> this.getAttribute('data-id')).get()

    $.ajax "/src_sets/#{set_name}",
      type: 'put'
      contentType: 'application/json'
      dataType: 'json'
      data: JSON.stringify(add_src_images: ids)
      success: ->
        $(window).attr('location', "/src_sets/#{set_name}")
      error: (xhr, text_status)->
        if xhr.status == 403
          message = "You do not own the set #{set_name}"
        else
          message = text_status

        add_alert(thumb_index, message)

window.thumb_selector_init = ->
  $('input:checkbox.selector').change (event) ->
    target = $(event.target)
    div = target.parents 'div.thumbnail'
    div.toggleClass 'selected', target.is(':checked')

    thumb_index = get_thumb_index(target)
    selected_ct = selected_count thumb_index

    if selected_ct > 0
      thumb_index.find('.enable-some-selected').removeClass('disabled')
    else
      thumb_index.find('.disable-none-selected').addClass('disabled')

    thumb_index.find('.selected-count').text selected_ct

  $('div.thumbnail').click (event) ->
    checkbox = $(event.target).find('input:checkbox.selector').first()
    checkbox.prop('checked', !checkbox.is(':checked')).trigger('change')

  $('.select-all').click select_all

  $('.select-none').click select_none

  $('.add-to-set').click add_to_set

$(document).ready ->
  thumb_selector_init()<commit_msg>Make enter in add to set form submit.<commit_after>get_thumb_index = (target) ->
  target.parents '.thumb-index'

select_all = (event) ->
  target = $(event.target)
  thumb_index = get_thumb_index(target)
  thumb_index.find('input:checkbox.selector:not(:checked)').prop('checked', true).trigger('change')

select_none = (event) ->
  target = $(event.target)
  thumb_index = get_thumb_index(target)
  thumb_index.find('input:checkbox.selector:checked').prop('checked', false).trigger('change')

selected_count = (parent) ->
  parent.find('input:checkbox.selector:checked').length

close_button = ->
  $('<button />').addClass('close').attr('data-dismiss', 'alert').append('&times;')

add_alert = (container, message) ->
  container.prepend($('<div />').addClass('alert alert-error').append(
    close_button).append(message))

add_to_set = (event) ->
  set_name = $('#add-to-set-name').val()

  unless set_name is ''
    target = $(event.target)
    thumb_index = get_thumb_index(target)
    ids = thumb_index.find('input:checkbox.selector:checked').map(-> this.getAttribute('data-id')).get()

    $.ajax "/src_sets/#{set_name}",
      type: 'put'
      contentType: 'application/json'
      dataType: 'json'
      data: JSON.stringify(add_src_images: ids)
      success: ->
        $(window).attr('location', "/src_sets/#{set_name}")
      error: (xhr, text_status)->
        if xhr.status == 403
          message = "You do not own the set #{set_name}"
        else
          message = text_status

        add_alert(thumb_index, message)

window.thumb_selector_init = ->
  $('input:checkbox.selector').change (event) ->
    target = $(event.target)
    div = target.parents 'div.thumbnail'
    div.toggleClass 'selected', target.is(':checked')

    thumb_index = get_thumb_index(target)
    selected_ct = selected_count thumb_index

    if selected_ct > 0
      thumb_index.find('.enable-some-selected').removeClass('disabled')
    else
      thumb_index.find('.disable-none-selected').addClass('disabled')

    thumb_index.find('.selected-count').text selected_ct

  $('div.thumbnail').click (event) ->
    checkbox = $(event.target).find('input:checkbox.selector').first()
    checkbox.prop('checked', !checkbox.is(':checked')).trigger('change')

  $('.select-all').click select_all

  $('.select-none').click select_none

  $('.add-to-set').click add_to_set

  $('#add-to-set-name').keypress (event) ->
    add_to_set(event) if event.keyCode == 13

$(document).ready ->
  thumb_selector_init()
{'fraction_non_alphanumeric': 0.17656698074559607, 'fraction_numerical': 0.0020483408439164277, 'mean_word_length': 4.003073770491803, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 38, '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': '6431455', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1530, 'n_words': 250}