<commit_before>'use strict';


/**
 *  client
 **/

/**
 *  client.common
 **/

/**
 *  client.common.auth
 **/

/**
 *  client.common.auth.register
 **/


/*global nodeca*/


/**
 *  client.common.auth.register.check_nick($elem, event)
 *
 *  send nick value on server
 *  and show error if nick exists
 **/
module.exports = function ($elem /*, event*/) {
  var nick = $elem.val();

  nodeca.server.users.auth.register.check_nick({ nick: nick }, function(err){
    var $control_group = $elem.parents('.control-group:first');

    if (err) {
      // Problems with nick
      if (err.statusCode === nodeca.io.BAD_REQUEST) {
        $control_group.addClass('error');

        $control_group.find('.help-block').text(
          err.message['nick']
        );
        return;
      }

      // something fatal
      nodeca.client.common.notify('error', err.message);
      return;
    }

    // no errors -> restore defaults

    $control_group.removeClass('error');
    $control_group.find('.help-block').text(
      nodeca.runtime.t('users.auth.reg_form.nick_help')
    );

  });
  return false;
};<commit_msg>Add delay on nick checking request<commit_after>'use strict';


/**
 *  client
 **/

/**
 *  client.common
 **/

/**
 *  client.common.auth
 **/

/**
 *  client.common.auth.register
 **/


/*global nodeca*/

var DELAY = 500;

var start_point;

/**
 *  client.common.auth.register.check_nick($elem, event)
 *
 *  send nick value on server
 *  and show error if nick exists
 **/
module.exports = function ($elem, event) {
  // update start point each time
  start_point = new Date();

  // delay request
  setTimeout(function() {

    // time is not come
    // new event(s) update start point
    if (DELAY > new Date() - start_point) {
      return;
    }

    // reset time
    start_point = null;

    var nick = $elem.val();
    nodeca.server.users.auth.register.check_nick({ nick: nick }, function(err){
      var $control_group = $elem.parents('.control-group:first');

      if (err) {
        // Problems with nick
        if (err.statusCode === nodeca.io.BAD_REQUEST) {
          $control_group.addClass('error');

          $control_group.find('.help-block').text(
            err.message['nick']
            );
          return;
        }

        // something fatal
        nodeca.client.common.notify('error', err.message);
        return;
      }

      // no errors -> restore defaults

      $control_group.removeClass('error');
      $control_group.find('.help-block').text(
        nodeca.runtime.t('users.auth.reg_form.nick_help')
      );

    });
  }, DELAY);
  return false;
};
{'fraction_non_alphanumeric': 0.16340621403912542, 'fraction_numerical': 0.0011507479861910242, 'mean_word_length': 2.3096446700507616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5615601', 'n_tokens_mistral': 849, 'n_tokens_neox': 820, 'n_words': 163}