This commit is contained in:
@@ -167,17 +167,7 @@ export default {
|
||||
if ((await window.$gz.dialog.confirmDelete()) != true) {
|
||||
return;
|
||||
}
|
||||
this.value.items.splice(this.pvm.selectedItemIndex, 1);
|
||||
this.pvm.selectItem(null); //select nothing in essence resetting a child selects and this one too clearing form
|
||||
|
||||
//todo: put this id in a collection at parent to be deleted when it's saved and marked dirty (a function "DeleteItem(index)")
|
||||
//if no concurrency then just remove and ignore, no need to save, if concurrency then it needs to be deleted at the server
|
||||
|
||||
// if (this.value.items.length > 0) {
|
||||
// this.pvm.selectedItemIndex = this.value.items.length - 1;
|
||||
// } else {
|
||||
// this.pvm.selectedItemIndex = null;
|
||||
// }
|
||||
this.pvm.deleteItem(this.pvm.selectedItemIndex);
|
||||
},
|
||||
selectItem: function(item) {
|
||||
this.selectedRow = [item];
|
||||
|
||||
@@ -195,6 +195,7 @@ export default {
|
||||
languageName: window.$gz.locale.getResolvedLanguage(),
|
||||
hour12: window.$gz.locale.getHour12(),
|
||||
selectedItemIndex: null,
|
||||
deletedItems: [],
|
||||
selectedScheduledUserItemIndex: null,
|
||||
selectLists: {
|
||||
wostatus: [],
|
||||
@@ -374,6 +375,18 @@ export default {
|
||||
//todo: all children here
|
||||
//this.selectedLaborIndex...blahblah etc
|
||||
},
|
||||
deleteItem: function(itemIndex) {
|
||||
if (itemIndex == null) {
|
||||
itemIndex = this.selectedItemIndex;
|
||||
}
|
||||
//add to deleted items if has concurrency / id
|
||||
let o = this.obj.items[itemIndex];
|
||||
if (o.id != 0) {
|
||||
this.deletedItems.push(o.id);
|
||||
}
|
||||
this.obj.items.splice(itemIndex, 1);
|
||||
this.selectItem(null); //select nothing in essence resetting a child selects and this one too clearing form
|
||||
},
|
||||
canSave: function() {
|
||||
return this.formState.valid && this.formState.dirty;
|
||||
},
|
||||
@@ -635,7 +648,7 @@ export default {
|
||||
//
|
||||
async function saveHeader(vm) {
|
||||
if (!vm.obj.isDirty) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}`, o);
|
||||
if (res.error) {
|
||||
@@ -647,6 +660,7 @@ async function saveHeader(vm) {
|
||||
vm.obj.id = res.id;
|
||||
vm.obj.serial = res.serial;
|
||||
vm.obj.isDirty = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -655,15 +669,29 @@ async function saveHeader(vm) {
|
||||
//
|
||||
async function saveItems(vm) {
|
||||
let totalItems = vm.obj.items.length;
|
||||
if (totalItems == 0) {
|
||||
return;
|
||||
let totalDeletedItems = vm.deletedItems.length;
|
||||
if (totalItems == 0 && totalDeletedItems == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//delete
|
||||
for (let i = 0; i < totalDeletedItems; i++) {
|
||||
let res = await window.$gz.api.remove(
|
||||
`${API_BASE_URL}${this.deletedItems[i]}`
|
||||
);
|
||||
if (res.error) {
|
||||
displayResError(vm, res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//upsert
|
||||
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");
|
||||
console.log("Is dirty, saving now for ", i);
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o);
|
||||
if (res.error) {
|
||||
displayResError(vm, res);
|
||||
@@ -676,7 +704,7 @@ async function saveItems(vm) {
|
||||
o.isDirty = false;
|
||||
}
|
||||
} else {
|
||||
console.log("Item not dirty skipping save");
|
||||
console.log("Item not dirty skipping save of ", i);
|
||||
}
|
||||
//------
|
||||
//save grandchildren
|
||||
@@ -693,18 +721,18 @@ async function saveItems(vm) {
|
||||
// SCHEDULED USERS
|
||||
//
|
||||
async function saveScheduledUsers(vm, woitemindex) {
|
||||
console.log("SaveSchedUsersProcessing for woitemindex:", 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 no items to save bailing");
|
||||
return true;
|
||||
}
|
||||
console.log("saveschedusers processing this many items: ", totalItems);
|
||||
// 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 });
|
||||
// console.log("checking for save scheduseritem: ", { item: o, index: i });
|
||||
if (o.isDirty) {
|
||||
console.log("sched user Is dirty, saving now");
|
||||
// console.log("sched user Is dirty, saving now");
|
||||
let res = await window.$gz.api.upsert(
|
||||
`${API_BASE_URL}items/scheduledusers`,
|
||||
o
|
||||
@@ -720,7 +748,7 @@ async function saveScheduledUsers(vm, woitemindex) {
|
||||
o.isDirty = false;
|
||||
}
|
||||
} else {
|
||||
console.log("schedUserItem not dirty skipping save");
|
||||
// console.log("schedUserItem not dirty skipping save");
|
||||
}
|
||||
}
|
||||
return true; //made it
|
||||
|
||||
Reference in New Issue
Block a user