<commit_before>{% from qiita_core.qiita_settings import qiita_config %}

<script type="text/javascript" src="{% raw qiita_config.portal_dir %}/static/vendor/js/jquery.validate.min.js"></script>
<script type="text/javascript>">
$(document).ready(function () {
  // Hide the user and new ontology divs
  $("#user-ena-info").hide();
  $("#new-ena-info").hide();
  // If the ena-ontology select changes, check if we need to show the user list
  $("#ena-ontology").change(function ( event ) {
    if( $("#ena-ontology").val() == "Other" ) {
      $("#user-ena-info").show();
    }
    else {
      $("#user-ena-info").hide();
      $("#new-ena-info").hide();
    }
  });
  // If the user-ena-info select changes, check if we need to show the
  $("#user-ena-info").change(function ( event ) {
    if( $("#user-ontology").val() == "New Type" ) {
      $("#new-ena-info").show();
    }
    else {
      $("#new-ena-info").hide();
    }
  });

  // Make sure that the form gets validated prior submission
  $("#create-prep-form").validate();

  // change the submit behavior
  $("#create-prep-form").submit(function(event){
    event.preventDefault();
    // Add the study id as parameter
    $('<input>').attr({
      type: 'hidden',
      name: 'study_id',
      value: '{{study_id}}'
    }).appendTo('#create-prep-form');
    $.ajax({
      url: $('#create-prep-form').attr('action'),
      type: "POST",
      data: $('#create-prep-form').serialize(),
      success: function(data) {
        if(data.status == 'error') { bootstrapAlert(data.message, "danger"); }
        else {
          if(data.status == 'warning') {
            // Note - the warning get's lost due to the reload below
            bootstrapAlert(data.message, "warning");
          }
          populate_data_type_menu_div();
          populate_main_div('{% raw qiita_config.portal_dir %}/study/description/prep_template/', { prep_id: data.id, study_id: {{study_id}} });
        }
      }
    });
  });
});
</script>
<h3>Add a new preparation file: <small>(* Required fields)</small></h3>

<form action="{% raw qiita_config.portal_dir %}/prep_template/" method="POST" id="create-prep-form">
  <!-- New user defined -->
  <div class="row form-group">
    <label class="col-sm-2 col-form-label">Name:</label>
    <div class="col-sm-3">
      <input type="textbox" id="name" name="name" class="form-control">
    </div>
  </div>
  <!-- File selection -->
  <div class="row form-group">
    <label class="col-sm-2 col-form-label">Select file: *</label>
    <div class="col-sm-3">
      <select name="prep-file" id="prep-file" class="form-control" required>
        <option value="">Choose file...</option>
        {% for file in prep_files %}
          <option value="{{file}}">{{file}}</option>
        {% end %}
      </select>
    </div>
  </div>
  <!-- Data type selection -->
  <div class="row form-group">
    <label class="col-sm-2 col-form-label">Select data type: *</label>
    <div class="col-sm-3">
      <select id="data-type-select" name="data-type" value="data-type" class="form-control" required>
        <option value="">Choose data type... </option>
        {% for t in data_types %}
          <option value="{{t}}">{{t}}</option>
        {% end %}
      </select>
    </div>
  </div>
  <!-- Investigation type selection -->
  <div class="row form-group">
    <label class="col-sm-2 col-form-label">Select Investigation Type: <small>Unsure? <a href="https://www.ebi.ac.uk/submission/#" target="_blank">Check</a></small></label>
    <div class="col-sm-3">
      <select id="ena-ontology" name="ena-ontology" value="ena-ontology" class="form-control">
        <option value=""></option>
        {% for o in ontology['ENA'] %}
          <option value="{{o}}">{{o}}</option>
        {% end %}
      </select>
    </div>
    <div class="col-sm-3">
      Not sure what to select? <a href="" target="_blank">Check</a>
    </div>
  </div>
  <!-- User defined investigation type selection -->
  <div class="row form-group" id="user-ena-info">
    <label class="col-sm-2 col-form-label">User defined investigation type:</label>
    <div class="col-sm-3">
      <select id="user-ontology" name="user-ontology" value="user-ontology" class="form-control">
        <option value=""></option>
        {% for o in ontology['User'] %}
          <option value="{{o}}">{{o}}</option>
        {% end %}
        <option value="New Type">New Type</option>
      </select>
    </div>
  </div><commit_msg>fix #2221<commit_after>{% from qiita_core.qiita_settings import qiita_config %}

<script type="text/javascript" src="{% raw qiita_config.portal_dir %}/static/vendor/js/jquery.validate.min.js"></script>
<script type="text/javascript>">
$(document).ready(function () {
  // Hide the user and new ontology divs
  $("#user-ena-info").hide();
  $("#new-ena-info").hide();
  // If the ena-ontology select changes, check if we need to show the user list
  $("#ena-ontology").change(function ( event ) {
    if( $("#ena-ontology").val() == "Other" ) {
      $("#user-ena-info").show();
    }
    else {
      $("#user-ena-info").hide();
      $("#new-ena-info").hide();
    }
  });
  // If the user-ena-info select changes, check if we need to show the
  $("#user-ena-info").change(function ( event ) {
    if( $("#user-ontology").val() == "New Type" ) {
      $("#new-ena-info").show();
    }
    else {
      $("#new-ena-info").hide();
    }
  });

  // Make sure that the form gets validated prior submission
  $("#create-prep-form").validate();

  // change the submit behavior
  $("#create-prep-form").submit(function(event){
    event.preventDefault();
    // Add the study id as parameter
    $('<input>').attr({
      type: 'hidden',
      name: 'study_id',
      value: '{{study_id}}'
    }).appendTo('#create-prep-form');
    $.ajax({
      url: $('#create-prep-form').attr('action'),
      type: "POST",
      data: $('#create-prep-form').serialize(),
      success: function(data) {
        if(data.status == 'error') { bootstrapAlert(data.message, "danger"); }
        else {
          if(data.status == 'warning') {
            // Note - the warning get's lost due to the reload below
            bootstrapAlert(data.message, "warning");
          }
          populate_data_type_menu_div();
          populate_main_div('{% raw qiita_config.portal_dir %}/study/description/prep_template/', { prep_id: data.id, study_id: {{study_id}} });
        }
      }
    });
  });
});
</script>
<h3>Add a new preparation file: <small>(* Required fields)</small></h3>

<form action="{% raw qiita_config.portal_dir %}/prep_template/" method="POST" id="create-prep-form">
  <!-- New user defined -->
  <div class="row form-group">
    <label class="col-sm-2 col-form-label">Name:</label>
    <div class="col-sm-3">
      <input type="textbox" id="name" name="name" class="form-control">
    </div>
  </div>
  <!-- File selection -->
  <div class="row form-group">
    <label class="col-sm-2 col-form-label">Select file: *</label>
    <div class="col-sm-3">
      <select name="prep-file" id="prep-file" class="form-control" required>
        <option value="">Choose file...</option>
        {% for file in prep_files %}
          <option value="{{file}}">{{file}}</option>
        {% end %}
      </select>
    </div>
  </div>
  <!-- Data type selection -->
  <div class="row form-group">
    <label class="col-sm-2 col-form-label">Select data type: *</label>
    <div class="col-sm-3">
      <select id="data-type-select" name="data-type" value="data-type" class="form-control" required>
        <option value="">Choose data type... </option>
        {% for t in data_types %}
          <option value="{{t}}">{{t}}</option>
        {% end %}
      </select>
    </div>
  </div>
  <!-- Investigation type selection -->
  <div class="row form-group">
    <label class="col-sm-2 col-form-label">Select Investigation Type: <small>Unsure? <a href="https://www.ebi.ac.uk/submission/#" target="_blank">Check</a></small></label>
    <div class="col-sm-3">
      <select id="ena-ontology" name="ena-ontology" value="ena-ontology" class="form-control">
        <option value=""></option>
        {% for o in ontology['ENA'] %}
          <option value="{{o}}">{{o}}</option>
        {% end %}
      </select>
    </div>
    <div class="col-sm-3">
      Not sure what to select? <a href="" target="_blank">Check</a>
    </div>
  </div>
  <!-- User defined investigation type selection -->
  <div class="row form-group" id="user-ena-info">
    <label class="col-sm-2 col-form-label">User defined investigation type:</label>
    <div class="col-sm-3">
      <select id="user-ontology" name="user-ontology" value="user-ontology" class="form-control">
        {% for o in ontology['User'] %}
          <option value="{{o}}">{{o}}</option>
        {% end %}
        <option value="New Type">New Type</option>
      </select>
    </div>
  </div>
{'fraction_non_alphanumeric': 0.20946478873239435, 'fraction_numerical': 0.0033802816901408453, 'mean_word_length': 2.837440553393861, 'pattern_counts': {'":': 0, '<': 161, '<?xml version=': 0, '>': 163, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5896072', 'n_tokens_mistral': 2930, 'n_tokens_neox': 2841, 'n_words': 630}