diff --git a/ayanova/src/views/adm-global-seeds.vue b/ayanova/src/views/adm-global-seeds.vue index 99d9a7d1..21e7d65e 100644 --- a/ayanova/src/views/adm-global-seeds.vue +++ b/ayanova/src/views/adm-global-seeds.vue @@ -11,20 +11,25 @@ > - - - + + - SEEDS HERE @@ -40,17 +45,6 @@ const FORM_KEY = "adm-global-seeds"; const API_BASE_URL = "global-biz-setting/seeds/"; export default { - 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); }, @@ -61,12 +55,12 @@ export default { 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"); - window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":delete"); + await vm.getDataFromApi(); + vm.formState.loading = false; } catch (err) { vm.formState.ready = true; @@ -76,18 +70,11 @@ export default { data() { return { obj: { - id: null, - concurrency: null, - template: null + purchaseOrderNextSerial: null, + workorderNextSerial: null, + quoteNextSerial: null, + pmNextSerial: null }, - selectLists: { - pickListTemplates: [] - }, - availableFields: [], - workingArray: [], - fieldKeys: [], - templateId: 0, - lastFetchedTemplateId: 0, formState: { ready: false, dirty: false, @@ -98,7 +85,7 @@ export default { appError: null, serverError: {} }, - rights: window.$gz.role.getRights(window.$gz.type.FormCustom) + rights: window.$gz.role.getRights(window.$gz.type.Global) }; }, //WATCHERS watch: { @@ -118,107 +105,39 @@ export default { } }, deep: true - }, - templateId(val) { - if (val) { - window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":delete"); - } else { - window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":delete"); - } } }, methods: { - includeChanged: function(item) { - window.$gz.form.setFormState({ - vm: this, - dirty: true - }); + ayaTypes: function() { + return window.$gz.type; }, - move: function(direction, index) { - let totalItems = this.workingArray.length; - let newIndex = 0; - //calculate new index - switch (direction) { - case "start": - newIndex = 0; - break; - case "left": - newIndex = index - 1; - if (newIndex < 0) { - newIndex = 0; - } - break; - case "right": - newIndex = index + 1; - if (newIndex > totalItems - 1) { - newIndex = totalItems - 1; - } - - break; - case "end": - newIndex = totalItems - 1; - break; - } - - this.workingArray.splice( - newIndex, - 0, - this.workingArray.splice(index, 1)[0] - ); - window.$gz.form.setFormState({ - vm: this, - dirty: true - }); + form() { + return window.$gz.form; }, - templateSelected: function() { - let vm = this; - if (vm.lastFetchedTemplateId == vm.templateId) { - return; //no change - } - vm.workingArray = []; - if (!vm.templateId || vm.templateId == 0) { - vm.lastFetchedTemplateId = 0; - return; - } else { - vm.getDataFromApi(); + fieldValueChanged(ref) { + if ( + this.formState.ready && + !this.formState.loading && + !this.formState.readOnly + ) { + window.$gz.form.fieldValueChanged(this, ref); } }, async getDataFromApi() { let vm = this; vm.formState.loading = true; - if (!vm.templateId || vm.templateId == 0) { - return; - } - 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 - ); - - if (res.error) { - vm.formState.serverError = res.error; - window.$gz.form.setErrorBoxErrors(vm); - } else { - vm.availableFields = res.data; - vm.fieldKeys = []; - for (let i = 0; i < res.data.length; i++) { - vm.fieldKeys.push(res.data[i].tKey); - } - 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); + //get current values + let res = await window.$gz.api.get(API_BASE_URL); 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, @@ -279,43 +198,6 @@ export default { vm.formState.loading = false; window.$gz.errorHandler.handleFormError(error, vm); } - }, - async remove() { - let vm = this; - if ( - (await window.$gz.dialog.confirmGeneric( - "ResetToDefault", - "warning" - )) !== true - ) { - 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); - - if (res.error) { - vm.formState.serverError = res.error; - window.$gz.form.setErrorBoxErrors(vm); - } else { - //trigger reload of form - this.getDataFromApi(); - } - } - } catch (error) { - //Update the form status - window.$gz.form.setFormState({ - vm: vm, - loading: false - }); - window.$gz.errorHandler.handleFormError(error, vm); - } } } }; @@ -353,35 +235,15 @@ function generateMenu(vm) { isMain: false, readOnly: vm.formState.readOnly, icon: null, - title: "PickListTemplates", - helpUrl: "adm-global-select-templates", + title: "GlobalNextSeeds", + helpUrl: "adm-global-seeds", formData: { - ayaType: window.$gz.type.FormCustom, + ayaType: window.$gz.type.global, formCustomTemplateKey: undefined }, menuItems: [] }; - if (vm.rights.change) { - menuOptions.menuItems.push({ - title: "Save", - icon: "$ayiSave", - surface: true, - key: FORM_KEY + ":save", - vm: vm - }); - - if (vm.rights.delete) { - menuOptions.menuItems.push({ - title: "ResetToDefault", - icon: "$ayiUndo", - surface: false, - key: FORM_KEY + ":delete", - vm: vm - }); - } - } - window.$gz.eventBus.$emit("menu-change", menuOptions); } @@ -390,7 +252,6 @@ function generateMenu(vm) { // async function initForm(vm) { await fetchTranslatedText(vm); - await populateSelectionLists(vm); } ////////////////////////////////////////////////////////// @@ -398,80 +259,12 @@ async function initForm(vm) { // Ensures UI translated text is available // async function fetchTranslatedText(vm) { - await window.$gz.translation.cacheTranslations(["Include", "ResetToDefault"]); -} - -////////////////////// -// -// -async function populateSelectionLists(vm) { - let 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); - } -} - -//////////////////// -// -function synthesizeWorkingArray(vm) { - vm.workingArray = []; - if (vm.obj.template == null) { - return; - } - let 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); - - if (afItem != null) { - //Push into working array - vm.workingArray.push({ - key: afItem.fieldKey, - required: afItem.isRowId == true, - include: true, - title: vm.$ay.t(afItem.tKey) - }); - } - } - - //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]; - //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, - required: afItem.isRowId == true, - include: false, - title: vm.$ay.t(afItem.tKey) - }); - } + await window.$gz.translation.cacheTranslations([ + "GlobalNextSeeds", + "NextPONumber", + "NextQuoteNumber", + "NextWorkorderNumber", + "NextPMNumber" + ]); }