<commit_before># Copyright 2014 Square Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

$(window).ready () ->
  expand_filter_bar = () ->
    if $(".collapse").data("toggle")
      $("#expand-search").removeClass("active")
      $(".collapse").data("toggle", false)
      $(".collapse").slideUp()
    else
      $("#expand-search").addClass("active")
      $(".collapse").data("toggle", true)
      $(".collapse").slideDown()

  $("#expand-search").click expand_filter_bar
  $("#expand-filters").click () ->
    $(window).scrollTop(0)
    expand_filter_bar()


  toggle = (row) ->
    entry = row.find('.description')
    full_description = entry.data('full-description')
    short_description = entry.data('short-description')

    if not entry.data("orig-height")
      orig_height = entry.prop('scrollHeight')
      entry.data("orig-height", orig_height)

    if full_description
      if row.hasClass("expanded")
        orig_height = entry.data("orig-height")
        entry.animate({height: orig_height}, 500, () ->
          entry.text(short_description)
          row.removeClass("expanded")
        )
        row.removeClass("expanded")
      else
        $(".expanded").each () ->
          toggle($(this))

        orig_height = entry.data("orig-height")
        orig_width = entry.width()

        entry.height(orig_height)
        entry.width(orig_width)

        entry.html(full_description)
        entry.animate({height: entry.prop('scrollHeight')}, 500, () ->
          entry.html(full_description)
          row.addClass("expanded")
        )
        row.addClass("expanded")

  $("table").find("input, select, button, a").click (e) ->
    e.stopPropagation()

  $(".datepicker").datepicker(
    autoclose: true
    startDate: new Date()
  ) 

  $('.translate-link').click () ->
    if ($(this).hasClass('disabled')) 
      return false

    sha = $(this).data('sha')
    project = $(this).data('project')
    locale = $(this).data('locale')
    
    if Locale.from_rfc5646( $("[name=locales]").val() ) != null
      locale = $("[name=locales]").val()

    url = '/locales/' + encodeURIComponent(locale) + '/projects/' + encodeURIComponent(project) + '?commit=' + sha
    window.location = url

    return false

  $('.translate-link-locale').keydown () ->
    if (($(this).val()).length > 0) 
      $($(this).data('target')).removeClass('disabled')
    else 
      $($(this).data('target')).addClass('disabled')
    return true

  new SmartForm $('#new_commit'), (notification) -> 
    $("#add-translation").closeModal()
    if notification.success 
      new Flash('success').text(notification.success);
    else if notification.alert
      new Flash('alert').text(notification.alert);


  $('#new_commit_project_id').change () ->
    project = $(this).val()
    $('#new_commit').attr('action', '/projects/' + project + '/commits.json')

  $('.edit_commit select, .edit_commit input[type="text"]').change () ->
    select = $(this)
    form = select.closest('form')
    authParam = $('meta[name=csrf-param]').attr('content')
    authToken = $('meta[name=csrf-token]').attr('content')
    data = form.serializeObject()
    data[authParam] = authToken

    $.ajax(form.attr('action'), 
      data: data,
      type: 'PATCH',
      success: () ->
        select.css('backgroundColor', '#dfd')
              .delay(200)
              .animate({backgroundColor: "white"}, 300)
      ,
      error: () ->
        new Flash('alert').text("Couldn't change commit priority.")
    )

  $('tbody tr').click () ->
    toggle($(this))

  filter_form = $('#filter')
  email_filter = filter_form.find('input[name=email]')
  exported_filter = filter_form.find('input[name=exported]')
  autoimport_filter = filter_form.find('input[name=show_autoimport]')
  status_filter = filter_form.find('select[name=status]')
  project_filter = filter_form.find('select[name=project_id]')

  if $.cookie('home_email_filter') and not $.url().param('email')?
    email_filter.prop 'checked', $.cookie('home_email_filter') != 'false'
  if $.cookie('home_exported_filter') and not $.url().param('exported')?
    exported_filter.prop 'checked', $.cookie('home_exported_filter') != 'false'
  if $.cookie('home_autoimport_filter') and not $.url().param('show_autoimport')?
    autoimport_filter.prop 'checked', $.cookie('home_autoimport_filter') != 'false'
  if $.cookie('home_status_filter') and not $.url().param('status')?
    status_filter.val($.cookie('home_status_filter'))
  if $.cookie('home_project_filter') and not $.url().param('project_id')?
    project_filter.val($.cookie('home_project_filter'))


  filter_form.submit ->
    if email_filter.is(':checked')
      $.cookie 'home_email_filter', email_filter.val(), expires: 7
    else
      $.cookie 'home_email_filter', email_filter.is(':checked'), expires: 7

    $.cookie 'home_exported_filter', exported_filter.is(':checked'), expires: 7
    $.cookie 'home_autoimport_filter', autoimport_filter.is(':checked'), expires: 7
    $.cookie 'home_status_filter', status_filter.val(), expires: 7
    $.cookie 'home_project_filter', project_filter.val(), expires: 7
<commit_msg>Adds cookies to request translation form<commit_after># Copyright 2014 Square Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

$(window).ready () ->
  expand_filter_bar = () ->
    if $(".collapse").data("toggle")
      $("#expand-search").removeClass("active")
      $(".collapse").data("toggle", false)
      $(".collapse").slideUp()
    else
      $("#expand-search").addClass("active")
      $(".collapse").data("toggle", true)
      $(".collapse").slideDown()

  $("#expand-search").click expand_filter_bar
  $("#expand-filters").click () ->
    $(window).scrollTop(0)
    expand_filter_bar()


  toggle = (row) ->
    entry = row.find('.description')
    full_description = entry.data('full-description')
    short_description = entry.data('short-description')

    if not entry.data("orig-height")
      orig_height = entry.prop('scrollHeight')
      entry.data("orig-height", orig_height)

    if full_description
      if row.hasClass("expanded")
        orig_height = entry.data("orig-height")
        entry.animate({height: orig_height}, 500, () ->
          entry.text(short_description)
          row.removeClass("expanded")
        )
        row.removeClass("expanded")
      else
        $(".expanded").each () ->
          toggle($(this))

        orig_height = entry.data("orig-height")
        orig_width = entry.width()

        entry.height(orig_height)
        entry.width(orig_width)

        entry.html(full_description)
        entry.animate({height: entry.prop('scrollHeight')}, 500, () ->
          entry.html(full_description)
          row.addClass("expanded")
        )
        row.addClass("expanded")

  $("table").find("input, select, button, a").click (e) ->
    e.stopPropagation()

  $(".datepicker").datepicker(
    autoclose: true
    startDate: new Date()
  ) 

  $('.translate-link').click () ->
    if ($(this).hasClass('disabled')) 
      return false

    sha = $(this).data('sha')
    project = $(this).data('project')
    locale = $(this).data('locale')
    
    if Locale.from_rfc5646( $("[name=locales]").val() ) != null
      locale = $("[name=locales]").val()

    url = '/locales/' + encodeURIComponent(locale) + '/projects/' + encodeURIComponent(project) + '?commit=' + sha
    window.location = url

    return false

  $('.translate-link-locale').keydown () ->
    if (($(this).val()).length > 0) 
      $($(this).data('target')).removeClass('disabled')
    else 
      $($(this).data('target')).addClass('disabled')
    return true

  new SmartForm $('#new_commit'), (notification) -> 
    $("#add-translation").closeModal()
    if notification.success 
      new Flash('success').text(notification.success);
    else if notification.alert
      new Flash('alert').text(notification.alert);


  $('#new_commit_project_id').change () ->
    project = $(this).val()
    $('#new_commit').attr('action', '/projects/' + project + '/commits.json')
    $.cookie 'home_new_commit_project', project, expires: 7

  $('.edit_commit select, .edit_commit input[type="text"]').change () ->
    select = $(this)
    form = select.closest('form')
    authParam = $('meta[name=csrf-param]').attr('content')
    authToken = $('meta[name=csrf-token]').attr('content')
    data = form.serializeObject()
    data[authParam] = authToken

    $.ajax(form.attr('action'), 
      data: data,
      type: 'PATCH',
      success: () ->
        select.css('backgroundColor', '#dfd')
              .delay(200)
              .animate({backgroundColor: "white"}, 300)
      ,
      error: () ->
        new Flash('alert').text("Couldn't change commit priority.")
    )

  $('tbody tr').click () ->
    toggle($(this))

  filter_form = $('#filter')

  email_filter = filter_form.find('input[name=email]')
  exported_filter = filter_form.find('input[name=exported]')
  autoimport_filter = filter_form.find('input[name=show_autoimport]')
  status_filter = filter_form.find('select[name=status]')
  project_filter = filter_form.find('select[name=project_id]')

  if $.cookie('home_email_filter') and not $.url().param('email')?
    email_filter.prop 'checked', $.cookie('home_email_filter') != 'false'
  if $.cookie('home_exported_filter') and not $.url().param('exported')?
    exported_filter.prop 'checked', $.cookie('home_exported_filter') != 'false'
  if $.cookie('home_autoimport_filter') and not $.url().param('show_autoimport')?
    autoimport_filter.prop 'checked', $.cookie('home_autoimport_filter') != 'false'
  if $.cookie('home_status_filter') and not $.url().param('status')?
    status_filter.val($.cookie('home_status_filter'))
  if $.cookie('home_project_filter') and not $.url().param('project_id')?
    project_filter.val($.cookie('home_project_filter'))
  if $.cookie('home_new_commit_project')
    $('#new_commit_project_id').val($.cookie('home_new_commit_project'))


  filter_form.submit ->
    if email_filter.is(':checked')
      $.cookie 'home_email_filter', email_filter.val(), expires: 7
    else
      $.cookie 'home_email_filter', email_filter.is(':checked'), expires: 7

    $.cookie 'home_exported_filter', exported_filter.is(':checked'), expires: 7
    $.cookie 'home_autoimport_filter', autoimport_filter.is(':checked'), expires: 7
    $.cookie 'home_status_filter', status_filter.val(), expires: 7
    $.cookie 'home_project_filter', project_filter.val(), expires: 7

{'fraction_non_alphanumeric': 0.17446512436945555, 'fraction_numerical': 0.005653157070794921, 'mean_word_length': 3.5147232037691403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6324930', 'n_tokens_mistral': 3524, 'n_tokens_neox': 3417, 'n_words': 685}