This commit is contained in:
2020-07-27 15:50:29 +00:00
parent 9a0a6f441f
commit b4ef3376b2
3 changed files with 228 additions and 10 deletions

View File

@@ -12,11 +12,11 @@ ____________
## CURRENT STAGE:
todo: UI QUICK NOTIFY need a place to send a General (old "quick") notification directly to a user and test it works via email delivery as well when user subscribes to general via email
todo: UI QUICK NOTIFY "Direct notification" need a place to send a General (old "quick") notification directly to a user and test it works via email delivery as well when user subscribes to general via email
Maybe from the IN APP notification form itself as a link in the menu?
Can choose any user except customer type unless you're of a certain higher level role allowed to deal with customers like service manager, sales manager, biz admin etc
todo: if no notifications in app should show "no data" or equivalent
todo: As biz objects are fleshed out need to also code their notification event stuff as well
todo: Localize this message or get rid of it, it's annoying and possibly useless
"Error checking for notifications, see about->log for details; log out and back in again to reset "

View File

@@ -235,7 +235,7 @@ async function clickHandler(menuItem) {
case "refresh":
await m.vm.getDataFromApi();
break;
// case "extensions":
// case "directnotify":
// let res = await m.vm.$refs.extensions.open();
// break;
@@ -284,12 +284,12 @@ function generateMenu(vm) {
// vm: vm
// });
// menuOptions.menuItems.push({
// title: "Extensions",
// icon: "fa-puzzle-piece",
// key: FORM_KEY + ":extensions",
// vm: vm
// });
menuOptions.menuItems.push({
title: "DirectNotification",
icon: "fa-comment-alt",
data: "home-notify-direct",
key: "app:nav"
});
window.$gz.eventBus.$emit("menu-change", menuOptions);
}
/////////////////////////////////
@@ -308,7 +308,8 @@ async function fetchTranslatedText(vm) {
await window.$gz.translation.cacheTranslations([
"NotifySubscription",
"Server",
"Notifications"
"Notifications",
"DirectNotification"
]);
}

View File

@@ -0,0 +1,217 @@
<template>
<v-row v-if="formState.ready">
<v-col>
<v-form ref="form">
<v-row>
<gz-error :errorBoxMessage="formState.errorBoxMessage"></gz-error>
</v-row>
</v-form>
</v-col>
</v-row>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
////////////////////////////////////////////////////////////////////////////////////////////////////////////
const FORM_KEY = "home-notify-direct";
export default {
async created() {
let vm = this;
try {
await initForm(vm);
vm.rights = window.$gz.role.fullRightsObject();
generateMenu(vm);
vm.formState.ready = true;
window.$gz.form.setFormState({
vm: vm,
dirty: false,
valid: true,
loading: false,
readOnly: false
});
window.$gz.eventBus.$on("menu-click", clickHandler);
//-------------
//------------------
} catch (err) {
vm.formState.ready = true;
window.$gz.errorHandler.handleFormError(err, vm);
}
},
async beforeRouteLeave(to, from, next) {
if (!this.formState.dirty) {
next();
return;
}
if ((await window.$gz.dialog.confirmLeaveUnsaved()) === true) {
next();
} else {
next(false);
}
},
beforeDestroy() {
window.$gz.eventBus.$off("menu-click", clickHandler);
},
components: {},
data() {
return {
users: [],
message: null,
formState: {
ready: false,
dirty: false,
valid: true,
readOnly: false,
loading: true,
errorBoxMessage: null,
appError: null,
serverError: {}
},
rights: window.$gz.role.fullRightsObject()
};
},
//WATCHERS
watch: {
formState: {
handler: function(val) {
//,oldval is available here too if necessary
if (this.formState.loading) {
return;
}
//enable / disable save button
let canSave = val.dirty && val.valid && !val.readOnly;
if (canSave) {
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
} else {
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
}
},
deep: true
}
},
computed: {
canSave: function() {
return this.formState.valid && this.formState.dirty;
}
},
methods: {
translation() {
return window.$gz.translation;
},
form() {
return window.$gz.form;
},
fieldValueChanged(ref) {
if (!this.formState.loading && !this.formState.readOnly) {
window.$gz.form.fieldValueChanged(this, ref);
}
},
async submit() {
let vm = this;
if (vm.canSave) {
vm.formState.loading = true;
//always submit from this form for the current logged in user id
let url = API_BASE_URL;
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(vm);
try {
let res = await window.$gz.api.upsert(url, vm.obj);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
//Only a post, no data returned
window.$gz.form.setFormState({
vm: vm,
dirty: false
});
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
} finally {
vm.loading = false;
}
}
}
}
};
/////////////////////////////
//
//
function clickHandler(menuItem) {
if (!menuItem) {
return;
}
let m = window.$gz.menu.parseMenuItem(menuItem);
if (m.owner == FORM_KEY && !m.disabled) {
switch (m.key) {
case "save":
m.vm.submit();
break;
default:
window.$gz.eventBus.$emit(
"notify-warning",
FORM_KEY + "::context click: [" + m.key + "]"
);
}
}
}
//////////////////////
//
//
function generateMenu(vm) {
let menuOptions = {
isMain: true,
icon: "fa-comment-alt",
title: "DirectNotification",
helpUrl: "form-home-notify-direct",
menuItems: []
};
if (vm.rights.change) {
menuOptions.menuItems.push({
title: "Save",
icon: "fa-save",
surface: true,
key: FORM_KEY + ":save",
vm: vm
});
}
window.$gz.eventBus.$emit("menu-change", menuOptions);
}
/////////////////////////////////
//
//
async function initForm(vm) {
await fetchTranslatedText(vm);
}
//////////////////////////////////////////////////////////
//
// Ensures UI translated text is available
//
async function fetchTranslatedText(vm) {
await window.$gz.translation.cacheTranslations([
"DirectNotification",
"UserList",
"MemoMessage"
]);
}
</script>