This commit is contained in:
2020-06-19 23:58:52 +00:00
parent f02888fae7
commit 5e1efbab24
18 changed files with 431 additions and 479 deletions

View File

@@ -63,43 +63,38 @@
const FORM_KEY = "customize";
const API_BASE_URL = "form-custom/";
export default {
beforeRouteLeave(to, from, next) {
//let vm = this;
if (this.formState.dirty) {
window.$gz.dialog.confirmLeaveUnsaved().then(dialogResult => {
if (dialogResult == true) {
next();
} else {
next(false);
}
});
} else {
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);
},
created() {
async created() {
let vm = this;
try {
initForm(vm);
initForm(vm)
.then(() => {
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, false); //default is never read only and passing in this 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");
})
.catch(err => {
window.$gz.errorHandler.handleFormError(err, vm);
})
.finally(function() {
vm.formState.ready = true;
vm.formState.loading = false;
});
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, false); //default is never read only and passing in this 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");
} catch (err) {
window.$gz.errorHandler.handleFormError(err, vm);
} finally {
vm.formState.ready = true;
vm.formState.loading = false;
}
},
data() {
return {
@@ -170,7 +165,7 @@ export default {
//nothing to scan here just set form dirty
this.formState.dirty = true;
},
submit() {
async submit() {
let vm = this;
vm.formState.loading = true;
@@ -217,42 +212,37 @@ 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);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
//Handle "put" of an existing record (UPDATE) (there is no POST of a new record for this particular object)
//now set the template as a json string
newObj.template = JSON.stringify(temp);
//Set store values for template and token
//(update our local cached copy of the form customizations)
window.$gz.formCustomTemplate.set(
vm.formCustomTemplateKey,
res.data.concurrency,
newObj.template
);
//set our local concurrency token value
vm.concurrency = res.data.concurrency;
window.$gz.api
.upsert(url, newObj)
.then(res => {
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
//Handle "put" of an existing record (UPDATE) (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,
res.data.concurrency,
newObj.template
);
//set our local concurrency token value
vm.concurrency = res.data.concurrency;
//form is now clean
window.$gz.form.setFormState({
vm: vm,
dirty: false
});
}
})
.catch(function handleSubmitError(error) {
window.$gz.errorHandler.handleFormError(error, vm);
})
.finally(function() {
vm.formState.loading = false;
});
//form is now clean
window.$gz.form.setFormState({
vm: vm,
dirty: false
});
}
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
} finally {
vm.formState.loading = false;
}
}
}
};
@@ -341,11 +331,11 @@ function initForm(vm) {
//
// Ensures UI translated text is available
//
function fetchTranslatedText(vm) {
async function fetchTranslatedText(vm) {
//NOTE: This form expects to arrive here from the form being customized
//so it does *not* attempt to fetch the translations for the field names of the form in question
//since they should already be set by that form.
let tKeysRequired = [
await window.$gz.translation.cacheTranslations([
"FormFieldEntryRequired",
"FormFieldVisible",
"UiFieldDataType",
@@ -357,9 +347,7 @@ function fetchTranslatedText(vm) {
"UiFieldDataTypesText",
"UiFieldDataTypesTimeOnly",
"UiFieldDataTypesTrueFalse"
];
return window.$gz.translation.cacheTranslations(tKeysRequired);
]);
}
/////////////////////////////////
@@ -392,54 +380,52 @@ function ensureTemplateIsInStore(vm) {
////////////////////
//
function initDataObject(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-definition/" + vm.$route.params.formCustomTemplateKey;
return window.$gz.api.get(url).then(res => {
if (res.error) {
throw res.error;
}
let res = await window.$gz.api.get(url);
if (res.error) {
throw res.error;
}
//set vm.obj to the combined synthesized snapshot array of template and availble fields for working data for this form
// - {key, ltdisplay, hideable, custom, required, hide, type}
//Iterate ObjectFields
//create a new object based on the f.a.f. item and any existing template values for that item
//set vm.obj to the combined synthesized snapshot array of template and availble fields for working data for this form
// - {key, ltdisplay, hideable, custom, required, hide, type}
//Iterate ObjectFields
//create a new object based on the f.a.f. item and any existing template values for that item
for (let i = 0; i < res.data.length; i++) {
//get the formAvailableField record into an object to save typing
let faf = res.data[i];
//get the customTemplate record for this field if it exists
for (let i = 0; i < res.data.length; i++) {
//get the formAvailableField record into an object to save typing
let faf = res.data[i];
//get the customTemplate record for this field if it exists
let templateItem = window.$gz.formCustomTemplate.getFieldTemplateValue(
vm.formCustomTemplateKey,
faf.fieldKey
);
let templateItem = window.$gz.formCustomTemplate.getFieldTemplateValue(
vm.formCustomTemplateKey,
faf.fieldKey
);
//handle non-existent template item (expected)
if (templateItem == null) {
templateItem = {
required: false,
hide: faf.isCustomField ? true : false, //hide if custom because it's not set to display if it's not present, all others are stock fields
type: 4 //text
};
}
let objItem = {
key: faf.fieldKey,
title: vm.$ay.t(faf.tKey),
stockRequired: !faf.hideable,
custom: faf.isCustomField,
required: faf.hideable === false || templateItem.required === true,
visible: templateItem.hide !== true,
type: templateItem.type
//handle non-existent template item (expected)
if (templateItem == null) {
templateItem = {
required: false,
hide: faf.isCustomField ? true : false, //hide if custom because it's not set to display if it's not present, all others are stock fields
type: 4 //text
};
vm.obj.push(objItem);
vm.concurrency = window.$gz.formCustomTemplate.getTemplateConcurrencyToken(
vm.formCustomTemplateKey
);
}
});
let objItem = {
key: faf.fieldKey,
title: vm.$ay.t(faf.tKey),
stockRequired: !faf.hideable,
custom: faf.isCustomField,
required: faf.hideable === false || templateItem.required === true,
visible: templateItem.hide !== true,
type: templateItem.type
};
vm.obj.push(objItem);
vm.concurrency = window.$gz.formCustomTemplate.getTemplateConcurrencyToken(
vm.formCustomTemplateKey
);
}
}
</script>