<commit_before><script>
  var ItemFieldSubjectSelect2 = {
    // Subject select2 options
    subjectSelect2options: {
      multiple: false,
      minimumInputLength: 1,
      width: "200px",
      allowClear: true,
      placeholder: <%= raw t("activerecord.attributes.subject.term").to_json %>,
      formatNoMatches: function(term) {
        return "'" + term + "' " + <%= raw t("agent.search_nomatch").to_json %>; 
      },
      formatSearching: function() {
        return <%= raw t("agent.search_searching").to_json %>;
      },
      formatInputTooShort: function(term, minLength){
        return <%= raw t("agent.search_placeholder").to_json %>;
      },
      ajax: {
        url: "/subjects/search_name.json",
        dataType: 'json',
        data: function (term, page) {
            var currentNumber = $(this).attr('id').match(/\d+/);
            var subjectTypeId = $('#subjects_' + currentNumber + '_subject_type_id').val();
            return {
              subject_type_id: subjectTypeId,
              search_phrase: term,
            };
        },
        results: function (data, page) {
            return {results: data};
        },
      },
      initSelection: function(element, callback) {
        var id = $(element).val();
        if (id != "") {
          $.ajax("/subjects/search_name.json?subject_id=" + id, {
              dataType: "json"
         }).done(function(data) { callback(data); });
        }
      },
      createSearchChoice: function(term, data) {
        if ($(data).filter(function() {
          return this.text.localeCompare(term)===0; }).length===0) {
          return {id:term, text:term};
        }
      },
    },
    // SubjectType select2 options
    subjectTypeSelect2options: {
      width: "200px",
      matcher: function(term, text, opt) {
        return text.toUpperCase().indexOf(term.toUpperCase())==0
            || opt.attr("alt").toUpperCase().indexOf(term.toUpperCase())==0;
      },
    },
    currentNumber : <%= raw (@subjects.size).to_json %>,
    actionTemplate : ''
      + '<%= button_to_function t('page.add_line'), "ItemFieldSubjectSelect2.add()" %>'
      + '<%= button_to_function t('page.del_line'), "ItemFieldSubjectSelect2.remove(__count__)" %>',
    add : function () {
      var newField = $("<div/>").attr("id", "SUBJECT" + this.currentNumber).attr("class", 'field');
      var typeFieldId = $("div[id ^= 'SUBJECT']:first").find("select[id $= 'subject_type_id']").attr('id');
      var termFieldId = $("div[id ^= 'SUBJECT']:first").find("input[id $= 'subject_id']").attr('id');
      var termTranscriptionFieldId = $("div[id ^= 'SUBJECT']:first").find("input[id $= 'term_transcription']").attr('id');
      var cloneType = this.cloneField(typeFieldId);
      var cloneTerm = this.cloneField(termFieldId);
      var cloneTermTranscription = this.cloneField(termTranscriptionFieldId);
      var actionButton = this.actionTemplate.replace(/__count__/mg, this.currentNumber);
      
      var div1 = $("<div/>").append(cloneType);
      var div2 = $("<div/>").append(cloneTerm).append(cloneTermTranscription).append(actionButton);

      newField.append(div1).append(div2);
      
      // select2の設定
      cloneType.select2(this.subjectTypeSelect2options);
      cloneTerm.val('');
      cloneTerm.select2(ItemFieldSubjectSelect2.subjectSelect2options);
      cloneTermTranscription.val('');

      $("#subjects").append(newField);

      this.currentNumber += 1;
    },
    cloneField : function (fieldId) {
      return $('#' + fieldId).clone().attr({
          'id' : $('#' + fieldId).attr('id').replace(/_\d+_/, '_' + this.currentNumber + '_'),
          'name' : $('#' + fieldId).attr('name').replace(/\[\d+\]/, '[' + this.currentNumber + ']'),
      });
    },
    remove : function (trNum) {
      if($("div[id ^= 'SUBJECT']").length == 1) this.add();
      removeDivField('SUBJECT', trNum)
    }
  }

  $(document).ready(function() {
    $("select[id $= 'subject_type_id']").select2(ItemFieldSubjectSelect2.subjectTypeSelect2options);
    $("input[id $= 'subject_id']").select2(ItemFieldSubjectSelect2.subjectSelect2options);
  });
  $(document).on("select2-selecting select2-removed", ".subject", function(e){
    var targetId = e.target.id;
    var targetNumber = targetId.match(/_(\d+)_/);
    if (e.type == 'select2-removed'){
        $("#subjects_" + targetNumber[1] + "_term_transcription").val('');
    }
    else if(e.val == parseInt(e.val)){
        $("#subjects_" + targetNumber[1] + "_id").val(e.object.id);
        $("#subjects_" + targetNumber[1] + "_term").val(e.object.text);
        $("#subjects_" + targetNumber[1] + "_term_transcription").val(e.object.term_transcription);
    }
    else{
        $("#subjects_" + targetNumber[1] + "_id").val("");
        $("#subjects_" + targetNumber[1] + "_term").val(e.object.id);
        $("#subjects_" + targetNumber[1] + "_term_transcription").val(e.object.term_transcription);
    }
  });
</script>

<div class="row">
  <div><%= f.label t('activerecord.attributes.manifestation.subject') %></div>
  <div id="subjects">
    <% @subjects.each_with_index do |subject, index| -%>
      <div class='field' id="SUBJECT<%= index %>" >
        <div> 
          <%= select2_tag("subjects_#{index}_subject_type_id",
                          "subjects[][subject_type_id]",
                          @subject_types,
                          subject[:subject_type_id],
                          :width => 200, :select_attribute => :id, :display_attribute => :display_name) %>
        </div>
        <div>
          <%= text_field_tag "subjects[][subject_id]", subject[:subject_id], :id => "subjects_#{index}_subject_id", :class => "subject" %>
        <%= text_field_tag "subjects[][term_transcription]", 
          subject[:term_transcription], 
          :id => "subjects_#{index}_term_transcription", 
          :placeholder => t("activerecord.attributes.subject.term_transcription"),
          :style => 'width: 250px;' %>
        <%= button_to_function t('page.add_line'), "ItemFieldSubjectSelect2.add()" -%>
        <%= button_to_function t('page.del_line'), "ItemFieldSubjectSelect2.remove(#{index})" -%>
      </div>
      </div>
    <% end %>
  </div>
</div><commit_msg>modified width of subject field<commit_after><script>
  var ItemFieldSubjectSelect2 = {
    // Subject select2 options
    subjectSelect2options: {
      multiple: false,
      minimumInputLength: 1,
      width: "200px",
      allowClear: true,
      placeholder: <%= raw t("activerecord.attributes.subject.term").to_json %>,
      formatNoMatches: function(term) {
        return "'" + term + "' " + <%= raw t("agent.search_nomatch").to_json %>; 
      },
      formatSearching: function() {
        return <%= raw t("agent.search_searching").to_json %>;
      },
      formatInputTooShort: function(term, minLength){
        return <%= raw t("agent.search_placeholder").to_json %>;
      },
      ajax: {
        url: "/subjects/search_name.json",
        dataType: 'json',
        data: function (term, page) {
            var currentNumber = $(this).attr('id').match(/\d+/);
            var subjectTypeId = $('#subjects_' + currentNumber + '_subject_type_id').val();
            return {
              subject_type_id: subjectTypeId,
              search_phrase: term,
            };
        },
        results: function (data, page) {
            return {results: data};
        },
      },
      initSelection: function(element, callback) {
        var id = $(element).val();
        if (id != "") {
          $.ajax("/subjects/search_name.json?subject_id=" + id, {
              dataType: "json"
         }).done(function(data) { callback(data); });
        }
      },
      createSearchChoice: function(term, data) {
        if ($(data).filter(function() {
          return this.text.localeCompare(term)===0; }).length===0) {
          return {id:term, text:term};
        }
      },
    },
    // SubjectType select2 options
    subjectTypeSelect2options: {
      width: "200px",
      matcher: function(term, text, opt) {
        return text.toUpperCase().indexOf(term.toUpperCase())==0
            || opt.attr("alt").toUpperCase().indexOf(term.toUpperCase())==0;
      },
    },
    currentNumber : <%= raw (@subjects.size).to_json %>,
    actionTemplate : ''
      + '<%= button_to_function t('page.add_line'), "ItemFieldSubjectSelect2.add()" %>'
      + '<%= button_to_function t('page.del_line'), "ItemFieldSubjectSelect2.remove(__count__)" %>',
    add : function () {
      var newField = $("<div/>").attr("id", "SUBJECT" + this.currentNumber).attr("class", 'field');
      var typeFieldId = $("div[id ^= 'SUBJECT']:first").find("select[id $= 'subject_type_id']").attr('id');
      var termFieldId = $("div[id ^= 'SUBJECT']:first").find("input[id $= 'subject_id']").attr('id');
      var termTranscriptionFieldId = $("div[id ^= 'SUBJECT']:first").find("input[id $= 'term_transcription']").attr('id');
      var cloneType = this.cloneField(typeFieldId);
      var cloneTerm = this.cloneField(termFieldId);
      var cloneTermTranscription = this.cloneField(termTranscriptionFieldId);
      var actionButton = this.actionTemplate.replace(/__count__/mg, this.currentNumber);
      
      var div1 = $("<div/>").append(cloneType);
      var div2 = $("<div/>").append(cloneTerm).append(cloneTermTranscription).append(actionButton);

      newField.append(div1).append(div2);
      
      // select2の設定
      cloneType.select2(this.subjectTypeSelect2options);
      cloneTerm.val('');
      cloneTerm.select2(ItemFieldSubjectSelect2.subjectSelect2options);
      cloneTermTranscription.val('');

      $("#subjects").append(newField);

      this.currentNumber += 1;
    },
    cloneField : function (fieldId) {
      return $('#' + fieldId).clone().attr({
          'id' : $('#' + fieldId).attr('id').replace(/_\d+_/, '_' + this.currentNumber + '_'),
          'name' : $('#' + fieldId).attr('name').replace(/\[\d+\]/, '[' + this.currentNumber + ']'),
      });
    },
    remove : function (trNum) {
      if($("div[id ^= 'SUBJECT']").length == 1) this.add();
      removeDivField('SUBJECT', trNum)
    }
  }

  $(document).ready(function() {
    $("select[id $= 'subject_type_id']").select2(ItemFieldSubjectSelect2.subjectTypeSelect2options);
    $("input[id $= 'subject_id']").select2(ItemFieldSubjectSelect2.subjectSelect2options);
  });
  $(document).on("select2-selecting select2-removed", ".subject", function(e){
    var targetId = e.target.id;
    var targetNumber = targetId.match(/_(\d+)_/);
    if (e.type == 'select2-removed'){
        $("#subjects_" + targetNumber[1] + "_term_transcription").val('');
    }
    else if(e.val == parseInt(e.val)){
        $("#subjects_" + targetNumber[1] + "_id").val(e.object.id);
        $("#subjects_" + targetNumber[1] + "_term").val(e.object.text);
        $("#subjects_" + targetNumber[1] + "_term_transcription").val(e.object.term_transcription);
    }
    else{
        $("#subjects_" + targetNumber[1] + "_id").val("");
        $("#subjects_" + targetNumber[1] + "_term").val(e.object.id);
        $("#subjects_" + targetNumber[1] + "_term_transcription").val(e.object.term_transcription);
    }
  });
</script>

<div class="row">
  <div><%= f.label t('activerecord.attributes.manifestation.subject') %></div>
  <div id="subjects">
    <% @subjects.each_with_index do |subject, index| -%>
      <div class='field' id="SUBJECT<%= index %>" >
        <div> 
          <%= select2_tag("subjects_#{index}_subject_type_id",
                          "subjects[][subject_type_id]",
                          @subject_types,
                          subject[:subject_type_id],
                          :width => 200, :select_attribute => :id, :display_attribute => :display_name) %>
        </div>
        <div>
          <%= text_field_tag "subjects[][subject_id]", subject[:subject_id], :id => "subjects_#{index}_subject_id", :class => "subject" %>
        <%= text_field_tag "subjects[][term_transcription]", 
          subject[:term_transcription], 
          :id => "subjects_#{index}_term_transcription", 
          :placeholder => t("activerecord.attributes.subject.term_transcription"),
          :style => 'width: 200px;' %>
        <%= button_to_function t('page.add_line'), "ItemFieldSubjectSelect2.add()" -%>
        <%= button_to_function t('page.del_line'), "ItemFieldSubjectSelect2.remove(#{index})" -%>
      </div>
      </div>
    <% end %>
  </div>
</div>
{'fraction_non_alphanumeric': 0.18721901091843288, 'fraction_numerical': 0.008831085420680796, 'mean_word_length': 2.891596376132459, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 85, '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': '5102864', 'n_tokens_mistral': 3962, 'n_tokens_neox': 3861, 'n_words': 571}