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

@@ -92,41 +92,27 @@
</v-overlay>
</div>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
const FORM_KEY = "inv-part-stock-levels";
//const API_BASE_URL = "part/";
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);
@@ -168,15 +154,12 @@ export default {
minimumQuantity: 1
};
},
//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 {
@@ -196,33 +179,29 @@ export default {
return this.obj.slice().sort(compare);
},
addItem: function() {
let vm = this;
let selectedPartWarehouse = vm.$refs.partWarehouseId.getFullSelectionValue();
//vm.selectedPartWarehouseId = null;
const vm = this;
const selectedPartWarehouse = vm.$refs.partWarehouseId.getFullSelectionValue();
if (selectedPartWarehouse == null || selectedPartWarehouse.id == null) {
return;
}
let index = vm.obj.findIndex(
const index = vm.obj.findIndex(
z => z.partWarehouseId == selectedPartWarehouse.id
);
if (index != -1) {
//already in the list
return;
}
vm.obj.push({
partId: vm.$route.params.recordid,
partWarehouseId: selectedPartWarehouse.id,
partWarehouseDisplay: selectedPartWarehouse.name,
minimumQuantity: 1
});
vm.formState.dirty = true;
},
removeItem: function(item) {
let vm = this;
let index = vm.obj.findIndex(
const vm = this;
const index = vm.obj.findIndex(
z => z.partWarehouseId == item.partWarehouseId
);
if (index == -1) {
@@ -238,9 +217,9 @@ export default {
});
},
quantityChanged: function(item) {
let vm = this;
const vm = this;
if (item.minimumQuantity == null || item.minimumQuantity < 1) {
let index = vm.obj.findIndex(
const index = vm.obj.findIndex(
z => z.partWarehouseId == item.partWarehouseId
);
if (index == -1) {
@@ -260,7 +239,7 @@ export default {
return window.$gz.form;
},
async getDataFromApi() {
let vm = this;
const vm = this;
window.$gz.form.setFormState({
vm: vm,
loading: true
@@ -268,14 +247,12 @@ export default {
if (!vm.$route.params.recordid) {
throw new Error(FORM_KEY + "::getDataFromApi -> Missing recordID!");
}
let url = `part/stock-levels/${vm.$route.params.recordid}`;
try {
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.get(url);
const res = await window.$gz.api.get(
`part/stock-levels/${vm.$route.params.recordid}`
);
if (res.error) {
//Not found?
if (res.error.code == "2010") {
window.$gz.form.handleObjectNotFound(vm);
}
@@ -283,9 +260,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,
@@ -303,29 +278,25 @@ export default {
}
},
async submit() {
let vm = this;
const vm = this;
if (vm.canSave == false) {
return;
}
try {
window.$gz.form.setFormState({
vm: vm,
loading: true
});
let url = `part/stock-levels/${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/stock-levels/${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 stock levels from server
//Update the form status
vm.obj = res.data;
window.$gz.form.setFormState({
vm: vm,
dirty: false,
@@ -341,7 +312,6 @@ export default {
});
}
}
//end methods
}
};
@@ -352,7 +322,7 @@ 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":
@@ -372,7 +342,7 @@ async function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
let menuOptions = {
const menuOptions = {
isMain: false,
readOnly: vm.formState.readOnly,
icon: null,