camper/web/templates/admin/form.gohtml

79 lines
3.6 KiB
Plaintext

<!--
SPDX-FileCopyrightText: 2023 jordi fita mas <jordi@tandem.blog>
SPDX-License-Identifier: AGPL-3.0-only
-->
{{ define "error-attrs" }}{{ if .Error }}aria-invalid="true" aria-errormessage="{{ .Name }}-error"{{ end }}{{ end }}
{{ define "error-message" -}}
{{ if .Error -}}
<strong id="{{ .Name }}-error" class="error">{{ .Error }}</strong><br>
{{- end }}
{{- end }}
{{ define "list-options" -}}
{{- range .Options }}
<option value="{{ .Value }}" {{ if $.IsSelected .Value }} selected="selected"{{ end }}>{{ .Label }}</option>
{{- end }}
{{- end }}
{{ define "radio-options" -}}
{{- range .Options }}
<label><input type="radio" name="{{ $.Name }}" value="{{ .Value }}"
{{ if $.IsSelected .Value }}checked{{ end }}> {{ .Label }}</label>
{{- end }}
{{- end }}
{{ define "month-input" -}}
<label>
<span class="sr-only">{{( pgettext "Month" "input" )}}</span>
<select name="{{ .Name }}.month">
<option value="1"{{ if eq .Month 1}} selected{{ end }}>{{( pgettext "January" "month" )}}</option>
<option value="2"{{ if eq .Month 2}} selected{{ end }}>{{( pgettext "February" "month" )}}</option>
<option value="3"{{ if eq .Month 3}} selected{{ end }}>{{( pgettext "March" "month" )}}</option>
<option value="4"{{ if eq .Month 4}} selected{{ end }}>{{( pgettext "April" "month" )}}</option>
<option value="5"{{ if eq .Month 5}} selected{{ end }}>{{( pgettext "May" "month" )}}</option>
<option value="6"{{ if eq .Month 6}} selected{{ end }}>{{( pgettext "June" "month" )}}</option>
<option value="7"{{ if eq .Month 7}} selected{{ end }}>{{( pgettext "July" "month" )}}</option>
<option value="8"{{ if eq .Month 8}} selected{{ end }}>{{( pgettext "August" "month" )}}</option>
<option value="9"{{ if eq .Month 9}} selected{{ end }}>{{( pgettext "September" "month" )}}</option>
<option value="10"{{ if eq .Month 10}} selected{{ end }}>{{( pgettext "October" "month" )}}</option>
<option value="11"{{ if eq .Month 11}} selected{{ end }}>{{( pgettext "November" "month" )}}</option>
<option value="12"{{ if eq .Month 12}} selected{{ end }}>{{( pgettext "December" "month" )}}</option>
</select>
</label>
<label>
<span class="sr-only">{{( pgettext "Year" "input" )}}</span>
<input name="{{ .Name }}.year" type="number" value="{{ .Year }}">
</label>
{{- end }}
{{ define "media-picker" -}}
{{- /*gotype: dev.tandem.ws/tandem/camper/pkg/form.Media*/ -}}
<fieldset data-hx-target="this" data-hx-swap="outerHTML">
<legend>{{( pgettext .Label "input" )}}</legend>
<input type="hidden" name="{{ .Name }}" value="{{ .Val }}">
<button type="button"
data-hx-get="/admin/media/picker?name={{ .Name | queryEscape }}&amp;value={{ .Val | queryEscape }}&amp;label={{ .Label | queryEscape }}&amp;prompt={{ .Prompt | queryEscape }}"
data-hx-swap="beforeend"
>
{{ if .Val -}}
<img src="/admin/media/{{ .Val }}/content" alt="">
{{ else -}}
{{( pgettext .Prompt "action" )}}
{{- end }}
</button>
{{ template "error-message" . }}
</fieldset>
{{- end }}
{{ define "init-lang" }}x-data="{ lang: '{{ .DefaultLang }}' }"{{ end }}
{{ define "lang-selector" -}}
<div class="lang-selector" role="toolbar">
{{ range $lang, $input := . -}}
<button :aria-pressed="lang === '{{ $lang }}'"
@click.prevent="lang = '{{ $lang }}'">{{ $lang }}</button>
{{- end }}
</div>
{{- end }}