<commit_before>/*
 * DbFrontend base class for all the JS classes that share similar structure with in-line editing features
 */

Ensembl.DbFrontend = Base.extend({

  // constructor initialises the el by manipulating the events on the buttons inside it
  constructor: function(el, panel) {
    var self   = this;
    this.panel = panel;
    this.el = $(el);
    $('._dbf_button', this.el).die('click').live('click', function(event) {
      event.preventDefault();
      self.buttonClick(this);
    });
  },

  // wrapper method around ajax
  makeRequest: function(eventTarget, responseTarget, options) {
    var self = this;
    if (this.ajax) {
      this.ajax.abort();
      this.ajax = false;
    }
    this.showLoading(responseTarget);
    var isForm = eventTarget.nodeName === 'FORM';
    var data   = options.data || (isForm ? $(eventTarget).serialize() : {});
    this.ajax  = $.ajax($.extend({
      url       : eventTarget.action || eventTarget.href || '',
      type      : isForm ? 'POST' : 'GET',
      dataType  : 'json',
      context   : this,
      error     : function() { self.showError(responseTarget, '', this.el); },
      complete  : function() { self.showLoading(responseTarget, false); }
    }, options, { //any value provided in options overrides the default ones above
      data      : typeof(data) === 'string' ? data + '&_ajax=1' : $.extend(data, {_ajax: 1})
    }));
  },

  //method to show/hide a 'Loading' message
  showLoading: function(target, flag) {
    if (flag === false) {
      $(target).removeClass('spinner');
    }
    else {
      $(target).empty().show().addClass('spinner');
    }
  },

  //method to parse the response json and return the required html node (jquery object)
  getResponseNode: function(json) {
    return $('._dbf_response', $('<div>').html(json.content));
  },
  
  //method to force the newly loaded forms to be validated before being submitted
  validateForms: function(formWrapper) {
    Ensembl.EventManager.trigger('validateForms', formWrapper);
  },

  // method to show error
  showError: function(target, message, el) {
    if (target) {
      target.html('<p class="dbf-error">' + (message || 'An error occoured at the server. Please try again.') + '</p>');
    }
    if (el) {
      el.show();
    }
  },

  // method to create form's wrapping element
  createForm: function() {
    return $('<div>').insertAfter(this.el).hide();
  },

  // initialises the form and binds live events to the form and its buttons
  initForm: function() {
    var self = this;<commit_msg>Fix typo in admin site.<commit_after>/*
 * DbFrontend base class for all the JS classes that share similar structure with in-line editing features
 */

Ensembl.DbFrontend = Base.extend({

  // constructor initialises the el by manipulating the events on the buttons inside it
  constructor: function(el, panel) {
    var self   = this;
    this.panel = panel;
    this.el = $(el);
    $('._dbf_button', this.el).die('click').live('click', function(event) {
      event.preventDefault();
      self.buttonClick(this);
    });
  },

  // wrapper method around ajax
  makeRequest: function(eventTarget, responseTarget, options) {
    var self = this;
    if (this.ajax) {
      this.ajax.abort();
      this.ajax = false;
    }
    this.showLoading(responseTarget);
    var isForm = eventTarget.nodeName === 'FORM';
    var data   = options.data || (isForm ? $(eventTarget).serialize() : {});
    this.ajax  = $.ajax($.extend({
      url       : eventTarget.action || eventTarget.href || '',
      type      : isForm ? 'POST' : 'GET',
      dataType  : 'json',
      context   : this,
      error     : function() { self.showError(responseTarget, '', this.el); },
      complete  : function() { self.showLoading(responseTarget, false); }
    }, options, { //any value provided in options overrides the default ones above
      data      : typeof(data) === 'string' ? data + '&_ajax=1' : $.extend(data, {_ajax: 1})
    }));
  },

  //method to show/hide a 'Loading' message
  showLoading: function(target, flag) {
    if (flag === false) {
      $(target).removeClass('spinner');
    }
    else {
      $(target).empty().show().addClass('spinner');
    }
  },

  //method to parse the response json and return the required html node (jquery object)
  getResponseNode: function(json) {
    return $('._dbf_response', $('<div>').html(json.content));
  },
  
  //method to force the newly loaded forms to be validated before being submitted
  validateForms: function(formWrapper) {
    Ensembl.EventManager.trigger('validateForms', formWrapper);
  },

  // method to show error
  showError: function(target, message, el) {
    if (target) {
      target.html('<p class="dbf-error">' + (message || 'An error occurred at the server. Please try again.') + '</p>');
    }
    if (el) {
      el.show();
    }
  },

  // method to create form's wrapping element
  createForm: function() {
    return $('<div>').insertAfter(this.el).hide();
  },

  // initialises the form and binds live events to the form and its buttons
  initForm: function() {
    var self = this;
{'fraction_non_alphanumeric': 0.15, 'fraction_numerical': 0.000784313725490196, 'mean_word_length': 2.948142414860681, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4724592', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1499, 'n_words': 439}