HUGE REFACTOR / CLEANUP
if there is a issue it's probably something in here that was changed
This commit is contained in:
@@ -24,17 +24,6 @@
|
||||
>
|
||||
</v-select>
|
||||
</v-col>
|
||||
<!-- <div>WORKING ARRAY: {{ workingArray }}</div> -->
|
||||
|
||||
<!-- <div>
|
||||
TEMPLATE:
|
||||
{{ obj }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
available fields:
|
||||
{{ availableFields }}
|
||||
</div> -->
|
||||
<template v-for="(item, index) in workingArray">
|
||||
<v-col :key="item.key" cols="12" sm="6" lg="4" xl="3" px-2>
|
||||
<v-card>
|
||||
@@ -79,9 +68,6 @@
|
||||
</v-row>
|
||||
</template>
|
||||
<script>
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/* Xeslint-disable */
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//NOTE: This is a simple form with no need for business rules or validation so stripped out any extraneous code related to all that
|
||||
//
|
||||
@@ -103,14 +89,13 @@ export default {
|
||||
window.$gz.eventBus.$off("menu-click", clickHandler);
|
||||
},
|
||||
async created() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
try {
|
||||
await initForm(vm);
|
||||
vm.formState.ready = true;
|
||||
vm.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");
|
||||
@@ -152,13 +137,10 @@ export default {
|
||||
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;
|
||||
const canSave = val.dirty && val.valid && !val.readOnly;
|
||||
if (canSave) {
|
||||
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
|
||||
} else {
|
||||
@@ -183,7 +165,7 @@ export default {
|
||||
});
|
||||
},
|
||||
move: function(direction, index) {
|
||||
let totalItems = this.workingArray.length;
|
||||
const totalItems = this.workingArray.length;
|
||||
let newIndex = 0;
|
||||
//calculate new index
|
||||
switch (direction) {
|
||||
@@ -219,7 +201,7 @@ export default {
|
||||
});
|
||||
},
|
||||
templateSelected: function() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
if (vm.lastFetchedTemplateId == vm.templateId) {
|
||||
return; //no change
|
||||
}
|
||||
@@ -232,7 +214,7 @@ export default {
|
||||
}
|
||||
},
|
||||
async getDataFromApi() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
vm.formState.loading = true;
|
||||
if (!vm.templateId || vm.templateId == 0) {
|
||||
return;
|
||||
@@ -240,7 +222,6 @@ export default {
|
||||
vm.lastFetchedTemplateId = vm.templateId;
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
try {
|
||||
//get available fields
|
||||
let res = await window.$gz.api.get(
|
||||
API_BASE_URL + "listfields/" + vm.templateId
|
||||
);
|
||||
@@ -256,18 +237,14 @@ export default {
|
||||
}
|
||||
await window.$gz.translation.cacheTranslations(vm.fieldKeys);
|
||||
}
|
||||
|
||||
//weirdly, this wasn't working properly until I put it in a function, it was just executing immediately before translations were resolved from fetch above
|
||||
//get current edited template
|
||||
res = await window.$gz.api.get(API_BASE_URL + vm.templateId);
|
||||
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
vm.obj = res.data;
|
||||
synthesizeWorkingArray(vm);
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
dirty: false,
|
||||
@@ -276,7 +253,6 @@ export default {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: false
|
||||
@@ -285,21 +261,17 @@ export default {
|
||||
}
|
||||
},
|
||||
async submit() {
|
||||
let vm = this;
|
||||
let url = API_BASE_URL;
|
||||
//clear any errors vm might be around from previous submit
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
|
||||
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 = {
|
||||
id: vm.templateId,
|
||||
const newObj = {
|
||||
id: this.templateId,
|
||||
template: "[]"
|
||||
};
|
||||
//temporary array to hold template for later stringification
|
||||
let temp = [];
|
||||
for (let i = 0; i < vm.workingArray.length; i++) {
|
||||
let ti = vm.workingArray[i];
|
||||
const temp = [];
|
||||
for (let i = 0; i < this.workingArray.length; i++) {
|
||||
const ti = this.workingArray[i];
|
||||
if (ti.include == true) {
|
||||
temp.push({
|
||||
fld: ti.key
|
||||
@@ -309,27 +281,26 @@ 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);
|
||||
|
||||
vm.formState.loading = false;
|
||||
const res = await window.$gz.api.upsert(API_BASE_URL, newObj);
|
||||
this.formState.loading = false;
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
this.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(this);
|
||||
} else {
|
||||
//It's a 204 no data response so no error means it's ok
|
||||
//form is now clean
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
vm: this,
|
||||
dirty: false
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
vm.formState.loading = false;
|
||||
window.$gz.errorHandler.handleFormError(error, vm);
|
||||
this.formState.loading = false;
|
||||
window.$gz.errorHandler.handleFormError(error, this);
|
||||
}
|
||||
},
|
||||
async remove() {
|
||||
let vm = this;
|
||||
const vm = this;
|
||||
if (
|
||||
(await window.$gz.dialog.confirmGeneric(
|
||||
"ResetToDefault",
|
||||
@@ -339,15 +310,10 @@ export default {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
//do the delete
|
||||
vm.formState.loading = true;
|
||||
//No need to delete a new record, just abandon it...
|
||||
if (vm.templateId && vm.templateId != 0) {
|
||||
let url = API_BASE_URL + vm.templateId;
|
||||
|
||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||
let res = await window.$gz.api.remove(url);
|
||||
|
||||
const res = await window.$gz.api.remove(API_BASE_URL + vm.templateId);
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
@@ -357,7 +323,6 @@ export default {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
//Update the form status
|
||||
window.$gz.form.setFormState({
|
||||
vm: vm,
|
||||
loading: false
|
||||
@@ -375,7 +340,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":
|
||||
@@ -397,7 +362,7 @@ function clickHandler(menuItem) {
|
||||
//
|
||||
//
|
||||
function generateMenu(vm) {
|
||||
let menuOptions = {
|
||||
const menuOptions = {
|
||||
isMain: false,
|
||||
readOnly: vm.formState.readOnly,
|
||||
icon: null,
|
||||
@@ -453,14 +418,13 @@ async function fetchTranslatedText(vm) {
|
||||
//
|
||||
//
|
||||
async function populateSelectionLists(vm) {
|
||||
let res = await window.$gz.api.get(API_BASE_URL + "list");
|
||||
const res = await window.$gz.api.get(API_BASE_URL + "list");
|
||||
if (res.error) {
|
||||
vm.formState.serverError = res.error;
|
||||
window.$gz.form.setErrorBoxErrors(vm);
|
||||
} else {
|
||||
res.data.sort(window.$gz.util.sortByKey("name"));
|
||||
vm.selectLists.pickListTemplates = res.data;
|
||||
|
||||
window.$gz.form.addNoSelectionItem(vm.selectLists.pickListTemplates);
|
||||
}
|
||||
}
|
||||
@@ -472,19 +436,11 @@ function synthesizeWorkingArray(vm) {
|
||||
if (vm.obj.template == null) {
|
||||
return;
|
||||
}
|
||||
let template = JSON.parse(vm.obj.template);
|
||||
|
||||
const template = JSON.parse(vm.obj.template);
|
||||
//first, insert the templated fields into the working array so they are in current selected order
|
||||
for (let i = 0; i < template.length; i++) {
|
||||
let templateItem = template[i];
|
||||
//de-lodash
|
||||
// let afItem = window.$gz. _.find(vm.availableFields, [
|
||||
// "fieldKey",
|
||||
// templateItem.fld
|
||||
// ]);
|
||||
|
||||
let afItem = vm.availableFields.find(z => z.fieldKey == templateItem.fld);
|
||||
|
||||
const templateItem = template[i];
|
||||
const afItem = vm.availableFields.find(z => z.fieldKey == templateItem.fld);
|
||||
if (afItem != null) {
|
||||
//Push into working array
|
||||
vm.workingArray.push({
|
||||
@@ -498,21 +454,15 @@ function synthesizeWorkingArray(vm) {
|
||||
|
||||
//Now iterate all the available fields and insert the ones that were not in the current template
|
||||
for (let i = 0; i < vm.availableFields.length; i++) {
|
||||
let afItem = vm.availableFields[i];
|
||||
const afItem = vm.availableFields[i];
|
||||
//skip the active column
|
||||
if (afItem.isActiveColumn == true) {
|
||||
continue;
|
||||
}
|
||||
//is this field already in the template and was added above?
|
||||
//de-lodash
|
||||
// if (window.$gz ._.find(template, ["fld", afItem.fieldKey]) != null) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
if (template.find(z => z.fld == afItem.fieldKey) != null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Push into working array
|
||||
vm.workingArray.push({
|
||||
key: afItem.fieldKey,
|
||||
|
||||
Reference in New Issue
Block a user