This commit is contained in:
2019-11-12 20:53:54 +00:00
parent 5372800378
commit 9fabd82715
4 changed files with 61 additions and 10 deletions

View File

@@ -2,6 +2,14 @@
/* Xeslint-disable */
var 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
@@ -17,16 +25,32 @@ export default {
///////////
//ERROR
window.$gz.eventBus.$on("notify-error", function handleNotifyWarn(msg) {
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: 5000 });
vm.$root.$gznotify({
message: msg,
type: "error",
timeout: CalculateDelay(msg),
helpUrl: helpUrl
});
});
///////////
//WARNING
window.$gz.eventBus.$on("notify-warning", function handleNotifyWarn(msg) {
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: 4000 });
vm.$root.$gznotify({
message: msg,
type: "warning",
timeout: CalculateDelay(msg),
helpUrl: helpUrl
});
});
///////////
@@ -39,15 +63,23 @@ export default {
vm.$root.$gznotify({
message: msg,
type: "info",
timeout: 3000,
timeout: CalculateDelay(msg),
helpUrl: helpUrl
});
});
///////////
//SUCCESS
window.$gz.eventBus.$on("notify-success", function handleNotifyWarn(msg) {
vm.$root.$gznotify({ message: msg, type: "success", timeout: 2000 });
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;