This commit is contained in:
2021-05-25 20:14:44 +00:00
parent 096e648568
commit 5546c9017f
2 changed files with 93 additions and 2 deletions

View File

@@ -788,6 +788,10 @@ async function saveItems(vm) {
z => (z.workorderItemId = vm.obj.items[i].id)
);
vm.obj.items[i].tasks.forEach(
z => (z.workorderItemId = vm.obj.items[i].id)
);
vm.obj.items[i].labors.forEach(
z => (z.workorderItemId = vm.obj.items[i].id)
);
@@ -810,6 +814,9 @@ async function saveItems(vm) {
if (!vm.saveResult.fatal) {
await saveScheduledUsers(vm, i);
}
if (!vm.saveResult.fatal) {
await saveTasks(vm, i);
}
if (!vm.saveResult.fatal) {
await saveLabors(vm, i);
}
@@ -944,6 +951,61 @@ async function deleteScheduledUsers(vm, woItemIndex) {
return;
}
/////////////////////////////
// SCHEDULED USERS
//
async function saveTasks(vm, woItemIndex) {
//DELETE FLAGGED ITEMS FIRST
await deleteTasks(vm, woItemIndex);
if (vm.saveResult.fatal) {
return;
}
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;
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/tasks`, o);
if (res.error) {
handleSaveError(vm, {
error: res.error,
itemUid: vm.obj.items[woItemIndex].uid,
childKey: "tasks",
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].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
}
}
}
return; //made it
}
async function deleteTasks(vm, woItemIndex) {
//walk the array backwards as items may be spliced out
for (var i = vm.obj.items[woItemIndex].tasks.length - 1; i >= 0; i--) {
const d = vm.obj.items[woItemIndex].tasks[i];
if (!d.deleted) {
continue;
}
let res = await window.$gz.api.remove(`${API_BASE_URL}items/tasks/${d.id}`);
if (res.error) {
handleSaveError(vm, {
error: res.error,
itemUid: vm.obj.items[woItemIndex].uid,
childKey: "tasks",
childUid: d.uid
});
} else {
vm.obj.items[woItemIndex].tasks.splice(i, 1);
}
}
//----
return;
}
/////////////////////////////
// LABOR
//