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

@@ -56,9 +56,6 @@
</v-row>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// CUSTOMIZE A FORM'S FIELDS
//
@@ -80,14 +77,13 @@ export default {
window.$gz.eventBus.$off("menu-click", clickHandler);
},
async created() {
let vm = this;
const vm = this;
try {
await initForm(vm);
vm.formState.readOnly = !vm.rights.change;
window.$gz.eventBus.$on("menu-click", clickHandler);
//NOTE: this would normally be in getDataFromAPI but this form doesn't really need that function so doing it here
//modify the menu as necessary
generateMenu(vm);
//init disable save button so it can be enabled only on edit to show dirty form
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
@@ -119,16 +115,12 @@ export default {
rights: window.$gz.role.getRights(window.$gz.type.FormCustom)
};
},
//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 {
@@ -168,26 +160,20 @@ export default {
this.formState.dirty = true;
},
async submit() {
let vm = this;
vm.formState.loading = true;
let url = API_BASE_URL + vm.formCustomTemplateKey;
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(vm);
this.formState.loading = true;
window.$gz.form.deleteAllErrorBoxErrors(this);
//Create template data object here....
//Note that server expects to see a string array of json template, not actual json
let newObj = {
formKey: vm.formCustomTemplateKey,
concurrency: vm.concurrency,
const newObj = {
formKey: this.formCustomTemplateKey,
concurrency: this.concurrency,
template: "[]"
};
//temporary array to hold template for later stringification
let temp = [];
const temp = [];
//Rules:
for (let i = 0; i < vm.obj.length; i++) {
let fldItem = vm.obj[i];
for (let i = 0; i < this.obj.length; i++) {
const fldItem = this.obj[i];
if (fldItem.custom == false) {
//Process regular stock field
//If it's set to hidden or required then it's template-worthy
@@ -214,33 +200,36 @@ export default {
try {
//now set the template as a json string
newObj.template = JSON.stringify(temp);
let res = await window.$gz.api.upsert(url, newObj);
const res = await window.$gz.api.upsert(
API_BASE_URL + this.formCustomTemplateKey,
newObj
);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
this.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(this);
} else {
//Handle "put" of an existing record (UPDATE) (there is no POST of a new record for this particular object)
// (there is no POST of a new record for this particular object)
//Set store values for template and token
//(update our local cached copy of the form customizations)
window.$gz.formCustomTemplate.set(
vm.formCustomTemplateKey,
this.formCustomTemplateKey,
res.data.concurrency,
newObj.template
);
//set our local concurrency token value
vm.concurrency = res.data.concurrency;
this.concurrency = res.data.concurrency;
//form is now clean
window.$gz.form.setFormState({
vm: vm,
vm: this,
dirty: false
});
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
window.$gz.errorHandler.handleFormError(error, this);
} finally {
vm.formState.loading = false;
this.formState.loading = false;
}
},
hideAll() {
@@ -259,7 +248,7 @@ 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":
@@ -282,7 +271,7 @@ function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
let menuOptions = {
const menuOptions = {
isMain: false,
readOnly: vm.formState.readOnly,
icon: "$ayiCustomize",
@@ -382,7 +371,6 @@ function populateSelectionLists(vm) {
//
function ensureTemplateIsInStore(vm) {
//Pre-cache if necessary the form customization settings that have been set before now
return window.$gz.formCustomTemplate.get(
vm.$route.params.formCustomTemplateKey
);
@@ -393,10 +381,10 @@ function ensureTemplateIsInStore(vm) {
async function initDataObject(vm) {
//Get all the fields *available* to this form (all the fields for the object defined in AyaFormFieldDefinitions.cs as SERVER)
//Note: this is not the actual customization data, just the list of fields that could be customized (or not if required mandatory)
let url = "form-field-reference/" + vm.$route.params.formCustomTemplateKey;
let res = await window.$gz.api.get(url);
const res = await window.$gz.api.get(
"form-field-reference/" + vm.$route.params.formCustomTemplateKey
);
if (res.error) {
//throw new Error(res.error);
throw new Error(window.$gz.errorHandler.errorToString(res, vm));
}
//set vm.obj to the combined synthesized snapshot array of template and availble fields for working data for this form
@@ -407,7 +395,7 @@ async function initDataObject(vm) {
//Iterate first to ensure the cached translations of field keys
//(due to this form being opened directly from things like record history so might not be cached yet)
//if they *are* cached then this is a pretty fast operation and no trip is made to the server
let requiredTranslations = [];
const requiredTranslations = [];
for (let i = 0; i < res.data.length; i++) {
if (
requiredTranslations.indexOf(res.data[i].tKey) === -1 &&
@@ -423,19 +411,15 @@ async function initDataObject(vm) {
}
}
await window.$gz.translation.cacheTranslations(requiredTranslations);
//Iterate a second time to build the working collection
for (let i = 0; i < res.data.length; i++) {
//get the formAvailableField record into an object to save typing
let faf = res.data[i];
const faf = res.data[i];
//get the customTemplate record for this field if it exists
let templateItem = window.$gz.formCustomTemplate.getFieldTemplateValue(
vm.formCustomTemplateKey,
faf.fieldKey
);
//handle non-existent template item (expected)
if (templateItem == null) {
templateItem = {
@@ -444,8 +428,7 @@ async function initDataObject(vm) {
type: 4 //text
};
}
let objItem = {
const objItem = {
key: faf.fieldKey,
tKey: faf.tKey,
title: null,
@@ -456,16 +439,13 @@ async function initDataObject(vm) {
hideable: faf.hideable,
requireable: faf.requireable
};
//set title including optional section prepended
if (faf.tKeySection != null) {
objItem.title = vm.$ay.t(faf.tKeySection) + "." + vm.$ay.t(faf.tKey);
} else {
objItem.title = vm.$ay.t(faf.tKey);
}
vm.obj.push(objItem);
vm.concurrency = window.$gz.formCustomTemplate.getTemplateConcurrencyToken(
vm.formCustomTemplateKey
);