domma-cms 1.35.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 +12 -0
- package/admin/js/api.js +1 -1
- package/admin/js/app.js +2 -2
- package/admin/js/lib/image-editor.js +1 -1
- package/admin/js/lib/media-arrange.js +1 -1
- package/admin/js/lib/media-picker.js +2 -2
- package/admin/js/lib/media-upload.js +1 -1
- package/admin/js/lib/seo-redirects.js +1 -1
- package/admin/js/templates/docs/usage-media.html +6 -0
- package/admin/js/templates/media.html +1 -0
- package/admin/js/views/media.js +3 -3
- package/bin/lib/left-free-tier.js +4 -1
- package/bin/update.js +4 -0
- package/docs/DommaFeatures.md +10 -5
- 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/routes/api/media.js +3 -1
- package/server/routes/api/sidebar.js +2 -2
- package/server/services/content.js +26 -2
- package/server/services/hooks.js +27 -4
- package/server/services/plugins.js +9 -3
- package/server/services/renderer.js +3 -1
- 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,603 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Booking › the slideovers every screen shares: one booking (details, status,
|
|
3
|
-
* staff note, history), a new booking, moving one, cancelling one - and the
|
|
4
|
-
* right-click / ⋮ menu a booking has wherever it is shown (Diary, Bookings).
|
|
5
|
-
*
|
|
6
|
-
* A clash is a 409 from the server; staff are asked "Book it anyway?" and the
|
|
7
|
-
* request goes again with `force`. "Email the customer" is the `notify` flag:
|
|
8
|
-
* without it, a change made by staff sends nothing.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
STATUS_LABEL, STATUS_TONE, api, claim, dateLabel, errText, esc, fmtDateTime, isClash, minutesLabel, openPanel, refreshBadge
|
|
13
|
-
} from '../lib/kit.js';
|
|
14
|
-
import {atWallClock, isDate, toMinutes, wallClock} from '/plugins/booking/public/lib/time.js';
|
|
15
|
-
import {answerRows, placesLabel, sourceLabel, withNames} from '../lib/details.js';
|
|
16
|
-
import {mountSections} from '../lib/extension-sections.js';
|
|
17
|
-
import {emailTo, looksLikeAddress, routeMailLinks} from '../lib/email.js';
|
|
18
|
-
|
|
19
|
-
/** Places per session a service takes (Booking Pro's classes); 1 for an appointment. */
|
|
20
|
-
const capacityOf = (svc) => Math.max(1, Number(svc?.ext?.['booking-pro']?.capacity) || 1);
|
|
21
|
-
|
|
22
|
-
const changed = (ctx) => { refreshBadge(); try { ctx.onBookingsChanged?.(); } catch { /* the screen went */ } };
|
|
23
|
-
|
|
24
|
-
/** "Tue 15/07/2031, 09:00-10:00" in the business zone. */
|
|
25
|
-
export function timeRange(b, tz) {
|
|
26
|
-
const s = wallClock(b.startAt, tz);
|
|
27
|
-
const e = wallClock(b.endAt, tz);
|
|
28
|
-
return `${dateLabel(s.date)}, ${s.time}-${e.time}${e.date !== s.date ? ` (${dateLabel(e.date)})` : ''}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ---- The menu --------------------------------------------------------------------
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The menu a booking has everywhere. `reload` is told after any change.
|
|
35
|
-
*
|
|
36
|
-
* @returns {object[]} E.contextMenu items
|
|
37
|
-
*/
|
|
38
|
-
export function bookingMenu(ctx, b) {
|
|
39
|
-
if (!b) return [];
|
|
40
|
-
const live = b.status !== 'cancelled';
|
|
41
|
-
return [
|
|
42
|
-
{label: 'Open', icon: 'external-link', action: () => openBooking(ctx, b.id)},
|
|
43
|
-
{label: 'Move…', icon: 'move', disabled: () => !live, action: () => moveBooking(ctx, b)},
|
|
44
|
-
{type: 'divider'},
|
|
45
|
-
{label: 'Mark as done', icon: 'check', disabled: () => !live || b.status === 'completed', action: () => setStatus(ctx, b, 'completed')},
|
|
46
|
-
{label: 'Mark as no-show', icon: 'user-remove', disabled: () => !live || b.status === 'no-show', action: () => setStatus(ctx, b, 'no-show')},
|
|
47
|
-
{label: 'Back to booked', icon: 'rotate-ccw', disabled: () => !live || b.status === 'confirmed', action: () => setStatus(ctx, b, 'confirmed')},
|
|
48
|
-
{type: 'divider'},
|
|
49
|
-
{label: 'Email the customer', icon: 'mail', disabled: () => !b.email, action: () => emailTo({to: [{name: b.name, address: b.email}], subject: `Your booking: ${b.serviceName}`})},
|
|
50
|
-
...(b.contactId && ctx.boot.contacts ? [{label: 'Open Contacts', icon: 'users', action: () => { location.hash = '#/contacts'; }}] : []),
|
|
51
|
-
{type: 'divider'},
|
|
52
|
-
live
|
|
53
|
-
? {label: 'Cancel booking…', icon: 'x-circle', action: () => cancelBooking(ctx, b)}
|
|
54
|
-
: {label: 'Delete', icon: 'trash', action: () => deleteBooking(ctx, b)}
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ---- Status, cancel, delete ------------------------------------------------------
|
|
59
|
-
|
|
60
|
-
export async function setStatus(ctx, b, status) {
|
|
61
|
-
try {
|
|
62
|
-
const next = await api.bookings.update(b.id, {status});
|
|
63
|
-
E.toast(`${b.name}: ${STATUS_LABEL[status].toLowerCase()}.`, {type: 'success'});
|
|
64
|
-
changed(ctx);
|
|
65
|
-
return next;
|
|
66
|
-
} catch (err) {
|
|
67
|
-
E.toast(`Not changed: ${errText(err)}`, {type: 'error'});
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Cancel, with a reason and whether to email the customer. Resolves the booking, or null. */
|
|
73
|
-
export function cancelBooking(ctx, b) {
|
|
74
|
-
const release = claim(`cancel:${b.id}`);
|
|
75
|
-
if (!release) return Promise.resolve(null);
|
|
76
|
-
return new Promise((resolve) => {
|
|
77
|
-
const reason = M.observable('');
|
|
78
|
-
const notify = M.observable(Boolean(b.email) && ctx.boot.mailReady);
|
|
79
|
-
let panel = null;
|
|
80
|
-
let done = null;
|
|
81
|
-
openPanel({
|
|
82
|
-
title: 'Cancel booking',
|
|
83
|
-
size: 'sm',
|
|
84
|
-
ctx, release,
|
|
85
|
-
model: {reason, notify},
|
|
86
|
-
html: `<div class="bk-form">
|
|
87
|
-
<p><strong>${esc(b.serviceName)}</strong> for <strong>${esc(b.name)}</strong><br><span class="bk-muted">${esc(timeRange(b, ctx.tz))}</span></p>
|
|
88
|
-
<p class="bk-note">The time becomes free for someone else straight away.</p>
|
|
89
|
-
<label class="form-label">Reason <span class="bk-muted">(optional)</span> <span data-help-title="Reason" data-help="Kept in the booking's history. It is not sent to the customer."></span></label>
|
|
90
|
-
<textarea class="form-input" rows="2" maxlength="300" data-model="reason.value"></textarea>
|
|
91
|
-
<label class="bk-check"><input type="checkbox" data-bool="notify" ${b.email ? '' : 'disabled'}> Email the customer that it is cancelled
|
|
92
|
-
<span data-help-title="Email the customer" data-help="They get a short cancellation email with a calendar file that takes it off their calendar. Off: nothing is sent - tell them yourself."></span></label>
|
|
93
|
-
${ctx.boot.mailReady ? '' : '<p class="bk-note is-warn">This site has no outgoing mail server set up, so no email can be sent.</p>'}
|
|
94
|
-
<div class="bk-actions"><span class="bk-spacer"></span>
|
|
95
|
-
<button type="button" class="btn btn-sm btn-ghost" data-on-click="keep">Keep it</button>
|
|
96
|
-
<button type="button" class="btn btn-sm btn-danger" data-on-click="save"><span data-icon="x-circle" data-icon-size="13"></span> Cancel booking</button></div>
|
|
97
|
-
</div>`,
|
|
98
|
-
before: (el) => {
|
|
99
|
-
const box = el.querySelector('[data-bool="notify"]');
|
|
100
|
-
box.checked = notify.peek();
|
|
101
|
-
box.addEventListener('change', () => { notify.value = box.checked; });
|
|
102
|
-
},
|
|
103
|
-
cleanup: () => resolve(done),
|
|
104
|
-
methods: {
|
|
105
|
-
keep: () => panel?.close(true),
|
|
106
|
-
async save() {
|
|
107
|
-
try {
|
|
108
|
-
done = await api.bookings.update(b.id, {status: 'cancelled', reason: reason.peek(), notify: notify.peek()});
|
|
109
|
-
E.toast(`Cancelled${notify.peek() ? ' - the customer has been emailed' : ''}.`, {type: 'success'});
|
|
110
|
-
changed(ctx);
|
|
111
|
-
panel?.close(true);
|
|
112
|
-
} catch (err) {
|
|
113
|
-
E.toast(`Not cancelled: ${errText(err)}`, {type: 'error'});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}).then(p => { panel = p; if (!p) resolve(null); }, (err) => {
|
|
118
|
-
// The panel could not be built (openPanel has released its claim and tidied up).
|
|
119
|
-
E.toast(`That could not open: ${errText(err)}`, {type: 'error'});
|
|
120
|
-
resolve(null);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export async function deleteBooking(ctx, b) {
|
|
126
|
-
if (!await E.confirm(`Delete the cancelled booking for <strong>${esc(b.name)}</strong> (${esc(timeRange(b, ctx.tz))})? It cannot be brought back.`)) return false;
|
|
127
|
-
try {
|
|
128
|
-
await api.bookings.remove(b.id);
|
|
129
|
-
E.toast('Deleted.', {type: 'success'});
|
|
130
|
-
changed(ctx);
|
|
131
|
-
return true;
|
|
132
|
-
} catch (err) {
|
|
133
|
-
E.toast(`Not deleted: ${errText(err)}`, {type: 'error'});
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// ---- Choosing a time (new and move share it) -------------------------------------
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* The date + free times + "or type a time" block, filled for a service and
|
|
142
|
-
* (optionally) one person or room. Plain DOM - it is redrawn whole on each
|
|
143
|
-
* change and holds no bindings.
|
|
144
|
-
*
|
|
145
|
-
* @returns {{el: HTMLElement, load: Function, value: () => {date: string, time: string}, set: Function}}
|
|
146
|
-
*/
|
|
147
|
-
function timePicker(ctx, {date, time = '', ignore = ''}) {
|
|
148
|
-
const el = document.createElement('div');
|
|
149
|
-
el.className = 'bk-picker';
|
|
150
|
-
el.innerHTML = `
|
|
151
|
-
<div class="bk-grid">
|
|
152
|
-
<div><label class="form-label">Date <span data-help-title="Date" data-help="The free times that day are listed below, in this business's time zone. Staff are not held to the service's notice or how-far-ahead rules."></span></label>
|
|
153
|
-
<input type="date" class="form-input" data-part="date"></div>
|
|
154
|
-
<div><label class="form-label">Time <span data-help-title="Time" data-help="Pick a free time below, or type any time (24-hour, e.g. 14:30). A typed time that clashes asks before booking over it."></span></label>
|
|
155
|
-
<input type="time" class="form-input" step="300" data-part="time"></div>
|
|
156
|
-
</div>
|
|
157
|
-
<div class="bk-slots" data-part="slots"><p class="bk-note">Pick a service to see free times.</p></div>`;
|
|
158
|
-
const dateIn = el.querySelector('[data-part="date"]');
|
|
159
|
-
const timeIn = el.querySelector('[data-part="time"]');
|
|
160
|
-
const box = el.querySelector('[data-part="slots"]');
|
|
161
|
-
dateIn.value = date || ctx.boot.today;
|
|
162
|
-
timeIn.value = time;
|
|
163
|
-
let current = {service: '', with: ''};
|
|
164
|
-
let seq = 0;
|
|
165
|
-
|
|
166
|
-
const mark = () => {
|
|
167
|
-
for (const b of box.querySelectorAll('[data-time]')) b.classList.toggle('is-on', b.dataset.time === timeIn.value);
|
|
168
|
-
};
|
|
169
|
-
async function load(q = current) {
|
|
170
|
-
current = q;
|
|
171
|
-
const my = ++seq;
|
|
172
|
-
if (!q.service) { box.innerHTML = '<p class="bk-note">Pick a service to see free times.</p>'; return; }
|
|
173
|
-
if (!isDate(dateIn.value)) { box.innerHTML = '<p class="bk-note">Pick a date.</p>'; return; }
|
|
174
|
-
box.innerHTML = '<p class="bk-note">Finding free times…</p>';
|
|
175
|
-
try {
|
|
176
|
-
const r = await api.slots({service: q.service, with: q.with, from: dateIn.value, to: dateIn.value, ignore});
|
|
177
|
-
if (my !== seq) return;
|
|
178
|
-
const slots = r.days?.[0]?.slots || [];
|
|
179
|
-
if (!slots.length) {
|
|
180
|
-
box.innerHTML = '<p class="bk-note">No free times that day (closed, or all booked). Type a time above to book anyway.</p>';
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
box.innerHTML = '';
|
|
184
|
-
// A class shows its places; an appointment (one place) does not need to.
|
|
185
|
-
const svc = ctx.boot.services.find(x => x.id === q.service);
|
|
186
|
-
const classy = capacityOf(svc) > 1 || slots.some(x => Number(x.left) > 1);
|
|
187
|
-
for (const s of slots) {
|
|
188
|
-
const b = document.createElement('button');
|
|
189
|
-
b.type = 'button';
|
|
190
|
-
b.className = 'bk-slot';
|
|
191
|
-
b.dataset.time = s.time;
|
|
192
|
-
b.textContent = s.time;
|
|
193
|
-
if (classy && Number.isFinite(Number(s.left))) {
|
|
194
|
-
const small = document.createElement('small');
|
|
195
|
-
small.textContent = placesLabel(s.left);
|
|
196
|
-
b.appendChild(small);
|
|
197
|
-
b.title = `${s.time} - ${placesLabel(s.left)}`;
|
|
198
|
-
}
|
|
199
|
-
box.appendChild(b);
|
|
200
|
-
}
|
|
201
|
-
mark();
|
|
202
|
-
} catch (err) {
|
|
203
|
-
if (my === seq) box.innerHTML = `<p class="bk-note is-bad">${esc(errText(err))}</p>`;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
box.addEventListener('click', (e) => {
|
|
207
|
-
const b = e.target.closest('[data-time]');
|
|
208
|
-
if (!b) return;
|
|
209
|
-
timeIn.value = b.dataset.time;
|
|
210
|
-
mark();
|
|
211
|
-
timeIn.dispatchEvent(new Event('input', {bubbles: true}));
|
|
212
|
-
});
|
|
213
|
-
dateIn.addEventListener('change', () => load());
|
|
214
|
-
timeIn.addEventListener('input', mark);
|
|
215
|
-
return {
|
|
216
|
-
el, load,
|
|
217
|
-
value: () => ({date: dateIn.value, time: timeIn.value}),
|
|
218
|
-
/** Put a date and time back (a draft), and look up that day's free times. */
|
|
219
|
-
set({date: d, time: t} = {}) {
|
|
220
|
-
if (isDate(d)) dateIn.value = d;
|
|
221
|
-
timeIn.value = typeof t === 'string' ? t : '';
|
|
222
|
-
load();
|
|
223
|
-
},
|
|
224
|
-
startAt() {
|
|
225
|
-
if (!isDate(dateIn.value) || !Number.isFinite(toMinutes(timeIn.value))) return '';
|
|
226
|
-
return atWallClock(dateIn.value, timeIn.value, ctx.tz).toISOString();
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/** Send `fn(force)`; on a clash ask, and send again with force. Resolves the answer, or null. */
|
|
232
|
-
async function withClashCheck(fn, what) {
|
|
233
|
-
try {
|
|
234
|
-
return await fn(false);
|
|
235
|
-
} catch (err) {
|
|
236
|
-
if (!isClash(err)) throw err;
|
|
237
|
-
if (!await E.confirm(`${esc(errText(err))}<br><br>${esc(what)} anyway, over the clash?`)) return null;
|
|
238
|
-
return fn(true);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// ---- New booking -------------------------------------------------------------------
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* @param {object} ctx
|
|
246
|
-
* @param {{serviceId?, bookableId?, date?, time?, name?, email?, phone?, notes?, contactId?}} prefill
|
|
247
|
-
*/
|
|
248
|
-
export async function newBooking(ctx, prefill = {}) {
|
|
249
|
-
const {boot} = ctx;
|
|
250
|
-
const services = boot.services.filter(s => s.active !== false || s.id === prefill.serviceId);
|
|
251
|
-
if (!boot.bookables.length || !boot.services.length) {
|
|
252
|
-
const ok = await E.confirm(!boot.bookables.length
|
|
253
|
-
? 'Add who or what can be booked first - a person or a room - then a service they provide.<br><br>Go to People & rooms now?'
|
|
254
|
-
: 'Add a service first - what can be booked, for how long, and with whom.<br><br>Go to Services now?');
|
|
255
|
-
if (ok && ctx.here()) ctx.go(!boot.bookables.length ? 'people' : 'services', 'new');
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
// One New booking at a time: a second click (or a click in the Diary) while it is open does nothing.
|
|
259
|
-
const release = claim('new-booking');
|
|
260
|
-
if (!release) return null;
|
|
261
|
-
const fromBookable = prefill.bookableId ? services.filter(s => s.bookables.includes(prefill.bookableId)) : [];
|
|
262
|
-
const f = {
|
|
263
|
-
serviceId: M.observable(prefill.serviceId || fromBookable[0]?.id || (services.length === 1 ? services[0].id : '')),
|
|
264
|
-
bookableId: M.observable(prefill.bookableId || ''),
|
|
265
|
-
name: M.observable(prefill.name || ''),
|
|
266
|
-
email: M.observable(prefill.email || ''),
|
|
267
|
-
phone: M.observable(prefill.phone || ''),
|
|
268
|
-
notes: M.observable(prefill.notes || ''),
|
|
269
|
-
staffNote: M.observable(''),
|
|
270
|
-
notify: M.observable(boot.mailReady && boot.settings.sendConfirmation !== false),
|
|
271
|
-
saving: M.observable(false)
|
|
272
|
-
};
|
|
273
|
-
// The contact it was opened from; a restored draft brings back its own.
|
|
274
|
-
let contactId = prefill.contactId || '';
|
|
275
|
-
const contactName = M.observable(contactId ? (prefill.name || prefill.email || '') : '');
|
|
276
|
-
const providers = M.observable([]);
|
|
277
|
-
const updateProviders = () => {
|
|
278
|
-
const svc = boot.services.find(s => s.id === f.serviceId.peek());
|
|
279
|
-
const list = svc ? boot.bookables.filter(b => svc.bookables.includes(b.id)) : [];
|
|
280
|
-
providers.value = list.map(b => ({id: b.id, name: b.name + (b.active === false ? ' (off)' : '')}));
|
|
281
|
-
if (f.bookableId.peek() && !list.some(b => b.id === f.bookableId.peek())) f.bookableId.value = '';
|
|
282
|
-
};
|
|
283
|
-
updateProviders();
|
|
284
|
-
const picker = timePicker(ctx, {date: prefill.date, time: prefill.time});
|
|
285
|
-
const typed = () => [f.name.peek(), f.email.peek(), f.phone.peek(), f.notes.peek(), f.staffNote.peek(), picker.value().time].join('|');
|
|
286
|
-
const opened = typed();
|
|
287
|
-
let panel = null;
|
|
288
|
-
let made = null;
|
|
289
|
-
let sections = null;
|
|
290
|
-
// Set in before(): put a service and a person back as if picked (the selects are drawn by hand).
|
|
291
|
-
let pickService = () => {};
|
|
292
|
-
const prefilled = Boolean(prefill.contactId || prefill.email || prefill.name || prefill.date || prefill.time || prefill.serviceId || prefill.bookableId);
|
|
293
|
-
|
|
294
|
-
return new Promise((resolve) => {
|
|
295
|
-
openPanel({
|
|
296
|
-
title: 'New booking',
|
|
297
|
-
size: 'md',
|
|
298
|
-
ctx, release,
|
|
299
|
-
model: {...f, providers, contactName},
|
|
300
|
-
dirty: () => !made && (typed() !== opened || Boolean(sections?.dirty())),
|
|
301
|
-
// Extension sections (Booking Pro's questions) are not in the draft: the section contract has
|
|
302
|
-
// values() but no way to put values back. What Booking's own form holds is.
|
|
303
|
-
draft: {
|
|
304
|
-
key: 'new-booking', kind: 'a new booking', label: () => f.name.peek(), prefilled,
|
|
305
|
-
values: () => ({serviceId: f.serviceId.peek(), bookableId: f.bookableId.peek(), ...picker.value(),
|
|
306
|
-
name: f.name.peek(), email: f.email.peek(), phone: f.phone.peek(), notes: f.notes.peek(),
|
|
307
|
-
staffNote: f.staffNote.peek(), notify: f.notify.peek(), contactId, contactName: contactName.peek()}),
|
|
308
|
-
apply(v, el) {
|
|
309
|
-
for (const k of ['name', 'email', 'phone', 'notes', 'staffNote']) if (typeof v[k] === 'string') f[k].value = v[k];
|
|
310
|
-
if (typeof v.notify === 'boolean') f.notify.value = v.notify;
|
|
311
|
-
contactId = typeof v.contactId === 'string' ? v.contactId : '';
|
|
312
|
-
contactName.value = contactId ? String(v.contactName || '') : '';
|
|
313
|
-
pickService(String(v.serviceId || ''), String(v.bookableId || ''));
|
|
314
|
-
picker.set({date: v.date, time: v.time});
|
|
315
|
-
const box = el.querySelector('[data-bool="notify"]');
|
|
316
|
-
if (box) box.checked = f.notify.peek();
|
|
317
|
-
}
|
|
318
|
-
},
|
|
319
|
-
html: `<div class="bk-form bk-new-booking">
|
|
320
|
-
<p class="bk-note" data-bind-hidden="!contactName.value"><span data-icon="user" data-icon-size="13"></span> From your contact <strong data-bind-text="contactName.value"></strong>.</p>
|
|
321
|
-
<div class="bk-grid">
|
|
322
|
-
<div><label class="form-label">Service <span data-help-title="Service" data-help="What is being booked. Its length and buffers decide which times are free."></span></label>
|
|
323
|
-
<select class="form-select" data-part="service"><option value="">Choose…</option>${services.map(s => `<option value="${esc(s.id)}">${esc(s.name)} (${esc(minutesLabel(s.duration))})${s.active === false ? ' - off' : ''}</option>`).join('')}</select></div>
|
|
324
|
-
<div><label class="form-label">With <span data-help-title="With" data-help="The person or room. Anyone: whoever is free takes it - the least busy that day."></span></label>
|
|
325
|
-
<select class="form-select" data-part="with"></select></div>
|
|
326
|
-
</div>
|
|
327
|
-
<div data-part="picker"></div>
|
|
328
|
-
<h4 class="bk-sub">Customer</h4>
|
|
329
|
-
<div class="bk-grid">
|
|
330
|
-
<div><label class="form-label">Name</label><input class="form-input" data-model="name.value" maxlength="120"><small class="bk-err" data-err="name" hidden></small></div>
|
|
331
|
-
<div><label class="form-label">Email <span data-help-title="Email" data-help="Where the confirmation goes. With Add customers to Contacts on (settings), they are added to Contacts unless they are there already."></span></label>
|
|
332
|
-
<input class="form-input" type="email" data-model="email.value" maxlength="200"><small class="bk-err" data-err="email" hidden></small></div>
|
|
333
|
-
<div><label class="form-label">Phone</label><input class="form-input" type="tel" data-model="phone.value" maxlength="40"><small class="bk-err" data-err="phone" hidden></small></div>
|
|
334
|
-
<div class="bk-wide"><label class="form-label">Their notes <span data-help-title="Their notes" data-help="What the customer asked or told you. It is in their confirmation email."></span></label>
|
|
335
|
-
<textarea class="form-input" rows="2" data-model="notes.value" maxlength="2000"></textarea></div>
|
|
336
|
-
<div class="bk-wide"><label class="form-label">Staff note <span data-help-title="Staff note" data-help="Only for you and your team - never sent to the customer."></span></label>
|
|
337
|
-
<textarea class="form-input" rows="2" data-model="staffNote.value" maxlength="4000"></textarea></div>
|
|
338
|
-
</div>
|
|
339
|
-
<div class="bk-ext-host" data-part="ext"></div>
|
|
340
|
-
<label class="bk-check"><input type="checkbox" data-bool="notify"> Send the customer a confirmation email
|
|
341
|
-
<span data-help-title="Confirmation email" data-help="The booking's details, a calendar file, and a link to change or cancel it (within your notice rules)."></span></label>
|
|
342
|
-
${boot.mailReady ? '' : '<p class="bk-note is-warn">This site has no outgoing mail server set up, so no email can be sent.</p>'}
|
|
343
|
-
<div class="bk-actions"><span class="bk-spacer"></span>
|
|
344
|
-
<button type="button" class="btn btn-sm btn-ghost" data-on-click="cancel">Cancel</button>
|
|
345
|
-
<button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-bind-disabled="saving.value"><span data-icon="check" data-icon-size="13"></span> Book</button></div>
|
|
346
|
-
</div>`,
|
|
347
|
-
before: (el) => {
|
|
348
|
-
el.querySelector('[data-part="picker"]').appendChild(picker.el);
|
|
349
|
-
const svcSel = el.querySelector('[data-part="service"]');
|
|
350
|
-
const withSel = el.querySelector('[data-part="with"]');
|
|
351
|
-
svcSel.value = f.serviceId.peek();
|
|
352
|
-
const drawWith = () => {
|
|
353
|
-
withSel.innerHTML = `<option value="">Anyone free</option>${providers.peek().map(p => `<option value="${esc(p.id)}">${esc(p.name)}</option>`).join('')}`;
|
|
354
|
-
withSel.value = f.bookableId.peek();
|
|
355
|
-
};
|
|
356
|
-
drawWith();
|
|
357
|
-
const serviceNow = () => boot.services.find(x => x.id === f.serviceId.peek()) || null;
|
|
358
|
-
sections = mountSections(el.querySelector('[data-part="ext"]'), 'newBooking', {boot, service: serviceNow()});
|
|
359
|
-
svcSel.addEventListener('change', () => {
|
|
360
|
-
f.serviceId.value = svcSel.value; updateProviders(); drawWith(); picker.load({service: svcSel.value, with: withSel.value});
|
|
361
|
-
sections.serviceChanged(serviceNow());
|
|
362
|
-
});
|
|
363
|
-
pickService = (serviceId, bookableId) => {
|
|
364
|
-
// A service that has gone (or been switched off) since is left unpicked.
|
|
365
|
-
svcSel.value = serviceId;
|
|
366
|
-
f.serviceId.value = svcSel.value;
|
|
367
|
-
updateProviders();
|
|
368
|
-
f.bookableId.value = providers.peek().some(p => p.id === bookableId) ? bookableId : '';
|
|
369
|
-
drawWith();
|
|
370
|
-
picker.load({service: svcSel.value, with: withSel.value});
|
|
371
|
-
sections.serviceChanged(serviceNow());
|
|
372
|
-
};
|
|
373
|
-
withSel.addEventListener('change', () => { f.bookableId.value = withSel.value; picker.load({service: svcSel.value, with: withSel.value}); });
|
|
374
|
-
const box = el.querySelector('[data-bool="notify"]');
|
|
375
|
-
box.checked = f.notify.peek();
|
|
376
|
-
box.addEventListener('change', () => { f.notify.value = box.checked; });
|
|
377
|
-
picker.load({service: f.serviceId.peek(), with: f.bookableId.peek()});
|
|
378
|
-
},
|
|
379
|
-
after: (el) => setTimeout(() => el.querySelector(f.serviceId.peek() ? '[data-part="date"]' : '[data-part="service"]')?.focus(), 60),
|
|
380
|
-
cleanup: () => { sections?.destroy(); resolve(made); },
|
|
381
|
-
methods: {
|
|
382
|
-
cancel: () => panel?.close(),
|
|
383
|
-
async save() {
|
|
384
|
-
if (f.saving.peek()) return;
|
|
385
|
-
if (!f.serviceId.peek()) { E.toast('Pick a service.', {type: 'warning'}); return; }
|
|
386
|
-
await sections?.ready;
|
|
387
|
-
const why = sections?.validate();
|
|
388
|
-
if (why) { E.toast(why, {type: 'warning'}); return; }
|
|
389
|
-
const startAt = picker.startAt();
|
|
390
|
-
if (!startAt) { E.toast('Pick a date and a time.', {type: 'warning'}); return; }
|
|
391
|
-
const body = {
|
|
392
|
-
serviceId: f.serviceId.peek(), bookableId: f.bookableId.peek(), startAt, contactId,
|
|
393
|
-
customer: {name: f.name.peek(), email: f.email.peek(), phone: f.phone.peek(), notes: f.notes.peek()},
|
|
394
|
-
staffNote: f.staffNote.peek(), notify: f.notify.peek()
|
|
395
|
-
};
|
|
396
|
-
const answers = sections?.answers() || {};
|
|
397
|
-
const ext = sections?.extFor() || {};
|
|
398
|
-
if (Object.keys(answers).length) body.answers = answers;
|
|
399
|
-
if (Object.keys(ext).length) body.ext = ext;
|
|
400
|
-
f.saving.value = true;
|
|
401
|
-
try {
|
|
402
|
-
made = await withClashCheck((force) => api.bookings.create({...body, force}), 'Book it');
|
|
403
|
-
if (!made) return;
|
|
404
|
-
E.toast(`Booked: ${made.serviceName} for ${made.name}, ${timeRange(made, ctx.tz)}.`, {type: 'success'});
|
|
405
|
-
await sections?.after(made);
|
|
406
|
-
changed(ctx);
|
|
407
|
-
panel?.close(true);
|
|
408
|
-
} catch (err) {
|
|
409
|
-
const errors = err?.body?.errors || {};
|
|
410
|
-
const el = panel?.panel;
|
|
411
|
-
if (el) for (const box of el.querySelectorAll('[data-err]')) { box.textContent = errors[box.dataset.err] || ''; box.hidden = !errors[box.dataset.err]; }
|
|
412
|
-
E.toast(`Not booked: ${errText(err)}`, {type: 'error'});
|
|
413
|
-
} finally {
|
|
414
|
-
f.saving.value = false;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}).then(p => { panel = p; if (!p) resolve(null); }, (err) => {
|
|
419
|
-
// The panel could not be built (openPanel has released its claim and tidied up).
|
|
420
|
-
E.toast(`That could not open: ${errText(err)}`, {type: 'error'});
|
|
421
|
-
resolve(null);
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// ---- Move ------------------------------------------------------------------------
|
|
427
|
-
|
|
428
|
-
export function moveBooking(ctx, b) {
|
|
429
|
-
const release = claim(`move:${b.id}`);
|
|
430
|
-
if (!release) return Promise.resolve(null);
|
|
431
|
-
const svc = ctx.boot.services.find(s => s.id === b.serviceId);
|
|
432
|
-
const list = svc ? ctx.boot.bookables.filter(x => svc.bookables.includes(x.id)) : ctx.boot.bookables.filter(x => x.id === b.bookableId);
|
|
433
|
-
const at = wallClock(b.startAt, ctx.tz);
|
|
434
|
-
const picker = timePicker(ctx, {date: at.date, time: at.time, ignore: b.id});
|
|
435
|
-
const withId = M.observable(b.bookableId);
|
|
436
|
-
const notify = M.observable(Boolean(b.email) && ctx.boot.mailReady);
|
|
437
|
-
let panel = null;
|
|
438
|
-
let moved = null;
|
|
439
|
-
return new Promise((resolve) => {
|
|
440
|
-
openPanel({
|
|
441
|
-
title: 'Move booking',
|
|
442
|
-
size: 'md',
|
|
443
|
-
ctx, release,
|
|
444
|
-
model: {withId, notify},
|
|
445
|
-
dirty: () => !moved && (picker.value().date !== at.date || picker.value().time !== at.time || withId.peek() !== b.bookableId),
|
|
446
|
-
html: `<div class="bk-form">
|
|
447
|
-
<p><strong>${esc(b.serviceName)}</strong> for <strong>${esc(b.name)}</strong><br><span class="bk-muted">Now: ${esc(timeRange(b, ctx.tz))}${withNames(b) ? ` with ${esc(withNames(b))}` : ''}</span></p>
|
|
448
|
-
<div><label class="form-label">With <span data-help-title="With" data-help="Keep the same person or room, or move it to another who provides this service."></span></label>
|
|
449
|
-
<select class="form-select" data-part="with">${list.map(x => `<option value="${esc(x.id)}">${esc(x.name)}</option>`).join('')}</select></div>
|
|
450
|
-
<div data-part="picker"></div>
|
|
451
|
-
<label class="bk-check"><input type="checkbox" data-bool="notify" ${b.email ? '' : 'disabled'}> Email the customer the new time
|
|
452
|
-
<span data-help-title="Email the customer" data-help="They get the new details and a calendar file that replaces the old one in their calendar."></span></label>
|
|
453
|
-
<div class="bk-actions"><span class="bk-spacer"></span>
|
|
454
|
-
<button type="button" class="btn btn-sm btn-ghost" data-on-click="cancel">Cancel</button>
|
|
455
|
-
<button type="button" class="btn btn-sm btn-primary" data-on-click="save"><span data-icon="move" data-icon-size="13"></span> Move</button></div>
|
|
456
|
-
</div>`,
|
|
457
|
-
before: (el) => {
|
|
458
|
-
el.querySelector('[data-part="picker"]').appendChild(picker.el);
|
|
459
|
-
const sel = el.querySelector('[data-part="with"]');
|
|
460
|
-
sel.value = b.bookableId;
|
|
461
|
-
sel.addEventListener('change', () => { withId.value = sel.value; picker.load({service: b.serviceId, with: sel.value}); });
|
|
462
|
-
const box = el.querySelector('[data-bool="notify"]');
|
|
463
|
-
box.checked = notify.peek();
|
|
464
|
-
box.addEventListener('change', () => { notify.value = box.checked; });
|
|
465
|
-
picker.load({service: b.serviceId, with: b.bookableId});
|
|
466
|
-
},
|
|
467
|
-
cleanup: () => resolve(moved),
|
|
468
|
-
methods: {
|
|
469
|
-
cancel: () => panel?.close(),
|
|
470
|
-
async save() {
|
|
471
|
-
const startAt = picker.startAt();
|
|
472
|
-
if (!startAt) { E.toast('Pick a date and a time.', {type: 'warning'}); return; }
|
|
473
|
-
try {
|
|
474
|
-
moved = await withClashCheck((force) => api.bookings.move(b.id, {startAt, bookableId: withId.peek(), notify: notify.peek(), force}), 'Move it');
|
|
475
|
-
if (!moved) return;
|
|
476
|
-
E.toast(`Moved to ${timeRange(moved, ctx.tz)}.`, {type: 'success'});
|
|
477
|
-
changed(ctx);
|
|
478
|
-
panel?.close(true);
|
|
479
|
-
} catch (err) {
|
|
480
|
-
E.toast(`Not moved: ${errText(err)}`, {type: 'error'});
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}).then(p => { panel = p; if (!p) resolve(null); }, (err) => {
|
|
485
|
-
// The panel could not be built (openPanel has released its claim and tidied up).
|
|
486
|
-
E.toast(`That could not open: ${errText(err)}`, {type: 'error'});
|
|
487
|
-
resolve(null);
|
|
488
|
-
});
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// ---- One booking ------------------------------------------------------------------
|
|
493
|
-
|
|
494
|
-
export async function openBooking(ctx, id) {
|
|
495
|
-
const release = claim(`booking:${id}`);
|
|
496
|
-
if (!release) return null;
|
|
497
|
-
let b;
|
|
498
|
-
try { b = await api.bookings.get(id); } catch (err) { release(); if (ctx.here()) E.toast(`That booking could not be opened: ${errText(err)}`, {type: 'error'}); return null; }
|
|
499
|
-
if (!ctx.here()) { release(); return null; }
|
|
500
|
-
const staffNote = M.observable(b.staffNote || '');
|
|
501
|
-
const saved = M.observable(b.staffNote || '');
|
|
502
|
-
const tone = `is-${STATUS_TONE[b.status] || 'muted'}`;
|
|
503
|
-
const history = (b.history || []).slice().reverse().map(h => {
|
|
504
|
-
const what = {made: 'Booked', moved: 'Moved', cancelled: 'Cancelled', completed: 'Marked done', 'no-show': 'Marked no-show', confirmed: 'Back to booked', pending: 'Pending', 'call-opened': 'Call opened early'}[h.what] || h.what;
|
|
505
|
-
const was = h.from ? wallClock(h.from, ctx.tz) : null;
|
|
506
|
-
const extra = h.what === 'moved' && was ? ` (was ${dateLabel(was.date)}, ${was.time})` : h.reason ? `: ${h.reason}` : '';
|
|
507
|
-
return `<li><strong>${esc(what)}</strong>${esc(extra)}<small>${esc(fmtDateTime(h.at))}${h.by ? ` · ${esc(h.by)}` : ''}</small></li>`;
|
|
508
|
-
}).join('');
|
|
509
|
-
const detail = (label, value, href = '') => (value ? `<dt>${esc(label)}</dt><dd>${href ? `<a href="${esc(href)}">${esc(value)}</a>` : esc(value)}</dd>` : '');
|
|
510
|
-
const live = b.status !== 'cancelled';
|
|
511
|
-
const answers = answerRows(b.ext?.answers, ctx.boot.services.find(x => x.id === b.serviceId));
|
|
512
|
-
let panel = null;
|
|
513
|
-
let sections = null;
|
|
514
|
-
let unrouteMail = () => {};
|
|
515
|
-
const act = (fn) => async () => { const r = await fn(); if (r) panel?.close(); };
|
|
516
|
-
panel = await openPanel({
|
|
517
|
-
title: `${b.serviceName}: ${b.name}`,
|
|
518
|
-
size: 'md',
|
|
519
|
-
ctx, release,
|
|
520
|
-
model: {staffNote, saved},
|
|
521
|
-
dirty: () => staffNote.peek() !== saved.peek(),
|
|
522
|
-
draft: {
|
|
523
|
-
key: `note:${b.id}`, label: `staff note for ${b.name}`, was: b.updatedAt || '',
|
|
524
|
-
values: () => ({staffNote: staffNote.peek()}),
|
|
525
|
-
apply: (v) => { if (typeof v.staffNote === 'string') staffNote.value = v.staffNote; }
|
|
526
|
-
},
|
|
527
|
-
cleanup: () => { sections?.destroy(); unrouteMail(); },
|
|
528
|
-
before: (el) => {
|
|
529
|
-
// The customer's address stays a link; a click goes to Email Pro's compose when it can.
|
|
530
|
-
unrouteMail = routeMailLinks(el);
|
|
531
|
-
sections = mountSections(el.querySelector('[data-part="ext"]'), 'bookingPanel', {boot: ctx.boot, booking: b,
|
|
532
|
-
refresh: () => { panel?.close(true); ctx.openBooking ? ctx.openBooking(b.id) : openBooking(ctx, b.id); }});
|
|
533
|
-
},
|
|
534
|
-
html: `<div class="bk-form bk-booking">
|
|
535
|
-
<div class="bk-booking-head">
|
|
536
|
-
<span class="bk-chip ${tone}">${esc(STATUS_LABEL[b.status] || b.status)}</span>
|
|
537
|
-
<strong>${esc(timeRange(b, ctx.tz))}</strong>
|
|
538
|
-
</div>
|
|
539
|
-
<dl class="bk-dl">
|
|
540
|
-
${detail('Service', `${b.serviceName} (${minutesLabel(b.duration || (Date.parse(b.endAt) - Date.parse(b.startAt)) / 60000)})`)}
|
|
541
|
-
${detail('With', withNames(b))}
|
|
542
|
-
${b.online ? detail('Where', 'Online - a video call') : ''}
|
|
543
|
-
${detail('Customer', b.name)}
|
|
544
|
-
${detail('Email', b.email, looksLikeAddress(b.email) ? `mailto:${encodeURIComponent(b.email)}` : '')}
|
|
545
|
-
${detail('Phone', b.phone, b.phone ? `tel:${b.phone.replace(/[^+\d]/g, '')}` : '')}
|
|
546
|
-
${detail('Their notes', b.notes)}
|
|
547
|
-
${detail('Booked', `${sourceLabel(b.source)} · ${fmtDateTime(b.createdAt || b.history?.[0]?.at)}`)}
|
|
548
|
-
${b.contactId && ctx.boot.contacts ? detail('Contact', 'In your Contacts', '#/contacts') : ''}
|
|
549
|
-
</dl>
|
|
550
|
-
${answers.length ? `<h4 class="bk-sub">Their answers</h4><dl class="bk-dl bk-answers">${answers.map(([k, v]) => `<dt>${esc(k)}</dt><dd>${esc(v)}</dd>`).join('')}</dl>` : ''}
|
|
551
|
-
<div class="bk-ext-host" data-part="ext"></div>
|
|
552
|
-
${b.hostUrl && live ? `<div class="bk-actions bk-actions-start bk-call-row">
|
|
553
|
-
<a class="btn btn-sm btn-primary" href="${esc(b.hostUrl)}" target="_blank" rel="noopener"><span data-icon="video" data-icon-size="13"></span> Start the call</a>
|
|
554
|
-
<span class="bk-muted">You are the host: let ${esc(b.name || 'them')} in when they arrive. ${Date.parse(b.callOpenedAt || '') > Date.now() - 2 * 3600000 ? 'It was opened early, so it is open now.' : 'It opens 10 minutes before the start.'}</span></div>` : ''}
|
|
555
|
-
${b.online && Number(b.callChat) > 0 ? `<div class="bk-actions bk-actions-start bk-call-chat">
|
|
556
|
-
<button type="button" class="btn btn-sm btn-outline" data-on-click="callChat"><span data-icon="message-circle" data-icon-size="13"></span> Call chat (${Number(b.callChat)} message${Number(b.callChat) === 1 ? '' : 's'})</button>
|
|
557
|
-
<span class="bk-muted">What was typed in the call's chat, read-only.</span></div>` : ''}
|
|
558
|
-
<div class="bk-actions bk-actions-start">
|
|
559
|
-
<button type="button" class="btn btn-sm btn-outline" data-on-click="move" ${live ? '' : 'disabled'}><span data-icon="move" data-icon-size="13"></span> Move</button>
|
|
560
|
-
<button type="button" class="btn btn-sm btn-outline" data-on-click="done" ${live && b.status !== 'completed' ? '' : 'disabled'}><span data-icon="check" data-icon-size="13"></span> Done</button>
|
|
561
|
-
<button type="button" class="btn btn-sm btn-outline" data-on-click="noshow" ${live && b.status !== 'no-show' ? '' : 'disabled'}><span data-icon="user-remove" data-icon-size="13"></span> No-show</button>
|
|
562
|
-
<span class="bk-spacer"></span>
|
|
563
|
-
${live
|
|
564
|
-
? '<button type="button" class="btn btn-sm btn-ghost bk-danger-text" data-on-click="cancelIt"><span data-icon="x-circle" data-icon-size="13"></span> Cancel booking</button>'
|
|
565
|
-
: '<button type="button" class="btn btn-sm btn-ghost bk-danger-text" data-on-click="remove"><span data-icon="trash" data-icon-size="13"></span> Delete</button>'}
|
|
566
|
-
</div>
|
|
567
|
-
<label class="form-label">Staff note <span data-help-title="Staff note" data-help="Only for you and your team - never sent to the customer. Ctrl+S saves it."></span></label>
|
|
568
|
-
<textarea class="form-input" rows="3" maxlength="4000" data-model="staffNote.value"></textarea>
|
|
569
|
-
<div class="bk-actions"><span class="bk-muted" data-bind-hidden="staffNote.value === saved.value">Not saved yet</span><span class="bk-spacer"></span>
|
|
570
|
-
<button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-bind-disabled="staffNote.value === saved.value">Save note</button></div>
|
|
571
|
-
<h4 class="bk-sub">History</h4>
|
|
572
|
-
<ul class="bk-history">${history || '<li class="bk-muted">Nothing yet.</li>'}</ul>
|
|
573
|
-
</div>`,
|
|
574
|
-
methods: {
|
|
575
|
-
async save() {
|
|
576
|
-
// What was sent is what is saved (the form is locked meanwhile, but say so plainly).
|
|
577
|
-
const sent = staffNote.peek();
|
|
578
|
-
try {
|
|
579
|
-
const next = await api.bookings.update(b.id, {staffNote: sent});
|
|
580
|
-
saved.value = sent;
|
|
581
|
-
panel?.rebase(next?.updatedAt);
|
|
582
|
-
E.toast('Note saved.', {type: 'success'});
|
|
583
|
-
changed(ctx);
|
|
584
|
-
} catch (err) {
|
|
585
|
-
E.toast(`Not saved: ${errText(err)}`, {type: 'error'});
|
|
586
|
-
}
|
|
587
|
-
},
|
|
588
|
-
async callChat() {
|
|
589
|
-
// The call's chat, read-only (1.5) - one per session, so a class's shared call has one.
|
|
590
|
-
try {
|
|
591
|
-
const [r, ui] = await Promise.all([api.bookings.callChat(b.id), import('/plugins/_lib/admin/ui/transcript.js')]);
|
|
592
|
-
await ui.openTranscript({title: `Call chat: ${b.serviceName}`, subtitle: timeRange(b, ctx.tz), items: r?.items || []});
|
|
593
|
-
} catch (err) { E.toast(`The chat could not be opened: ${errText(err)}`, {type: 'error'}); }
|
|
594
|
-
},
|
|
595
|
-
move: act(() => moveBooking(ctx, b)),
|
|
596
|
-
done: act(() => setStatus(ctx, b, 'completed')),
|
|
597
|
-
noshow: act(() => setStatus(ctx, b, 'no-show')),
|
|
598
|
-
cancelIt: act(() => cancelBooking(ctx, b)),
|
|
599
|
-
remove: act(() => deleteBooking(ctx, b))
|
|
600
|
-
}
|
|
601
|
-
});
|
|
602
|
-
return panel;
|
|
603
|
-
}
|