{{ define "eiffel.elicitation.form" }} {{ $rules := .Data.Form.Template.Rules }} {{ $displayTypes := .Data.Form.DisplayTypes }} {{ $parsingResult := .Data.Form.ParsingResult }} {{ $segments := .Data.Form.SegmentMap }}

{{ t "eiffel.elicitation.form.title" }}

{{/* TODO beautify this code and improve readability - good templating is hard :/ */}} {{ $first := true }} {{ range $i, $ruleName := .Data.Form.Variant.Rules }} {{ $rule := index $rules . }} {{ $displayType := index $displayTypes $ruleName }} {{ $col := "col-6" }} {{ if eq $rule.Size "small" }} {{ $col = "col-3" }} {{ else if eq $rule.Size "medium" }} {{ $col = "col-6" }} {{ else if eq $rule.Size "large" }} {{ $col = "col-9" }} {{ else if eq $rule.Size "full" }} {{ $col = "col-12" }} {{ end }} {{ $violations := "" }} {{ if $parsingResult }} {{ $violations = $parsingResult.ViolationsForRule $ruleName }} {{ end }} {{ $displayName := $rule.Name }} {{ if not $rule.Optional }} {{ $displayName = printf "%s %s" $displayName "*" }} {{ end }} {{ $inputName := printf "segment-%s" $ruleName }}
{{ if or (eq $displayType "input-text") (eq $displayType "text") (eq $displayType "input-single-select") }} {{ $optionalText := and (eq $displayType "text") $rule.Optional }} {{ $nonOptionalText := and (eq $displayType "text") (not $optionalText) }}
i {{/* this has to be before the input, otherwise the border radius on the group will not match */}} {{ if eq $displayType "input-single-select"}} {{ range $i, $option := $rule.Value }} {{ end }} {{ end }} {{ if $nonOptionalText }} {{ end }} {{ if or (not $segments) (not (index $segments $ruleName)) }} {{ else }} {{ end }} {{ if $violations }}
{{ range $i, $violation := $violations }} {{ tryTranslate $violation }} {{ end }}
{{ end }}
{{ else if eq $displayType "input-textarea" }}
i {{ if or (not $segments) (not (index $segments $ruleName)) }} {{ else }} {{ end }} {{ if $violations }}
{{ range $i, $violation := $violations }} {{ tryTranslate $violation }} {{ end }}
{{ end }}
{{ end }}
{{ $first = false}} {{ end }}
{{ range .Data.Successes }}
{{ end }} {{ range .Data.AllViolations }}
{{ end }} {{ range .Data.AllValidationErrors }}
{{ end }} {{ if .Data.Form.ParsingResult }} {{ if not .Data.Form.ParsingResult.Ok }}
{{ end }} {{ range .Data.Form.ParsingResult.Warnings }}
{{ end }} {{ range .Data.Form.ParsingResult.Notices }}
{{ end }} {{ if .Data.Form.ParsingResult.Requirement }} {{ if .Data.Form.ParsingResult.Ok }}
{{ end }} {{ end }} {{ end }}
{{ end }}