diff options
Diffstat (limited to 'web/templates/partials/shopping-item-edit.html')
| -rw-r--r-- | web/templates/partials/shopping-item-edit.html | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/web/templates/partials/shopping-item-edit.html b/web/templates/partials/shopping-item-edit.html new file mode 100644 index 0000000..e5220f5 --- /dev/null +++ b/web/templates/partials/shopping-item-edit.html @@ -0,0 +1,114 @@ +{{define "shopping-item-edit"}} +<div id="shopping-edit-backdrop" + class="fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/60 backdrop-blur-sm p-0 sm:p-4" + onclick="if(event.target === this) this.remove()"> + <div class="w-full sm:max-w-md bg-slate-900 border border-white/10 rounded-t-2xl sm:rounded-2xl p-5 space-y-4"> + + <div class="flex items-start justify-between gap-3"> + <h3 class="text-lg font-medium text-white">{{if .Editable}}Edit item{{else}}Item{{end}}</h3> + <button type="button" class="text-white/40 hover:text-white text-xl leading-none" + onclick="document.getElementById('shopping-edit-backdrop').remove()">×</button> + </div> + + {{if .Editable}} + <form hx-post="/shopping/item/{{.ID}}" + hx-target="#shopping-items-list" + hx-swap="innerHTML" + hx-on::after-request="if(event.detail.successful) document.getElementById('shopping-edit-backdrop').remove()" + class="space-y-4"> + + <div> + <label class="block text-xs uppercase tracking-wide text-white/50 mb-1">Name</label> + <input type="text" name="name" value="{{.Name}}" required autocomplete="off" + class="w-full bg-white/10 border border-white/20 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:ring-2 focus:ring-white/30"> + </div> + + <div> + <label class="block text-xs uppercase tracking-wide text-white/50 mb-1">Store</label> + <select name="store" id="edit-store-select" required + class="w-full bg-white/10 border border-white/20 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:ring-2 focus:ring-white/30"> + {{range .Stores}} + <option value="{{.Name}}" {{if .Selected}}selected{{end}}>{{.Name}}</option> + {{end}} + </select> + </div> + + <div> + <label class="block text-xs uppercase tracking-wide text-white/50 mb-1">Section</label> + <select name="section" id="edit-section-select" + class="w-full bg-white/10 border border-white/20 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:ring-2 focus:ring-white/30"> + <option value="">— none —</option> + </select> + <p class="text-xs text-white/30 mt-1">Sections belong to a store; changing store changes the options.</p> + </div> + + <div class="flex gap-2 pt-1"> + <button type="submit" + class="flex-1 bg-white/20 hover:bg-white/30 text-white px-4 py-2 rounded-lg text-sm font-medium transition-colors"> + Save + </button> + <button type="button" + class="px-4 py-2 rounded-lg text-sm border border-red-500/30 text-red-400 hover:bg-red-500/10 transition-colors" + hx-delete="/shopping/item/{{.ID}}" + hx-target="#shopping-items-list" + hx-swap="innerHTML" + hx-confirm="Delete {{.Name}}?" + hx-on::after-request="if(event.detail.successful) document.getElementById('shopping-edit-backdrop').remove()"> + Delete + </button> + </div> + </form> + + <script> + (function() { + // Section options are per-store, so they are rebuilt whenever the + // store changes rather than shipped as one flat list — otherwise + // you could file a Costco item under a Safeway aisle. + var sectionsByStore = { + {{- range .Stores}} + {{.Name}}: [{{range $i, $s := .Sections}}{{if $i}}, {{end}}{{$s.Name}}{{end}}], + {{- end}} + }; + var current = {{.Section}}; + var storeSel = document.getElementById('edit-store-select'); + var sectionSel = document.getElementById('edit-section-select'); + + function rebuild() { + var opts = sectionsByStore[storeSel.value] || []; + sectionSel.innerHTML = '<option value="">— none —</option>'; + opts.forEach(function(name) { + var o = document.createElement('option'); + o.value = name; + o.textContent = name; + if (name === current) o.selected = true; + sectionSel.appendChild(o); + }); + } + storeSel.addEventListener('change', function() { current = ''; rebuild(); }); + rebuild(); + })(); + </script> + + {{else}} + <div class="space-y-3"> + <div> + <div class="text-white">{{.Name}}</div> + <div class="text-sm text-white/50">{{.Store}}</div> + </div> + <p class="text-sm text-amber-300/80 bg-amber-500/10 border border-amber-500/20 rounded-lg p-3"> + {{.ReadOnlyWhy}} + </p> + <button type="button" + class="w-full px-4 py-2 rounded-lg text-sm border border-red-500/30 text-red-400 hover:bg-red-500/10 transition-colors" + hx-delete="/shopping/item/{{.ID}}?source={{.Source}}" + hx-target="#shopping-items-list" + hx-swap="innerHTML" + hx-confirm="Remove {{.Name}} from the list?" + hx-on::after-request="if(event.detail.successful) document.getElementById('shopping-edit-backdrop').remove()"> + Remove from list + </button> + </div> + {{end}} + </div> +</div> +{{end}} |
