<commit_before>function resetFormGroup(input) {
  $(input).parent().removeClass("has-success has-error has-feedback");
  $(input).parent().find(".form-control-feedback").remove();
  $(input).parent().find(".form-control-status").remove();
}
function successFormGroup(input) {
  $(input).parent().addClass("has-success has-feedback");
  $(input).after('<span class="glyphicon glyphicon-floppy-saved form-control-feedback" aria-hidden="true"></span> \
  <span class="sr-only form-control-status">(success)</span>');
}
function errorFormGroup(input) {
  $(input).parent().addClass("has-error has-feedback");
  $(input).after('<span class="glyphicon glyphicon-floppy-remove form-control-feedback" aria-hidden="true"></span> \
  <span class="sr-only form-control-status">(error)</span>');
}
$(document).on("focus", "#codelists-data input", function(e) {
  resetFormGroup(this);
});
$("#confirm-delete").on('show.bs.modal', function(e) {
  $(this).find(".btn-ok").on("click", function(f) {
    deleteCode(e.relatedTarget);
    $("#confirm-delete").modal("hide");
  });
});

function deleteCode(target) {
  var data = {
    'codelist_code': $(target).closest("table").attr("data-codelist"),
    'code': $(target).closest("tr").attr("data-code"),
    "action": "delete"
  }
  var deleteButton = target;
  $.post("/api/codelists/delete/", data, 
    function(returndata){
      if (returndata == 'False'){
          alert("There was an error deleting that code.");
      } else {
        $(deleteButton).closest("tr").fadeOut();
      }
    }
  );
}

// $(document).on("click", ".deleteCode", function(e) {
//   e.preventDefault();
//   var data = {
//     'codelist_code': $(this).closest("table").attr("data-codelist"),
//     'code': $(this).closest("tr").attr("data-code"),
//     "action": "delete"
//   }
//   var deleteButton = this;
//   $.post("/api/codelists/delete/", data,
//     function(returndata){
//       if (returndata == 'False'){
//           alert("There was an error deleting that code.");
//       } else {
//         $(deleteButton).closest("tr").fadeOut();
//       }
//     }
//   );
// });
$(document).on("click", ".addCode", function(e) {
  e.preventDefault();
  var codelist = $(this).attr("data-codelist");
  var data = {
    "codelist_code": codelist,
    "code": "",
    "name": ""
  }
  $.post("/api/codelists/new/", data, 
    function(returndata){
      if (returndata == 'False'){
          alert("There was an error creating that code.");
      } else {
        var row_codelist_template = $('#row-codelist-template').html();
        var data = {
          "code": "",
          "name": ""
        }
      	var rendered_row = Mustache.render(row_codelist_template, data);
      	$('#table-' + codelist + ' tbody').append(rendered_row);
      }
    }
  );
});

$(document).on("change", ".codelists-data input[type=text]", function(e) {
  var data = {
    'codelist_code': $(this).closest("table").attr("data-codelist"),<commit_msg>Correct error message<commit_after>function resetFormGroup(input) {
  $(input).parent().removeClass("has-success has-error has-feedback");
  $(input).parent().find(".form-control-feedback").remove();
  $(input).parent().find(".form-control-status").remove();
}
function successFormGroup(input) {
  $(input).parent().addClass("has-success has-feedback");
  $(input).after('<span class="glyphicon glyphicon-floppy-saved form-control-feedback" aria-hidden="true"></span> \
  <span class="sr-only form-control-status">(success)</span>');
}
function errorFormGroup(input) {
  $(input).parent().addClass("has-error has-feedback");
  $(input).after('<span class="glyphicon glyphicon-floppy-remove form-control-feedback" aria-hidden="true"></span> \
  <span class="sr-only form-control-status">(error)</span>');
}
$(document).on("focus", "#codelists-data input", function(e) {
  resetFormGroup(this);
});
$("#confirm-delete").on('show.bs.modal', function(e) {
  $(this).find(".btn-ok").on("click", function(f) {
    deleteCode(e.relatedTarget);
    $("#confirm-delete").modal("hide");
  });
});

function deleteCode(target) {
  var data = {
    'codelist_code': $(target).closest("table").attr("data-codelist"),
    'code': $(target).closest("tr").attr("data-code"),
    "action": "delete"
  }
  var deleteButton = target;
  $.post("/api/codelists/delete/", data, 
    function(returndata){
      if (returndata == 'ERROR'){
          alert("There was an error deleting that code.");
      } else {
        $(deleteButton).closest("tr").fadeOut();
      }
    }
  );
}

// $(document).on("click", ".deleteCode", function(e) {
//   e.preventDefault();
//   var data = {
//     'codelist_code': $(this).closest("table").attr("data-codelist"),
//     'code': $(this).closest("tr").attr("data-code"),
//     "action": "delete"
//   }
//   var deleteButton = this;
//   $.post("/api/codelists/delete/", data,
//     function(returndata){
//       if (returndata == 'False'){
//           alert("There was an error deleting that code.");
//       } else {
//         $(deleteButton).closest("tr").fadeOut();
//       }
//     }
//   );
// });
$(document).on("click", ".addCode", function(e) {
  e.preventDefault();
  var codelist = $(this).attr("data-codelist");
  var data = {
    "codelist_code": codelist,
    "code": "",
    "name": ""
  }
  $.post("/api/codelists/new/", data, 
    function(returndata){
      if (returndata == 'ERROR'){
          alert("There was an error creating that code.");
      } else {
        var row_codelist_template = $('#row-codelist-template').html();
        var data = {
          "code": "",
          "name": ""
        }
      	var rendered_row = Mustache.render(row_codelist_template, data);
      	$('#table-' + codelist + ' tbody').append(rendered_row);
      }
    }
  );
});

$(document).on("change", ".codelists-data input[type=text]", function(e) {
  var data = {
    'codelist_code': $(this).closest("table").attr("data-codelist"),
{'fraction_non_alphanumeric': 0.22510968612892338, 'fraction_numerical': 0.0, 'mean_word_length': 3.3612950699043416, 'pattern_counts': {'":': 14, '<': 19, '<?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': '5383471', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1892, 'n_words': 299}