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

@@ -66,20 +66,13 @@
</template>
</div>
</template>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Xeslint-disable */
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
import GzWoHeader from "../components/work-order-header.vue";
import GzWoItems from "../components/work-order-items.vue";
const FORM_KEY = "workorder-edit";
const API_BASE_URL = "workorder/";
const FORM_CUSTOM_TEMPLATE_KEY = "WorkOrder"; //<-- Should always be CoreBizObject AyaType name here where possible
const FORM_CUSTOM_TEMPLATE_KEY = "WorkOrder";
export default {
components: {
@@ -91,13 +84,9 @@ export default {
try {
await initForm(vm);
//set base rights
vm.rights = window.$gz.role.getRights(window.$gz.type.WorkOrder);
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
@@ -111,9 +100,9 @@ export default {
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;
const wi = this.$route.params.copyItem;
if (wi) {
this.washWorkOrderItem(wi);
wi.workOrderId = vm.obj.id;
@@ -221,7 +210,7 @@ export default {
vm: vm,
loading: false,
dirty: setDirty,
valid: setValid
valid: true
});
//update which areas are available to user and force generate menu
@@ -232,7 +221,6 @@ 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
const gotype = Number(this.$route.params.gotype);
const goid = Number(this.$route.params.goid);
@@ -322,7 +310,6 @@ export default {
timeZoneName: window.$gz.locale.getResolvedTimeZoneName(),
languageName: window.$gz.locale.getResolvedLanguage(),
hour12: window.$gz.locale.getHour12(),
// resetSelections: false,
selectLists: {
wostatus: [],
allowedwostatus: [],
@@ -346,23 +333,18 @@ 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",
@@ -412,12 +394,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;
@@ -452,7 +429,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);
}
@@ -512,12 +488,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,
@@ -546,7 +520,6 @@ export default {
loading: true
});
//clear any errors vm might be around from previous submit
window.$gz.form.deleteAllErrorBoxErrors(vm);
//#######################################################
@@ -625,12 +598,11 @@ export default {
name: "workorder-edit",
params: {
recordid: vm.obj.id
// ,obj: vm.obj // Do NOT Pass data object to new form as normal because for a workorder, it's not a full and complete record at this end
// Do NOT Pass data object to new form as normal because for a workorder, it's not a full and complete record at this end
}
});
} else {
//check if full refresh is necessary
if (
vm.obj.contractId != vm.lastGetContractId ||
vm.obj.customerId != vm.lastGetCustomerId
@@ -660,42 +632,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
@@ -703,16 +669,6 @@ export default {
window.$gz.errorHandler.handleFormError(error, vm);
}
},
// duplicate() {
// //Navigate to new record
// this.$router.push({
// name: "workorder-edit",
// params: {
// recordid: 0,
// obj: this.obj
// }
// });
// },
duplicateHandler() {
switch (this.duplicateTo) {
case "pm":
@@ -727,7 +683,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 = {
@@ -738,7 +694,7 @@ export default {
if (!this.genCopyWiki) {
cp.wiki = null; //already copied, need to remove it instead
}
//Navigate to new record
this.$router.push({
name: "workorder-edit",
params: {
@@ -748,7 +704,7 @@ export default {
});
},
generateQuote() {
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 = {
@@ -774,7 +730,6 @@ export default {
cp.submitted = null;
cp.approved = null;
//Navigate to new record
this.$router.push({
name: "quote-edit",
params: {
@@ -784,7 +739,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 = {
@@ -800,7 +755,6 @@ export default {
x.partRequests = [];
});
cp.id = 0;
//PM Defaults copied from PM data object
cp.stopGeneratingDate = null;
cp.excludeDaysOfWeek = 96;
@@ -812,7 +766,6 @@ export default {
cp.generateBeforeInterval = 14;
cp.generateDate = null;
//Navigate to new record
this.$router.push({
name: "pm-edit",
params: {
@@ -902,8 +855,6 @@ export default {
});
}
}
//end methods
}
};
@@ -929,7 +880,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 {
@@ -961,15 +912,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 {
@@ -992,7 +943,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 {
@@ -1028,7 +979,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) {
@@ -1139,7 +1090,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) {
@@ -1173,7 +1124,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,
@@ -1185,7 +1136,7 @@ async function saveUnits(vm, woItemIndex) {
//Server will update fields on put or post for most workorder 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);
}
}
}
@@ -1217,7 +1168,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,
@@ -1227,7 +1177,7 @@ async function saveScheduledUsers(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most workorder 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);
}
}
}
@@ -1246,7 +1196,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) {
@@ -1295,7 +1245,7 @@ async function saveTasks(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most workorder 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);
}
}
}
@@ -1311,7 +1261,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) {
@@ -1342,7 +1292,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) {
@@ -1384,7 +1334,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;
@@ -1401,7 +1351,7 @@ async function saveParts(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most workorder 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);
}
}
}
@@ -1419,7 +1369,7 @@ async function deletePartRequests(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/part-requests/${d.id}`
);
if (res.error) {
@@ -1468,7 +1418,7 @@ async function savePartRequests(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here
res.data.isDirty = false; //prime isDirty to detect future edits
vm.obj.items[woItemIndex].partRequests.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].partRequests.splice(i, 1, res.data);
}
}
}
@@ -1504,7 +1454,7 @@ async function saveLabors(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most workorder 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);
}
}
}
@@ -1519,7 +1469,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) {
@@ -1571,7 +1521,7 @@ async function saveTravels(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most workorder 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);
}
}
}
@@ -1586,7 +1536,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) {
@@ -1618,7 +1568,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) {
@@ -1667,7 +1617,7 @@ async function saveExpenses(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most workorder 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);
}
}
}
@@ -1685,7 +1635,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) {
@@ -1731,7 +1681,7 @@ async function saveLoans(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most workorder 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);
}
}
}
@@ -1753,7 +1703,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) {
@@ -1802,7 +1752,7 @@ async function saveOutsideServices(vm, woItemIndex) {
} else {
//Server will update fields on put or post for most workorder 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);
}
}
}
@@ -1827,7 +1777,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;
}
@@ -1836,7 +1786,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) {
@@ -1869,7 +1819,7 @@ function formErrorFromSaveResult(vm) {
//{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,
@@ -1879,14 +1829,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;
}
@@ -1916,7 +1861,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":
@@ -1947,7 +1892,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.WorkOrder,
selectedRowIds: [m.vm.obj.id]
@@ -1992,12 +1937,6 @@ async function clickHandler(menuItem) {
id: m.vm.obj.fromPMId
});
break;
// case "csr":
// window.$gz.eventBus.$emit("openobject", {
// type: window.$gz.type.CustomerServiceRequest,
// id: m.vm.obj.fromCSRId
// });
// break;
default:
window.$gz.eventBus.$emit(
"notify-warning",
@@ -2011,7 +1950,7 @@ async function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
let menuOptions = {
const menuOptions = {
isMain: false,
readOnly: vm.formState.readOnly,
hideCoreBizStandardOptions: vm.obj.userIsRestrictedType,
@@ -2052,8 +1991,6 @@ function generateMenu(vm) {
});
}
//REPORTS
//Report not Print, print is a further option
menuOptions.menuItems.push({
title: "Report",
icon: "$ayiFileAlt",
@@ -2061,8 +1998,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,
@@ -2153,7 +2089,6 @@ function generateMenu(vm) {
}
menuOptions.menuItems.push({ divider: true, inset: false });
//MIGRATE_OUTSTANDING test once have quote pm and csr created workorders
let hasFromInsertDivider = false;
if (
@@ -2177,18 +2112,6 @@ function generateMenu(vm) {
});
hasFromInsertDivider = true;
}
// if (
// vm.obj.fromCSRId != null &&
// window.$gz.role.canOpen(window.$gz.type.CustomerServiceRequest)
// ) {
// menuOptions.menuItems.push({
// title: "CustomerServiceRequest",
// icon: "$ayiConciergeBell",
// key: FORM_KEY + ":csr",
// vm: vm
// });
// hasFromInsertDivider = true;
// }
if (hasFromInsertDivider) {
menuOptions.menuItems.push({ divider: true, inset: false });