<commit_before>#= require jquery-fileupload

$.fn.ouvragesFileUpload = ->
  this.each ->
    $(this).find('.ofu-input').fileupload(
      autoUpload: true
      url: $(this).closest('.ofu-field').data('url')
      uploadTemplateId: null
      downloadTemplateId: null
      paramName: 'files[]'
      progressall: (e, data) ->
        progress = parseInt(data.loaded / data.total * 100, 10)
        $(this).closest('.ofu-field').find('.ofu-progress-bar').css('width', progress + "%").text(progress + "%")
    ).bind('fileuploadstart', (e, data) ->
      $(this).closest('.ofu-field').find('.ofu-files-container').empty()
      $(this).closest('.ofu-field').find('.ofu-files-container').append("<div class='progress'><div class='ofu-progress-bar bar' style='width: 0;'></div></div>")
      return
    ).bind('fileuploaddone', (e, data) ->
      $(this).closest('.ofu-field').find('input[type=hidden]').val(data.result.files[0].id)

      fileCount--
      return
    ).bind('fileuploadfail', (e, data) ->
      fileCount--
      return
    ).bind('fileuploadadd', (e, data) ->
      $(this).closest('.ofu-field').find('.ofu-files-container').empty()
      return
    )

fileCount = 0

$(document).ready ->
  $('.ofu-field[data-auto=true]').ouvragesFileUpload()

$(window).bind 'beforeunload', ->
  if fileCount > 0
    console.log("PREVENT")<commit_msg>Handles uploading in progress<commit_after>#= require jquery-fileupload

$.fn.ouvragesFileUpload = ->
  this.each ->
    $(this).find('.ofu-input').fileupload(
      autoUpload: true
      url: $(this).closest('.ofu-field').data('url')
      uploadTemplateId: null
      downloadTemplateId: null
      paramName: 'files[]'
      progressall: (e, data) ->
        progress = parseInt(data.loaded / data.total * 100, 10)
        $(this).closest('.ofu-field').find('.ofu-progress-bar').css('width', progress + "%").text(progress + "%")
    ).bind('fileuploadstart', (e, data) ->
      window.ofuFileCount++
      $(this).closest('.ofu-field').find('.ofu-files-container').empty()
      $(this).closest('.ofu-field').find('.ofu-files-container').append("<div class='progress'><div class='ofu-progress-bar bar' style='width: 0;'></div></div>")
      return
    ).bind('fileuploaddone', (e, data) ->
      $(this).closest('.ofu-field').find('input[type=hidden]').val(data.result.files[0].id)

      window.ofuFileCount--
      return
    ).bind('fileuploadfail', (e, data) ->
      window.ofuFileCount--
      return
    ).bind('fileuploadadd', (e, data) ->
      $(this).closest('.ofu-field').find('.ofu-files-container').empty()
      return
    )

window.ofuFileCount = 0

$(document).ready ->
  $('.ofu-field[data-auto=true]').ouvragesFileUpload()

$(window).bind 'beforeunload', ->
  if window.ofuFileCount > 0
    console.log("PREVENT")
{'fraction_non_alphanumeric': 0.21700143472022956, 'fraction_numerical': 0.006456241032998565, 'mean_word_length': 3.290769230769231, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2486572', 'n_tokens_mistral': 945, 'n_tokens_neox': 921, 'n_words': 131}