oficina / fichas Public

Clone
git clone https://amadan.net/oficina/fichas

Plain git — no account needed to clone.

Download

Download this file

1{{/* Shared app partials, parsed into every shell page. Not named with a
2 leading underscore: go:embed silently skips such files, and the first
3 version of this file was never in the binary. */}}
4{{/* fichas-input — one card field as a form control, chosen by kind, with
5 its error beside it. Keys: F (a FieldView), Error (string), Autofocus. */}}
6{{define "fichas-input"}}
7{{- $f := .F -}}
8{{- if eq $f.Def.Kind "enum" -}}
9 {{template "field-select" (dict "ID" $f.Def.Key "Name" $f.Def.Key "Label" $f.Label "Options" (options $f.Options $f.Value) "Error" .Error)}}
10{{- else if eq $f.Def.Kind "date" -}}
11 {{template "field-date" (dict "Name" $f.Def.Key "Label" $f.Label "Value" $f.Value "Error" .Error)}}
12{{- else if eq $f.Def.Kind "url" -}}
13 {{/* Not type="url": browsers reject "example.com" without a scheme, and
14 Paul asked for forgiving. text + inputmode="url" gets the URL keyboard
15 with none of the validation; the server normalises (urls.go). The
16 markup mirrors rastrillo's field partial, which has no inputmode key. */}}
17 <div rst-field><label rst-field-label for="{{$f.Def.Key}}">{{$f.Label}}</label>
18 <input rst-input type="text" inputmode="url" autocomplete="url" autocapitalize="none" autocorrect="off" spellcheck="false" id="{{$f.Def.Key}}" name="{{$f.Def.Key}}"{{with $f.Value}} value="{{displayURL .}}"{{end}} placeholder="example.com"{{if .Autofocus}} autofocus{{end}}{{if .Error}} aria-invalid="true" aria-describedby="{{$f.Def.Key}}-error"{{end}}>
19 {{if .Error}}<p rst-field-error id="{{$f.Def.Key}}-error" role="alert">{{.Error}}</p>{{end}}</div>
20{{- else if or (eq $f.Def.Kind "email") (eq $f.Def.Kind "phone") (eq $f.Def.Kind "number") -}}
21 {{/* The right keyboard and autofill for each. The card forms are
22 novalidate, so the browser's own check (its words, not ours, and
23 stricter than the server's) never runs; the server's message shows
24 beside the field instead. */}}
25 <div rst-field><label rst-field-label for="{{$f.Def.Key}}">{{$f.Label}}</label>
26 {{- if eq $f.Def.Kind "number"}}<input type="hidden" name="{{$f.Def.Key}}.locale" value="{{.L.Format}}">{{end}}
27 <input rst-input id="{{$f.Def.Key}}" name="{{$f.Def.Key}}"
28 {{- if eq $f.Def.Kind "email"}} type="email" inputmode="email" autocomplete="email" autocapitalize="none" autocorrect="off" spellcheck="false" placeholder="name@example.com"
29 {{- else if eq $f.Def.Kind "phone"}} type="tel" inputmode="tel" autocomplete="tel" placeholder="+353 1 555 0100"
30 {{- else}} type="text" inputmode="decimal" fichas-number{{end}}
31 {{- with $f.Value}} value="{{.}}"{{end}}{{if .Autofocus}} autofocus{{end}}{{if .Error}} aria-invalid="true" aria-describedby="{{$f.Def.Key}}-error"{{end}}>
32 {{if .Error}}<p rst-field-error id="{{$f.Def.Key}}-error" role="alert">{{.Error}}</p>{{end}}</div>
33{{- else if isLong $f.Def -}}
34 {{template "field-textarea" (dict "Name" $f.Def.Key "Label" $f.Label "Value" $f.Value "Rows" 4 "Error" .Error)}}
35{{- else -}}
36 {{template "field" (dict "ID" $f.Def.Key "Name" $f.Def.Key "Label" $f.Label "Value" $f.Value "Error" .Error "Autofocus" .Autofocus)}}
37{{- end -}}
38{{end}}
39
40{{/* fichas-rail: the rail (level-up §3.2, R1): Search (the list's Find
41 box, ⌘K; the bar has none, Paul 2026-11-18), each type with its icon
42 and count, New type below a rule, and the fold at its foot. The fold
43 is two submit buttons, one per state; CSS shows the one that fits
44 what is on screen, so it works with scripts off and with no cookie.
45 Below 800px the bar's Menu sheet carries the types instead. */}}
46{{define "fichas-rail"}}<nav fichas-rail aria-label="Types">
47 <a fichas-rail-item data-fichas-search href="{{.Search}}" aria-keyshortcuts="Meta+K Control+K" title="Search">{{icon "search"}}<span fichas-rail-label>Search</span><kbd fichas-kbd aria-hidden="true">⌘K</kbd></a>
48 {{- range .Nav}}
49 <a fichas-rail-item href="{{.Href}}"{{if .Current}} aria-current="page"{{end}} title="{{.Label}}">{{icon "users"}}<span fichas-rail-label>{{.Label}}</span><span fichas-rail-count>{{number $.L .Count}}</span></a>
50 {{- end}}
51 <hr fichas-rail-rule>
52 <a fichas-rail-item fichas-rail-new href="/types/new" title="New type">{{icon "plus"}}<span fichas-rail-label>New type</span></a>
53 <form fichas-rail-foot method="post" action="/view/rail" data-busy="false">
54 <input type="hidden" name="return_to" value="{{.Here}}">
55 <button fichas-rail-item fichas-fold-to="rail" type="submit" name="rail" value="rail" aria-keyshortcuts="Meta+Backslash Control+Backslash" title="Narrow the side panel">{{icon "panel-left"}}<span fichas-rail-label>Fold rail</span><kbd fichas-kbd aria-hidden="true">⌘\</kbd></button>
56 <button fichas-rail-item fichas-fold-to="open" type="submit" name="rail" value="open" aria-keyshortcuts="Meta+Backslash Control+Backslash" title="Widen the side panel">{{icon "panel-left"}}<span fichas-rail-label>Unfold rail</span></button>
57 </form>
58</nav>{{end}}
59
60{{/* fichas-menubar: File, Edit, View, Type, Help (§3.1). Each menu is a
61 <details> in estilo's exclusive group, so it opens with no script. A
62 command row is disabled until grid.js binds it; a form row is a real
63 POST, so it works with scripts off. Data: menuBar. */}}
64{{define "fichas-menubar"}}<nav estilo-menubar aria-label="{{.Label}}">
65 {{- range .Menus}}<details estilo-menubar-menu name="estilo-menus" id="fichas-menu-{{.ID}}">
66 <summary estilo-menubar-title>{{.Title}}</summary>
67 <div estilo-menu>
68 {{- range .Items}}
69 {{- if eq .Kind "divider"}}<hr>
70 {{- else if eq .Kind "link"}}<a estilo-menu-item{{if .Danger}}="danger"{{end}} href="{{.Href}}">{{template "fichas-menu-body" .}}</a>
71 {{- else if eq .Kind "form"}}<form method="post" action="{{.Action}}"{{with .Command}} data-fichas-menu="{{.}}"{{end}}>{{range $name, $value := .Fields}}<input type="hidden" name="{{$name}}" value="{{$value}}">{{end}}<button estilo-menu-item type="submit">{{template "fichas-menu-body" .}}</button></form>
72 {{- else if eq .Kind "dialog"}}<button estilo-menu-item type="button" commandfor="{{.Dialog}}" command="show-modal">{{template "fichas-menu-body" .}}</button>
73 {{- else}}<button estilo-menu-item type="button" data-fichas-command="{{.Command}}" disabled>{{template "fichas-menu-body" .}}</button>
74 {{- end}}
75 {{- end}}
76 </div>
77 </details>{{end}}
78</nav>{{end}}
79{{define "fichas-menu-body"}}<span estilo-menu-label>{{.Label}}</span>{{with .Key}}<kbd estilo-menu-key aria-hidden="true">{{.}}</kbd>{{end}}{{end}}
80
81{{/* fichas-keys: Help's list of keys (§5.6). */}}
82{{define "fichas-keys"}}<dialog fichas-keys-dialog id="fichas-keys" aria-labelledby="fichas-keys-title">
83 <h2 id="fichas-keys-title">Keyboard shortcuts</h2>
84 <dl fichas-keys-list>
85 <dt><kbd>←</kbd> <kbd>→</kbd> <kbd>↑</kbd> <kbd>↓</kbd></dt><dd>Move between cells</dd>
86 <dt><kbd>Enter</kbd></dt><dd>Change the cell. In a cell, save and move down</dd>
87 <dt>Typing</dt><dd>Replace the cell's value with what you type</dd>
88 <dt><kbd>Esc</kbd></dt><dd>Cancel a change. Press again to leave the table</dd>
89 <dt><kbd>Delete</kbd></dt><dd>Clear the cell</dd>
90 <dt><kbd>Tab</kbd></dt><dd>In a cell, save and move right</dd>
91 <dt><kbd>⌘Z</kbd> <kbd>⇧⌘Z</kbd></dt><dd>Undo and redo your changes</dd>
92 <dt><kbd>J</kbd> <kbd>K</kbd></dt><dd>Next and previous card, beside the list</dd>
93 <dt><kbd>⌘K</kbd></dt><dd>Search</dd>
94 <dt><kbd>⌘\</kbd></dt><dd>Narrow the side panel</dd>
95 </dl>
96 <form method="dialog"><button rst-btn type="submit">Close</button></form>
97</dialog>{{end}}
98
99{{/* fichas-cell-value: what a table cell shows for one field, as the
100 list draws it and as an edit draws it again. Keys: F (FieldView), L. */}}
101{{define "fichas-cell-value"}}{{$f := .F}}{{$v := $f.Value}}
102{{- if not $v}}<span fichas-empty-cell>—</span>
103{{- else if eq $f.Def.Kind "enum"}}{{template "status-pill" (dict "Label" $v "Tone" (stageTone $v))}}
104{{- else if eq $f.Def.Kind "date"}}<time datetime="{{$v}}" title="{{longDate .L $v}}"{{with dateLang .L $v}} lang="{{.}}"{{end}}>{{dateAgo .L $v}}</time>
105{{- else if eq $f.Def.Kind "number"}}<span fichas-number>{{showNumber .L $v}}</span>
106{{- else if eq $f.Def.Kind "url"}}{{displayURL $v}}
107{{- else}}{{$v}}{{end}}{{end}}
108
109{{/* fichas-notice: what a scriptless edit comes back with: "Saved.
110 Undo", "Undone. Redo", or why nothing was written. Keys: N
111 (*notice), Card (the card id). */}}
112{{define "fichas-notice"}}{{with .N}}<div fichas-notice="{{.Kind}}" role="status">
113 <span>{{.Text}}</span>
114 {{- if and .EventID (ne .EventID "0")}}<form method="post" action="/cards/{{.CardID}}/undo"><input type="hidden" name="event" value="{{.EventID}}"><input type="hidden" name="return_to" value="{{$.Here}}"><button rst-btn="sm" type="submit">{{if eq .Kind "undone"}}Redo{{else}}Undo{{end}}</button></form>{{end}}
115</div>{{end}}{{end}}
116
117{{/* fichas-quiet: one field on the card, a quiet input that is always
118 editable (§5.1). Its was rides beside it, and a number's locale.
119 With script it saves when it loses focus; without, the card's Save
120 button posts them all. Keys: F, L, Error. */}}
121{{define "fichas-quiet"}}{{$f := .F}}{{$id := printf "card-%s" $f.Def.Key}}
122<div fichas-quiet-field data-field="{{$f.Def.Key}}" data-kind="{{$f.Def.Kind}}">
123 <label fichas-quiet-label for="{{$id}}">{{$f.Label}}</label>
124 <input type="hidden" name="was.{{$f.Def.Key}}" value="{{$f.Value}}">
125 {{- if eq $f.Def.Kind "enum"}}
126 <select fichas-quiet id="{{$id}}" name="{{$f.Def.Key}}"{{if .Error}} aria-invalid="true" aria-describedby="{{$id}}-error"{{end}}>{{range options $f.Options $f.Value}}<option value="{{.Value}}"{{if .Selected}} selected{{end}}>{{.Label}}</option>{{end}}</select>
127 {{- else if eq $f.Def.Kind "date"}}
128 <input fichas-quiet type="date" id="{{$id}}" name="{{$f.Def.Key}}" value="{{$f.Value}}"{{if .Error}} aria-invalid="true" aria-describedby="{{$id}}-error"{{end}}>
129 {{- else if isLong $f.Def}}
130 <textarea fichas-quiet id="{{$id}}" name="{{$f.Def.Key}}" rows="3"{{if .Error}} aria-invalid="true" aria-describedby="{{$id}}-error"{{end}}>{{$f.Value}}</textarea>
131 {{- else}}
132 {{- if eq $f.Def.Kind "number"}}<input type="hidden" name="{{$f.Def.Key}}.locale" value="{{.L.Format}}">{{end}}
133 <input fichas-quiet id="{{$id}}" name="{{$f.Def.Key}}" value="{{seed .L $f.Def $f.Value}}"
134 {{- if eq $f.Def.Kind "email"}} type="email" inputmode="email" autocomplete="off" autocapitalize="none" spellcheck="false"
135 {{- else if eq $f.Def.Kind "phone"}} type="tel" inputmode="tel" autocomplete="off"
136 {{- else if eq $f.Def.Kind "number"}} type="text" inputmode="decimal" fichas-number
137 {{- else if eq $f.Def.Kind "url"}} type="text" inputmode="url" autocapitalize="none" spellcheck="false"
138 {{- else}} type="text"{{end}}{{if .Error}} aria-invalid="true" aria-describedby="{{$id}}-error"{{end}}>
139 {{- with $f.Value}}
140 {{- if eq $f.Def.Kind "url"}}{{with safeHref .}}<a fichas-quiet-open href="{{.}}" target="_blank" rel="noopener noreferrer">{{icon "maximize-2"}}<span class="rst-sr-only">Visit {{displayURL $f.Value}}</span></a>{{end}}
141 {{- else if eq $f.Def.Kind "email"}}{{with mailHref .}}<a fichas-quiet-open href="{{.}}">{{icon "maximize-2"}}<span class="rst-sr-only">Write to {{$f.Value}}</span></a>{{end}}
142 {{- else if eq $f.Def.Kind "phone"}}{{with telHref .}}<a fichas-quiet-open href="{{.}}">{{icon "phone"}}<span class="rst-sr-only">Call {{$f.Value}}</span></a>{{end}}{{end}}
143 {{- end}}
144 {{- end}}
145 {{if .Error}}<p rst-field-error id="{{$id}}-error">{{.Error}}</p>{{end}}
146</div>{{end}}
147
148{{/* fichas-card: the card, beside the list or on its own page (§5.4):
149 its title, who edited it last, where it sits in the list, its fields
150 as quiet inputs, its long text, and the call log. Keys: P (cardPane),
151 L, Here, EntryFields, Errors, Pane (bool: beside the list). */}}
152{{define "fichas-card"}}{{$c := .P.Card}}{{$L := .L}}
153<article fichas-card-view rst-stack data-card="{{$c.Card.ID}}" aria-labelledby="card-title-{{$c.Card.ID}}">
154 {{if .Pane}}<div fichas-card-top>
155 <div fichas-card-steps>
156 {{with .P.PrevHref}}<a rst-btn="sm" rel="prev" href="{{.}}" data-fichas-step="prev">{{icon "chevron-left"}}Previous</a>{{end}}
157 {{with .P.NextHref}}<a rst-btn="sm" rel="next" href="{{.}}" data-fichas-step="next">Next{{icon "chevron-right"}}</a>{{end}}
158 {{if or .P.PrevHref .P.NextHref}}<span fichas-meta aria-hidden="true"><kbd fichas-kbd>J</kbd> <kbd fichas-kbd>K</kbd> next and previous</span>{{end}}
159 </div>
160 <a rst-btn="sm" href="/cards/{{$c.Card.ID}}">{{icon "maximize-2"}}Full page</a>
161 <a rst-btn="sm" href="/cards/{{$c.Card.ID}}/history">{{icon "history"}}History</a>
162 <a fichas-card-close href="{{.P.CloseHref}}" aria-label="Close the card" aria-keyshortcuts="Escape" data-fichas-close>{{icon "x"}}</a>
163 </div>{{end}}
164 <form method="post" action="/cards/{{$c.Card.ID}}" fichas-card-form rst-stack data-card="{{$c.Card.ID}}" novalidate>
165 <input type="hidden" name="return_to" value="{{.Here}}">
166 {{range $c.Fields}}{{if $c.IsTitle .Def.Key}}
167 <input type="hidden" name="was.{{.Def.Key}}" value="{{.Value}}">
168 <h2 fichas-card-heading id="card-title-{{$c.Card.ID}}"><label class="rst-sr-only" for="card-{{.Def.Key}}">{{.Label}}</label><input fichas-quiet fichas-quiet-title data-field="{{.Def.Key}}" data-kind="{{.Def.Kind}}" id="card-{{.Def.Key}}" name="{{.Def.Key}}" value="{{.Value}}" autocomplete="off"{{with errFor $.Errors .Def.Key}} aria-invalid="true"{{end}}></h2>
169 {{with errFor $.Errors .Def.Key}}<p rst-field-error>{{.}}</p>{{end}}
170 {{end}}{{end}}
171 <p fichas-card-meta>
172 <span>{{$c.TypeLabel}}</span>
173 {{with .P.EditedBy}}<span>Edited by {{.}} <time datetime="{{$.P.EditedAt.Format "2006-01-02T15:04:05Z07:00"}}" title="{{stamp $.L $.P.EditedAt}}"{{with agoLang $.L $.P.EditedAt}} lang="{{.}}"{{end}}>{{ago $.L $.P.EditedAt}}</time></span>{{end}}
174 {{if .Pane}}{{with .P.Pos}}<span>{{number $L .At}} of {{number $L .Total}}</span>{{else}}<span fichas-not-in-view>{{icon "info"}}Not in this view</span>{{end}}{{end}}
175 </p>
176 <div fichas-card-fields>
177 {{range $c.Fields}}{{if and (not ($c.IsTitle .Def.Key)) (not (isLong .Def))}}{{template "fichas-quiet" (dict "F" . "L" $L "Error" (errFor $.Errors .Def.Key))}}{{end}}{{end}}
178 </div>
179 {{range $c.Fields}}{{if and (not ($c.IsTitle .Def.Key)) (isLong .Def)}}<div fichas-card-long>{{template "fichas-quiet" (dict "F" . "L" $L "Error" (errFor $.Errors .Def.Key))}}</div>{{end}}{{end}}
180 <div fichas-card-save rst-actions><button rst-btn="primary" type="submit">Save changes</button></div>
181 </form>
182 <section fichas-card-log rst-stack rst-section aria-labelledby="call-log-{{$c.Card.ID}}">
183 <h3 id="call-log-{{$c.Card.ID}}">Call log</h3>
184 <form method="post" action="/cards/{{$c.Card.ID}}/entries" rst-stack>
185 <input type="hidden" name="return_to" value="{{.Here}}">
186 {{range $f := .EntryFields}}{{if eq $f.Def.Key "f_body"}}
187 {{template "field-textarea" (dict "Name" $f.Def.Key "Label" "Log a call" "Rows" 2 "Value" $f.Value "Error" (errFor $.Errors $f.Def.Key) "Hint" "⌘↩ to save")}}
188 {{end}}{{end}}
189 {{template "form-foot" (dict "Submit" "Log this call")}}
190 </form>
191 {{if $c.Entries}}
192 <ol fichas-timeline>
193 {{range $c.Entries}}
194 <li><time datetime="{{.Entry.CreatedAt.Format "2006-01-02"}}" title="{{stamp $.L .Entry.CreatedAt}}"{{with agoLang $.L .Entry.CreatedAt}} lang="{{.}}"{{end}}>{{ago $.L .Entry.CreatedAt}}</time><p>{{.Body}}</p></li>
195 {{end}}
196 </ol>
197 {{else}}
198 <p fichas-meta>No calls logged yet. Each one you add here builds this {{lower $c.TypeLabel}}'s history.</p>
199 {{end}}
200 </section>
201</article>{{end}}
202