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

@@ -5,7 +5,6 @@
<gz-error :error-box-message="formState.errorBoxMessage"></gz-error>
<gz-alert :alert-message="obj.alertViz" pop-alert></gz-alert>
<gz-alert :alert-message="obj.customerTechNotesViz"></gz-alert>
<!-- SERVERERROR:{{ formState.serverError }} -->
<v-form ref="form">
<GzQuoteHeader
v-model="obj"
@@ -66,20 +65,13 @@
</template>
</div>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
import GzQuoteHeader from "../components/quote-header.vue";
import GzQuoteItems from "../components/quote-items.vue";
const FORM_KEY = "quote-edit";
const API_BASE_URL = "quote/";
const FORM_CUSTOM_TEMPLATE_KEY = "Quote"; //<-- Should always be CoreBizObject AyaType name here where possible
const FORM_CUSTOM_TEMPLATE_KEY = "Quote";
export default {
components: {
@@ -92,12 +84,9 @@ export default {
try {
await initForm(vm);
//set base rights
vm.rights = window.$gz.role.getRights(window.$gz.type.Quote);
window.$gz.eventBus.$on("menu-click", clickHandler);
let setDirty = false;
let setValid = true;
//id 0 means create or duplicate to new
if (vm.$route.params.recordid != 0) {
//open existing path
@@ -105,13 +94,12 @@ export default {
if (this.$route.params.obj) {
//yes, no need to fetch it
this.obj = this.$route.params.obj;
window.$gz.form.setFormState({
vm: vm,
loading: false
});
} else {
await vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
await vm.getDataFromApi(vm.$route.params.recordid);
//check for copy wo item on route params
let wi = this.$route.params.copyItem;
if (wi) {
@@ -152,7 +140,7 @@ export default {
vm: vm,
loading: false,
dirty: setDirty,
valid: setValid
valid: true
});
//update which areas are available to user and force generate menu
@@ -163,8 +151,7 @@ export default {
vm.formState.ready = true;
//navigate somewhere??
if (this.$route.params.gotype != null) {
//console.log("wo-go:", this.$route.params);
//find out which woitem and then find out which type to set and then set them as the active item somehow
//find out which woitem and then find out which type to set and then set them as the active item
const gotype = Number(this.$route.params.gotype);
const goid = Number(this.$route.params.goid);
if (gotype != window.$gz.type.Quote) {
@@ -247,7 +234,6 @@ export default {
timeZoneName: window.$gz.locale.getResolvedTimeZoneName(),
languageName: window.$gz.locale.getResolvedLanguage(),
hour12: window.$gz.locale.getHour12(),
// resetSelections: false,
selectLists: {
quotestatus: [],
allowedquotestatus: [],
@@ -271,23 +257,19 @@ export default {
genCopyAttachments: false
};
},
//WATCHERS
watch: {
formState: {
handler: function(val) {
//,oldval is available here too if necessary
if (this.formState.loading) {
return;
}
//enable / disable save button
if (val.dirty && val.valid) {
window.$gz.eventBus.$emit("menu-enable-item", FORM_KEY + ":save");
} else {
window.$gz.eventBus.$emit("menu-disable-item", FORM_KEY + ":save");
}
//enable / disable duplicate / new button
if (!val.dirty && val.valid && !val.readOnly) {
window.$gz.eventBus.$emit(
"menu-enable-item",
@@ -337,12 +319,7 @@ export default {
},
methods: {
setDirty: function() {
//console.log("WO HEADER SET DIRTY!! TRIGGERED");
this.formState.dirty = true;
// window.$gz.form.setFormState({
// vm: this,
// dirty: true
// });
},
canSave: function() {
return this.formState.valid && this.formState.dirty;
@@ -377,7 +354,6 @@ export default {
const res = await window.$gz.api.get(url);
if (res.error) {
//Not found?
if (res.error.code == "2010") {
window.$gz.form.handleObjectNotFound(vm);
}
@@ -434,12 +410,10 @@ export default {
vm.lastGetContractId = vm.obj.contractId; //preserve for triggering full update if something changes it later
vm.lastGetCustomerId = vm.obj.customerId; //preserve for triggering full update if something changes it later
//modify the menu as necessary
generateMenu(vm);
//update which areas are available to user
updateRights(vm);
//Update the form status
window.$gz.form.setFormState({
vm: vm,
dirty: false,
@@ -468,7 +442,6 @@ export default {
loading: true
});
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(vm);
//#######################################################
@@ -582,42 +555,36 @@ export default {
}
},
async remove() {
let vm = this;
const vm = this;
try {
let dialogResult = await window.$gz.dialog.confirmDelete();
const dialogResult = await window.$gz.dialog.confirmDelete();
if (dialogResult != true) {
return;
}
//do the delete
window.$gz.form.setFormState({
vm: vm,
loading: true
});
//No need to delete a new record, just abandon it...
if (vm.$route.params.recordid == 0) {
//this should not get offered for delete but to be safe and clear just in case:
JUST_DELETED = true;
// navigate backwards
vm.$router.go(-1);
} else {
let url = API_BASE_URL + vm.$route.params.recordid;
window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.remove(url);
const res = await window.$gz.api.remove(
API_BASE_URL + vm.$route.params.recordid
);
if (res.error) {
vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm);
} else {
//workaround to prevent warning about leaving dirty record
//For some reason I couldn't just reset isdirty in formstate
JUST_DELETED = true;
// navigate backwards
vm.$router.go(-1);
}
}
} catch (error) {
//Update the form status
window.$gz.form.setFormState({
vm: vm,
loading: false
@@ -639,7 +606,7 @@ export default {
}
},
duplicate() {
let cp = JSON.parse(JSON.stringify(this.obj));
const cp = JSON.parse(JSON.stringify(this.obj));
if (this.genCopyAttachments) {
//this property set will trigger server to copy attachments
cp.genCopyAttachmentsFrom = {
@@ -650,7 +617,7 @@ export default {
if (!this.genCopyWiki) {
cp.wiki = null; //already copied, need to remove it instead
}
//Navigate to new record
this.$router.push({
name: "quote-edit",
params: {
@@ -660,7 +627,7 @@ export default {
});
},
generateWorkOrder() {
let cp = JSON.parse(JSON.stringify(this.obj));
const cp = JSON.parse(JSON.stringify(this.obj));
if (this.genCopyAttachments) {
//this property set will trigger server to copy attachments
cp.genCopyAttachmentsFrom = {
@@ -691,7 +658,6 @@ export default {
cp.techSignatureName = null;
cp.techSignatureCaptured = null;
//Navigate to new record
this.$router.push({
name: "workorder-edit",
params: {
@@ -701,7 +667,7 @@ export default {
});
},
generatePM() {
let cp = JSON.parse(JSON.stringify(this.obj));
const cp = JSON.parse(JSON.stringify(this.obj));
if (this.genCopyAttachments) {
//this property set will trigger server to copy attachments
cp.genCopyAttachmentsFrom = {
@@ -729,7 +695,6 @@ export default {
cp.generateBeforeInterval = 14;
cp.generateDate = null;
//Navigate to new record
this.$router.push({
name: "pm-edit",
params: {
@@ -813,8 +778,6 @@ export default {
});
}
}
//end methods
}
};
@@ -840,7 +803,7 @@ async function saveHeader(vm) {
headerOnly.contractViz = undefined;
headerOnly.customerViz = undefined;
let res = await window.$gz.api.upsert(`${API_BASE_URL}`, headerOnly);
const res = await window.$gz.api.upsert(`${API_BASE_URL}`, headerOnly);
if (res.error) {
handleSaveError(vm, { fatal: true, error: res.error });
} else {
@@ -872,15 +835,15 @@ async function saveHeader(vm) {
//
async function saveState(vm) {
//CHANGED?
let totalItems = vm.obj.states.length;
const totalItems = vm.obj.states.length;
if (totalItems == 0) {
return;
}
for (let i = 0; i < totalItems; i++) {
let o = vm.obj.states[i];
const o = vm.obj.states[i];
if (o.concurrency == null) {
//it's new so save it
let res = await window.$gz.api.upsert(`${API_BASE_URL}states`, o);
const res = await window.$gz.api.upsert(`${API_BASE_URL}states`, o);
if (res.error) {
handleSaveError(vm, { error: res.error });
} else {
@@ -903,7 +866,7 @@ async function deleteItems(vm) {
if (!d.deleted) {
continue;
}
let res = await window.$gz.api.remove(`${API_BASE_URL}items/${d.id}`);
const res = await window.$gz.api.remove(`${API_BASE_URL}items/${d.id}`);
if (res.error) {
handleSaveError(vm, { error: res.error, itemUid: d.uid });
} else {
@@ -938,7 +901,7 @@ async function saveItems(vm) {
} = vm.obj.items[i];
const isPost = o.id == 0;
let res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o);
const res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o);
if (res.error) {
handleSaveError(vm, { error: res.error, itemUid: o.uid });
if (isPost) {
@@ -1043,7 +1006,7 @@ async function deleteUnits(vm, woItemIndex) {
continue;
}
if (d.id != 0) {
let res = await window.$gz.api.remove(
const res = await window.$gz.api.remove(
`${API_BASE_URL}items/units/${d.id}`
);
if (res.error) {
@@ -1077,7 +1040,7 @@ async function saveUnits(vm, woItemIndex) {
vm.obj.items[woItemIndex].units[i],
["uid", "isDirty"]
);
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/units`, o);
const res = await window.$gz.api.upsert(`${API_BASE_URL}items/units`, o);
if (res.error) {
handleSaveError(vm, {
error: res.error,
@@ -1089,7 +1052,7 @@ async function saveUnits(vm, woItemIndex) {
//Server will update fields on put or post for most graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
res.data.warrantyViz = null; //Add local key so it's reactive in vue
vm.obj.items[woItemIndex].units.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].units.splice(i, 1, res.data);
}
}
}
@@ -1121,7 +1084,6 @@ async function saveScheduledUsers(vm, woItemIndex) {
o
);
if (res.error) {
//console.log("ERROR", vm.obj.items[woItemIndex].scheduledUsers[i].uid);
handleSaveError(vm, {
error: res.error,
itemUid: vm.obj.items[woItemIndex].uid,
@@ -1131,11 +1093,11 @@ async function saveScheduledUsers(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
vm.obj.items[woItemIndex].scheduledUsers.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].scheduledUsers.splice(i, 1, res.data);
}
}
}
return; //made it
return;
}
async function deleteScheduledUsers(vm, woItemIndex) {
@@ -1150,7 +1112,7 @@ async function deleteScheduledUsers(vm, woItemIndex) {
continue;
}
if (d.id != 0) {
let res = await window.$gz.api.remove(
const res = await window.$gz.api.remove(
`${API_BASE_URL}items/scheduled-users/${d.id}`
);
if (res.error) {
@@ -1165,8 +1127,6 @@ async function deleteScheduledUsers(vm, woItemIndex) {
}
vm.obj.items[woItemIndex].scheduledUsers.splice(i, 1);
}
//----
return;
}
@@ -1199,7 +1159,7 @@ async function saveTasks(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
vm.obj.items[woItemIndex].tasks.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].tasks.splice(i, 1, res.data);
}
}
}
@@ -1215,7 +1175,7 @@ async function deleteTasks(vm, woItemIndex) {
}
if (d.id != 0) {
let res = await window.$gz.api.remove(
const res = await window.$gz.api.remove(
`${API_BASE_URL}items/tasks/${d.id}`
);
if (res.error) {
@@ -1230,8 +1190,6 @@ async function deleteTasks(vm, woItemIndex) {
}
vm.obj.items[woItemIndex].tasks.splice(i, 1);
}
//----
return;
}
@@ -1246,7 +1204,7 @@ async function deleteParts(vm, woItemIndex) {
continue;
}
if (d.id != 0) {
let res = await window.$gz.api.remove(
const res = await window.$gz.api.remove(
`${API_BASE_URL}items/parts/${d.id}`
);
if (res.error) {
@@ -1288,7 +1246,7 @@ async function saveParts(vm, woItemIndex) {
const balanceError = res.error.details.find(z => z.error == "2040");
if (balanceError && balanceError.message) {
//set the amount requestable so it surfaces in the UI and can be requested
let balance = window.$gz.util.stringToFloat(balanceError.message);
const balance = window.$gz.util.stringToFloat(balanceError.message);
if (balance != null || balance != 0) {
vm.obj.items[woItemIndex].parts[i].requestAmountViz =
vm.obj.items[woItemIndex].parts[i].quantity - balance;
@@ -1305,7 +1263,7 @@ async function saveParts(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most quote graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
vm.obj.items[woItemIndex].parts.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].parts.splice(i, 1, res.data);
}
}
}
@@ -1341,7 +1299,7 @@ async function saveLabors(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most quote graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
vm.obj.items[woItemIndex].labors.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].labors.splice(i, 1, res.data);
}
}
}
@@ -1356,7 +1314,7 @@ async function deleteLabors(vm, woItemIndex) {
continue;
}
if (d.id != 0) {
let res = await window.$gz.api.remove(
const res = await window.$gz.api.remove(
`${API_BASE_URL}items/labors/${d.id}`
);
if (res.error) {
@@ -1408,7 +1366,7 @@ async function saveTravels(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most quote graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
vm.obj.items[woItemIndex].travels.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].travels.splice(i, 1, res.data);
}
}
}
@@ -1423,7 +1381,7 @@ async function deleteTravels(vm, woItemIndex) {
continue;
}
if (d.id != 0) {
let res = await window.$gz.api.remove(
const res = await window.$gz.api.remove(
`${API_BASE_URL}items/travels/${d.id}`
);
if (res.error) {
@@ -1455,7 +1413,7 @@ async function deleteExpenses(vm, woItemIndex) {
continue;
}
if (d.id != 0) {
let res = await window.$gz.api.remove(
const res = await window.$gz.api.remove(
`${API_BASE_URL}items/expenses/${d.id}`
);
if (res.error) {
@@ -1504,7 +1462,7 @@ async function saveExpenses(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most quote graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
vm.obj.items[woItemIndex].expenses.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].expenses.splice(i, 1, res.data);
}
}
}
@@ -1522,7 +1480,7 @@ async function deleteLoans(vm, woItemIndex) {
continue;
}
if (d.id != 0) {
let res = await window.$gz.api.remove(
const res = await window.$gz.api.remove(
`${API_BASE_URL}items/loans/${d.id}`
);
if (res.error) {
@@ -1568,7 +1526,7 @@ async function saveLoans(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most quote graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
vm.obj.items[woItemIndex].loans.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].loans.splice(i, 1, res.data);
}
}
}
@@ -1590,7 +1548,7 @@ async function deleteOutsideServices(vm, woItemIndex) {
continue;
}
if (d.id != 0) {
let res = await window.$gz.api.remove(
const res = await window.$gz.api.remove(
`${API_BASE_URL}items/outside-services/${d.id}`
);
if (res.error) {
@@ -1639,7 +1597,7 @@ async function saveOutsideServices(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most quote graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
vm.obj.items[woItemIndex].outsideServices.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].outsideServices.splice(i, 1, res.data);
}
}
}
@@ -1649,8 +1607,6 @@ async function saveOutsideServices(vm, woItemIndex) {
//######################################### UTILITY METHODS ###########################################
function handleSaveError(vm, e) {
//### NOTE: Nothing using FATAL yet, but if necessary here is where it should be determined and set
if (vm.saveResult.errors == null) {
vm.saveResult.errors = [];
}
@@ -1664,7 +1620,7 @@ function errorTargetFromSaveResult(vm, r, t) {
return t;
}
let woitemindex = vm.obj.items.findIndex(z => z.uid == r.itemUid);
const woitemindex = vm.obj.items.findIndex(z => z.uid == r.itemUid);
if (woitemindex == -1) {
return null;
}
@@ -1673,7 +1629,7 @@ function errorTargetFromSaveResult(vm, r, t) {
return `Items[${woitemindex}].${t}`;
}
let childindex = vm.obj.items[woitemindex][r.childKey].findIndex(
const childindex = vm.obj.items[woitemindex][r.childKey].findIndex(
z => z.uid == r.childUid
);
if (childindex == -1) {
@@ -1700,13 +1656,10 @@ function formErrorFromSaveResult(vm) {
details: [],
message: "ErrorAPI2200"
};
//console.log("formErrorFromSaveResult - input is:", vm.saveResult.errors);
vm.saveResult.errors.forEach(z => {
//console.log("z", z);
//{error:{code:xx,message:xx,target:xx},fatal:true}
if (z.error.details != null) {
z.error.details.forEach(x => {
let target = errorTargetFromSaveResult(vm, z, x.target);
const target = errorTargetFromSaveResult(vm, z, x.target);
if (target != null) {
ret.details.push({
message: x.message,
@@ -1717,13 +1670,9 @@ function formErrorFromSaveResult(vm) {
});
} else {
//only one error so just return it
//console.log("single error path:", z.error);
ret = z.error;
//ret.details.push(z.error);
}
});
//console.log("formErrorFromSaveResult Returning ret=:", ret);
return ret;
}
@@ -1753,7 +1702,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":
@@ -1784,7 +1733,7 @@ async function clickHandler(menuItem) {
m.vm.duplicateDlg = true;
break;
case "report":
let res = await m.vm.$refs.reportSelector.open(
const res = await m.vm.$refs.reportSelector.open(
{
AType: window.$gz.type.Quote,
selectedRowIds: [m.vm.obj.id]
@@ -1848,7 +1797,7 @@ async function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
let menuOptions = {
const menuOptions = {
isMain: false,
readOnly: vm.formState.readOnly,
hideCoreBizStandardOptions: vm.obj.userIsRestrictedType,
@@ -1889,8 +1838,6 @@ function generateMenu(vm) {
});
}
//REPORTS
//Report not Print, print is a further option
menuOptions.menuItems.push({
title: "Report",
icon: "$ayiFileAlt",
@@ -1898,8 +1845,7 @@ function generateMenu(vm) {
vm: vm
});
//get last report selected
let lastReport = window.$gz.form.getLastReport(FORM_KEY);
const lastReport = window.$gz.form.getLastReport(FORM_KEY);
if (lastReport != null && !vm.obj.userIsRestrictedType) {
menuOptions.menuItems.push({
title: lastReport.name,
@@ -1958,8 +1904,6 @@ function generateMenu(vm) {
});
}
//--- /show all ---
if (!vm.obj.userIsRestrictedType) {
menuOptions.menuItems.push({ divider: true, inset: false });
menuOptions.menuItems.push({