{% extends "layout.html" %}
{% from "macros.html" import render_field, form_tag %}

{% block content %}
  {% call form_tag(form) %}
    <div class="row">
      <div class="col-md-9 col-sm-8 col-xs-12">
        <h1>{{tile or ("Education" if section_type == "EDU" else "Funding" if section_type == "FUN" else "Peer Review" if
          section_type == "PRR" else "Work" if section_type == "WOR" else "Researcher Url" if section_type == "RUR" else
          "Other Name" if section_type == "ONR" else "Keyword" if section_type == "KWR" else
          "Address" if section_type == "ADR" else "Other IDs" if section_type == "EXR" else "Employment")}}</h1>
      </div>
    </div>
    <div class="row">
      <div class="col-md-6 col-sm-6 col-xs-12">
        {% if section_type in ["RUR", "ONR", "KWR", "ADR", "EXR"] %}
          {{ render_field(form.display_index) }}
          {{ render_field(form.visibility) }}
          {% if section_type == "EXR" %}
            {{ render_field(form.type) }}
          {% endif %}
        {% else %}
          {% if section_type == "WOR" %}
            {{ render_field(form.work_type) }}
            {{ render_field(form.title) }}
            {{ render_field(form.subtitle) }}
            {{ render_field(form.translated_title) }}
            {{ render_field(form.translated_title_language_code) }}
          {% else %}
            {{ render_field(form.org_name) }}
            {{ render_field(form.city) }}
            {{ render_field(form.state) }}
            {{ render_field(form.disambiguated_id) }}
          {% endif %}
          {{ render_field(form.country) }}
        {% endif %}

        {% if section_type in ["FUN", "PRR", "WOR"] %}
          {# Dynamically addded external IDs #}
          {% raw %}
          <div id="external-ids" class="box-white">
            <div class="form-group text-right">
              <button type="button" class="btn btn-success" @click="addEntry();">External Identifier Info (add at least one entry)</button>
            </div>
            <div v-for="(m, index) in externalids">

                <div class="form-group">
                  <label for="grant-type-{{idex}}">{{labelPrefix}} Type</label>
                  <select v-model="m.grant_type" class="form-control" name="grant_type" id="grant-type-{{index}}">
                    <option value="">-- Select --</option>
                    <option v-for="o in grantTypeList" v-bind:value="o.value">{{o.label}}</option>
                  </select>
                </div>

                <div class="form-group">
                  <label for="grant-number-{{idex}}">{{labelPrefix}}</label>
                  <input type="text" class="form-control" name="grant_number" v-model="m.grant_number" id="grant-number-{{index}}"/>
                </div>

                <div class="form-group">
                  <label for="grant-url-{{idex}}">{{labelPrefix}} Url</label>
                  <input type="text" class="form-control" name="grant_url" v-model="m.grant_url" id="grant-url-{{index}}"/>
                </div>

                <div class="form-group">
                  <label for="grant-relationship-{{idex}}">{{labelPrefix}} Relationship</label>
                  <select v-model="m.grant_relationship" class="form-control" name="grant_relationship" id="grant-relationship-{{index}}">
                    <option value="">-- Select --</option>
                    <option v-for="o in grantRelationshipList" v-bind:value="o.value">{{o.label}}</option>
                  </select>
                </div>

                <div class="form-group text-right">
                  <button type="button" class="btn btn-danger" @click="deleteEntry(index);">Remove</button>
                </div>

            </div>
          </div>
          {% endraw %}
        {% endif %}

      </div>
      <div class="col-md-6 col-sm-6 col-xs-12">
        {% if section_type == "WOR" %}
          {{ render_field(form.journal_title) }}
          {{ render_field(form.short_description) }}
          {{ render_field(form.citation_type) }}
          {{ render_field(form.citation) }}
          {{ render_field(form.publication_date) }}
          {{ render_field(form.url) }}
          {{ render_field(form.language_code) }}
        {% elif section_type == "PRR" %}
          {{ render_field(form.reviewer_role) }}
          {{ render_field(form.review_url) }}
          {{ render_field(form.review_type) }}
          {{ render_field(form.review_group_id) }}
          {{ render_field(form.subject_external_identifier_type) }}
          {{ render_field(form.subject_external_identifier_value) }}
          {{ render_field(form.subject_external_identifier_url) }}
          {{ render_field(form.subject_external_identifier_relationship) }}
          {{ render_field(form.subject_container_name) }}
          {{ render_field(form.subject_type) }}
          {{ render_field(form.subject_title) }}
          {{ render_field(form.subject_subtitle) }}
          {{ render_field(form.subject_translated_title) }}
          {{ render_field(form.subject_translated_title_language_code) }}
          {{ render_field(form.subject_url) }}
          {{ render_field(form.review_completion_date) }}
          {{ render_field(form.disambiguation_source) }}
        {% elif section_type == "RUR" %}
          {{ render_field(form.name) }}
          {{ render_field(form.value) }}
        {% elif section_type == "ADR" %}
          {{ render_field(form.country) }}
        {% elif section_type == "EXR" %}
          {{ render_field(form.value) }}
          {{ render_field(form.url) }}
          {{ render_field(form.relationship) }}
        {% elif section_type in ["ONR", "KWR"] %}
          {{ render_field(form.content) }}
        {% else %}
          {% if section_type == "FUN" %}
            {{ render_field(form.funding_title) }}
            {{ render_field(form.funding_translated_title) }}
            {{ render_field(form.translated_title_language) }}
            {{ render_field(form.funding_type) }}
            {{ render_field(form.funding_subtype) }}
            {{ render_field(form.funding_description) }}
            {{ render_field(form.total_funding_amount) }}
            {{ render_field(form.total_funding_amount_currency) }}
          {% else %}
            {{ render_field(form.department) }}
            {{ render_field(form.role) }}
          {% endif %}
          {{ render_field(form.start_date) }}
          {{ render_field(form.end_date) }}
          {{ render_field(form.disambiguation_source) }}
        {% endif %}
        <button type="submit" class="btn btn-primary" value="Save">Save</button>
        <a role="button" class="btn btn-default" href="{{_url}}">Cancel</a>
      </div>
    </div>
  {% endcall %}
{% endblock %}
{% if section_type in ["FUN", "PRR", "WOR"] %}
{% block scripts %}
  {{super()}}
  {%- if config.debug %}
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  {% else %}
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
  {% endif -%}

<script>
var vm = new Vue({
  el: "#external-ids",
  data: {
      labelPrefix: '{{"External ID" if section_type != "FUN" else "Funding Grant"}}',
      externalids: {{grant_data_list | safe}},
      grantTypeList: [
        {"label": "Agricola", "value": "agr"}, {"label": "Archival Resource Key Identifier", "value": "ark"},
        {"label": "ArXiv", "value": "arxiv"}, {"label": "Amazon Standard Identification Number", "value": "asin"},
        {"label": "ASIN top-level domain", "value": "asin-tld"}, {"label": "AuthenticusID", "value": "authenticusid"},
        {"label": "Bibcode", "value": "bibcode"}, {"label": "Chinese Biological Abstracts", "value": "cba"},
        {"label": "Ciência-IUL Identifier", "value": "cienciaiul"}, {"label": "CiteSeer", "value": "cit"},
        {"label": "CiteExplore submission", "value": "ctx"}, {"label": "German National Library identifier", "value": "dnb"},
        {"label": "Digital object identifier", "value": "doi"}, {"label": "Scopus Identifier", "value": "eid"},
        {"label": "EThOS Peristent ID", "value": "ethos"}, {"label": "grant number", "value": "grant_number"},
        {"label": "Handle", "value": "handle"}, {"label": "Chinese Biological Abstracts", "value": "cba"},
        {"label": "NHS Evidence", "value": "hir"}, {"label": "International Standard Book Number", "value": "isbn"},
        {"label": "International Standard Serial Number. Includes print and electronic ISSN", "value": "issn"},
        {"label": "Jahrbuch über die Fortschritte der Mathematik", "value": "jfm"}, {"label": "JSTOR abstract", "value": "jstor"},
        {"label": "KoreaMed Unique Identifier", "value": "kuid"}, {"label": "Mathematical Reviews", "value": "mr"},
        {"label": "Online Computer Library Center", "value": "oclc"}, {"label": "Open Library", "value": "ol"},
        {"label": "Office of Scientific and Technical Information", "value": "osti"}, {"label": "Other identifier type", "value": "other-id"},
        {"label": "Patent number", "value": "pat"}, {"label": "Protein Data Bank identifier", "value": "pdb"},
        {"label": "PubMed Central article number", "value": "pmc"}, {"label": "PubMed Unique Identifier", "value": "pmid"},
        {"label": "Request for Comments", "value": "rfc"}, {"label": "Research Resource IDentifier", "value": "rrid"},
        {"label": "Non-standard ID from work data source", "value": "source-work-id"}, {"label": "Social Science Research Network", "value": "ssrn"},
        {"label": " URI", "value": "uri"}, {"label": "URN", "value": "urn"}, {"label": "Web of Science™ identifier", "value": "wosuid"},
        {"label": "Zentralblatt MATH", "value": "zbl"}],
      grantRelationshipList: [{"label": "Part Of", "value": "PART_OF"}, {"label": "Self", "value": "SELF"}]
  },
  methods: {
    addEntry: function() {
      this.externalids.unshift({grant_type: "", grant_relationship: ""});
      return false;
    },
    deleteEntry: function(index) {
      if (window.confirm("Do you want to delete?")) {
          this.externalids.splice(index, 1);
          return false;
      }
    }
  }
});
</script>
{% endblock %}
{%endif%}
