{{ define "content" }}

<div class="container">

  {{if .Options.Get "update"}}
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="/activities?{{query "tpl_layout" "base" "tpl_content" "activities"}}">Attività</a></li>
      <li class="breadcrumb-item active"><a href="#">Aggiorna l'attività</a></li>
    </ol>
  </nav>
  {{else}}
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="/activities?{{query "tpl_layout" "base" "tpl_content" "activities"}}">Attività</a></li>
      <li class="breadcrumb-item active"><a href="#">Aggiungi</a></li>
    </ol>
  </nav>
  {{end}}

  {{if .Options.Get "update"}}
  <div class="karmen-info-header">
    <div class="row">
      <div class="col-md-8">
	<h1>Aggiorna l'attività</h1>
      </div>
      <div class="col-md-4">
	<a href="/activities/{{.Data.Activity.ID}}/delete"
	   data-url="/activities/{{.Data.Activity.ID}}/delete"
	   class="btn btn-danger karmen-ajax-delete float-right">
	  <span class="fa fa-trash" aria-hidden="true"></span>
	  Elimina
	</a>
      </div>
    </div>
  </div>
  
  {{else}}
  <h1 class="karmen-info-header">Crea una nuova attività</h1>
  {{end}}

  {{if .Options.Get "update"}}
  <form id="form_activities_add_update" action="/activities/{{.Data.Activity.ID}}/update" method="POST" role="form" class="needs-validation">
  {{else}}
  <form id="form_activities_add_update" action="/activities/add/" method="POST" role="form" class="needs-validation">
  {{end}}
   
    <div class="form-group">
      <label class="control-label" for="subject_id">Materia</label>
      <select name="subject_id" class="form-control selectpicker" id="subject_id" placeholder="Materia" data-live-search="true" form="form_activities_add_update" title="Seleziona il nome della materia" data-dropup-auto="false" required>
	<option value="0"></option>
  	{{range $subject := .Data.AllSubjects}}
	{{if $.Options.Get "update"}}
  	<option
	   value="{{$subject.ID}}"
	   {{index $.Data.SelectedSubject $subject.ID}}>{{$subject.Name}}
	</option>
	{{else}}
  	<option value="{{$subject.ID}}">{{$subject.Name}}</option>
	{{end}}
  	{{end}}
      </select>
    </div>
    
    <div class="form-group">
      <label class="control-label" for="class_id">Classe</label>
      <select name="class_id" class="form-control selectpicker" id="class_id" placeholder="Classe" data-live-search="true" form="form_activities_add_update" title="Seleziona la classe" data-dropup-auto="false">
	<option value="0"></option>
  	{{range $class := .Data.AllClasses}}
	{{if $.Options.Get "update"}}
  	<option
	   value="{{$class.ID}}"
	   {{index $.Data.SelectedClass $class.ID}}>{{$class.Name}}
	</option>
	{{else}}
  	<option value="{{$class.ID}}">{{$class.Name}}</option>
	{{end}}
  	{{end}}
      </select>
    </div>

    <div class="form-group">
      <label class="control-label" for="student_id">Studente</label>
      <select name="student_id" class="form-control selectpicker" id="student_id" placeholder="Docente" data-live-search="true" form="form_activities_add_update" title="Seleziona il nome del docente" data-dropup-auto="false">
	<option value="0"></option>
  	{{range $student := .Data.AllStudents}}
	{{if $.Options.Get "update"}}
  	<option
	  value="{{$student.ID}}"
	  {{index $.Data.SelectedStudent $student.ID}}>{{$student.Name}} {{$student.Surname}}
	</option>
	{{else}}
  	<option value="{{$student.ID}}">{{$student.Name}} {{$student.Surname}}</option>
	{{end}}
  	{{end}}
      </select>
    </div>

    <div class="form-group">
      <label class="control-label" for="teacher_id">Docente</label>
      <select name="teacher_id" class="form-control selectpicker" id="teacher_id" placeholder="Docente" data-live-search="true" form="form_activities_add_update" title="Seleziona il nome del docente" data-dropup-auto="false">
	<option value="0"></option>
  	{{range $teacher := .Data.AllTeachers}}
	{{if $.Options.Get "update"}}
  	<option
	   value="{{$teacher.ID}}"
	   {{index $.Data.SelectedTeacher $teacher.ID}}>{{$teacher.Name}} {{$teacher.Surname}}
	</option>
	{{else}}
  	<option value="{{$teacher.ID}}">{{$teacher.Name}} {{$teacher.Surname}}</option>
	{{end}}
  	{{end}}
      </select>
    </div>

    <div class="form-group">
      <label class="control-label" for="supply_teacher_id">Docente supplente</label>
      <select name="supply_teacher_id" class="form-control selectpicker" id="supply_teacher_id" placeholder="Docente supplente" data-live-search="true" form="form_activities_add_update" title="Seleziona il nome del docente supplente" data-dropup-auto="false">
	<option value="0"></option>
  	{{range $supplyTeacher := .Data.AllTeachers}}
	{{if $.Options.Get "update"}}
  	<option
	   value="{{$supplyTeacher.ID}}"
	   {{index $.Data.SelectedSupplyTeacher $supplyTeacher.ID}}>{{$supplyTeacher.Name}} {{$supplyTeacher.Surname}}
	</option>
	{{else}}
  	<option value="{{$supplyTeacher.ID}}">{{$supplyTeacher.Name}} {{$supplyTeacher.Surname}}</option>
	{{end}}
  	{{end}}
      </select>
    </div>


    <div class="form-group">
      <label class="control-label" for="hours">Numero di ore</label>
      <input class="form-control" min="0" type="number" name="hours" id="hours" {{if .Options.Get "update"}}value="{{.Data.Activity.Hours}}"{{end}} required>
    </div>

    
    <div class="form-group">
      <div class="form-check">
        <input type="checkbox" name="GroupActivity" class="form-check-input" id="activity_group_activity" {{if .Options.Get "update"}}{{if .Data.Activity.GroupActivity}}checked{{end}}{{end}}>
        <label class="form-check-label" for="activity_group_activity">Attività di gruppo</label>
        <small id="activity_group_help_box" class="form-text text-muted">
          Spuntare la casella sopra nel caso di attività che coinvolgono più studenti contemporaneamente.
        </small>
      </div>
    </div>

    <div class="form-group">
      <label class="control-label" for="group_activity_hours">Numero di ore dell'attività di gruppo</label>
      <input class="form-control" min="0" type="number" name="group_activity_hours" id="group_activity_hours" {{if .Options.Get "update"}}value="{{.Data.Activity.GroupActivityHours}}"{{end}}>
      <small id="activity_group_hours_help_box" class="form-text text-muted">
        Indicare il numero totale di ore che il docente spende nell'attività di gruppo.
      </small>        
    </div>


    <div class="form-group">
      <button type="submit" class="btn btn-primary">Salva</button>
      {{if .Options.Get "update"}}
      <a href="/activities/{{.Data.Activity.ID}}?{{query "tpl_layout" "base" "tpl_content" "activities_show"}}" class="btn btn-default">Annulla</a>
      {{else}}
      <a href="/activities?{{query "tpl_layout" "base" "tpl_content" "activities"}}" class="btn btn-default">Annulla</a>
      {{end}}
    </div>
    
  </form>

</div>

{{ end }}
