<commit_before>// handles the article selection and saving on add-articles.html
jQuery(function(d, $){
  (function(){

    var $list_count = $('.list-count');
    var initial_list_count = parseInt($list_count.text(), 10);
    var preview_list_count = initial_list_count;
    var $preview_list_count_elem = $('.preview-list-count');
    var results_span_pages = ($('.pagination-number').length > 1);
    var select_all_error_msg_visible = false;

    return {
      init : function() {
        // update the header and the sidebar with the current list count
        this.updateListCount(initial_list_count);
        if (initial_list_count == 0) {
          this.disableButton($('#preview-list-submit'));
        }

        // set up event handlers
        $('.check-save-article').on("click", jQuery.proxy(this.checkboxClickHandler, this));
        $('.select-all-articles-link').on("click", { 'mode' : "SAVE" }, jQuery.proxy(this.toggleAllArticles, this));
        $('.unselect-all-articles-link').on("click", { 'mode' : "REMOVE" }, jQuery.proxy(this.toggleAllArticles, this));
        $('.reset-btn').on("click", { 'mode' : "REMOVE" }, jQuery.proxy(this.toggleAllArticles, this));
        
        // We want the preview list count to be accurate even if the user navigates
        // with the back button.  So we always load the current preview list count
        // via ajax.
        $.ajax("/get-article-count", {
          type: "GET",
          cache: false,
          success: jQuery.proxy(function(resp) {
            this.updateListCount(resp);
          }, this)
        });
      },

      // Replaces the preview list counts in the UI with the new value.
      updateListCount : function(new_count) {
        preview_list_count = new_count;
        
        // update "your list" box in header
        $list_count.text(new_count);

        // update preview list button
        $preview_list_count_elem.val("Preview List (" + new_count + ")");

        // add the correct options depending on the user action 
        // remove all children
        $('#your-list-choices').children().remove();
        // add the correct options
        if (new_count == 0) {
          $('#your-list-choices').append('<span>View Report</span><span>Edit List</span>');
        } else {
          $('#your-list-choices').append('<a href="/reports/generate">View Report</a><a href="/preview-list">Edit List</a>')
        }
      },
      
      // Increments the preview list counts in the UI by the specified delta, which
      // can be positive or negative.
      incrementListCount : function(delta) {
        this.updateListCount(preview_list_count + delta);
      },

      checkboxClickHandler : function(e) {
        var $checkbox = $(e.target);

        // If we are over the limit, and it's a check event, don't do anything
        // (and uncheck the checkbox).
        if ($checkbox.prop("checked")) {
          if (preview_list_count >= VIZ_LIMIT && preview_list_count < ARTICLE_LIMIT) {
            this.showErrorDialog("viz-limit-error-message");
          } else if (preview_list_count >= ARTICLE_LIMIT) {
            $checkbox.prop("checked", false);
            this.showErrorDialog("article-limit-error-message");
            return;
          }
        }

        // create some data that we want to send to the server
        var ajax_data = {
          // grab the article ID from the checkbox value
          article_ids : [$checkbox.val()],

          // set the "mode" based on what state the checkbox is transitioning to<commit_msg>ALM-376 added logic to make sure the next action button is in the correct state<commit_after>// handles the article selection and saving on add-articles.html
jQuery(function(d, $){
  (function(){

    var $list_count = $('.list-count');
    var initial_list_count = parseInt($list_count.text(), 10);
    var preview_list_count = initial_list_count;
    var $preview_list_count_elem = $('.preview-list-count');
    var results_span_pages = ($('.pagination-number').length > 1);
    var select_all_error_msg_visible = false;

    return {
      init : function() {
        // update the header and the sidebar with the current list count
        this.updateListCount(initial_list_count);
        if (initial_list_count == 0) {
          this.disableButton($('#preview-list-submit'));
        }

        // set up event handlers
        $('.check-save-article').on("click", jQuery.proxy(this.checkboxClickHandler, this));
        $('.select-all-articles-link').on("click", { 'mode' : "SAVE" }, jQuery.proxy(this.toggleAllArticles, this));
        $('.unselect-all-articles-link').on("click", { 'mode' : "REMOVE" }, jQuery.proxy(this.toggleAllArticles, this));
        $('.reset-btn').on("click", { 'mode' : "REMOVE" }, jQuery.proxy(this.toggleAllArticles, this));
        
        // We want the preview list count to be accurate even if the user navigates
        // with the back button.  So we always load the current preview list count
        // via ajax.
        $.ajax("/get-article-count", {
          type: "GET",
          cache: false,
          success: jQuery.proxy(function(resp) {
            this.updateListCount(resp);
          }, this)
        });
      },

      // Replaces the preview list counts in the UI with the new value.
      updateListCount : function(new_count) {
        preview_list_count = new_count;
        
        // update "your list" box in header
        $list_count.text(new_count);

        // update preview list button
        $preview_list_count_elem.val("Preview List (" + new_count + ")");

        // add the correct options depending on the user action 
        // remove all children
        $('#your-list-choices').children().remove();
        // add the correct options
        if (new_count == 0) {
          $('#your-list-choices').append('<span>View Report</span><span>Edit List</span>');
        } else {
          $('#your-list-choices').append('<a href="/reports/generate">View Report</a><a href="/preview-list">Edit List</a>')
        }

        // make sure the next action button is in a correct state
        if (new_count === 0) {
          this.disableButton($('#create-report-submit'));
          this.disableButton($('#preview-list-submit'));
        } else {
          this.enableButton($('#create-report-submit'));
          this.enableButton($('#preview-list-submit'));
        }

      },
      
      // Increments the preview list counts in the UI by the specified delta, which
      // can be positive or negative.
      incrementListCount : function(delta) {
        this.updateListCount(preview_list_count + delta);
      },

      checkboxClickHandler : function(e) {
        var $checkbox = $(e.target);

        // If we are over the limit, and it's a check event, don't do anything
        // (and uncheck the checkbox).
        if ($checkbox.prop("checked")) {
          if (preview_list_count >= VIZ_LIMIT && preview_list_count < ARTICLE_LIMIT) {
            this.showErrorDialog("viz-limit-error-message");
          } else if (preview_list_count >= ARTICLE_LIMIT) {
            $checkbox.prop("checked", false);
            this.showErrorDialog("article-limit-error-message");
            return;
          }
        }

        // create some data that we want to send to the server
        var ajax_data = {
          // grab the article ID from the checkbox value
          article_ids : [$checkbox.val()],

          // set the "mode" based on what state the checkbox is transitioning to
{'fraction_non_alphanumeric': 0.13347513959053442, 'fraction_numerical': 0.0018612071257644244, 'mean_word_length': 2.3629861421546714, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, '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': '7297728', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2052, 'n_words': 562}