This commit is contained in:
@@ -497,7 +497,7 @@ export default {
|
||||
if (this.saveResult.errors != null) {
|
||||
//# FAIL ROUTE
|
||||
|
||||
vm.formState.serverError = formErrorFromSaveResult();
|
||||
vm.formState.serverError = formErrorFromSaveResult(this);
|
||||
window.$gz.form.setErrorBoxErrors(vm); //set generalerror errors in error box at top, not related to form field errors which happen alternatively based on formState.serverError which is confusing
|
||||
|
||||
//TODO: If it's a fatal error set accordingly and bail out here
|
||||
@@ -641,7 +641,7 @@ async function saveHeader(vm) {
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}`, headerOnly);
|
||||
if (res.error) {
|
||||
if (isPost) {
|
||||
handleSaveError({ fatal: true, error: res.error });
|
||||
handleSaveError(vm, { fatal: true, error: res.error });
|
||||
}
|
||||
} else {
|
||||
//update any server changed fields
|
||||
@@ -672,7 +672,7 @@ async function saveState(vm) {
|
||||
//it's new so save it
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}states`, o);
|
||||
if (res.error) {
|
||||
handleSaveError({ error: res.error });
|
||||
handleSaveError(vm, { error: res.error });
|
||||
} else {
|
||||
vm.obj.states[i] = res.data;
|
||||
|
||||
@@ -695,7 +695,7 @@ async function deleteItems(vm) {
|
||||
}
|
||||
let res = await window.$gz.api.remove(`${API_BASE_URL}items/${d.id}`);
|
||||
if (res.error) {
|
||||
handleSaveError({ error: res.error, itemUid: d.uid });
|
||||
handleSaveError(vm, { error: res.error, itemUid: d.uid });
|
||||
} else {
|
||||
vm.obj.items.splice(i, 1);
|
||||
}
|
||||
@@ -706,7 +706,7 @@ async function deleteItems(vm) {
|
||||
async function saveItems(vm) {
|
||||
//DELETE FLAGGED WOITEMS FIRST
|
||||
await deleteItems(vm);
|
||||
if (this.saveResult.fatal) {
|
||||
if (vm.saveResult.fatal) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -730,7 +730,7 @@ async function saveItems(vm) {
|
||||
const isPost = o.id == 0;
|
||||
let res = await window.$gz.api.upsert(`${API_BASE_URL}items`, o);
|
||||
if (res.error) {
|
||||
handleSaveError({ error: res.error, itemUid: o.uid });
|
||||
handleSaveError(vm, { error: res.error, itemUid: o.uid });
|
||||
if (isPost) {
|
||||
//a post error precludes further operations on this item below
|
||||
//however, an update error doesn't necessarily because it's still a existing workorder item
|
||||
@@ -759,7 +759,7 @@ async function saveItems(vm) {
|
||||
}
|
||||
//------
|
||||
//save grandchildren
|
||||
if (!this.saveResult.fatal) {
|
||||
if (!vm.saveResult.fatal) {
|
||||
await saveScheduledUsers(vm, i);
|
||||
}
|
||||
//todo: other grandchildren
|
||||
@@ -787,7 +787,7 @@ async function deleteScheduledUsers(vm, woItemIndex) {
|
||||
`${API_BASE_URL}items/scheduledusers/${d.id}`
|
||||
);
|
||||
if (res.error) {
|
||||
handleSaveError({
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "scheduledUsers",
|
||||
@@ -805,7 +805,7 @@ async function deleteScheduledUsers(vm, woItemIndex) {
|
||||
async function saveScheduledUsers(vm, woItemIndex) {
|
||||
//DELETE FLAGGED ITEMS FIRST
|
||||
await deleteScheduledUsers(vm, woItemIndex);
|
||||
if (this.saveResult.fatal) {
|
||||
if (vm.saveResult.fatal) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -818,7 +818,7 @@ async function saveScheduledUsers(vm, woItemIndex) {
|
||||
o
|
||||
);
|
||||
if (res.error) {
|
||||
handleSaveError({
|
||||
handleSaveError(vm, {
|
||||
error: res.error,
|
||||
itemUid: vm.obj.items[woItemIndex].uid,
|
||||
childKey: "scheduledUsers",
|
||||
@@ -845,7 +845,7 @@ async function saveScheduledUsers(vm, woItemIndex) {
|
||||
|
||||
//######################################### UTILITY METHODS ###########################################
|
||||
|
||||
function handleSaveError(e) {
|
||||
function handleSaveError(vm, e) {
|
||||
//TODO: decide if fatal here and set accordingly
|
||||
/**
|
||||
* {
|
||||
@@ -856,20 +856,20 @@ function handleSaveError(e) {
|
||||
}
|
||||
*
|
||||
*/
|
||||
if (this.saveResult.errors == null) {
|
||||
this.saveResult.errors = [];
|
||||
if (vm.saveResult.errors == null) {
|
||||
vm.saveResult.errors = [];
|
||||
}
|
||||
this.saveResult.errors.push(e);
|
||||
vm.saveResult.errors.push(e);
|
||||
}
|
||||
|
||||
function errorTargetFromSaveResult(r, t) {
|
||||
function errorTargetFromSaveResult(vm, r, t) {
|
||||
//no particular target
|
||||
//or not a woitem tree error (header)
|
||||
if (r.itemUid == null || t == null || t == "generalerror") {
|
||||
return t;
|
||||
}
|
||||
|
||||
let woitemindex = this.obj.items.findIndex(z => z.uid == r.itemUid);
|
||||
let woitemindex = vm.obj.items.findIndex(z => z.uid == r.itemUid);
|
||||
if (woitemindex == -1) {
|
||||
return null;
|
||||
}
|
||||
@@ -878,7 +878,7 @@ function errorTargetFromSaveResult(r, t) {
|
||||
return `Items[${woitemindex}].${t}`;
|
||||
}
|
||||
|
||||
let childindex = this.obj.items[woitemindex][r.childKey].findIndex(
|
||||
let childindex = vm.obj.items[woitemindex][r.childKey].findIndex(
|
||||
z => z.uid == r.childUid
|
||||
);
|
||||
if (childindex == -1) {
|
||||
@@ -887,7 +887,7 @@ function errorTargetFromSaveResult(r, t) {
|
||||
return `Items[${woitemindex}].${r.childKey}[${childindex}].${t}`;
|
||||
}
|
||||
|
||||
function formErrorFromSaveResult() {
|
||||
function formErrorFromSaveResult(vm) {
|
||||
//digest saveresult and compile into standard form error and return
|
||||
/**
|
||||
* {
|
||||
@@ -905,9 +905,9 @@ function formErrorFromSaveResult() {
|
||||
message: "ErrorAPI2200"
|
||||
}
|
||||
};
|
||||
this.saveResult.errors.forEach(z => {
|
||||
vm.saveResult.errors.forEach(z => {
|
||||
z.error.details.forEach(x => {
|
||||
let target = errorTargetFromSaveResult(z, x.target);
|
||||
let target = errorTargetFromSaveResult(vm, z, x.target);
|
||||
if (target != null) {
|
||||
ret.error.details.push({
|
||||
message: x.message,
|
||||
@@ -918,10 +918,27 @@ function formErrorFromSaveResult() {
|
||||
});
|
||||
});
|
||||
|
||||
return ret;
|
||||
console.log("source:", JSON.stringify(vm.saveResult));
|
||||
console.log("result: ", JSON.stringify(ret));
|
||||
|
||||
return ret.error;
|
||||
|
||||
/*
|
||||
|
||||
source: {"fatal":false,"errors":[{"error":{"code":"2200","details":[{"message":"SAVE TEST ERROR","target":"Notes","error":"2203"}],"message":"ErrorAPI2200"},"itemUid":0}]}
|
||||
result: {"error":{"code":"2200","details":[{"message":"SAVE TEST ERROR","error":"2203","target":"Items[0].Notes"}],"message":"ErrorAPI2200"}}
|
||||
|
||||
{"error":{"code":"2200","details":[{"message":"SAVE TEST ERROR","target":"Notes","error":"2203"}],"message":"ErrorAPI2200"}
|
||||
{"error":{"code":"2200","details":[{"message":"SAVE TEST ERROR","error":"2203","target":"Items[0].Notes"}],"message":"ErrorAPI2200"}}
|
||||
|
||||
{error: {code: "2200",details: [{ message: "SAVE TEST ERROR", target: "Notes", error: "2203" }],message: "ErrorAPI2200"}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
`Items[${activeWoItemIndex}].scheduledUsers[${activeItemIndex}].estimatedQuantity`
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user