Files
raven-client/ayanova/src/api/gzdialog.js
2020-04-02 14:08:12 +00:00

143 lines
3.9 KiB
JavaScript

/* Xeslint-disable */
let VM_LOCAL = null;
//Calculate a reasonable time to show the alert based on the size of the message and some sane bounds
//https://ux.stackexchange.com/a/85898
function CalculateDelay(msg) {
//Min 2 seconds max 8 seconds
return Math.min(Math.max(msg.length * 50, 3000), 8000);
}
/////////////////////////////////
// Dialog, toast, notification
// utils and handlers
//
export default {
///////////////////////////////////
// WIRE UP DIALOG EVENTS
//
// called once from app.vue only
//
wireUpEventHandlers(vm) {
//Notifications: pops up and slowly disappears
///////////
//ERROR
window.$gz.eventBus.$on("notify-error", function handleNotifyWarn(
msg,
helpUrl
) {
window.$gz.store.commit("logItem", "notify-error: " + msg);
vm.$root.$gznotify({
message: msg,
type: "error",
timeout: CalculateDelay(msg),
helpUrl: helpUrl
});
});
///////////
//WARNING
window.$gz.eventBus.$on("notify-warning", function handleNotifyWarn(
msg,
helpUrl
) {
window.$gz.store.commit("logItem", "notify-warning: " + msg);
vm.$root.$gznotify({
message: msg,
type: "warning",
timeout: CalculateDelay(msg),
helpUrl: helpUrl
});
});
///////////
//INFO
window.$gz.eventBus.$on("notify-info", function handleNotifyWarn(
msg,
helpUrl
) {
window.$gz.store.commit("logItem", "notify-info: " + msg);
vm.$root.$gznotify({
message: msg,
type: "info",
timeout: CalculateDelay(msg),
helpUrl: helpUrl
});
});
///////////
//SUCCESS
window.$gz.eventBus.$on("notify-success", function handleNotifyWarn(
msg,
helpUrl
) {
vm.$root.$gznotify({
message: msg,
type: "success",
timeout: CalculateDelay(msg),
helpUrl: helpUrl
});
});
VM_LOCAL = vm;
},
/////////////////////////////////////
// Are you sure you want to delete?
//
confirmDelete() {
return VM_LOCAL.$root.$gzconfirm({
message: window.$gz.translation.get("DeletePrompt"),
yesButtonText: window.$gz.translation.get("Delete"),
noButtonText: window.$gz.translation.get("Cancel")
});
},
/////////////////////////////////////
// Are you sure you want to leave unsaved?
//
confirmLeaveUnsaved() {
return VM_LOCAL.$root.$gzconfirm({
message: window.$gz.translation.get("AreYouSureUnsavedChanges"),
yesButtonText: window.$gz.translation.get("Leave"),
noButtonText: window.$gz.translation.get("Cancel")
});
},
/////////////////////////////////////
// Display LT message with wait for ok
//
displayLTErrorMessage(tKeyText, tKeyTitle = undefined) {
return VM_LOCAL.$root.$gzconfirm({
message: tKeyText ? window.$gz.translation.get(tKeyText) : "",
title: tKeyTitle ? window.$gz.translation.get(tKeyTitle) : "",
yesButtonText: window.$gz.translation.get("OK"),
type: "error"
});
},
/////////////////////////////////////
// Custom confirmation
//
confirmGeneric(tKey) {
return VM_LOCAL.$root.$gzconfirm({
message: window.$gz.translation.get(tKey),
yesButtonText: window.$gz.translation.get("OK"),
noButtonText: window.$gz.translation.get("Cancel")
});
}
//TODO: Implement the following as it's own re-usable component instead of here
/////////////////////////////////////
// // Show a report list
// //
// async getReportChoice(vm, reports, preselected) {
// const result = await vm.$dialog.showAndWait(reportChooser, {
// reports: reports,
// title: window.$gz.translation.get("Report"),
// oktext: window.$gz.translation.get("Print"),
// canceltext: window.$gz.translation.get("Cancel"),
// selectedvalue: preselected
// });
// return result;
// }
//new functions above here
};