{{ define "content" }}

<div class="container">

  {{if .Options.Get "update"}}
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="/subjects">Materie</a></li>
      <li class="breadcrumb-item"><a href="/subjects/{{.Data.Subject.ID}}">{{.Data.Subject.Name}}</a></li>
      <li class="breadcrumb-item active"><a href="#">Aggiorna materia</a></li>
    </ol>
  </nav>
  {{else}}
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="/subjects">Materie</a></li>
      <li class="breadcrumb-item active"><a href="#">Aggiungi</a></li>
    </ol>
  </nav>
  {{end}}

  {{if .Options.Get "update"}}
  <h1 class="karmen-info-header">Aggiorna la materia "{{.Data.Subject.Name}}"</h1>
  {{else}}
  <h1 class="karmen-info-header">Crea una nuova materia</h1>
  {{end}}

  {{if .Options.Get "update"}}
  <form id="form_subjects_add_update" action="/subjects/{{.Data.Subject.ID}}/update" method="POST" role="form" class="needs-validation">
  {{else}}
  <form id="form_subjects_add_update" action="/subjects/add/" method="POST" role="form" class="needs-validation">
  {{end}}  
    
    <div class="form-group">
      <label class="control-label" for="subject_name">Nome</label>
      <input type="text" name="Name" class="form-control" id="subject_name" placeholder="Nome" {{if .Options.Get "update"}} value="{{.Data.Subject.Name}}" {{end}} required>
    </div>

    <div class="form-group">
      <label class="control-label" for="subject_alias">Nome alternativo</label>
      <input type="text" name="Alias" class="form-control" id="subject_alias" placeholder="Nome alternativo" {{if .Options.Get "update"}} value="{{.Data.Subject.Alias}}" {{end}} required>
    </div>

    <div class="form-group">
      <label class="control-label" for="department_id">Dipartimento</label>
      <select name="department_id" class="form-control selectpicker" id="department_id" placeholder="Dipartimento" data-live-search="true" form="form_subjects_add_update" title="Seleziona il nome del dipartimento" data-dropup-auto="false">
	<option value="0"></option>
  	{{range $department := .Data.AllDepartments}}
	{{if $.Options.Get "update"}}
  	<option
	   value="{{$department.ID}}"
	   {{index $.Data.SelectedDepartment $department.ID}}>{{$department.Name}}
	</option>
	{{else}}
  	<option value="{{$department.ID}}">{{$department.Name}}</option>
	{{end}}
  	{{end}}
      </select>
    </div>
	
    <div class="form-group">
      <button type="submit" class="btn btn-primary">Salva</button>
      {{if .Options.Get "update"}}
      <a href="/subjects/{{.Data.Subject.ID}}?{{query "tpl_layout" "base" "tpl_content" "subjects_show"}}" class="btn btn-default">Annulla</a>
      {{else}}
      <a href="/subjects?{{query "tpl_layout" "base" "tpl_content" "subjects"}}" class="btn btn-default">Annulla</a>
      {{end}}
    </div>
    
  </form>

  
</div>

{{ end }}
