This commit is contained in:
@@ -862,7 +862,7 @@ async function saveItems(vm) {
|
||||
//## GRANDCHILDREN
|
||||
|
||||
/////////////////////////////
|
||||
// EXPENSES
|
||||
// UNITS
|
||||
//
|
||||
async function deleteUnits(vm, woItemIndex) {
|
||||
//walk the array backwards as items may be spliced out
|
||||
@@ -898,7 +898,7 @@ async function saveUnits(vm, woItemIndex) {
|
||||
for (let i = 0; i < vm.obj.items[woItemIndex].units.length; i++) {
|
||||
let o = vm.obj.items[woItemIndex].units[i];
|
||||
if (o.isDirty) {
|
||||
const isPost = o.id == 0;
|
||||
//const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/units`, o);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
@@ -931,7 +931,7 @@ async function saveScheduledUsers(vm, woItemIndex) {
|
||||
if (o.isDirty) {
|
||||
const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(
|
||||
`${API_BASE_URL}items/scheduledusers`,
|
||||
`${API_BASE_URL}items/scheduled-users`,
|
||||
o
|
||||
);
|
||||
if (res.error) {
|
||||
@@ -962,7 +962,7 @@ async function deleteScheduledUsers(vm, woItemIndex) {
|
||||
continue;
|
||||
}
|
||||
let res = await window.$gz.api.remove(
|
||||
`${API_BASE_URL}items/scheduledusers/${d.id}`
|
||||
`${API_BASE_URL}items/scheduled-users/${d.id}`
|
||||
);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
@@ -993,7 +993,7 @@ async function saveTasks(vm, woItemIndex) {
|
||||
for (let i = 0; i < vm.obj.items[woItemIndex].tasks.length; i++) {
|
||||
let o = vm.obj.items[woItemIndex].tasks[i];
|
||||
if (o.isDirty) {
|
||||
const isPost = o.id == 0;
|
||||
// const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/tasks`, o);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
@@ -1072,7 +1072,7 @@ async function saveParts(vm, woItemIndex) {
|
||||
for (let i = 0; i < vm.obj.items[woItemIndex].parts.length; i++) {
|
||||
let o = vm.obj.items[woItemIndex].parts[i];
|
||||
if (o.isDirty) {
|
||||
const isPost = o.id == 0;
|
||||
//const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/parts`, o);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
@@ -1090,6 +1090,66 @@ async function saveParts(vm, woItemIndex) {
|
||||
return; //made it
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// PART REQUESTS
|
||||
//
|
||||
async function deletePartRequests(vm, woItemIndex) {
|
||||
//walk the array backwards as items may be spliced out
|
||||
for (var i = vm.obj.items[woItemIndex].partRequests.length - 1; i >= 0; i--) {
|
||||
const d = vm.obj.items[woItemIndex].partRequests[i];
|
||||
if (!d.deleted) {
|
||||
continue;
|
||||
}
|
||||
let res = await window.$gz.api.remove(
|
||||
`${API_BASE_URL}items/part-requests/${d.id}`
|
||||
);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "partRequests",
|
||||
childUid: d.uid
|
||||
});
|
||||
} else {
|
||||
vm.obj.items[woItemIndex].partRequests.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//----
|
||||
return;
|
||||
}
|
||||
|
||||
async function savePartRequests(vm, woItemIndex) {
|
||||
//DELETE FLAGGED ITEMS FIRST
|
||||
await deletePartRequests(vm, woItemIndex);
|
||||
if (vm.saveResult.fatal) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < vm.obj.items[woItemIndex].partRequests.length; i++) {
|
||||
let o = vm.obj.items[woItemIndex].partRequests[i];
|
||||
if (o.isDirty) {
|
||||
//const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(
|
||||
`${API_BASE_URL}items/part-requests`,
|
||||
o
|
||||
);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "partRequests",
|
||||
childUid: o.uid
|
||||
});
|
||||
} else {
|
||||
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
return; //made it
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// LABOR
|
||||
//
|
||||
@@ -1244,7 +1304,7 @@ async function saveExpenses(vm, woItemIndex) {
|
||||
for (let i = 0; i < vm.obj.items[woItemIndex].expenses.length; i++) {
|
||||
let o = vm.obj.items[woItemIndex].expenses[i];
|
||||
if (o.isDirty) {
|
||||
const isPost = o.id == 0;
|
||||
//const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/expenses`, o);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
@@ -1262,7 +1322,119 @@ async function saveExpenses(vm, woItemIndex) {
|
||||
return; //made it
|
||||
}
|
||||
|
||||
//todo: other grandchildren
|
||||
/////////////////////////////
|
||||
// LOANS
|
||||
//
|
||||
async function deleteExpenses(vm, woItemIndex) {
|
||||
//walk the array backwards as items may be spliced out
|
||||
for (var i = vm.obj.items[woItemIndex].expenses.length - 1; i >= 0; i--) {
|
||||
const d = vm.obj.items[woItemIndex].expenses[i];
|
||||
if (!d.deleted) {
|
||||
continue;
|
||||
}
|
||||
let res = await window.$gz.api.remove(
|
||||
`${API_BASE_URL}items/expenses/${d.id}`
|
||||
);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "expenses",
|
||||
childUid: d.uid
|
||||
});
|
||||
} else {
|
||||
vm.obj.items[woItemIndex].expenses.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//----
|
||||
return;
|
||||
}
|
||||
|
||||
async function saveExpenses(vm, woItemIndex) {
|
||||
//DELETE FLAGGED ITEMS FIRST
|
||||
await deleteExpenses(vm, woItemIndex);
|
||||
if (vm.saveResult.fatal) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < vm.obj.items[woItemIndex].expenses.length; i++) {
|
||||
let o = vm.obj.items[woItemIndex].expenses[i];
|
||||
if (o.isDirty) {
|
||||
//const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/expenses`, o);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "expenses",
|
||||
childUid: o.uid
|
||||
});
|
||||
} else {
|
||||
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
return; //made it
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// OUTSIDE SERVICES
|
||||
//
|
||||
async function deleteExpenses(vm, woItemIndex) {
|
||||
//walk the array backwards as items may be spliced out
|
||||
for (var i = vm.obj.items[woItemIndex].expenses.length - 1; i >= 0; i--) {
|
||||
const d = vm.obj.items[woItemIndex].expenses[i];
|
||||
if (!d.deleted) {
|
||||
continue;
|
||||
}
|
||||
let res = await window.$gz.api.remove(
|
||||
`${API_BASE_URL}items/expenses/${d.id}`
|
||||
);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "expenses",
|
||||
childUid: d.uid
|
||||
});
|
||||
} else {
|
||||
vm.obj.items[woItemIndex].expenses.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//----
|
||||
return;
|
||||
}
|
||||
|
||||
async function saveExpenses(vm, woItemIndex) {
|
||||
//DELETE FLAGGED ITEMS FIRST
|
||||
await deleteExpenses(vm, woItemIndex);
|
||||
if (vm.saveResult.fatal) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < vm.obj.items[woItemIndex].expenses.length; i++) {
|
||||
let o = vm.obj.items[woItemIndex].expenses[i];
|
||||
if (o.isDirty) {
|
||||
//const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/expenses`, o);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "expenses",
|
||||
childUid: o.uid
|
||||
});
|
||||
} else {
|
||||
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
return; //made it
|
||||
}
|
||||
|
||||
//######################################### UTILITY METHODS ###########################################
|
||||
|
||||
|
||||
Reference in New Issue
Block a user