{{ define "content" }}

<div class="container">

  {{$update := .Options.Get "update"}}

  {{if $update}}
  {{template "breadcrumb" toSlice "Documenti" (all "Document") (.Data|string) (.Data.ID|show "Document") "Aggiorna" "current"}}
  {{else}}
  {{template "breadcrumb" toSlice "Documenti" (all "Document") "Aggiungi" "current"}}
  {{end}}
  
  {{template "add_update_header" dict "update" $update "addTitle" "Crea nuovo documento" "updateTitle" (printf "Aggiorna documento %s" (.Data|string))}}

  {{$form := "form_documents_add_update"}}
  <form
    class="needs-validation"
    action="{{if $update}}{{.Data.ID|update "Document"}}{{else}}{{create "Document"}}{{end}}"
    method="POST"
    role="form"
    id={{$form}}>

    {{$options := ` { name: "Name",id: "document_name",label: "Nome",placeholder: "Nome",type: "text",required: "true"} `}}
    {{template "input" dict "options" ($options|yaml) "value" (.Data|field "Name") "update" $update}}

    {{$options := ` { name: "CloudPath",id: "document_cloud_path",label: "Cartella di lavoro remota",placeholder: "Documents/",type: "text",required: "true"} `}}
    {{template "input" dict "options" ($options|yaml) "value" (.Data|field "CloudPath") "update" $update}}

    {{$options := `
    name: "KeepArtifacts"
    id: "document_keep_artifacts"
    label: "Mantieni gli artefatti"
    formClass: "form-group form-check"
    help: "Se selezionato carica sulla cartella remota gli artefatti derivati dalla produzione del documento (es: markdown, odt, etc.). "
    `}}
    {{template "checkbox" dict "options" ($options|yaml) "value" (.Data|field "KeepArtifacts") "update" $update}}

    {{$options := `
    name: "generator_type_id"
    id: "generator_type_id"
    label: "Tipo di generatore"
    title: "Seleziona il tipo di generatore"
    `}}
    {{template "select" dict "options" ($options|yaml) "data" (.Data|field "AllGeneratorTypes") "selected" (.Data|field "SelectedGeneratorType") "update" $update "form" $form}}
    
    {{ $options := ` { cancelTitle: "Annulla", saveTitle: "Salva", model: "Document"} ` }}
    {{template "submit_cancel_buttons" dict "options" ($options|yaml) "id" (.Data|field "ID") "update" $update}}
  
  </form>
  
</div>

{{ end }}
