<commit_before>$(function(){
  var hiscorepageDefaultErrMsg = '请求失败,请稍后重试,或联系管理员!';
  $('#checkboxSelectAll').change(function(e){
    var ck = false;
    if($('#checkboxSelectAll').is(':checked')){
      ck = true;
    }
    $('[name="checkboxSelect"]').each(function(){
      $(this).prop('checked', ck ? 'checked' : false);
    });
  });

  function checkIdInList(id, lst){
    for(var i=0; i<lst.length; i++){
      if(lst[i] == id){
        return true;
      }
    }
    return false;
  }
  $('#delHighscore').click(function(e){
    var ids = [];
    var allItems = $('[name="checkboxSelect"]');
    for(var i=0; i < allItems.length; i++){
      var item = $(allItems[i]);
      if(item.prop('checked')){
        ids[ids.length] = item.prop('value');
      }
    }
    if(ids.length > 0){
      var params = {'action': 'delete', 'ids': ids.join(',')};
      $.post("/teacher/highscore/", params, function(result){
          if(result){
              if(result.ok){
                  var allItems = $('[name="checkboxSelect"]');
                  for(var i=0; i < allItems.length; i++){
                    var item = $(allItems[i]);
                    if(checkIdInList(item.prop('value'), ids)){
                      item.parent().parent().remove();
                    }
                  }
              }else{
                  alert(result.msg);
              }
              return;
          }
          alert(hiscorepageDefaultErrMsg);
      }, 'json').fail(function(){
          alert(hiscorepageDefaultErrMsg);
      });
    }
  });
  $('#saveNewItem').click(function(e){
    var teacherId = $('#teacherId').val();
    var stname = $('#stname').val();
    var inscore = $('#inscore').val();
    var schoolname = $('#schoolname').val();
    var admittedTo = $('#admittedTo').val();

    if(stname == '' ||
      inscore == '' ||
      schoolname == '' ||
      admittedTo == ''
    ){
      alert("必须填写所有内容！");
      return false;
    }

    var params = {
      'action': 'add',
      'id': teacherId,
      'name': stname,
      'increased_scores': inscore,
      'school_name': schoolname,
      'admitted_to': admittedTo,
    };
    $.post("/teacher/highscore/", params, function(result){
        if(result){
          if(result.ok){
            $('#addItemsModal').modal('hide');
            location.reload();
          }else{
            alert(result.msg);
          }
        }else{
          alert(hiscorepageDefaultErrMsg);
        }
    }, 'json').fail(function(){
      $('#addItemsModal').modal('hide');
      alert(hiscorepageDefaultErrMsg);
    });
  });
  $('#addHighscore').click(function(e){
    $('#addItemsModal').modal({backdrop: 'static', keyboard: false});
  });
});<commit_msg>TWEB-162: prevent from clicking twice<commit_after>$(function(){
  var hiscorepageDefaultErrMsg = '请求失败,请稍后重试,或联系管理员!';
  $('#checkboxSelectAll').change(function(e){
    var ck = false;
    if($('#checkboxSelectAll').is(':checked')){
      ck = true;
    }
    $('[name="checkboxSelect"]').each(function(){
      $(this).prop('checked', ck ? 'checked' : false);
    });
  });

  function checkIdInList(id, lst){
    for(var i=0; i<lst.length; i++){
      if(lst[i] == id){
        return true;
      }
    }
    return false;
  }
  $('#delHighscore').click(function(e){
    var ids = [];
    var allItems = $('[name="checkboxSelect"]');
    for(var i=0; i < allItems.length; i++){
      var item = $(allItems[i]);
      if(item.prop('checked')){
        ids[ids.length] = item.prop('value');
      }
    }
    if(ids.length > 0){
      var params = {'action': 'delete', 'ids': ids.join(',')};
      $.post("/teacher/highscore/", params, function(result){
          if(result){
              if(result.ok){
                  var allItems = $('[name="checkboxSelect"]');
                  for(var i=0; i < allItems.length; i++){
                    var item = $(allItems[i]);
                    if(checkIdInList(item.prop('value'), ids)){
                      item.parent().parent().remove();
                    }
                  }
              }else{
                  alert(result.msg);
              }
              return;
          }
          alert(hiscorepageDefaultErrMsg);
      }, 'json').fail(function(){
          alert(hiscorepageDefaultErrMsg);
      });
    }
  });
  var isSaving = false;
  $('#saveNewItem').click(function(e){
    if (isSaving) return;
    isSaving = true;
    var $saveBtn = $(this);
    $saveBtn.addClass('disabled');
    var teacherId = $('#teacherId').val();
    var stname = $('#stname').val();
    var inscore = $('#inscore').val();
    var schoolname = $('#schoolname').val();
    var admittedTo = $('#admittedTo').val();

    if(stname == '' ||
      inscore == '' ||
      schoolname == '' ||
      admittedTo == ''
    ){
      alert("必须填写所有内容！");
      $saveBtn.removeClass('disabled');
      isSaving = false;
      return false;
    }

    var params = {
      'action': 'add',
      'id': teacherId,
      'name': stname,
      'increased_scores': inscore,
      'school_name': schoolname,
      'admitted_to': admittedTo,
    };
    $.post("/teacher/highscore/", params, function(result){
        if(result){
          if(result.ok){
            $('#addItemsModal').modal('hide');
            location.reload();
          }else{
            alert(result.msg);
          }
        }else{
          alert(hiscorepageDefaultErrMsg);
        }
      $saveBtn.removeClass('disabled');
      isSaving = false;
    }, 'json').fail(function(){
      $('#addItemsModal').modal('hide');
      alert(hiscorepageDefaultErrMsg);
      $saveBtn.removeClass('disabled');
      isSaving = false;
    });
  });
  $('#addHighscore').click(function(e){
    $('#addItemsModal').modal({backdrop: 'static', keyboard: false});
  });
});
{'fraction_non_alphanumeric': 0.1959529574541681, 'fraction_numerical': 0.0019024558976132827, 'mean_word_length': 2.1108122646584184, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2641806', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1827, 'n_words': 295}