<commit_before>var sharedSchema = new SimpleSchema({
  "description": {
    type: String,
  },
  // "study_label": {
  //   type: String,
  //
  // }
});

Template.optionsAndSubmit.helpers({
  classifySubmissionType: function () {
    var documentTypes = getDocumentTypes(this._id);

    if (documentTypes.length === 1) {
      return documentTypes[0];
    }

    return null;
  },
  superpathwaySchema: function () {
    return new SimpleSchema([
      sharedSchema,
      {
        "update_or_create": {
          type: String,
          label: "Update or create",
          allowedValues: ["update", "create"],
        },
      },
      Superpathways.simpleSchema().pick(['name']),
    ]);
  },
  mutationSchema: function () {
    return new SimpleSchema([
      sharedSchema,
      Mutations.simpleSchema().pick([
        "biological_source",
        "mutation_impact_assessor",
      ]),
    ]);
  },
});

Template.submissionOptions.helpers({
  currentOptions: function () {
    return Template.instance().parent().data.options;
  },
});

function getUpdateOrCreate() {
  return AutoForm.getFieldValue("update_or_create", "submission-options");
}

Template.superpathwayFields.helpers({
  updateCreateSelected: function () {
    return getUpdateOrCreate() !== undefined;
  },
  selectOrText: function () {
    if (getUpdateOrCreate() === "update") {
      return "select";
    } else {
      return "text";
    }
  },
  superpathwayOptions: function () {
    var sortedNames = _.pluck(Superpathways.find({}).fetch(), "name").sort();

    var uniqueNames = [];
    _.each(sortedNames, function (value, index) {
      if (index === 0 || sortedNames[index - 1] !== value) {
        uniqueNames.push(value);
      }
    });

    return _.map(uniqueNames, function (value) {
      return {
        "label": value,
        "value": value,
      };
    });
  },
});

Template.validateAndSubmit.events({
  "click .save-for-later": function (event, instance) {
    event.preventDefault();
    WranglerSubmissions.update(instance.parent().parent().data._id, {
      $set: {
        "options": AutoForm.getFormValues("submission-options").insertDoc
      }
    });
  },
  "click .reset-options": function (event, instance) {
    event.preventDefault();
    WranglerSubmissions.update(instance.parent().parent().data._id, {
      $set: {
        "options": {}
      }
    });
    AutoForm.resetForm("submission-options");
  },
  "click .validate-and-submit": function (event, instance) {
    event.preventDefault();
    if (AutoForm.validateForm("submission-options")) {
      WranglerSubmissions.update(instance.data._id, {
        $set: {
          "options": AutoForm.getFormValues("submission-options").insertDoc
        }
      });

      Meteor.call("submitSubmission", instance.parent().parent().data._id);
    }
  },
});<commit_msg>fixed bug<commit_after>var sharedSchema = new SimpleSchema({
  "description": {
    type: String,
  },
  // "study_label": {
  //   type: String,
  //
  // }
});

Template.optionsAndSubmit.helpers({
  classifySubmissionType: function () {
    var documentTypes = getDocumentTypes(this._id);

    if (documentTypes.length === 1) {
      return documentTypes[0];
    }

    return null;
  },
  superpathwaySchema: function () {
    return new SimpleSchema([
      sharedSchema,
      {
        "update_or_create": {
          type: String,
          label: "Update or create",
          allowedValues: ["update", "create"],
        },
      },
      Superpathways.simpleSchema().pick(['name']),
    ]);
  },
  mutationSchema: function () {
    return new SimpleSchema([
      sharedSchema,
      Mutations.simpleSchema().pick([
        "biological_source",
        "mutation_impact_assessor",
      ]),
    ]);
  },
});

Template.submissionOptions.helpers({
  currentOptions: function () {
    return Template.instance().parent().data.options;
  },
});

function getUpdateOrCreate() {
  return AutoForm.getFieldValue("update_or_create", "submission-options");
}

Template.superpathwayFields.helpers({
  updateCreateSelected: function () {
    return getUpdateOrCreate() !== undefined;
  },
  selectOrText: function () {
    if (getUpdateOrCreate() === "update") {
      return "select";
    } else {
      return "text";
    }
  },
  superpathwayOptions: function () {
    var sortedNames = _.pluck(Superpathways.find({}).fetch(), "name").sort();

    var uniqueNames = [];
    _.each(sortedNames, function (value, index) {
      if (index === 0 || sortedNames[index - 1] !== value) {
        uniqueNames.push(value);
      }
    });

    return _.map(uniqueNames, function (value) {
      return {
        "label": value,
        "value": value,
      };
    });
  },
});

Template.validateAndSubmit.events({
  "click .save-for-later": function (event, instance) {
    event.preventDefault();
    WranglerSubmissions.update(instance.parent().parent().data._id, {
      $set: {
        "options": AutoForm.getFormValues("submission-options").insertDoc
      }
    });
  },
  "click .reset-options": function (event, instance) {
    event.preventDefault();
    WranglerSubmissions.update(instance.parent().parent().data._id, {
      $set: {
        "options": {}
      }
    });
    AutoForm.resetForm("submission-options");
  },
  "click .validate-and-submit": function (event, instance) {
    event.preventDefault();
    if (AutoForm.validateForm("submission-options")) {
      var submissionId = instance.parent().parent().data._id;
      WranglerSubmissions.update(submissionId, {
        $set: {
          "options": AutoForm.getFormValues("submission-options").insertDoc
        }
      });

      Meteor.call("submitSubmission", submissionId);
    }
  },
});
{'fraction_non_alphanumeric': 0.1601685985247629, 'fraction_numerical': 0.0014049877063575693, 'mean_word_length': 2.8119143239625166, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 3, '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': '6612062', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1696, 'n_words': 280}