Files
ladill-transfer/resources/js/ladill-modals.js
T
isaaccladandCursor c1e3d8b3ac Initial Ladill Transfer app — file sharing with QR links.
Scaffolded from the Ladill mini/events extraction pattern: multi-file transfers,
retention controls, public landing pages, analytics, and Gitea deploy workflow.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-08 09:25:30 +00:00

76 lines
2.0 KiB
JavaScript

/**
* Lightweight modal dispatch helpers (optional — balanceGate in layout is primary).
*/
export function openLadillModal(name) {
if (!name) {
return false;
}
window.dispatchEvent(new CustomEvent('open-modal', { detail: name, bubbles: true }));
return true;
}
export function closeLadillModal(name) {
if (!name) {
return false;
}
window.dispatchEvent(new CustomEvent('close-modal', { detail: name, bubbles: true }));
return true;
}
export function ladillNeedsTopup(balance, price) {
const normalizedBalance = Number.parseFloat(balance);
const normalizedPrice = Number.parseFloat(price);
if (!Number.isFinite(normalizedBalance) || !Number.isFinite(normalizedPrice)) {
return false;
}
return normalizedBalance <= 0 || normalizedBalance < normalizedPrice;
}
export function registerLadillConfirmStore(Alpine) {
Alpine.store('ladillConfirm', {
open: false,
title: '',
message: '',
confirmLabel: 'Confirm',
cancelLabel: 'Cancel',
variant: 'danger',
_resolve: null,
ask(options = {}) {
return new Promise((resolve) => {
this.title = options.title || 'Are you sure?';
this.message = options.message || '';
this.confirmLabel = options.confirmLabel || 'Confirm';
this.cancelLabel = options.cancelLabel || 'Cancel';
this.variant = options.variant || 'danger';
this._resolve = resolve;
this.open = true;
});
},
answer(confirmed) {
if (this._resolve) {
this._resolve(confirmed);
}
this.open = false;
this._resolve = null;
},
});
window.ladillConfirm = (options = {}) => Alpine.store('ladillConfirm').ask(options);
}
export function registerLadillModalHelpers() {
window.openLadillModal = openLadillModal;
window.closeLadillModal = closeLadillModal;
window.ladillNeedsTopup = ladillNeedsTopup;
}