Files
raven-client/ayanova/src/api/gzdialog.js
2020-06-16 23:42:19 +00:00

147 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 handleNotifyInfo(
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 handleNotifySuccess(
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"
});
},
/////////////////////////////////////
// Display LT message with wait for ok
//
displayLTModalNotificationMessage(
tKeyText,
tKeyTitle = undefined,
ttype = "info",
tHelpUrl = 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: ttype,
helpUrl: tHelpUrl
});
},
/////////////////////////////////////
// Custom confirmation
//
confirmGeneric(tKey, ttype = "info") {
return VM_LOCAL.$root.$gzconfirm({
message: window.$gz.translation.get(tKey),
yesButtonText: window.$gz.translation.get("OK"),
noButtonText: window.$gz.translation.get("Cancel"),
type: ttype
});
}
//new functions above here
};