blob: e5220f5852f73b6af05258e71615b0dff6bb126d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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}}
|