This commit is contained in:
@@ -791,6 +791,10 @@ async function saveItems(vm) {
|
||||
z => (z.workorderItemId = vm.obj.items[i].id)
|
||||
);
|
||||
|
||||
vm.obj.items[i].travels.forEach(
|
||||
z => (z.workorderItemId = vm.obj.items[i].id)
|
||||
);
|
||||
|
||||
//todo: other grandchildren
|
||||
}
|
||||
}
|
||||
@@ -808,6 +812,9 @@ async function saveItems(vm) {
|
||||
if (!vm.saveResult.fatal) {
|
||||
await saveLabors(vm, i);
|
||||
}
|
||||
if (!vm.saveResult.fatal) {
|
||||
await saveTravels(vm, i);
|
||||
}
|
||||
//todo: other grandchildren
|
||||
//------
|
||||
}
|
||||
@@ -992,6 +999,65 @@ async function deleteLabors(vm, woItemIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// TRAVEL
|
||||
//
|
||||
async function saveTravels(vm, woItemIndex) {
|
||||
//DELETE FLAGGED ITEMS FIRST
|
||||
await deleteTravels(vm, woItemIndex);
|
||||
if (vm.saveResult.fatal) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < vm.obj.items[woItemIndex].travels.length; i++) {
|
||||
let o = vm.obj.items[woItemIndex].travels[i];
|
||||
if (o.isDirty) {
|
||||
const res = await window.$gz.api.upsert(
|
||||
`${API_BASE_URL}items/travels`,
|
||||
o
|
||||
);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "travels",
|
||||
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].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
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
async function deleteTravels(vm, woItemIndex) {
|
||||
//walk the array backwards as items may be spliced out
|
||||
for (var i = vm.obj.items[woItemIndex].travels.length - 1; i >= 0; i--) {
|
||||
const d = vm.obj.items[woItemIndex].travels[i];
|
||||
if (!d.deleted) {
|
||||
continue;
|
||||
}
|
||||
let res = await window.$gz.api.remove(
|
||||
`${API_BASE_URL}items/travels/${d.id}`
|
||||
);
|
||||
if (res.error) {
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "travels",
|
||||
childUid: d.uid
|
||||
});
|
||||
} else {
|
||||
vm.obj.items[woItemIndex].travels.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//----
|
||||
return;
|
||||
}
|
||||
|
||||
//todo: other grandchildren
|
||||
|
||||
//######################################### UTILITY METHODS ###########################################
|
||||
|
||||
Reference in New Issue
Block a user