<commit_before>$ ->
  if isOnPage 'attachments', 'index'

    # selecting/deselecting an attachment
    $(".attachment-checkbox").on "click", ->
      updateAll()

    # initialize all
    updateAll()

    # bind uploader
    uploaderCallbacks =
      onComplete: (id, name, response) ->
        if response.success
          $.get response.redirect_url, (data) ->
            window.setTimeout ->
              $('.file-uploader').hide()
              mconf.Modal.closeWindows()
            , 1000
            window.setTimeout ->
              window.location.assign(response.redirect_url)
            , 1500

      onSubmit: (id, name) ->
        $('.upload-button').hide()

    $(document).on "modal-shown.attachments-uploader", ->
      mconf.Uploader.bind
        dragAndDrop: true
        callbacks: uploaderCallbacks

updateAll = ->
  updateDeleteLink()
  updateDownloadLink()
  updateSelectedLabel()

# Update the link and state of the "delete multiple" button depending on the files that
# are selected (if any).
updateDeleteLink = ->
  $button = $("#attachments-delete")
  attachments = getSelectedAttachments()
  if attachments.length > 0 and canDeleteSelected()
    baseUrl = $button.data("base-url")
    $button.attr "href", "#{baseUrl}?attachment_ids=#{attachments.join(",")}"
    $button.attr "data-method", "delete"
    $button.attr "disabled", null
    $button.removeClass "disabled"
  else
    $button.attr "href", "#"
    $button.attr "data-method", null
    $button.attr "disabled", "disabled"
    $button.addClass "disabled"

# Update the link and state of the "download multiple" button depending on the files that
# are selected (if any).
updateDownloadLink = ->
  $button = $("#attachments-download")
  attachments = getSelectedAttachments()<commit_msg>In attachments view, dont activate uploader if other modals are shown<commit_after>$ ->
  if isOnPage 'attachments', 'index'

    # selecting/deselecting an attachment
    $(".attachment-checkbox").on "click", ->
      updateAll()

    # initialize all
    updateAll()

    # bind uploader
    uploaderCallbacks =
      onComplete: (id, name, response) ->
        if response.success
          $.get response.redirect_url, (data) ->
            window.setTimeout ->
              $('.file-uploader').hide()
              mconf.Modal.closeWindows()
            , 1000
            window.setTimeout ->
              window.location.assign(response.redirect_url)
            , 1500

      onSubmit: (id, name) ->
        $('.upload-button').hide()

    $("#new-file").on "modal-shown", ->
      mconf.Uploader.bind
        dragAndDrop: true
        callbacks: uploaderCallbacks

updateAll = ->
  updateDeleteLink()
  updateDownloadLink()
  updateSelectedLabel()

# Update the link and state of the "delete multiple" button depending on the files that
# are selected (if any).
updateDeleteLink = ->
  $button = $("#attachments-delete")
  attachments = getSelectedAttachments()
  if attachments.length > 0 and canDeleteSelected()
    baseUrl = $button.data("base-url")
    $button.attr "href", "#{baseUrl}?attachment_ids=#{attachments.join(",")}"
    $button.attr "data-method", "delete"
    $button.attr "disabled", null
    $button.removeClass "disabled"
  else
    $button.attr "href", "#"
    $button.attr "data-method", null
    $button.attr "disabled", "disabled"
    $button.addClass "disabled"

# Update the link and state of the "download multiple" button depending on the files that
# are selected (if any).
updateDownloadLink = ->
  $button = $("#attachments-download")
  attachments = getSelectedAttachments()
{'fraction_non_alphanumeric': 0.13216471897607124, 'fraction_numerical': 0.005008347245409015, 'mean_word_length': 2.8822894168466524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '975679', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1006, 'n_words': 259}