This commit is contained in:
@@ -11,20 +11,25 @@
|
|||||||
></button>
|
></button>
|
||||||
<v-row>
|
<v-row>
|
||||||
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
|
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
|
||||||
<v-col cols="12">
|
<v-col cols="12" sm="6" lg="4" xl="3">
|
||||||
<v-select
|
<v-text-field
|
||||||
v-model="templateId"
|
v-model="obj.purchaseOrderNextSerial"
|
||||||
:items="selectLists.pickListTemplates"
|
:readonly="formState.readOnly"
|
||||||
item-text="name"
|
:label="$ay.t('NextPONumber')"
|
||||||
item-value="id"
|
ref="purchaseOrderNextSerial"
|
||||||
:label="$ay.t('PickListTemplates')"
|
data-cy="purchaseOrderNextSerial"
|
||||||
@input="templateSelected"
|
:rules="[
|
||||||
data-cy="selectTemplate"
|
form().integerValid(this, 'purchaseOrderNextSerial'),
|
||||||
:disabled="formState.dirty"
|
form().required(this, 'purchaseOrderNextSerial')
|
||||||
>
|
]"
|
||||||
</v-select>
|
:error-messages="
|
||||||
|
form().serverErrors(this, 'purchaseOrderNextSerial')
|
||||||
|
"
|
||||||
|
@input="fieldValueChanged('purchaseOrderNextSerial')"
|
||||||
|
append-outer-icon="$ayiSave"
|
||||||
|
@click:append-outer="set(ayaTypes.PurchaseOrder)"
|
||||||
|
></v-text-field>
|
||||||
</v-col>
|
</v-col>
|
||||||
SEEDS HERE
|
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-form>
|
</v-form>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -40,17 +45,6 @@
|
|||||||
const FORM_KEY = "adm-global-seeds";
|
const FORM_KEY = "adm-global-seeds";
|
||||||
const API_BASE_URL = "global-biz-setting/seeds/";
|
const API_BASE_URL = "global-biz-setting/seeds/";
|
||||||
export default {
|
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() {
|
beforeDestroy() {
|
||||||
window.$gz.eventBus.$off("menu-click", clickHandler);
|
window.$gz.eventBus.$off("menu-click", clickHandler);
|
||||||
},
|
},
|
||||||
@@ -61,12 +55,12 @@ export default {
|
|||||||
vm.formState.ready = true;
|
vm.formState.ready = true;
|
||||||
vm.readOnly = !vm.rights.change;
|
vm.readOnly = !vm.rights.change;
|
||||||
window.$gz.eventBus.$on("menu-click", clickHandler);
|
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
|
//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
|
//modify the menu as necessary
|
||||||
generateMenu(vm);
|
generateMenu(vm);
|
||||||
//init disable save button so it can be enabled only on edit to show dirty form
|
await vm.getDataFromApi();
|
||||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
|
|
||||||
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":delete");
|
|
||||||
vm.formState.loading = false;
|
vm.formState.loading = false;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
vm.formState.ready = true;
|
vm.formState.ready = true;
|
||||||
@@ -76,18 +70,11 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
obj: {
|
obj: {
|
||||||
id: null,
|
purchaseOrderNextSerial: null,
|
||||||
concurrency: null,
|
workorderNextSerial: null,
|
||||||
template: null
|
quoteNextSerial: null,
|
||||||
|
pmNextSerial: null
|
||||||
},
|
},
|
||||||
selectLists: {
|
|
||||||
pickListTemplates: []
|
|
||||||
},
|
|
||||||
availableFields: [],
|
|
||||||
workingArray: [],
|
|
||||||
fieldKeys: [],
|
|
||||||
templateId: 0,
|
|
||||||
lastFetchedTemplateId: 0,
|
|
||||||
formState: {
|
formState: {
|
||||||
ready: false,
|
ready: false,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
@@ -98,7 +85,7 @@ export default {
|
|||||||
appError: null,
|
appError: null,
|
||||||
serverError: {}
|
serverError: {}
|
||||||
},
|
},
|
||||||
rights: window.$gz.role.getRights(window.$gz.type.FormCustom)
|
rights: window.$gz.role.getRights(window.$gz.type.Global)
|
||||||
};
|
};
|
||||||
}, //WATCHERS
|
}, //WATCHERS
|
||||||
watch: {
|
watch: {
|
||||||
@@ -118,107 +105,39 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
deep: true
|
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: {
|
methods: {
|
||||||
includeChanged: function(item) {
|
ayaTypes: function() {
|
||||||
window.$gz.form.setFormState({
|
return window.$gz.type;
|
||||||
vm: this,
|
|
||||||
dirty: true
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
move: function(direction, index) {
|
form() {
|
||||||
let totalItems = this.workingArray.length;
|
return window.$gz.form;
|
||||||
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
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
templateSelected: function() {
|
fieldValueChanged(ref) {
|
||||||
let vm = this;
|
if (
|
||||||
if (vm.lastFetchedTemplateId == vm.templateId) {
|
this.formState.ready &&
|
||||||
return; //no change
|
!this.formState.loading &&
|
||||||
}
|
!this.formState.readOnly
|
||||||
vm.workingArray = [];
|
) {
|
||||||
if (!vm.templateId || vm.templateId == 0) {
|
window.$gz.form.fieldValueChanged(this, ref);
|
||||||
vm.lastFetchedTemplateId = 0;
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
vm.getDataFromApi();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async getDataFromApi() {
|
async getDataFromApi() {
|
||||||
let vm = this;
|
let vm = this;
|
||||||
vm.formState.loading = true;
|
vm.formState.loading = true;
|
||||||
if (!vm.templateId || vm.templateId == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
vm.lastFetchedTemplateId = vm.templateId;
|
|
||||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||||
try {
|
try {
|
||||||
//get available fields
|
//get current values
|
||||||
let res = await window.$gz.api.get(
|
let res = await window.$gz.api.get(API_BASE_URL);
|
||||||
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);
|
|
||||||
|
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
vm.formState.serverError = res.error;
|
vm.formState.serverError = res.error;
|
||||||
window.$gz.form.setErrorBoxErrors(vm);
|
window.$gz.form.setErrorBoxErrors(vm);
|
||||||
} else {
|
} else {
|
||||||
vm.obj = res.data;
|
vm.obj = res.data;
|
||||||
synthesizeWorkingArray(vm);
|
|
||||||
//Update the form status
|
//Update the form status
|
||||||
window.$gz.form.setFormState({
|
window.$gz.form.setFormState({
|
||||||
vm: vm,
|
vm: vm,
|
||||||
@@ -279,43 +198,6 @@ export default {
|
|||||||
vm.formState.loading = false;
|
vm.formState.loading = false;
|
||||||
window.$gz.errorHandler.handleFormError(error, vm);
|
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,
|
isMain: false,
|
||||||
readOnly: vm.formState.readOnly,
|
readOnly: vm.formState.readOnly,
|
||||||
icon: null,
|
icon: null,
|
||||||
title: "PickListTemplates",
|
title: "GlobalNextSeeds",
|
||||||
helpUrl: "adm-global-select-templates",
|
helpUrl: "adm-global-seeds",
|
||||||
formData: {
|
formData: {
|
||||||
ayaType: window.$gz.type.FormCustom,
|
ayaType: window.$gz.type.global,
|
||||||
formCustomTemplateKey: undefined
|
formCustomTemplateKey: undefined
|
||||||
},
|
},
|
||||||
menuItems: []
|
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);
|
window.$gz.eventBus.$emit("menu-change", menuOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,7 +252,6 @@ function generateMenu(vm) {
|
|||||||
//
|
//
|
||||||
async function initForm(vm) {
|
async function initForm(vm) {
|
||||||
await fetchTranslatedText(vm);
|
await fetchTranslatedText(vm);
|
||||||
await populateSelectionLists(vm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////
|
||||||
@@ -398,80 +259,12 @@ async function initForm(vm) {
|
|||||||
// Ensures UI translated text is available
|
// Ensures UI translated text is available
|
||||||
//
|
//
|
||||||
async function fetchTranslatedText(vm) {
|
async function fetchTranslatedText(vm) {
|
||||||
await window.$gz.translation.cacheTranslations(["Include", "ResetToDefault"]);
|
await window.$gz.translation.cacheTranslations([
|
||||||
}
|
"GlobalNextSeeds",
|
||||||
|
"NextPONumber",
|
||||||
//////////////////////
|
"NextQuoteNumber",
|
||||||
//
|
"NextWorkorderNumber",
|
||||||
//
|
"NextPMNumber"
|
||||||
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)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user