add success dialog

This commit is contained in:
2025-02-13 13:57:49 +08:00
parent bd59a1c267
commit fe23e8e8b3
4 changed files with 148 additions and 14 deletions

View File

@@ -20,6 +20,7 @@ const classItems = [
let notificationEl;
let loadingEl;
let dialogEl;
function getHeaderSpace(className, isDetailPage) {
const headerSpace = (isDetailPage ? kintone.app.record : kintone.app).getHeaderMenuSpaceElement();
@@ -231,16 +232,16 @@ function convertToWesternYear(year, era) {
function getFormatDateString(dateObjOrYear, month, date) {
let year = dateObjOrYear;
if (typeof dateObjOrYear === "object") {
if (typeof dateObjOrYear === "object" && !month && !date) {
year = dateObjOrYear.getFullYear();
month = dateObjOrYear.getMonth() + 1;
date = dateObjOrYear.getDate();
}
const formatY = year;
const formatM = String(month).padStart(2, '0');
const formatD = String(date).padStart(2, '0');
const formatD = date ? String(date).padStart(2, '0') : '';
return `${formatY}-${formatM}-${formatD}`;
return formatY + '-' + formatM + (formatD && ('-' + formatD));
}
function loading(show, text) {
@@ -286,6 +287,70 @@ function buildNotification(type, text, duration = -1) {
if (!notificationEl) {
notificationEl = new Kuc.Notification(param);
} else {
Object.assign(notificationEl, param)
Object.assign(notificationEl, param);
}
}
/**
options: {
icon: '' | 'info' | 'success' | 'error' | 'warning' | 'question',
title: string,
content: string|HTMLElement,
header: string|HTMLElement,
footer: string|HTMLElement,
dataHolder: {},
// ↓ if not footer ↓
ok: string = 'OK',
cancel: boolean|string = 'キャンセル',
onOk: (dataHolder, e) => void,
onCancel: (dataHolder, e) => void,
onClose: (dataHolder, e) => void,
}
*/
function showDialog(options) {
if (!dialogEl) {
createDialogEl(options);
} else {
Object.assign(dialogEl, options);
}
dialogEl.open();
}
function createDialogEl({ ok, cancel, onOk, onCancel, onClose, ...options }) {
if (!options.footer) {
const divEl = document.createElement('div');
divEl.style.textAlign = 'right';
if (cancel !== false) {
const cancelButton = new Kuc.Button({
text: cancel || 'Cancel',
type: 'normal'
});
cancelButton.style.paddingRight = '8px';
cancelButton.addEventListener('click', (event) => {
onCancel && onCancel(dialogEl.dataHolder, event);
dialogEl.close();
});
divEl.appendChild(cancelButton);
}
const okButton = new Kuc.Button({
text: ok || 'OK',
type: 'submit'
});
okButton.addEventListener('click', (event) => {
onOk && onOk(dialogEl.dataHolder, event);
dialogEl.close();
});
divEl.appendChild(okButton);
options.footer = divEl;
}
dialogEl = new Kuc.Dialog(options);
if (onClose) {
dialogEl.addEventListener('close', (event) => {
onClose(dialogEl.dataHolder, event);
});
}
}