BrainMinder/assets/templates/items/fields.tmpl
2024-12-18 18:01:59 +01:00

40 lines
2.1 KiB
Cheetah

{{ define "items:fields" }}
{{ range (index .FieldsSection .uisection) }}
{{ $field := .}}
{{ $values := (index $.FieldsValues .Type_field_id)}}
{{ if eq .Is_multiple 1}}
<fieldset>
<label>{{ .Title }}</label>
<div id="fields-{{ .Type_field_id }}">
{{ $g_counter := 0 }}
{{ range $counter, $value := $values}}
<input type="hidden" id="FieldsValuesToRemove-{{$field.Type_field_id}}-{{$counter}}" name="FieldsValuesToRemove-{{$field.Type_field_id}}-{{$counter}}" value="0"/>
<div class="field">
<div id="FieldsValues-{{$field.Type_field_id}}-{{$counter}}" class="field-value">{{ field_widget $field.Widget $field.Type_field_id $counter "" $value $field.Valid_values ""}}</div>
<div class="field-buttons">
<button id="Delete-{{$field.Type_field_id}}-{{$counter}}" class="delete" type="button" _="on click set {value: '1'} on #FieldsValuesToRemove-{{$field.Type_field_id}}-{{$counter}} then hide me then show #Undelete-{{$field.Type_field_id}}-{{$counter}} then add .w3-opacity-max to #FieldsValues-{{$field.Type_field_id}}-{{$counter}}" ><i class="bi bi-dash-square" title="Remove"></i></button>
<button id="Undelete-{{$field.Type_field_id}}-{{$counter}}" style="margin-right: 5px; display: none" class="delete" type="button" _="on click set {value: ''} on #FieldsValuesToRemove-{{$field.Type_field_id}}-{{$counter}} then hide me then show #Delete-{{$field.Type_field_id}}-{{$counter}} then remove .w3-opacity-max from #FieldsValues-{{$field.Type_field_id}}-{{$counter}}"><i class="bi bi-arrow-counterclockwise" title="Undo"></i></button>
</div>
</div>
{{ $g_counter = $counter}}
{{ end }}
</div>
<span class="hide" id="fields-{{.Type_field_id}}-counter">{{incr $g_counter }}</span>
<button type="button" onclick="bm_item_field_add('{{.Type_field_id}}', '{{.Widget}}')" class="main"><i class='bi bi-plus-square-fill'></i> <span> Add value</span></button>
</fieldset>
{{ else }}
<p>
{{ $value := ""}}
{{ if gt (len $values) 0 }}
{{ $value = index $values 0 }}
{{ end }}
{{ field_widget .Widget .Type_field_id 0 .Title $value .Valid_values ""}}
</p>
{{ end }}
{{ end }}
{{ end }}