<commit_before>$(function() {

  // Before submitting the form
  $('form').submit(function (e) {
    // Update locales
    var arr = [];
    $("#selected").parent().siblings('ul').find('li:not(".no-match")').each(function() {
      arr.push($(this).data('id'));
    });
    $('#id_locales').val(arr);

    // Append slash to the URL field
    var url = $('#id_url').val();
    if (url.length > 0 && url[url.length-1] !== '/') {
      $('#id_url').val(url + '/');
    }

    // Update form action
    var slug = $('#id_slug').val();
    if (slug.length > 0) {
      slug += '/';
    }
    $('form').attr('action', $('form').attr('action').split('/project/')[0] + '/project/' + slug);
  });

  // Submit form with Enter
  $('html').unbind("keydown.pontoon").bind("keydown.pontoon", function (e) {
    if ($('input[type=text]:not("input[type=search], #id_transifex_username, #id_transifex_password"):focus').length > 0) {
      var key = e.keyCode || e.which;
      if (key === 13) { // Enter
        // A short delay to allow digest of autocomplete before submit 
        setTimeout(function() {
          $('form').submit();
        }, 1);
        return false;
      }
    }
  });

  // Suggest slugified name for new projects
  $('#id_name').blur(function() {
    if ($('input[name=pk]').length > 0) {
      return;
    }
    $('#id_slug').attr('placeholder', 'Retrieving...');
    $.ajax({
      url: '/admin/get-slug/',
      data: {
        name: $('#id_name').val()
      },
      success: function(data) {
        var value = (data === "error") ? "" : data;
        $('#id_slug').val(value);
      },
      error: function() {
        $('#id_slug').attr('placeholder', '');
      }
    });
  });

  // Choose locales
  $('.locale.select li').live('click.pontoon', function (e) {
    var target = $(this).parents('.locale.select').siblings('.locale.select').find('ul'),
        clone = $(this).remove();
    target.prepend(clone);
  });

  // Choose/remove all locales
  $('.choose-all, .remove-all').live('click.pontoon', function (e) {
    e.preventDefault();
    var ls = $(this).parents('.locale.select'),
        target = ls.siblings('.locale.select').find('ul'),
        items = ls.find('li:visible:not(".no-match")').remove();
    target.prepend(items);
  });

  // Select repository type
  $('body').live("click.pontoon", function () {
    $('.repository .menu').hide();
    $('.select').removeClass('opened');
  });
  $('.repository .type li').live("click.pontoon", function () {
    var selected = $(this).html(),
        selected_lower = selected.toLowerCase();
    $(this).parents('.select').find('.title').html(selected);
    $('#id_repository_type').val(selected_lower);
    $('.details-wrapper').attr('data-repository-type', selected_lower);
  });
  // Show human-readable value
  $('.repository .type li[data-type=' + $('#id_repository_type').val() + ']').click();

  // Update from repository
  $('.repository .update:not(".disabled"), .transifex .update:not(".disabled")').unbind('click.pontoon').bind('click.pontoon', function (e) {
    e.preventDefault();
    $(this).addClass('disabled');

    var source = $(this).data('source'),
        icon = $(this).find('span').attr('class', 'fa fa-refresh fa-spin'),
        params = {
          pk: $('input[name=pk]').val(),
          csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val()
        };

    if (source === 'transifex') {
      if ($(this).parents('.popup').length === 0) {
        project = $('.transifex input#id_transifex_project');
        resource = $('.transifex input#id_transifex_resource');
        params[project.attr('name')] = project.val();
        params[resource.attr('name')] = resource.val();
      } else {
        $('.transifex input').each(function() {
          var val = $(this).val();
          if (val) {
            if ($(this).attr('name') === 'remember') {
              params[$(this).attr('name')] = ($(this).is(':checked')) ? "on" : "off";
            } else {
              params[$(this).attr('name')] = val;
            }
          }
        });
      }
    }

    $.ajax({
      url: '/admin/' + source + '/',
      type: 'POST',
      data: params,
      success: function(data) {
        if (data === "200") {
          icon.attr('class', 'fa fa-check');
          $('.repository').removeClass('authenticate');
          $('.warning').fadeOut();
          $('.links .translate').removeClass('hidden');
        } else if (data === "authenticate") {
          icon.attr('class', 'fa fa-refresh');
          $('.repository').addClass('authenticate');
        } else if (data.type === "error") {
          icon.attr('class', 'fa fa-warning');
          $('.repository').find('.errorlist').remove().end().append(
            '<ul class="errorlist"><li>' + data.message + '</li></ul>');
        }
      },<commit_msg>Remove error message on success<commit_after>$(function() {

  // Before submitting the form
  $('form').submit(function (e) {
    // Update locales
    var arr = [];
    $("#selected").parent().siblings('ul').find('li:not(".no-match")').each(function() {
      arr.push($(this).data('id'));
    });
    $('#id_locales').val(arr);

    // Append slash to the URL field
    var url = $('#id_url').val();
    if (url.length > 0 && url[url.length-1] !== '/') {
      $('#id_url').val(url + '/');
    }

    // Update form action
    var slug = $('#id_slug').val();
    if (slug.length > 0) {
      slug += '/';
    }
    $('form').attr('action', $('form').attr('action').split('/project/')[0] + '/project/' + slug);
  });

  // Submit form with Enter
  $('html').unbind("keydown.pontoon").bind("keydown.pontoon", function (e) {
    if ($('input[type=text]:not("input[type=search], #id_transifex_username, #id_transifex_password"):focus').length > 0) {
      var key = e.keyCode || e.which;
      if (key === 13) { // Enter
        // A short delay to allow digest of autocomplete before submit 
        setTimeout(function() {
          $('form').submit();
        }, 1);
        return false;
      }
    }
  });

  // Suggest slugified name for new projects
  $('#id_name').blur(function() {
    if ($('input[name=pk]').length > 0) {
      return;
    }
    $('#id_slug').attr('placeholder', 'Retrieving...');
    $.ajax({
      url: '/admin/get-slug/',
      data: {
        name: $('#id_name').val()
      },
      success: function(data) {
        var value = (data === "error") ? "" : data;
        $('#id_slug').val(value);
      },
      error: function() {
        $('#id_slug').attr('placeholder', '');
      }
    });
  });

  // Choose locales
  $('.locale.select li').live('click.pontoon', function (e) {
    var target = $(this).parents('.locale.select').siblings('.locale.select').find('ul'),
        clone = $(this).remove();
    target.prepend(clone);
  });

  // Choose/remove all locales
  $('.choose-all, .remove-all').live('click.pontoon', function (e) {
    e.preventDefault();
    var ls = $(this).parents('.locale.select'),
        target = ls.siblings('.locale.select').find('ul'),
        items = ls.find('li:visible:not(".no-match")').remove();
    target.prepend(items);
  });

  // Select repository type
  $('body').live("click.pontoon", function () {
    $('.repository .menu').hide();
    $('.select').removeClass('opened');
  });
  $('.repository .type li').live("click.pontoon", function () {
    var selected = $(this).html(),
        selected_lower = selected.toLowerCase();
    $(this).parents('.select').find('.title').html(selected);
    $('#id_repository_type').val(selected_lower);
    $('.details-wrapper').attr('data-repository-type', selected_lower);
  });
  // Show human-readable value
  $('.repository .type li[data-type=' + $('#id_repository_type').val() + ']').click();

  // Update from repository
  $('.repository .update:not(".disabled"), .transifex .update:not(".disabled")').unbind('click.pontoon').bind('click.pontoon', function (e) {
    e.preventDefault();
    $(this).addClass('disabled');

    var source = $(this).data('source'),
        icon = $(this).find('span').attr('class', 'fa fa-refresh fa-spin'),
        params = {
          pk: $('input[name=pk]').val(),
          csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val()
        };

    if (source === 'transifex') {
      if ($(this).parents('.popup').length === 0) {
        project = $('.transifex input#id_transifex_project');
        resource = $('.transifex input#id_transifex_resource');
        params[project.attr('name')] = project.val();
        params[resource.attr('name')] = resource.val();
      } else {
        $('.transifex input').each(function() {
          var val = $(this).val();
          if (val) {
            if ($(this).attr('name') === 'remember') {
              params[$(this).attr('name')] = ($(this).is(':checked')) ? "on" : "off";
            } else {
              params[$(this).attr('name')] = val;
            }
          }
        });
      }
    }

    $.ajax({
      url: '/admin/' + source + '/',
      type: 'POST',
      data: params,
      success: function(data) {
        if (data === "200") {
          icon.attr('class', 'fa fa-check');
          $('.repository').removeClass('authenticate')
            .find('.errorlist').remove();
          $('.warning').fadeOut();
          $('.links .translate').removeClass('hidden');
        } else if (data === "authenticate") {
          icon.attr('class', 'fa fa-refresh');
          $('.repository').addClass('authenticate');
        } else if (data.type === "error") {
          icon.attr('class', 'fa fa-warning');
          $('.repository')
            .find('.errorlist').remove().end()
          .append(
            '<ul class="errorlist"><li>' + data.message + '</li></ul>');
        }
      },
{'fraction_non_alphanumeric': 0.23270826928988625, 'fraction_numerical': 0.0026642073982990062, 'mean_word_length': 2.53495110467222, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '6980458', 'n_tokens_mistral': 3079, 'n_tokens_neox': 3028, 'n_words': 531}