<commit_before>class Tenon.features.ItemVersionAutosave
  constructor: ->
    @$form = $('form[data-autosave="true"]')
    @$form.on('keyup change cocoon:after-insert cocoon:after-remove', $.debounce(6000, @autosave))

  autosave: =>
    console.log('saved')
    jqxhr = $.ajax
      url: @$form.data('version-create-path')
      data: @_formData()
      method: 'POST'
    jqxhr.done(@_updateAutosave)

  _updateAutosave: (data) =>
    $('.last-autosave')
      .text("Last draft autosave on #{data.created_at}")
      .fadeIn()

  _formData:  =>
    itemFormData = URI("?" + @$form.serialize()).query(true)

    # Serialize the checkbox in a way that rails can get down with
    @$form.find("input:checkbox").each ->
      if !(@.checked)
        itemFormData[@.name] = "0"
      else
        itemFormData[@.name] = "1"

    versionData =
      item_version:
        item_type: @$form.data('item-type')
        item_id: @$form.data('item-id')
        save_type: 'autosave'
        title: 'Auto-Save'
    delete(itemFormData._method)
    $.extend(itemFormData, versionData)<commit_msg>Drop console.log from autosave<commit_after>class Tenon.features.ItemVersionAutosave
  constructor: ->
    @$form = $('form[data-autosave="true"]')
    @$form.on('keyup change cocoon:after-insert cocoon:after-remove', $.debounce(6000, @autosave))

  autosave: =>
    jqxhr = $.ajax
      url: @$form.data('version-create-path')
      data: @_formData()
      method: 'POST'
    jqxhr.done(@_updateAutosave)

  _updateAutosave: (data) =>
    $('.last-autosave')
      .text("Last draft autosave on #{data.created_at}")
      .fadeIn()

  _formData:  =>
    itemFormData = URI("?" + @$form.serialize()).query(true)

    # Serialize the checkbox in a way that rails can get down with
    @$form.find("input:checkbox").each ->
      if !(@.checked)
        itemFormData[@.name] = "0"
      else
        itemFormData[@.name] = "1"

    versionData =
      item_version:
        item_type: @$form.data('item-type')
        item_id: @$form.data('item-id')
        save_type: 'autosave'
        title: 'Auto-Save'
    delete(itemFormData._method)
    $.extend(itemFormData, versionData)
{'fraction_non_alphanumeric': 0.1645101663585952, 'fraction_numerical': 0.005545286506469501, 'mean_word_length': 2.987108655616943, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6346918', 'n_tokens_mistral': 774, 'n_tokens_neox': 744, 'n_words': 137}