From 5a2b19022dad5b4a05a6a86617bd8183631f73e5 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 8 Apr 2021 18:44:18 +0000 Subject: [PATCH] --- ayanova/src/components/work-order-items.vue | 19 ++++++----- ayanova/src/views/svc-workorder.vue | 36 +++++++++++++++++---- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/ayanova/src/components/work-order-items.vue b/ayanova/src/components/work-order-items.vue index a5fd2ac5..33eb9cf1 100644 --- a/ayanova/src/components/work-order-items.vue +++ b/ayanova/src/components/work-order-items.vue @@ -39,7 +39,7 @@ 0) { - this.pvm.selectedItemIndex = this.value.items.length - 1; - } else { - this.pvm.selectedItemIndex = null; - } + this.pvm.selectIndex(null); //select nothing in essence resetting a child selects and this one too clearing form + + // if (this.value.items.length > 0) { + // this.pvm.selectedItemIndex = this.value.items.length - 1; + // } else { + // this.pvm.selectedItemIndex = null; + // } }, selectItem: function(item) { this.selectedRow = [item]; diff --git a/ayanova/src/views/svc-workorder.vue b/ayanova/src/views/svc-workorder.vue index c0a9e770..cfa90173 100644 --- a/ayanova/src/views/svc-workorder.vue +++ b/ayanova/src/views/svc-workorder.vue @@ -364,6 +364,16 @@ export default { } }, methods: { + selectItem: function(itemIndex) { + if (itemIndex == this.selectedItemIndex) { + return; + } + this.selectedItemIndex = itemIndex; + //reset all children + this.selectedScheduledUserItemIndex = null; + //todo: all children here + //this.selectedLaborIndex...blahblah etc + }, canSave: function() { return this.formState.valid && this.formState.dirty; }, @@ -648,11 +658,12 @@ async function saveItems(vm) { if (totalItems == 0) { return; } - + console.log("saveItems processing this many items: ", totalItems); for (let i = 0; i < totalItems; i++) { let o = vm.obj.items[i]; - + console.log("checking for save item: ", { item: o, index: i }); if (o.isDirty) { + console.log("Is dirty, saving now"); let res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o); if (res.error) { displayResError(vm, res); @@ -664,29 +675,39 @@ async function saveItems(vm) { o.workorderId = res.workorderId; o.isDirty = false; } + } else { + console.log("Item not dirty skipping save"); } //------ //save grandchildren - if (!(await saveScheduledUsers(vm, o.id))) { + if (!(await saveScheduledUsers(vm, i))) { return false; } //------ + console.log("Bottom of items loop", { totalItems: totalItems, i: i }); } } ///////////////////////////// // SCHEDULED USERS // -async function saveScheduledUsers(vm, woitemid) { - let woitemindex = vm.obj.items.findIndex(z => z.id == woitemid); +async function saveScheduledUsers(vm, woitemindex) { + console.log("SaveSchedUsersProcessing for woitemindex:", woitemindex); let totalItems = vm.obj.items[woitemindex].scheduledUsers.length; if (totalItems == 0) { + console.log("saveschedusers no items to save bailing"); return; } + console.log("saveschedusers processing this many items: ", totalItems); for (let i = 0; i < totalItems; i++) { let o = vm.obj.items[woitemindex].scheduledUsers[i]; + console.log("checking for save item: ", { item: o, index: i }); if (o.isDirty) { - let res = await window.$gz.api.upsert(`${API_BASE_URL}scheduledusers`, o); + console.log("sched user Is dirty, saving now"); + let res = await window.$gz.api.upsert( + `${API_BASE_URL}items/scheduledusers`, + o + ); if (res.error) { displayResError(vm, res); return false; @@ -697,6 +718,8 @@ async function saveScheduledUsers(vm, woitemid) { o.workOrderItemId = res.workOrderItemId; o.isDirty = false; } + } else { + console.log("schedUserItem not dirty skipping save"); } } } @@ -731,6 +754,7 @@ async function saveState(vm) { // Error display // function displayResError(vm, res) { + console.log("DISPLAY RES ERROR: ", res); vm.formState.serverError = res.error; window.$gz.form.setErrorBoxErrors(vm); }