{%extends "base.html"%}
{%from "flash_messages.html" import flash_messages %}

{%block title%}Upload R/qtl2 Bundle{%endblock%}

{%block contents%}
<h2 class="heading">Phenotype(ProbeSet) Study</h2>

<div class="row">
  <p>The R/qtl2 bundle you uploaded contains (a) "<strong>pheno</strong>"
    file(s). This data needs to be organised under a study.</p>
  <p>In this page, you can either select from a existing dataset:</p>

  <form method="POST"
        action="{{url_for('expression-data.rqtl2.select_probeset_study',
	        species_id=species.SpeciesId, population_id=population.Id)}}"
        id="frm:select-probeset-study">
    <legend class="heading">Select from existing ProbeSet studies</legend>
    {{flash_messages("error-rqtl2-select-probeset-study")}}

    <input type="hidden" name="species_id" value="{{species.SpeciesId}}" />
    <input type="hidden" name="population_id"
	   value="{{population.InbredSetId}}" />
    <input type="hidden" name="rqtl2_bundle_file"
	   value="{{rqtl2_bundle_file}}" />
    <input type="hidden" name="geno-dataset-id" value="{{geno_dataset.Id}}" />
    <input type="hidden" name="tissueid" value="{{tissue.Id}}" />

    <div>
      <label for="select:probe-study" class="form-label">Study</label>
      <select id="select:probe-study"
	      name="probe-study-id"
	      required="required"
              aria-describedby="help-select-probeset-study"
	      {%if studies | length == 0%}disabled="disabled"{%endif%}
              class="form-control">
        <option value="">Select a study</option>
        {%for study in studies%}
        <option value={{study.Id}}>
	  {{study.Name}}
	  {%if study.FullName%}
	  -- ({{study.FullName}})
	  {%endif%}
        </option>
        {%endfor%}
      </select>
      <small id="help-select-probeset-study" class="form-text text-muted">
        Select from existing ProbeSet studies.
      </small>
    </div>

    <button type="submit" class="btn btn-primary">select study</button>
  </form>
</div>

<div class="row">
  <p style="color:#FE3535; padding-left:20em; font-weight:bolder;">OR</p>
</div>

<div class="row">

  <p>Create a new ProbeSet dataset below:</p>

  <form method="POST"
        action="{{url_for('expression-data.rqtl2.create_probeset_study',
	        species_id=species.SpeciesId, population_id=population.Id)}}"
        id="frm:create-probeset-study">
    <legend class="heading">Create new ProbeSet study</legend>

    {{flash_messages("error-rqtl2-create-probeset-study")}}

    <input type="hidden" name="species_id" value="{{species.SpeciesId}}" />
    <input type="hidden" name="population_id"
	   value="{{population.InbredSetId}}" />
    <input type="hidden" name="rqtl2_bundle_file"
	   value="{{rqtl2_bundle_file}}" />
    <input type="hidden" name="geno-dataset-id" value="{{geno_dataset.Id}}" />
    <input type="hidden" name="tissueid" value="{{tissue.Id}}" />

    <div>
      <label for="select:platform" class="form-label">Platform</label>
      <select id="select:platform"
	      name="platformid"
	      required="required"
              aria-describedby="help-select-platform"
	      {%if platforms | length == 0%}disabled="disabled"{%endif%}
              class="form-control">
        <option value="">Select a platform</option>
        {%for platform in platforms%}
        <option value="{{platform.GeneChipId}}">
	  {{platform.GeneChipName}} ({{platform.Name}})
        </option>
        {%endfor%}
      </select>
      <small id="help-select-platform" class="form-text text-muted">
        Select from a list of known genomics platforms.
      </small>
    </div>

    <div class="form-group">
      <label for="txt:studyname" class="form-label">Study name</label>
      <input type="text" id="txt:studyname" name="studyname"
	     placeholder="Name of the study. (Required)"
	     required="required"
	     maxlength="100"
             class="form-control" />
      <span class="form-text text-muted" id="help-study-name">
        Provide a name for the study.</span>
    </div>

    <div class="form-group">
      <label for="txt:studyfullname" class="form-label">Full Study Name</label>
      <input type="text"
             id="txt:studyfullname"
             name="studyfullname"
	     placeholder="Longer name of the study. (Optional)"
	     maxlength="100"
             class="form-control" />
      <span class="form-text text-muted" id="help-study-full-name">
        Provide a longer, more descriptive name for the study. This is optional
        and you can leave it blank.
      </span>
    </div>

    <div class="form-group">
      <label for="txt:studyshortname" class="form-label">Short Study Name</label>
      <input type="text"
             id="txt:studyshortname"
             name="studyshortname"
	     placeholder="Shorter name of the study. (Optional)"
	     maxlength="100"
             class="form-control" />
      <span class="form-text text-muted" id="help-study-short-name">
        Provide a shorter name for the study. This is optional and you can leave
        it blank.
      </span>
    </div>

    <button type="submit" class="btn btn-primary">create study</button>
  </form>
</div>

{%endblock%}