fix
This commit is contained in:
@@ -52,6 +52,33 @@ export function confirmDialog({ title, body, confirmText = 'CONFIRM', cancelText
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A modal dialog around caller-built content (form fields and so on). Returns
|
||||
* { result, confirm, close }: `result` resolves true on the confirm button and
|
||||
* false on cancel or Escape; the caller can enable/disable `confirm` as it
|
||||
* validates, and reads its own fields after `result` resolves.
|
||||
*/
|
||||
export function customDialog({ title, content, confirmText = 'OK', cancelText = 'CANCEL', danger = false }) {
|
||||
const dlg = document.getElementById('dialog');
|
||||
let resolve;
|
||||
const result = new Promise((r) => { resolve = r; });
|
||||
const finish = (v) => {
|
||||
if (dlg.open) dlg.close();
|
||||
resolve(v);
|
||||
};
|
||||
const confirm = h('button', { class: `btn ${danger ? 'danger' : 'primary'}`, type: 'button', onclick: () => finish(true) }, confirmText);
|
||||
clear(dlg).append(
|
||||
h('div', { class: `panel dialog ${danger ? 'danger' : ''}` },
|
||||
h('div', { class: 'panel-title' }, title),
|
||||
h('div', { class: 'panel-body stack' }, ...content),
|
||||
h('div', { class: 'actions' }, h('button', { class: 'btn', type: 'button', onclick: () => finish(false) }, cancelText), confirm),
|
||||
),
|
||||
);
|
||||
dlg.oncancel = () => resolve(false);
|
||||
dlg.showModal();
|
||||
return { result, confirm, close: finish };
|
||||
}
|
||||
|
||||
export function download(filename, bytes, type = 'application/octet-stream') {
|
||||
const url = URL.createObjectURL(new Blob([bytes], { type }));
|
||||
const a = h('a', { href: url, download: filename });
|
||||
|
||||
Reference in New Issue
Block a user