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

@@ -129,65 +129,19 @@
</v-overlay>
</div>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
const FORM_KEY = "reminder-edit";
const API_BASE_URL = "reminder/";
const FORM_CUSTOM_TEMPLATE_KEY = "Reminder"; //<-- Should always be CoreBizObject AyaType name here where possible
const FORM_CUSTOM_TEMPLATE_KEY = "Reminder";
export default {
async created() {
let vm = this;
const vm = this;
try {
await initForm(vm);
vm.rights = window.$gz.role.getRights(window.$gz.type.Reminder);
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;
// window.$gz.form.setFormState({
// vm: vm,
// loading: false
// });
// } else {
// await vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
// }
// } else {
// //----------------------------------------------------------
// //NEW OBJECT DEFAULTS
// let defaultDates = window.$gz.locale.defaultStartDateTime(
// window.$gz.type.Reminder
// );
// vm.obj.startDate = defaultDates.start;
// vm.obj.stopDate = defaultDates.end;
// //----------------------------------------------------------
// window.$gz.form.setFormState({
// vm: vm,
// loading: false
// });
// }
// 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?
@@ -195,7 +149,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
@@ -216,7 +170,7 @@ export default {
} else {
//----------------------------------------------------------
//NEW OBJECT DEFAULTS
let defaultDates = window.$gz.locale.defaultStartDateTime(
const defaultDates = window.$gz.locale.defaultStartDateTime(
window.$gz.type.Reminder
);
vm.obj.startDate = defaultDates.start;
@@ -230,7 +184,7 @@ export default {
vm: vm,
loading: false,
dirty: setDirty,
valid: setValid
valid: true
});
generateMenu(vm);
@@ -257,26 +211,20 @@ export default {
data() {
return {
formCustomTemplateKey: FORM_CUSTOM_TEMPLATE_KEY,
obj:
//IMPORTANT NOTE: Fields that are NON NULLABLE in the schema for the table but *are* hideable **MUST** have a default value set here or else there will be no way to save the record
//I.E. Serial, usertype fields, ACTIVE
//Also, if it's a non-nullable Enum backed field then it should have a valid selection i.e. not zero if there is no zero
{
id: 0,
concurrency: 0,
name: null,
active: true,
notes: null,
wiki: null,
customFields: "{}",
tags: [],
startDate: null,
stopDate: null,
userId: window.$gz.store.state.userId,
color: "#EBEBEBFF" //very light gray or it will be invisible in white schedule control
},
//mStartDate = new SmartDate(DBUtil.CurrentWorkingDateTime);//case 1967 set starting date so can't save with no date
//mStopDate = new SmartDate(DBUtil.CurrentWorkingDateTime.AddHours(1));//case 1967 starting default
obj: {
id: 0,
concurrency: 0,
name: null,
active: true,
notes: null,
wiki: null,
customFields: "{}",
tags: [],
startDate: null,
stopDate: null,
userId: window.$gz.store.state.userId,
color: "#EBEBEBFF" //very light gray or it will be invisible in white schedule control
},
formState: {
ready: false,
dirty: false,
@@ -291,23 +239,17 @@ export default {
ayaType: window.$gz.type.Reminder
};
},
//WATCHERS
watch: {
formState: {
handler: function(val) {
//,oldval is available here too if necessary
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",
@@ -348,150 +290,120 @@ export default {
}
},
async getDataFromApi(recordId) {
let vm = this;
window.$gz.form.setFormState({
vm: vm,
vm: this,
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);
window.$gz.form.deleteAllErrorBoxErrors(this);
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);
window.$gz.form.handleObjectNotFound(this);
}
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
this.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(this);
} else {
vm.obj = res.data;
//modify the menu as necessary
generateMenu(vm);
//Update the form status
this.obj = res.data;
generateMenu(this);
window.$gz.form.setFormState({
vm: vm,
vm: this,
dirty: false,
valid: true,
loading: false
});
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
window.$gz.errorHandler.handleFormError(error, this);
} finally {
window.$gz.form.setFormState({
vm: vm,
vm: this,
loading: false
});
}
},
async submit() {
let vm = this;
if (vm.canSave == false) {
if (this.canSave == false) {
return;
}
try {
window.$gz.form.setFormState({
vm: vm,
vm: this,
loading: true
});
let url = API_BASE_URL; // + vm.$route.params.recordid;
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.upsert(url, vm.obj);
window.$gz.form.deleteAllErrorBoxErrors(this);
const res = await window.$gz.api.upsert(API_BASE_URL, this.obj);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
this.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(this);
} 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
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()
//POST
this.obj = res.data;
this.$router.replace({
name: "reminder-edit",
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)
vm.obj.concurrency = res.data.concurrency;
//PUT
this.obj.concurrency = res.data.concurrency;
}
//Update the form status
window.$gz.form.setFormState({
vm: vm,
vm: this,
dirty: false,
valid: true
});
}
} catch (ex) {
window.$gz.errorHandler.handleFormError(ex, vm);
window.$gz.errorHandler.handleFormError(ex, this);
} finally {
window.$gz.form.setFormState({
vm: vm,
vm: this,
loading: false
});
}
},
async remove() {
let vm = this;
try {
let dialogResult = await window.$gz.dialog.confirmDelete();
const dialogResult = await window.$gz.dialog.confirmDelete();
if (dialogResult != true) {
return;
}
//do the delete
window.$gz.form.setFormState({
vm: vm,
vm: this,
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:
if (this.$route.params.recordid == 0) {
JUST_DELETED = true;
// navigate backwards
vm.$router.go(-1);
this.$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);
window.$gz.form.deleteAllErrorBoxErrors(this);
const res = await window.$gz.api.remove(
API_BASE_URL + this.$route.params.recordid
);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
this.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(this);
} 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);
this.$router.go(-1);
}
}
} catch (error) {
//Update the form status
window.$gz.form.setFormState({
vm: vm,
vm: this,
loading: false
});
window.$gz.errorHandler.handleFormError(error, vm);
window.$gz.errorHandler.handleFormError(error, this);
}
},
duplicate() {
//Navigate to new record
this.$router.push({
name: "reminder-edit",
params: {
@@ -500,8 +412,6 @@ export default {
}
});
}
//end methods
}
};
@@ -512,7 +422,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":
@@ -531,7 +441,7 @@ async function clickHandler(menuItem) {
m.vm.duplicate();
break;
case "report":
let res = await m.vm.$refs.reportSelector.open(
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.Reminder,
selectedRowIds: [m.vm.obj.id]
@@ -558,7 +468,7 @@ async function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
let menuOptions = {
const menuOptions = {
isMain: false,
readOnly: vm.formState.readOnly,
icon: "$ayiStickyNote",
@@ -592,8 +502,6 @@ function generateMenu(vm) {
});
}
//REPORTS
//Report not Print, print is a further option
menuOptions.menuItems.push({
title: "Report",
icon: "$ayiFileAlt",
@@ -601,8 +509,7 @@ function generateMenu(vm) {
vm: vm
});
//get last report selected
let lastReport = window.$gz.form.getLastReport(FORM_KEY);
const lastReport = window.$gz.form.getLastReport(FORM_KEY);
if (lastReport != null) {
menuOptions.menuItems.push({
title: lastReport.name,
@@ -642,7 +549,7 @@ let JUST_DELETED = false;
//
//
async function initForm(vm) {
await fetchTranslatedText(vm);
await fetchTranslatedText();
await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
}
@@ -650,7 +557,7 @@ async function initForm(vm) {
//
// Ensures UI translated text is available
//
async function fetchTranslatedText(vm) {
async function fetchTranslatedText() {
await window.$gz.translation.cacheTranslations([
"Reminder",
"ReminderName",