#26 - Loading animation + success message fix

This commit was merged in pull request #31.
This commit is contained in:
Martin Slachta
2026-06-22 11:20:28 +02:00
parent c754e18a82
commit 97ee8fc991
32 changed files with 597 additions and 175 deletions
+19 -28
View File
@@ -1,3 +1,5 @@
import { defaultEngine } from '../templating/RsvDefaultEngine.js';
export const RsvFormSender = {
get_form_url(form_id) {
return ReservairServiceAPI.restUrl + '/form/' + form_id;
@@ -36,7 +38,7 @@ export const RsvFormSender = {
form.prepend(summary);
},
show_success(form, _data) {
show_success(form, data) {
const s = ReservairStrings.form;
const wrapper = form.parentElement;
const existing = Array.from(wrapper.children);
@@ -59,7 +61,7 @@ export const RsvFormSender = {
icon.className = 'rsv-success-icon';
icon.appendChild(svg);
const body = this.build_success_body(form, s);
const body = this.build_success_body(form, s, data);
const state = document.createElement('div');
state.className = 'rsv-success-state';
@@ -86,35 +88,24 @@ export const RsvFormSender = {
state.querySelectorAll('[data-rsv-reset]').forEach(btn => btn.addEventListener('click', reset));
},
// Body of the success card. Uses the admin-configured template when the form
// ships one, filling the .rsv-success-summary placeholder (expanded server-side
// from <reservation-summary>) with a snapshot of the selected slots; otherwise
// falls back to the default text.
build_success_body(form, strings) {
const tpl = form.parentElement?.querySelector('template.rsv-form-success');
if (!tpl) {
const subtitle = document.createElement('p');
subtitle.className = 'rsv-success-msg';
subtitle.textContent = strings.success_subtitle;
return subtitle;
build_success_body(form, strings, data = {}) {
if (data.template) {
const body = document.createElement('div');
body.className = 'rsv-success-msg';
body.innerHTML = defaultEngine.render(data.template, data.data ?? {});
return body;
}
const body = document.createElement('div');
body.className = 'rsv-success-msg';
body.appendChild(tpl.content.cloneNode(true));
const subtitle = document.createElement('p');
subtitle.className = 'rsv-success-msg';
subtitle.textContent = strings.success_subtitle;
return subtitle;
},
const placeholder = body.querySelector('.rsv-success-summary');
if (placeholder) {
const summary = form.querySelector('rsv-reservation-summary');
if (summary && typeof summary.snapshot === 'function') {
placeholder.replaceWith(summary.snapshot());
} else {
placeholder.remove();
}
}
return body;
// Renders a message template (interpolation + custom elements) to HTML the
// same way show_success does — used by the admin editor's live preview.
render_template(template, data = {}) {
return defaultEngine.render(template ?? '', data ?? {});
},
set_loading(form, is_loading) {