HUGE REFACTOR / CLEANUP

if there is a issue it's probably something in here that was changed
This commit is contained in:
2021-09-28 20:19:44 +00:00
parent 51eddfede9
commit d0afdd9855
238 changed files with 3127 additions and 8614 deletions

View File

@@ -5,7 +5,6 @@
<v-form ref="form">
<v-row>
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
<!-- {{ obj }} -->
<v-col cols="12" sm="6" lg="4" xl="3">
<v-select
v-model="obj.eventType"
@@ -51,7 +50,6 @@
>$ayiCheckCircle</v-icon
></v-list-item-title
>
<v-list-item-subtitle>
{{ data.item.notes }}</v-list-item-subtitle
>
@@ -194,51 +192,18 @@
</v-overlay>
</div>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
const FORM_KEY = "notify-subscription";
const API_BASE_URL = "notify-subscription/";
export default {
async created() {
//created is called when the route is updated to show a new record even though we don't need to re-init again
let vm = this;
const vm = this;
try {
await initForm(vm);
vm.rights = window.$gz.role.getRights(window.$gz.type.NotifySubscription);
vm.formState.readOnly = !vm.rights.change;
window.$gz.eventBus.$on("menu-click", clickHandler);
// //id 0 means create or duplicate to new
// if (vm.$route.params.recordid != 0) {
// //is there already an obj from a prior operation?
// if (this.$route.params.obj) {
// //yes, no need to fetch it
// this.obj = this.$route.params.obj;
// vm.formState.loading = false; //here we handle it immediately
// } else {
// await vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
// }
// } else {
// //default to their configured email address on new record
// this.obj.deliveryAddress = this.$store.state.userOptions.emailAddress;
// vm.formState.loading = false; //here we handle it immediately
// }
// //set initial form status
// window.$gz.form.setFormState({
// vm: vm,
// dirty: false,
// valid: true
// });
let setDirty = false;
let setValid = true;
//id 0 means create or duplicate to new
if (vm.$route.params.recordid != 0) {
//is there already an obj from a prior operation?
@@ -246,7 +211,7 @@ export default {
//yes, no need to fetch it
this.obj = this.$route.params.obj;
} else {
await vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
await vm.getDataFromApi(vm.$route.params.recordid);
}
} else {
//Might be a duplicate and contain another record
@@ -260,14 +225,12 @@ export default {
this.obj.deliveryAddress = this.$store.state.userOptions.emailAddress;
}
}
window.$gz.form.setFormState({
vm: vm,
loading: false,
dirty: setDirty,
valid: setValid
valid: true
});
generateMenu(vm);
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
@@ -297,22 +260,6 @@ export default {
deliveryMethods: [],
coreAyaTypes: []
},
/* public long Id { get; set; }
public uint Concurrency { get; set; }
[Required]
public long UserId { get; set; }
public AyaType? AyaType { get; set; }
[Required]
public NotifyEventType EventType { get; set; }
public TimeSpan? AdvanceNotice { get; set; } //Note: I've been doing nullable wrong sort of: https://stackoverflow.com/a/29149207/8939
public long? IdValue { get; set; }
public decimal? DecValue { get; set; }
[Required]
public NotifyDeliveryMethod DeliveryMethod { get; set; }
public string DeliveryAddress { get; set; }
public long? LinkReportId { get; set; }
public List<string> tags { get; set; }*/
obj: {
id: 0,
concurrency: 0,
@@ -327,7 +274,6 @@ export default {
linkReportId: 0,
tags: []
},
formState: {
ready: false,
dirty: false,
@@ -342,22 +288,17 @@ export default {
ayaType: window.$gz.type.NotifySubscription
};
},
//WATCHERS
watch: {
formState: {
handler: function(val) {
if (this.formState.loading) {
return;
}
//enable / disable save button
if (val.dirty && val.valid && !val.readOnly) {
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
} else {
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
}
//enable / disable duplicate / new button
if (!val.dirty && val.valid && !val.readOnly) {
window.$gz.eventBus.$emit(
"menu-enable-item",
@@ -402,7 +343,6 @@ export default {
//UnitMeterReadingMultipleExceeded=26,
return this.obj.eventType == 26;
},
showAyaType() {
switch (this.obj.eventType) {
case 1:
@@ -486,7 +426,6 @@ export default {
!this.formState.loading &&
!this.formState.readOnly
) {
//"fieldValueChanged('eventType')"
//if it's a general notification make sure delivery is set to email
if (ref == "eventType" && this.obj.eventType == 27) {
this.obj.deliveryMethod = 2;
@@ -495,19 +434,15 @@ export default {
}
},
async getDataFromApi(recordId) {
let vm = this;
const vm = this;
vm.formState.loading = true;
if (!recordId) {
throw new Error(FORM_KEY + "::getDataFromApi -> Missing recordID!");
}
let url = API_BASE_URL + recordId;
try {
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.get(url);
const res = await window.$gz.api.get(API_BASE_URL + recordId);
if (res.error) {
//Not found?
if (res.error.code == "2010") {
window.$gz.form.handleObjectNotFound(vm);
}
@@ -516,11 +451,7 @@ export default {
vm.formState.loading = false;
} else {
vm.obj = res.data;
//modify the menu as necessary
generateMenu(vm);
//Update the form status
window.$gz.form.setFormState({
vm: vm,
dirty: false,
@@ -535,48 +466,37 @@ export default {
}
},
async submit() {
let vm = this;
const vm = this;
if (vm.canSave == false) {
return;
}
try {
vm.formState.loading = true;
let url = API_BASE_URL;
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(vm);
//don't send the deliveryaddress if it's an in-app notification
if (vm.obj.deliveryMethod == 1) {
vm.obj.deliveryAddress = null;
}
let res = await window.$gz.api.upsert(url, vm.obj);
const res = await window.$gz.api.upsert(API_BASE_URL, vm.obj);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
//Logic for detecting if a post or put: if id then it was a post, if no id then it was a put
if (res.data.id) {
//POST - whole new object returned
//POST
vm.obj = res.data;
//Change URL to new record
//NOTE: will not cause a page re-render, almost nothing does unless forced with a KEY property or using router.GO()
this.$router.replace({
name: "home-notify-subscription",
params: {
recordid: res.data.id,
obj: res.data //Pass data object to new form
obj: res.data
}
});
} else {
//PUT - only concurrency token is returned (**warning, if server changes object other fields then this needs to act more like POST above but is more efficient this way**)
//Handle "put" of an existing record (UPDATE)
//PUT
vm.obj.concurrency = res.data.concurrency;
}
//Update the form status
window.$gz.form.setFormState({
vm: vm,
dirty: false,
@@ -590,34 +510,26 @@ export default {
}
},
async remove() {
let vm = this;
const vm = this;
try {
let dialogResult = await window.$gz.dialog.confirmDelete();
const dialogResult = await window.$gz.dialog.confirmDelete();
if (dialogResult != true) {
return;
}
//do the delete
vm.formState.loading = true;
//No need to delete a new record, just abandon it...
if (vm.$route.params.recordid == 0) {
//this should not get offered for delete but to be safe and clear just in case:
JUST_DELETED = true;
// navigate backwards
vm.$router.go(-1);
} else {
let url = API_BASE_URL + vm.$route.params.recordid;
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.remove(url);
const res = await window.$gz.api.remove(
API_BASE_URL + vm.$route.params.recordid
);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
//workaround to prevent warning about leaving dirty record
//For some reason I couldn't just reset isdirty in formstate
JUST_DELETED = true;
// navigate backwards
vm.$router.go(-1);
}
}
@@ -628,7 +540,6 @@ export default {
}
},
duplicate() {
//Navigate to new record
this.$router.push({
name: "home-notify-subscription",
params: {
@@ -647,7 +558,7 @@ async function clickHandler(menuItem) {
if (!menuItem) {
return;
}
let m = window.$gz.menu.parseMenuItem(menuItem);
const m = window.$gz.menu.parseMenuItem(menuItem);
if (m.owner == FORM_KEY && !m.disabled) {
switch (m.key) {
case "save":
@@ -665,20 +576,6 @@ async function clickHandler(menuItem) {
case "duplicate":
m.vm.duplicate();
break;
// case "report":
// let res = await m.vm.$refs.reportSelector.open(
// {
// AType: window.$gz.type.NotifySubscription,
// selectedRowIds: [m.vm.obj.id]
// },
// m.id
// );
// if (res == null) {
// return;
// }
// window.$gz.form.setLastReport(FORM_KEY, res);
// generateMenu(m.vm);
// break;
default:
window.$gz.eventBus.$emit(
"notify-warning",
@@ -692,7 +589,7 @@ async function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
let menuOptions = {
const menuOptions = {
isMain: false,
readOnly: vm.formState.readOnly,
icon: "$ayiBullhorn",
@@ -753,7 +650,6 @@ let JUST_DELETED = false;
//
async function initForm(vm) {
await fetchTranslatedText(vm);
// await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
await populateSelectionLists(vm);
}
@@ -787,7 +683,6 @@ async function populateSelectionLists(vm) {
if (window.$gz.store.getters.isCustomerUser) {
vm.selectLists.eventTypes = tempEventTypes.filter(z => {
//return true if it's a type allowed by customer *and* they have customerRights to it
switch (z.id) {
case 6:
return window.$gz.store.state.customerRights.notifyCSRAccepted;
@@ -808,15 +703,12 @@ async function populateSelectionLists(vm) {
z => z.id != 6 && z.id != 7 && z.id != 21 && z.id != 31
);
}
await window.$gz.enums.fetchEnumList("NotifyDeliveryMethod");
vm.selectLists.deliveryMethods = window.$gz.enums.getSelectionList(
"NotifyDeliveryMethod"
);
await window.$gz.enums.fetchEnumList("coreview");
vm.selectLists.coreAyaTypes = window.$gz.enums.getSelectionList("coreview");
const res = await window.$gz.api.get("work-order-status/list");
if (res.error) {
vm.formState.serverError = res.error;