{%extends "populations/base.html"%}
{%from "flash_messages.html" import flash_all_messages%}
{%from "species/macro-select-species.html" import select_species_form%}
{%from "species/macro-display-species-card.html" import display_species_card%}

{%block title%}Create Population{%endblock%}

{%block pagetitle%}Create Population{%endblock%}

{%block lvl3_breadcrumbs%}
<li {%if activelink=="create-population"%}
    class="breadcrumb-item active"
    {%else%}
    class="breadcrumb-item"
    {%endif%}>
  <a href="{{url_for('species.populations.create_population',
           species_id=species.SpeciesId)}}">create population</a>
</li>
{%endblock%}


{%block contents%}
<div class="row">
  <p>The population is the next hierarchical node under Species. Data is grouped under a specific population, under a particular species.</p>
  <p>
    This page enables you to create a new population, in the case that you
    cannot find the population you want in the
    <a
      href="{{url_for('species.populations.list_species_populations',
            species_id=species.SpeciesId)}}"
      title="Population for species '{{species.FullName}}'.">
      list of species populations
    </a>
  </p>
</div>

<div class="row">
  <form method="POST"
        action="{{url_for('species.populations.create_population',
                species_id=species.SpeciesId)}}">

    <legend>Create Population</legend>

    {{flash_all_messages()}}

    <div {%if errors.population_fullname%}
         class="form-group has-error"
         {%else%}
         class="form-group"
         {%endif%}>
      <label for="txt-population-fullname" class="form-label">Full Name</label>
      {%if errors.population_fullname%}
      <small class="form-text text-danger">{{errors.population_fullname}}</small>
      {%endif%}
      <input type="text"
             id="txt-population-fullname"
             name="population_fullname"
             required="required"
             minLength="3"
             maxLength="100"
             value="{{error_values.population_fullname or ''}}"
             class="form-control" />
      <small class="form-text text-muted">
        <p>
          This is a descriptive name for your population &mdash; useful for
          humans.
        </p>
      </small>
    </div>

    <div {%if errors.population_name%}
         class="form-group has-error"
         {%else%}
         class="form-group"
         {%endif%}>
      <label for="txt-population-name" class="form-label">Name</label>
      {%if errors.population_name%}
      <small class="form-text text-danger">{{errors.population_name}}</small>
      {%endif%}
      <input type="text"
             id="txt-population-name"
             name="population_name"
             required="required"
             minLength="3"
             maxLength="30"
             value="{{error_values.population_name or ''}}"
             class="form-control" />
      <small class="form-text text-muted">
        <p>
          This is a short representative, but constrained name for your
          population.
          <br />
          The field will only accept letters ('A-Za-z'), numbers (0-9), hyphens
          and underscores. Any other character will cause the name to be
          rejected.
        </p>
      </small>
    </div>

    <div class="form-group">
      <label for="txt-population-code" class="form-label">Population Code</label>
      <input type="text"
             id="txt-population-code"
             name="population_code"
             maxLength="5"
             minLength="3"
             value="{{error_values.population_code or ''}}"
             class="form-control" />
      <small class="form-text text-muted">
        <p class="text-danger">
          <span class="glyphicon glyphicon-exclamation-sign"></span>
          What is this field is for? Confirm with Arthur and the rest.
        </p>
      </small>
    </div>

    <div {%if errors.population_description%}
         class="form-group has-error"
         {%else%}
         class="form-group"
         {%endif%}>
      <label for="txt-population-description" class="form-label">
        Description
      </label>
      {%if errors.population_description%}
      <small class="form-text text-danger">{{errors.population_description}}</small>
      {%endif%}
      <textarea
        id="txt-population-description"
        name="population_description"
        required="required"
        class="form-control"
        rows="5">{{error_values.population_description or ''}}</textarea>
      <small class="form-text text-muted">
        <p>
          This is a more detailed description for your population. This is
          useful to communicate with other researchers some details regarding
          your population, and what its about.
          <br />
          Put, here, anything that describes your population but does not go
          cleanly under metadata.
        </p>
      </small>
    </div>

    <div {%if errors.population_family%}
         class="form-group has-error"
         {%else%}
         class="form-group"
         {%endif%}>
      <label for="select-population-family" class="form-label">Family</label>
      <select id="select-population-family"
              name="population_family"
              class="form-control"
              required="required">
        <option value="">Please select a family</option>
        {%for family in families%}
        <option value="{{family}}"
                {%if error_values.population_family == family%}
                selected="selected"
                {%endif%}>{{family}}</option>
        {%endfor%}
      </select>
      <small class="form-text text-muted">
        <p>
          This is a rough grouping of the populations in GeneNetwork into lists
          of common types of populations.
        </p>
      </small>
    </div>

    <div {%if errors.population_mapping_method_id%}
         class="form-group has-error"
         {%else%}
         class="form-group"
         {%endif%}>
      <label for="select-population-mapping-methods"
             class="form-label">Mapping Methods</label>

      <select id="select-population-mapping-methods"
              name="population_mapping_method_id"
              class="form-control"
              required="required">
        <option value="">Select appropriate mapping methods</option>
        {%for mmethod in mapping_methods%}
        <option value="{{mmethod.id}}"
                {%if error_values.population_mapping_method_id == mmethod.id%}
                selected="selected"
                {%endif%}>{{mmethod.value}}</option>
        {%endfor%}
      </select>

      <small class="form-text text-muted">
        <p>Select the mapping methods that your population will support.</p>
      </small>
    </div>

    <div {%if errors.population_genetic_type%}
         class="form-group has-error"
         {%else%}
         class="form-group"
         {%endif%}>
      <label for="select-population-genetic-type"
             class="form-label">Genetic Type</label>
      <select id="select-population-genetic-type"
              name="population_genetic_type"
              class="form-control">
        <option value="">Select proper genetic type</option>
        {%for gtype in genetic_types%}
        <option value="{{gtype}}"
                {%if error_values.population_genetic_type == gtype%}
                selected="selected"
                {%endif%}>{{gtype}}</option>
        {%endfor%}
      </select>
      <small class="form-text text-muted text-danger">
        <p>
          <span class="glyphicon glyphicon-exclamation-sign"></span>
          This might be a poorly named field.
        </p>
        <p>
          It probably has more to do with the mating crosses/crossings used to
          produce the individuals in the population. I am no biologist, however,
          and I'm leaving this here to remind myself to confirm this.
        </p>
        <p>
          I still don't know what riset is.<br />
          … probably something to do with Recombinant Inbred Strains
        </p>
        <p>
          Possible resources for this:
          <ul>
            <li>https://www.informatics.jax.org/silver/chapters/3-2.shtml</li>
            <li>https://www.informatics.jax.org/silver/chapters/9-2.shtml</li>
          </ul>
        </p>
      </small>
    </div>

    <div class="form-group">
      <input type="submit"
             value="create population"
             class="btn btn-primary"  />
    </div>

  </form>
</div>
{%endblock%}

{%block sidebarcontents%}
{{display_species_card(species)}}
{%endblock%}