add success dialog
This commit is contained in:
73
src/utils.js
73
src/utils.js
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -29,11 +29,29 @@ class BatchCreateHandler {
|
||||
// console.log(records);
|
||||
|
||||
const createResult = await this.createData(api, records, todayString);
|
||||
showSuccess(true, "出欠簿一括作成完了");
|
||||
location.reload();
|
||||
// showSuccess(true, "出欠簿一括作成完了");
|
||||
|
||||
this.showSuccessDialog(createResult);
|
||||
loading(false);
|
||||
}
|
||||
|
||||
showSuccessDialog(result) {
|
||||
const contentEl = document.createElement('div');
|
||||
contentEl.style.fontSize = '16px';
|
||||
if (!result) {
|
||||
contentEl.innerHTML = "データの更新はありません。既に最新の状態です。";
|
||||
} else {
|
||||
contentEl.innerHTML = `${result.records.length}件のデータを挿入しました。`;
|
||||
}
|
||||
showDialog({
|
||||
title: '出欠簿一括作成完了',
|
||||
content: contentEl,
|
||||
ok: '更新して確認',
|
||||
cancel: false,
|
||||
onClose: () => { location.reload() }
|
||||
});
|
||||
}
|
||||
|
||||
generateRecords = (today, todayString, masterRecords) => {
|
||||
return masterRecords.reduce((acc, masterRecord) => {
|
||||
if (this.needCreateData(masterRecord, today)) {
|
||||
|
||||
@@ -12,7 +12,29 @@ class Link1Handler {
|
||||
headerSpace.appendChild(elements['link-1-action-area']);
|
||||
}
|
||||
|
||||
handleLink(e, { year, month }) {
|
||||
handleLink = async (e, { year, month }) => {
|
||||
loading(true, '日誌データ連携中...');
|
||||
showError(false);
|
||||
const api = new KintoneRestAPIClient();
|
||||
|
||||
const dateString = getFormatDateString(year, month);
|
||||
|
||||
// 本アプリからデータを読み取る
|
||||
// const currentAppRecords = await this.getRecords(api, dateString);
|
||||
// if (!currentAppRecords) {
|
||||
// // エラー
|
||||
// loading(false);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// const record = this.generateRecord(dateString, currentAppRecords);
|
||||
// console.log(record);
|
||||
|
||||
// const result = await this.insertOrUpdateData(api, record, dateString);
|
||||
// if (result) {
|
||||
// showSuccess(true, "日誌データ連携作成完了");
|
||||
// }
|
||||
// loading(false);
|
||||
}
|
||||
|
||||
static getInstance(headerSpace) {
|
||||
|
||||
@@ -34,17 +34,38 @@ class Link2Handler {
|
||||
|
||||
const result = await this.insertOrUpdateData(api, record, dateString);
|
||||
if (result) {
|
||||
showSuccess(true, "日誌データ連携作成完了");
|
||||
// showSuccess(true, "日誌データ連携作成完了");
|
||||
this.showSuccessDialog(result);
|
||||
}
|
||||
loading(false);
|
||||
}
|
||||
|
||||
showSuccessDialog(result) {
|
||||
const contentEl = document.createElement('div');
|
||||
contentEl.style.fontSize = '16px';
|
||||
if (!result.size) {
|
||||
contentEl.innerHTML = `${result.dateString}に園児別テーブルに追加するデータはありませんでした。`;
|
||||
} else if (result.type === 'update') {
|
||||
contentEl.innerHTML = `${result.dateString}の園児別テーブルに${result.size}件のデータを再作成しました。`;
|
||||
} else {
|
||||
contentEl.innerHTML = `${result.dateString}の日誌は生成しましたが、園児別テーブルに${result.size}件のデータを追加しました。`;
|
||||
}
|
||||
showDialog({
|
||||
title: '日誌データ連携作成完了',
|
||||
content: contentEl,
|
||||
ok: 'アプリへ行く',
|
||||
cancel: '閉じる',
|
||||
dataHolder: result,
|
||||
onOk: (dataHolder) => { window.open(`${location.origin}/k/${env["2歳以上日誌出力用"].appId}/show#record=` + dataHolder.id) },
|
||||
});
|
||||
}
|
||||
|
||||
getRecords = async (api, dateString) => {
|
||||
try {
|
||||
return await api.record.getAllRecordsWithId({
|
||||
app: env["園児別出欠簿入力"].appId,
|
||||
fields: ['クラス', "園児名", "園での様子_伝達事項", "評価反省"],
|
||||
condition: `学年 in ("2歳児", "3歳児", "4歳児", "5歳児") and 登園日 = "${dateString}"`
|
||||
condition: `学年 not in ("", "0歳児", "1歳児") and 登園日 = "${dateString}"`
|
||||
});
|
||||
} catch (e) {
|
||||
showError(true, '園児台帳アプリのデータ読み取りエラー\n - ' + e);
|
||||
@@ -83,16 +104,24 @@ class Link2Handler {
|
||||
app: env["2歳以上日誌出力用"].appId,
|
||||
record
|
||||
}
|
||||
const result = {
|
||||
id: generatedRecordId,
|
||||
type: generatedRecordId ? 'update' : 'insert',
|
||||
size: record["園児別テーブル"].value.length,
|
||||
dateString
|
||||
};
|
||||
|
||||
let addResult;
|
||||
if (generatedRecordId) {
|
||||
let awaitResult;
|
||||
if (result.type === 'update') {
|
||||
param.id = generatedRecordId;
|
||||
// 本アプリの当日データでテーブルを上書きし、対応する園児データがない行を【削除】します
|
||||
addResult = await api.record.updateRecord(param);
|
||||
awaitResult = await api.record.updateRecord(param);
|
||||
} else {
|
||||
addResult = await api.record.addRecord(param);
|
||||
awaitResult = await api.record.addRecord(param);
|
||||
}
|
||||
return addResult;
|
||||
Object.assign(result, awaitResult);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
showError(true, '日誌データ連携作成失敗\n - ' + e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user