<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 ->
  table = $('#translations')
  searchForm = $('#filter-form')

  $("input[name='commit[exported]']").change ->
    checkbox = $(this)
    form = checkbox.closest('form')
    authParam = $('meta[name=csrf-param]').attr('content')
    authToken = $('meta[name=csrf-token]').attr('content')
    data = form.serializeObject()
    data['commit[exported]'] = checkbox.prop("checked")
    data[authParam] = authToken

    $.ajax form.attr('action'),
      data: data,
      type: 'PATCH',
      success: ->
        new Flash('success').text("Commit export status has been updated")
      error: ->
        new Flash('alert').text("Couldn't update commit export status")

  prefillForm = () ->
    for own param, val of $.url().param()
      searchForm.find("[name=#{param}]").val(val.trim())

  prefillForm()

  makeURL = -> "#{table.data('url')}?#{searchForm.serialize()}"
  localeOrder = table.data('locales').split(',')

  addKey = (key) ->
    tr = $('<tr/>').appendTo(table)
    td = $('<td/>').text(key.original_key).appendTo(tr)
    $('<br/>').appendTo td
    $('<small/>').addClass('muted').text(key.source).appendTo td

    for locale in localeOrder
      do (locale) ->
        translation = (t for t in key.translations when t.locale.rfc5646 == locale)[0]

        if translation?
          klass = if translation.approved
            'text-success'
          else if translation.approved == false
            'text-error'
          else if translation.translated
            'text-info'
          else
            'muted'

          copy = if translation.translated == false
            "(not yet translated)"
          else if /\A\s*\z/.test(translation.copy)
            "(blank string)"
          else
            translation.copy[0..30]

          td = $('<td/>').appendTo(tr)
          $('<a/>').attr('href', translation.url).addClass(klass).
          text(copy).appendTo(td)
        else
          $('<td/>').appendTo tr

  scroll = table.infiniteScroll makeURL,
    windowScroll: true
    renderer: (keys) =>
      for key in keys
        do (key) -> addKey(key)

  searchForm.submit ->
    table.find('tbody').empty()
    scroll.reset()
    # ONLY HTML5
    window.history.pushState("params", "", "?#{searchForm.serialize()}")
    scroll.loadNextPage()
    false

  window.onpopstate =  (e) ->
    prefillForm()
    table.find('tbody').empty()
    scroll.reset()
    scroll.loadNextPage()
    false<commit_msg>Fixes small search history bug where it wouldn't work when backing to empty forms<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 ->
  table = $('#translations')
  searchForm = $('#filter-form')

  $("input[name='commit[exported]']").change ->
    checkbox = $(this)
    form = checkbox.closest('form')
    authParam = $('meta[name=csrf-param]').attr('content')
    authToken = $('meta[name=csrf-token]').attr('content')
    data = form.serializeObject()
    data['commit[exported]'] = checkbox.prop("checked")
    data[authParam] = authToken

    $.ajax form.attr('action'),
      data: data,
      type: 'PATCH',
      success: ->
        new Flash('success').text("Commit export status has been updated")
      error: ->
        new Flash('alert').text("Couldn't update commit export status")

  prefillForm = () ->
    if $.isEmptyObject($.url().param())
      searchForm.trigger('reset')
    else
      for own param, val of $.url().param()
        searchForm.find("[name=#{param}]").val(val.trim())

  prefillForm()

  makeURL = -> "#{table.data('url')}?#{searchForm.serialize()}"
  localeOrder = table.data('locales').split(',')

  addKey = (key) ->
    tr = $('<tr/>').appendTo(table)
    td = $('<td/>').text(key.original_key).appendTo(tr)
    $('<br/>').appendTo td
    $('<small/>').addClass('muted').text(key.source).appendTo td

    for locale in localeOrder
      do (locale) ->
        translation = (t for t in key.translations when t.locale.rfc5646 == locale)[0]

        if translation?
          klass = if translation.approved
            'text-success'
          else if translation.approved == false
            'text-error'
          else if translation.translated
            'text-info'
          else
            'muted'

          copy = if translation.translated == false
            "(not yet translated)"
          else if /\A\s*\z/.test(translation.copy)
            "(blank string)"
          else
            translation.copy[0..30]

          td = $('<td/>').appendTo(tr)
          $('<a/>').attr('href', translation.url).addClass(klass).
          text(copy).appendTo(td)
        else
          $('<td/>').appendTo tr

  scroll = table.infiniteScroll makeURL,
    windowScroll: true
    renderer: (keys) =>
      for key in keys
        do (key) -> addKey(key)

  searchForm.submit ->
    table.find('tbody').empty()
    scroll.reset()
    # ONLY HTML5
    window.history.pushState("params", "", "?#{searchForm.serialize()}")
    scroll.loadNextPage()
    false

  window.addEventListener 'load', ->
    setTimeout ->
      window.onpopstate =  (e) ->
        prefillForm()
        table.find('tbody').empty()
        scroll.reset()
        scroll.loadNextPage()
    , 0

{'fraction_non_alphanumeric': 0.15430640843961582, 'fraction_numerical': 0.005510943158557708, 'mean_word_length': 2.59682899207248, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 43, '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': '3375315', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1831, 'n_words': 481}