domma-cms 1.36.0 → 1.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/bin/lib/left-free-tier.js +4 -1
- package/bin/update.js +4 -0
- package/docs/DommaFeatures.md +8 -6
- package/docs/plugin-development.md +2 -2
- package/package.json +1 -1
- package/plugins/docs/tests/plugin.test.js +2 -0
- package/plugins/free-tier.lock.json +2 -50
- package/server/services/siteGitignore.js +1 -1
- package/plugins/booking/CLAUDE.md +0 -204
- package/plugins/booking/admin/css/index.css +0 -192
- package/plugins/booking/admin/lib/details.js +0 -58
- package/plugins/booking/admin/lib/diary-layout.js +0 -158
- package/plugins/booking/admin/lib/drafts.js +0 -139
- package/plugins/booking/admin/lib/email.js +0 -191
- package/plugins/booking/admin/lib/extension-sections.js +0 -160
- package/plugins/booking/admin/lib/kit.js +0 -471
- package/plugins/booking/admin/templates/booking.html +0 -1
- package/plugins/booking/admin/views/booking.js +0 -216
- package/plugins/booking/admin/views/bookings.js +0 -132
- package/plugins/booking/admin/views/diary.js +0 -382
- package/plugins/booking/admin/views/panels.js +0 -603
- package/plugins/booking/admin/views/people.js +0 -318
- package/plugins/booking/admin/views/services.js +0 -264
- package/plugins/booking/admin/views/settings.js +0 -222
- package/plugins/booking/collections/booking-bookables.json +0 -17
- package/plugins/booking/collections/booking-bookings.json +0 -18
- package/plugins/booking/collections/booking-services.json +0 -17
- package/plugins/booking/config.js +0 -36
- package/plugins/booking/docs/guide.md +0 -73
- package/plugins/booking/inject/body.html +0 -1
- package/plugins/booking/lib/call.js +0 -88
- package/plugins/booking/lib/extensions.js +0 -169
- package/plugins/booking/lib/mail.js +0 -113
- package/plugins/booking/lib/store.js +0 -392
- package/plugins/booking/plugin.js +0 -905
- package/plugins/booking/plugin.json +0 -81
- package/plugins/booking/plugin.public.js +0 -175
- package/plugins/booking/public/booking.css +0 -159
- package/plugins/booking/public/booking.js +0 -808
- package/plugins/booking/public/lib/clean.js +0 -141
- package/plugins/booking/public/lib/page-format.js +0 -121
- package/plugins/booking/public/lib/slots.js +0 -247
- package/plugins/booking/public/lib/time.js +0 -131
- package/plugins/booking/templates/booking.html +0 -5
- package/plugins/booking/tests/admin-diary.test.js +0 -81
- package/plugins/booking/tests/admin-drafts.test.js +0 -67
- package/plugins/booking/tests/api.test.js +0 -651
- package/plugins/booking/tests/email.test.js +0 -69
- package/plugins/booking/tests/public.test.js +0 -72
- package/plugins/booking/tests/pure.test.js +0 -189
- package/plugins/booking/tests/seo.test.js +0 -71
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Booking - one Tool, one sidebar entry, its screens as tabs under the
|
|
3
|
-
* banner: Diary, Bookings, Services, People & rooms, and any an extension
|
|
4
|
-
* (Booking Pro) adds.
|
|
5
|
-
*
|
|
6
|
-
* #/plugins/booking Diary
|
|
7
|
-
* #/plugins/booking/diary
|
|
8
|
-
* #/plugins/booking/bookings[/<id>] Bookings (an id opens that booking)
|
|
9
|
-
* #/plugins/booking/services[/<id>|new]
|
|
10
|
-
* #/plugins/booking/people[/<id>|new] People & rooms
|
|
11
|
-
* #/plugins/booking/new?contact=<id> the Diary with New booking open, filled from a contact
|
|
12
|
-
* #/plugins/booking/new?email=&name= ... or from an email's sender (Email's "Book Sam…")
|
|
13
|
-
* #/plugins/booking/<ext-key> an extension's screen
|
|
14
|
-
* #/plugins/booking/<action-id>?contact=<id> | ?email=&name=
|
|
15
|
-
* the Diary, then an extension's banner action run with that prefill
|
|
16
|
-
* (Booking Pro's "Call now" from a contact's or an email's menu)
|
|
17
|
-
*
|
|
18
|
-
* Settings are behind the banner's cog, in a slideover.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import {V, api, errText, loadKit, store} from '../lib/kit.js';
|
|
22
|
-
import {sectionApi} from '../lib/extension-sections.js';
|
|
23
|
-
|
|
24
|
-
const ROUTE = /^#\/plugins\/booking(\/|\?|$)/;
|
|
25
|
-
const TABS = [
|
|
26
|
-
{key: 'diary', label: 'Diary', icon: 'calendar', module: `/plugins/booking/admin/views/diary.js?v=${V}`},
|
|
27
|
-
{key: 'bookings', label: 'Bookings', icon: 'list', module: `/plugins/booking/admin/views/bookings.js?v=${V}`},
|
|
28
|
-
{key: 'services', label: 'Services', icon: 'briefcase', module: `/plugins/booking/admin/views/services.js?v=${V}`},
|
|
29
|
-
{key: 'people', label: 'People & rooms', icon: 'users', module: `/plugins/booking/admin/views/people.js?v=${V}`}
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
let lifetime = null;
|
|
33
|
-
|
|
34
|
-
/** tab, id and query from the address. `new` is the Diary with New booking open. */
|
|
35
|
-
function where() {
|
|
36
|
-
const [path, query = ''] = location.hash.split('?');
|
|
37
|
-
const m = path.match(/^#\/plugins\/booking(?:\/([a-z0-9-]+))?(?:\/([^/?#]+))?/);
|
|
38
|
-
const q = Object.fromEntries(new URLSearchParams(query));
|
|
39
|
-
const tab = m?.[1] || 'diary';
|
|
40
|
-
return {tab, id: m?.[2] ? decodeURIComponent(m[2]) : '', query: q};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const bookingView = {
|
|
44
|
-
templateUrl: '/plugins/booking/admin/templates/booking.html',
|
|
45
|
-
|
|
46
|
-
async onMount($container) {
|
|
47
|
-
const kit = await loadKit();
|
|
48
|
-
lifetime ??= kit.viewLifetime(ROUTE);
|
|
49
|
-
if (!ROUTE.test(location.hash)) return;
|
|
50
|
-
lifetime.reset();
|
|
51
|
-
const scope = (fn) => { lifetime.add(fn); return fn; };
|
|
52
|
-
const container = $container.get(0);
|
|
53
|
-
const root = container.querySelector('[data-booking-admin]') || container;
|
|
54
|
-
let mountedFor = location.hash;
|
|
55
|
-
const here = () => location.hash === mountedFor && root.isConnected;
|
|
56
|
-
const {tab, id, query} = where();
|
|
57
|
-
|
|
58
|
-
// The first load: a skeleton (core's loading.js) in a slot that goes when the screen draws.
|
|
59
|
-
root.innerHTML = '';
|
|
60
|
-
const slot = document.createElement('div');
|
|
61
|
-
slot.className = 'bk-note bk-loading-slot dm-loading-slot';
|
|
62
|
-
slot.textContent = 'Loading…';
|
|
63
|
-
root.appendChild(slot);
|
|
64
|
-
let boot;
|
|
65
|
-
try {
|
|
66
|
-
boot = await kit.whileLoading(slot, api.bootstrap(), kit.SHAPES.rows);
|
|
67
|
-
} catch (err) {
|
|
68
|
-
if (!here()) return;
|
|
69
|
-
root.innerHTML = '';
|
|
70
|
-
const p = document.createElement('p');
|
|
71
|
-
p.className = 'bk-error';
|
|
72
|
-
p.textContent = `Booking could not load: ${errText(err)}`;
|
|
73
|
-
root.appendChild(p);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (!here()) return;
|
|
77
|
-
|
|
78
|
-
const tabs = [...TABS, ...(boot.tabs || [])];
|
|
79
|
-
const actions = (boot.actions || []).filter(a => a && typeof a.module === 'string' && a.module.startsWith(`/plugins/${a.owner}/`));
|
|
80
|
-
const wantNew = tab === 'new';
|
|
81
|
-
const wantAction = actions.find(a => a.id === tab) || null;
|
|
82
|
-
const current = tabs.find(t => t.key === (wantNew || wantAction ? 'diary' : tab)) || TABS[0];
|
|
83
|
-
|
|
84
|
-
// "Booking › Diary" in the banner.
|
|
85
|
-
const name = container.querySelector('.dm-plugin-banner-name');
|
|
86
|
-
if (name) {
|
|
87
|
-
name.textContent = '';
|
|
88
|
-
const a = document.createElement('span');
|
|
89
|
-
a.className = 'dm-plugin-banner-parent';
|
|
90
|
-
a.textContent = 'Booking';
|
|
91
|
-
const sep = document.createElement('span');
|
|
92
|
-
sep.className = 'dm-plugin-banner-sep';
|
|
93
|
-
sep.textContent = '›';
|
|
94
|
-
sep.setAttribute('aria-hidden', 'true');
|
|
95
|
-
name.append(a, sep, document.createTextNode(current.label));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
root.innerHTML = '';
|
|
99
|
-
const nav = document.createElement('nav');
|
|
100
|
-
nav.className = 'bk-nav';
|
|
101
|
-
nav.setAttribute('aria-label', 'Booking');
|
|
102
|
-
for (const t of tabs) {
|
|
103
|
-
const a = document.createElement('a');
|
|
104
|
-
a.href = t.key === 'diary' ? '#/plugins/booking' : `#/plugins/booking/${t.key}`;
|
|
105
|
-
const icon = document.createElement('span');
|
|
106
|
-
icon.setAttribute('data-icon', t.icon || 'plug');
|
|
107
|
-
icon.setAttribute('data-icon-size', '15');
|
|
108
|
-
a.append(icon, document.createTextNode(t.label));
|
|
109
|
-
if (t.owner) a.classList.add('is-ext');
|
|
110
|
-
if (t === current) { a.classList.add('is-on'); a.setAttribute('aria-current', 'page'); }
|
|
111
|
-
nav.appendChild(a);
|
|
112
|
-
}
|
|
113
|
-
const body = document.createElement('div');
|
|
114
|
-
body.className = 'bk-body';
|
|
115
|
-
root.append(nav, body);
|
|
116
|
-
I.scan(nav);
|
|
117
|
-
|
|
118
|
-
const ctx = {
|
|
119
|
-
kit, scope, here, root: body, container, boot, settings: boot.settings, id, query,
|
|
120
|
-
/** Like scope, but answers the remover: a panel lets go of the screen when it closes first. */
|
|
121
|
-
hold: (fn) => lifetime.add(fn),
|
|
122
|
-
/** Tidy the address (a deep link done with) without leaving the screen. */
|
|
123
|
-
replaceHash(h) { history.replaceState(null, '', h); mountedFor = location.hash; },
|
|
124
|
-
tz: boot.settings.timeZone,
|
|
125
|
-
go(t, i = '') { location.hash = `#/plugins/booking${t && t !== 'diary' ? `/${t}` : ''}${i ? `/${encodeURIComponent(i)}` : ''}`; },
|
|
126
|
-
/** Fresh services / people / settings, after an edit elsewhere. */
|
|
127
|
-
async refresh() {
|
|
128
|
-
const next = await api.bootstrap();
|
|
129
|
-
Object.assign(boot, next);
|
|
130
|
-
ctx.settings = boot.settings;
|
|
131
|
-
ctx.tz = boot.settings.timeZone;
|
|
132
|
-
return boot;
|
|
133
|
-
},
|
|
134
|
-
async openSettings(section) {
|
|
135
|
-
const m = await import(`/plugins/booking/admin/views/settings.js?v=${V}`);
|
|
136
|
-
return m.openSettings(ctx, section);
|
|
137
|
-
},
|
|
138
|
-
async openBooking(bookingId, opts) {
|
|
139
|
-
const m = await import(`/plugins/booking/admin/views/panels.js?v=${V}`);
|
|
140
|
-
return m.openBooking(ctx, bookingId, opts);
|
|
141
|
-
},
|
|
142
|
-
async newBooking(prefill, opts) {
|
|
143
|
-
const m = await import(`/plugins/booking/admin/views/panels.js?v=${V}`);
|
|
144
|
-
return m.newBooking(ctx, prefill, opts);
|
|
145
|
-
},
|
|
146
|
-
/** Screens set this to be told a booking changed (made, moved, cancelled). */
|
|
147
|
-
onBookingsChanged: () => {}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
kit.addBannerAction($container, {id: 'booking-settings', icon: 'settings', title: 'Booking settings', onClick: () => ctx.openSettings()});
|
|
151
|
-
kit.addBannerAction($container, {id: 'booking-visit', icon: 'external-link', title: 'Open the booking page in a new tab',
|
|
152
|
-
onClick: () => window.open(ctx.settings.bookingPath, '_blank', 'noopener')});
|
|
153
|
-
kit.addBannerAction($container, {id: 'booking-new', icon: 'plus', title: 'New booking',
|
|
154
|
-
onClick: () => ctx.newBooking({})});
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* An extension's banner action (Booking 1.4): its module's `run(ctx, prefill)`, imported on the click.
|
|
158
|
-
* ctx is the screen's (boot, openBooking, refresh, go...) plus what sections get (api, owner, helpPopovers).
|
|
159
|
-
* Anything that must open a new tab does so on a click of its own, never after this import.
|
|
160
|
-
*/
|
|
161
|
-
const runAction = async (a, prefill = {}) => {
|
|
162
|
-
try {
|
|
163
|
-
const mod = await import(a.module);
|
|
164
|
-
const run = mod.run || mod.default?.run;
|
|
165
|
-
if (typeof run !== 'function') throw new Error('no run()');
|
|
166
|
-
return await run({...ctx, owner: a.owner, api: sectionApi, bookables: boot.bookables, services: boot.services,
|
|
167
|
-
helpPopovers: (el) => kit.helpPopovers(el)}, prefill);
|
|
168
|
-
} catch (err) {
|
|
169
|
-
console.warn(`[booking] ${a.owner} action ${a.id}:`, err);
|
|
170
|
-
E.toast(`${a.title} could not start: ${errText(err)}`, {type: 'error'});
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
for (const a of actions) {
|
|
175
|
-
kit.addBannerAction($container, {id: `booking-x-${a.id}`, icon: a.icon, title: a.title, onClick: () => runAction(a)});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
const mod = await import(current.module);
|
|
180
|
-
if (!here()) return;
|
|
181
|
-
const mount = mod.mount || mod.default?.mount;
|
|
182
|
-
const cleanup = await mount(body, ctx);
|
|
183
|
-
if (typeof cleanup === 'function') scope(cleanup);
|
|
184
|
-
} catch (err) {
|
|
185
|
-
body.innerHTML = '';
|
|
186
|
-
const p = document.createElement('p');
|
|
187
|
-
p.className = 'bk-error';
|
|
188
|
-
p.textContent = `This screen could not load: ${errText(err)}`;
|
|
189
|
-
body.appendChild(p);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
store.set('booking.last-tab', current.key);
|
|
193
|
-
|
|
194
|
-
// From Contacts or Email: the New booking slideover (or an extension's action), filled in. The
|
|
195
|
-
// address goes back to the Diary so a reload does not open it again.
|
|
196
|
-
if ((wantNew || wantAction) && here()) {
|
|
197
|
-
ctx.replaceHash('#/plugins/booking/diary');
|
|
198
|
-
const prefill = {email: query.email || '', name: query.name || ''};
|
|
199
|
-
if (query.contact) {
|
|
200
|
-
try {
|
|
201
|
-
const c = await api.contact(query.contact);
|
|
202
|
-
Object.assign(prefill, {contactId: c.id, name: c.name, email: c.email, phone: c.phone});
|
|
203
|
-
} catch (err) {
|
|
204
|
-
E.toast(`That contact could not be read: ${errText(err)}`, {type: 'warning'});
|
|
205
|
-
}
|
|
206
|
-
} else if (query.email && ctx.boot.contacts) {
|
|
207
|
-
// From an email: a sender already in the caller's Contacts books as that contact.
|
|
208
|
-
const c = await api.contactByEmail(query.email).catch(() => null);
|
|
209
|
-
if (c?.id) Object.assign(prefill, {contactId: c.id, name: c.name || prefill.name, phone: c.phone});
|
|
210
|
-
}
|
|
211
|
-
if (!here()) return;
|
|
212
|
-
if (wantAction) runAction(wantAction, prefill);
|
|
213
|
-
else ctx.newBooking(prefill);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
};
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Booking › Bookings.
|
|
3
|
-
*
|
|
4
|
-
* Every booking as a list: chips for Upcoming, Past and Cancelled (with
|
|
5
|
-
* counts), search over name, email, phone, service and who, rows with a
|
|
6
|
-
* right-click / ⋮ / Shift+F10 menu (the same one the Diary has). Click opens
|
|
7
|
-
* the booking. A notification's link (#/plugins/booking/bookings/<id>) opens one.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import {STATUS_LABEL, STATUS_TONE, V, api, dateLabel, errText, esc, store, wireRows} from '../lib/kit.js';
|
|
11
|
-
import {wallClock} from '/plugins/booking/public/lib/time.js';
|
|
12
|
-
import {sourceShort, withNames} from '../lib/details.js';
|
|
13
|
-
|
|
14
|
-
const FILTERS = [
|
|
15
|
-
{key: 'upcoming', label: 'Upcoming', match: (b, now) => b.status !== 'cancelled' && b.endAt > now},
|
|
16
|
-
{key: 'today', label: 'Today', match: (b, now, today, tz) => b.status !== 'cancelled' && wallClock(b.startAt, tz).date === today},
|
|
17
|
-
{key: 'past', label: 'Past', match: (b, now) => b.status !== 'cancelled' && b.endAt <= now},
|
|
18
|
-
{key: 'cancelled', label: 'Cancelled', match: (b) => b.status === 'cancelled'},
|
|
19
|
-
{key: 'all', label: 'All', match: () => true}
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const ROW = `
|
|
23
|
-
<div class="bk-row" data-id="{{id}}" tabindex="0">
|
|
24
|
-
<span class="bk-dot" data-bind-data-colour="colour"></span>
|
|
25
|
-
<span class="bk-when-col"><strong data-bind-text="day"></strong><small data-bind-text="time"></small></span>
|
|
26
|
-
<span class="bk-main"><strong data-bind-text="who"></strong><small data-bind-text="meta"></small></span>
|
|
27
|
-
<span class="bk-chip" data-bind-class="tone" data-bind-text="statusLabel"></span>
|
|
28
|
-
<button type="button" class="bk-kebab" aria-label="Actions" title="Actions">⋮</button>
|
|
29
|
-
</div>`;
|
|
30
|
-
|
|
31
|
-
export async function mount(root, ctx) {
|
|
32
|
-
const {kit, scope, here, boot, tz} = ctx;
|
|
33
|
-
const panels = await import(`/plugins/booking/admin/views/panels.js?v=${V}`);
|
|
34
|
-
if (!here()) return;
|
|
35
|
-
|
|
36
|
-
const all = M.observable([]);
|
|
37
|
-
const loading = M.observable(true);
|
|
38
|
-
const error = M.observable('');
|
|
39
|
-
const filter = M.observable(FILTERS.some(f => f.key === store.get('booking.list-filter')) ? store.get('booking.list-filter') : 'upcoming');
|
|
40
|
-
const query = M.observable('');
|
|
41
|
-
scope(M.effect(() => store.set('booking.list-filter', filter.value)));
|
|
42
|
-
const colours = new Map(boot.bookables.map(b => [b.id, b.colour || 'blue']));
|
|
43
|
-
|
|
44
|
-
const counts = M.observable({});
|
|
45
|
-
const rows = M.observable([]);
|
|
46
|
-
scope(M.effect(() => {
|
|
47
|
-
const now = new Date().toISOString();
|
|
48
|
-
const c = {};
|
|
49
|
-
for (const f of FILTERS) c[f.key] = all.value.filter(b => f.match(b, now, boot.today, tz)).length;
|
|
50
|
-
counts.value = c;
|
|
51
|
-
const f = FILTERS.find(x => x.key === filter.value) || FILTERS[0];
|
|
52
|
-
const q = query.value.trim().toLowerCase();
|
|
53
|
-
const list = all.value
|
|
54
|
-
.filter(b => f.match(b, now, boot.today, tz))
|
|
55
|
-
.filter(b => !q || [b.name, b.email, b.phone, b.serviceName, withNames(b), b.notes].join(' ').toLowerCase().includes(q));
|
|
56
|
-
// Coming up: soonest first. Looking back: latest first.
|
|
57
|
-
list.sort((a, b) => (f.key === 'upcoming' || f.key === 'today' ? a.startAt.localeCompare(b.startAt) : b.startAt.localeCompare(a.startAt)));
|
|
58
|
-
rows.value = list.map(b => {
|
|
59
|
-
const s = wallClock(b.startAt, tz);
|
|
60
|
-
const e = wallClock(b.endAt, tz);
|
|
61
|
-
return {
|
|
62
|
-
id: b.id,
|
|
63
|
-
colour: colours.get(b.bookableId) || 'grey',
|
|
64
|
-
day: dateLabel(s.date),
|
|
65
|
-
time: `${s.time}-${e.time}`,
|
|
66
|
-
who: b.name || b.email,
|
|
67
|
-
meta: [b.serviceName, withNames(b) && `with ${withNames(b)}`, b.email, sourceShort(b.source)].filter(Boolean).join(' · '),
|
|
68
|
-
statusLabel: STATUS_LABEL[b.status] || b.status,
|
|
69
|
-
tone: `is-${STATUS_TONE[b.status] || 'muted'}`
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
}));
|
|
73
|
-
const emptyText = M.computed(() => (all.value.length
|
|
74
|
-
? (query.value ? 'No bookings match.' : 'Nothing here.')
|
|
75
|
-
: 'No bookings yet. They appear here as soon as someone books - on your booking page, or from New booking.'));
|
|
76
|
-
|
|
77
|
-
root.innerHTML = '';
|
|
78
|
-
const view = document.createElement('div');
|
|
79
|
-
view.className = 'bk-card bk-bookings';
|
|
80
|
-
view.innerHTML = `
|
|
81
|
-
<div class="bk-bar">
|
|
82
|
-
<div class="bk-seg" role="group" aria-label="Show">
|
|
83
|
-
${FILTERS.map(f => `<button type="button" data-filter="${f.key}" data-bind-class="filter.value === '${f.key}' && 'is-on'">${esc(f.label)} <b data-bind-text="counts.value.${f.key}"></b></button>`).join('')}
|
|
84
|
-
</div>
|
|
85
|
-
<input type="search" class="form-input bk-search" placeholder="Search name, email, service…" aria-label="Search bookings" data-model="query.value">
|
|
86
|
-
<span data-help-title="Bookings" data-help="Every booking, newest changes included. Click one to open it; right-click (or ⋮, or Shift+F10) to move it, mark it done or a no-show, or cancel it. Cancelled bookings free their time and can then be deleted."></span>
|
|
87
|
-
</div>
|
|
88
|
-
<div class="bk-note bk-loading-slot dm-loading-slot" data-bind-hidden="!loading.value">Loading…</div>
|
|
89
|
-
<p class="bk-note is-bad" data-bind-hidden="!error.value" data-bind-text="error.value"></p>
|
|
90
|
-
<p class="bk-note" data-bind-hidden="loading.value || error.value || rows.value.length" data-bind-text="emptyText.value"></p>
|
|
91
|
-
<div class="bk-list" data-each="rows.value key=id"></div>`;
|
|
92
|
-
root.appendChild(view);
|
|
93
|
-
view.querySelector('.bk-list').innerHTML = ROW;
|
|
94
|
-
scope(kit.helpPopovers(view, {position: 'bottom'}));
|
|
95
|
-
const bindings = M.applyBindings({loading, error, filter, query, rows, counts, emptyText}, view);
|
|
96
|
-
scope(() => bindings.dispose());
|
|
97
|
-
view.querySelector('.bk-seg').addEventListener('click', (e) => {
|
|
98
|
-
const b = e.target.closest('[data-filter]');
|
|
99
|
-
if (b) filter.value = b.dataset.filter;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// The first load shows a skeleton in the slot; a reload keeps the list on screen.
|
|
103
|
-
let first = true;
|
|
104
|
-
async function load() {
|
|
105
|
-
try {
|
|
106
|
-
const slot = first ? view.querySelector('.bk-loading-slot') : null;
|
|
107
|
-
first = false;
|
|
108
|
-
const list = await (slot ? kit.whileLoading(slot, api.bookings.list(), kit.SHAPES.rows) : api.bookings.list());
|
|
109
|
-
if (!here()) return;
|
|
110
|
-
all.value = Array.isArray(list) ? list : [];
|
|
111
|
-
error.value = '';
|
|
112
|
-
} catch (err) {
|
|
113
|
-
if (!here()) return;
|
|
114
|
-
error.value = `The bookings could not load: ${errText(err)}`;
|
|
115
|
-
} finally {
|
|
116
|
-
loading.value = false;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
ctx.onBookingsChanged = () => { if (here()) load(); };
|
|
120
|
-
scope(() => { ctx.onBookingsChanged = () => {}; });
|
|
121
|
-
|
|
122
|
-
const byId = (id) => all.peek().find(b => b.id === id);
|
|
123
|
-
wireRows(view.querySelector('.bk-list'), {
|
|
124
|
-
openMenuAt: kit.openMenuAt,
|
|
125
|
-
scope,
|
|
126
|
-
main: (id) => ctx.openBooking(id),
|
|
127
|
-
items: (id) => panels.bookingMenu(ctx, byId(id))
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
await load();
|
|
131
|
-
if (ctx.id && here()) ctx.openBooking(ctx.id);
|
|
132
|
-
}
|