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

@@ -62,42 +62,28 @@
</v-overlay>
</div>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
const FORM_KEY = "inv-part-serials";
//const API_BASE_URL = "part/";
const FORM_CUSTOM_TEMPLATE_KEY = "inv-part-serials"; //<-- Should always be CoreBizObject AyaType name here where possible
const FORM_CUSTOM_TEMPLATE_KEY = "inv-part-serials";
export default {
async created() {
let vm = this;
const vm = this;
try {
await initForm(vm);
vm.rights = window.$gz.role.getRights(window.$gz.type.Part);
vm.formState.readOnly = !vm.rights.change;
window.$gz.eventBus.$on("menu-click", clickHandler);
//id 0 means create or duplicate to new
if (vm.$route.params.recordid == 0) {
throw "Invalid partid";
} else {
await vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
await vm.getDataFromApi(vm.$route.params.recordid);
}
window.$gz.form.setFormState({
vm: vm,
dirty: false,
valid: true
});
generateMenu(vm);
} catch (error) {
window.$gz.errorHandler.handleFormError(error, vm);
@@ -142,15 +128,12 @@ export default {
newSerial: null
};
},
//WATCHERS
watch: {
formState: {
handler: function(val) {
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 {
@@ -165,7 +148,6 @@ export default {
if (this.obj == null || this.obj.length == 0) {
return [];
}
return this.obj.slice().sort();
},
removeItem: function(index) {
@@ -182,7 +164,7 @@ export default {
//add to list, may be in various formats so handle that
let splitted = this.newSerial.split(/[\s,]+/).filter(Boolean); //filter Boolean is equivalent to array.filter(item => Boolean(item)) and it's to filter out nulls concisely from badly formatted strings
splitted = [...splitted, ...this.obj];
let uniqueItems = [...new Set(splitted)]; //remove any dupes with Set
const uniqueItems = [...new Set(splitted)]; //remove any dupes with Set
uniqueItems.sort();
this.obj = uniqueItems;
this.formState.dirty = true;
@@ -194,17 +176,8 @@ export default {
form() {
return window.$gz.form;
},
// fieldValueChanged(ref) {
// if (
// this.formState.ready &&
// !this.formState.loading &&
// !this.formState.readOnly
// ) {
// window.$gz.form.fieldValueChanged(this, ref);
// }
// },
async getDataFromApi(recordId) {
let vm = this;
const vm = this;
window.$gz.form.setFormState({
vm: vm,
loading: true
@@ -212,14 +185,10 @@ export default {
if (!recordId) {
throw new Error(FORM_KEY + "::getDataFromApi -> Missing recordID!");
}
let url = `part/serials/${recordId}`;
try {
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.get(url);
const res = await window.$gz.api.get(`part/serials/${recordId}`);
if (res.error) {
//Not found?
if (res.error.code == "2010") {
window.$gz.form.handleObjectNotFound(vm);
}
@@ -227,9 +196,7 @@ export default {
window.$gz.form.setErrorBoxErrors(vm);
} else {
vm.obj = res.data;
//modify the menu as necessary
generateMenu(vm);
//Update the form status
window.$gz.form.setFormState({
vm: vm,
dirty: false,
@@ -247,7 +214,7 @@ export default {
}
},
async submit() {
let vm = this;
const vm = this;
if (vm.canSave == false) {
return;
}
@@ -257,39 +224,16 @@ export default {
vm: vm,
loading: true
});
// let url = `part/serials/${vm.$route.params.recordid}`;
let url = `part/serials/${vm.$route.params.recordid}`;
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.put(url, vm.obj);
const res = await window.$gz.api.put(
`part/serials/${vm.$route.params.recordid}`,
vm.obj
);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
vm.obj = res.data; //updated list of serials from server
//PRETTY SURE DON"T NEED ANY OF THIS
// //Logic for detecting if a post or put: if id then it was a post, if no id then it was a put
// if (res.data.id) {
// //POST - whole new object returned
// vm.obj = res.data;
// //Change URL to new record
// //NOTE: will not cause a page re-render, almost nothing does unless forced with a KEY property or using router.GO()
// this.$router.push({
// name: "project-edit",
// params: {
// recordid: res.data.id,
// obj: res.data // Pass data object to new form
// }
// });
// } else {
// //PUT - only concurrency token is returned (**warning, if server changes object other fields then this needs to act more like POST above but is more efficient this way**)
// //Handle "put" of an existing record (UPDATE)
// vm.obj.concurrency = res.data.concurrency;
// }
//Update the form status
window.$gz.form.setFormState({
vm: vm,
dirty: false,
@@ -305,7 +249,6 @@ export default {
});
}
}
//end methods
}
};
@@ -316,13 +259,12 @@ async 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":
m.vm.submit();
break;
default:
window.$gz.eventBus.$emit(
"notify-warning",
@@ -336,18 +278,12 @@ async function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
let menuOptions = {
const menuOptions = {
isMain: false,
readOnly: vm.formState.readOnly,
icon: null,
title: "PartSerialNumbersAvailable",
helpUrl: "inv-part-serials",
formData: {
// ayaType: window.$gz.type.Par,
// recordId: vm.$route.params.recordid,
// formCustomTemplateKey: FORM_CUSTOM_TEMPLATE_KEY,
// recordName: vm.obj.name
},
menuItems: []
};
@@ -371,7 +307,6 @@ let JUST_DELETED = false;
//
async function initForm(vm) {
await fetchTranslatedText(vm);
//await window.$gz.formCustomTemplate.get(FORM_CUSTOM_TEMPLATE_KEY, vm);
}
//////////////////////////////////////////////////////////