<commit_before>/* global Fae, fae_chosen, fileinputer, FCH, Cookies */

/**
 * Fae Filtering, Sorting and Paging
 * @namespace form.filtering
 * @memberof form
 */
Fae.form.filtering = {

  init: function() {
    this.$filter_form = $('.js-filter-form');
    this.$pagination = $('.pagination');
    this.has_hash_on_load_and_cookie = false;

    // init only on pages with filering, sorting or paging
    if (this.$filter_form.length || this.$pagination.length || $('.js-sort-column').length) {
      this.applyCookies();
      var window_hash = window.location.hash;
      var has_hash_on_load = window_hash.length > 2;
      this.fry = new Fryr(this._refreshTable, {}, has_hash_on_load);

      // this.fry.params needs to be set to the "deep link" passed params
      if(has_hash_on_load) {
        this.fry.parse(window_hash);
      }

      this.setFilterDropDowns();
      this.setTextInputs();
      this.filterFormListeners();
      this.paginationListeners();
      this.sortingSetup();
    }
  },

  /**
   * Fryr callback, POSTs to Fae's endpoint and updates the view
   */
  _refreshTable: function() {
    // hardcode _this because this === Fryr object
    var _this = Fae.form.filtering;

    if (_this.$filter_form.length) {
      post_url = _this.$filter_form.attr('action');
      $current_table = _this.$filter_form.next('table');
    } else {
      post_url = _this.$pagination.data('filter-path');
      $current_table = _this.$pagination.prevAll(":visible:first");
    }

    var $results_table = ($(".js-results-table").length) ? $(".js-results-table").first() : $current_table;

    $results_table.addClass('loading-fade');

    $.post(post_url, this.params, function(data){
      var $data = $(data);
      var $table_from_data = $data.find('table').first();

      // replace table
      $results_table.replaceWith($table_from_data);

      // replace sticky header
      $('.sticky-table-header thead').html($table_from_data.find('thead').html());
      // replace pagination
      _this.$pagination.html($data.find('.pagination').first().html());

      // reinit a few things on the fresh table
      Fae.tables.columnSorting();
      Fae.tables.rowSorting();
      Fae.navigation.lockFooter();

      _this.sortingSetup();

      // dont set the cookie if it's a "deep link" and they have an existing cookie - leave that intact with their old saved filter
      if (!_this.has_hash_on_load_and_cookie) {
        _this.setCookie();
      }
    });
  },


  /**
   * Adds listeners to the filter forms
   */
  filterFormListeners: function() {
    var _this = this;

    this.$filter_form
      // update search param when form submits
      .on('submit', function(ev) {
        $('.js-reset-btn').show();
        _this.updateFryrAndResetPaging('search', $('#filter_search').val());
        return false;
      })

      // update search param when search btn is clicked
      .on('click', '.table-filter-keyword-wrapper i', function() {
        _this.updateFryrAndResetPaging('search', $('#filter_search').val());
      })

      // reset filter button
      .on('click', '.js-reset-btn', function(ev) {
        var $this = $(this);
        ev.preventDefault();

        // reset params and form selects
        _this.fry.merge({ page: '' }, true);
        $('#filter_search').val('');
        $this.closest('form').find('select').val('').trigger('chosen:updated');
        $this.hide();
      })

      // update hash when filter dropdowns changed
      .on('change', 'select', function() {
        // get key and value from select
        var key = $(this).attr('id').split('filter_')[1];
        var value = $(this).val();
<commit_msg>77451 unhide the reset btn on search submit too<commit_after>/* global Fae, fae_chosen, fileinputer, FCH, Cookies */

/**
 * Fae Filtering, Sorting and Paging
 * @namespace form.filtering
 * @memberof form
 */
Fae.form.filtering = {

  init: function() {
    this.$filter_form = $('.js-filter-form');
    this.$pagination = $('.pagination');
    this.has_hash_on_load_and_cookie = false;

    // init only on pages with filering, sorting or paging
    if (this.$filter_form.length || this.$pagination.length || $('.js-sort-column').length) {
      this.applyCookies();
      var window_hash = window.location.hash;
      var has_hash_on_load = window_hash.length > 2;
      this.fry = new Fryr(this._refreshTable, {}, has_hash_on_load);

      // this.fry.params needs to be set to the "deep link" passed params
      if(has_hash_on_load) {
        this.fry.parse(window_hash);
      }

      this.setFilterDropDowns();
      this.setTextInputs();
      this.filterFormListeners();
      this.paginationListeners();
      this.sortingSetup();
    }
  },

  /**
   * Fryr callback, POSTs to Fae's endpoint and updates the view
   */
  _refreshTable: function() {
    // hardcode _this because this === Fryr object
    var _this = Fae.form.filtering;

    if (_this.$filter_form.length) {
      post_url = _this.$filter_form.attr('action');
      $current_table = _this.$filter_form.next('table');
    } else {
      post_url = _this.$pagination.data('filter-path');
      $current_table = _this.$pagination.prevAll(":visible:first");
    }

    var $results_table = ($(".js-results-table").length) ? $(".js-results-table").first() : $current_table;

    $results_table.addClass('loading-fade');

    $.post(post_url, this.params, function(data){
      var $data = $(data);
      var $table_from_data = $data.find('table').first();

      // replace table
      $results_table.replaceWith($table_from_data);

      // replace sticky header
      $('.sticky-table-header thead').html($table_from_data.find('thead').html());
      // replace pagination
      _this.$pagination.html($data.find('.pagination').first().html());

      // reinit a few things on the fresh table
      Fae.tables.columnSorting();
      Fae.tables.rowSorting();
      Fae.navigation.lockFooter();

      _this.sortingSetup();

      // dont set the cookie if it's a "deep link" and they have an existing cookie - leave that intact with their old saved filter
      if (!_this.has_hash_on_load_and_cookie) {
        _this.setCookie();
      }
    });
  },


  /**
   * Adds listeners to the filter forms
   */
  filterFormListeners: function() {
    var _this = this;

    this.$filter_form
      // update search param when form submits
      .on('submit', function(ev) {
        $('.js-reset-btn').show();
        $('.js-reset-btn').removeClass('hidden');
        _this.updateFryrAndResetPaging('search', $('#filter_search').val());
        return false;
      })

      // update search param when search btn is clicked
      .on('click', '.table-filter-keyword-wrapper i', function() {
        _this.updateFryrAndResetPaging('search', $('#filter_search').val());
      })

      // reset filter button
      .on('click', '.js-reset-btn', function(ev) {
        var $this = $(this);
        ev.preventDefault();

        // reset params and form selects
        _this.fry.merge({ page: '' }, true);
        $('#filter_search').val('');
        $this.closest('form').find('select').val('').trigger('chosen:updated');
        $this.hide();
      })

      // update hash when filter dropdowns changed
      .on('change', 'select', function() {
        // get key and value from select
        var key = $(this).attr('id').split('filter_')[1];
        var value = $(this).val();

{'fraction_non_alphanumeric': 0.15826368293340523, 'fraction_numerical': 0.0012132650310056618, 'mean_word_length': 2.739415322580645, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '7382225', 'n_tokens_mistral': 2324, 'n_tokens_neox': 2255, 'n_words': 499}