This commit is contained in:
@@ -39,7 +39,7 @@ function stringifyPrimitive(v) {
|
|||||||
// Try to handle an api error
|
// Try to handle an api error
|
||||||
// return true if handled or false if not
|
// return true if handled or false if not
|
||||||
//
|
//
|
||||||
function handleError(action, error, route, reject) {
|
function handleError(action, error, route) {
|
||||||
let errorMessage =
|
let errorMessage =
|
||||||
"API error: " + action + " route =" + route + ", message =" + error.message;
|
"API error: " + action + " route =" + route + ", message =" + error.message;
|
||||||
window.$gz.store.commit("logItem", errorMessage);
|
window.$gz.store.commit("logItem", errorMessage);
|
||||||
@@ -56,12 +56,9 @@ function handleError(action, error, route, reject) {
|
|||||||
window.$gz.translation.get("ErrorUserNotAuthorized")
|
window.$gz.translation.get("ErrorUserNotAuthorized")
|
||||||
);
|
);
|
||||||
router.push(window.$gz.store.state.homePage);
|
router.push(window.$gz.store.state.homePage);
|
||||||
if (reject) {
|
|
||||||
return reject("[ErrorUserNotAuthorized]");
|
|
||||||
} else {
|
|
||||||
throw "[ErrorUserNotAuthorized]";
|
throw "[ErrorUserNotAuthorized]";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//Handle 401 not authenticated
|
//Handle 401 not authenticated
|
||||||
if (error.message && error.message.includes("NotAuthenticated")) {
|
if (error.message && error.message.includes("NotAuthenticated")) {
|
||||||
@@ -75,12 +72,9 @@ function handleError(action, error, route, reject) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
router.push("/login");
|
router.push("/login");
|
||||||
if (reject) {
|
|
||||||
return reject("[ErrorUserNotAuthenticated]");
|
|
||||||
} else {
|
|
||||||
throw "[ErrorUserNotAuthenticated]";
|
throw "[ErrorUserNotAuthenticated]";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//is it a network error?
|
//is it a network error?
|
||||||
//https://medium.com/@vinhlh/how-to-handle-networkerror-when-using-fetch-ff2663220435
|
//https://medium.com/@vinhlh/how-to-handle-networkerror-when-using-fetch-ff2663220435
|
||||||
@@ -104,13 +98,8 @@ function handleError(action, error, route, reject) {
|
|||||||
window.$gz.eventBus.$emit("notify-error", msg);
|
window.$gz.eventBus.$emit("notify-error", msg);
|
||||||
//note: using translation key in square brackets
|
//note: using translation key in square brackets
|
||||||
|
|
||||||
if (reject) {
|
|
||||||
return reject(msg);
|
|
||||||
} else {
|
|
||||||
throw msg;
|
throw msg;
|
||||||
}
|
}
|
||||||
//throw "Error: unable to contact server";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Ideally this should never get called because any issue should be addressed above
|
//Ideally this should never get called because any issue should be addressed above
|
||||||
@@ -122,13 +111,11 @@ export default {
|
|||||||
status(response) {
|
status(response) {
|
||||||
//Handle expected api errors
|
//Handle expected api errors
|
||||||
if (response.status == 401) {
|
if (response.status == 401) {
|
||||||
//must reject if not Authenticated
|
throw new Error("[ErrorUserNotAuthenticated]");
|
||||||
return Promise.reject(new Error("[ErrorUserNotAuthenticated]"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status == 403) {
|
if (response.status == 403) {
|
||||||
//must reject if not Authorized
|
throw new Error("[ErrorUserNotAuthorized]");
|
||||||
return Promise.reject(new Error("[ErrorUserNotAuthorized]"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//404 not found is an expected status not worth logging allow to bubble up
|
//404 not found is an expected status not worth logging allow to bubble up
|
||||||
@@ -140,9 +127,7 @@ export default {
|
|||||||
if (response.status == 405) {
|
if (response.status == 405) {
|
||||||
//Probably a development error
|
//Probably a development error
|
||||||
|
|
||||||
return Promise.reject(
|
throw new Error("Method Not Allowed (route issue?) " + response.url);
|
||||||
new Error("Method Not Allowed (route issue?) " + response.url)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status >= 200 && response.status < 300) {
|
if (response.status >= 200 && response.status < 300) {
|
||||||
@@ -165,12 +150,10 @@ export default {
|
|||||||
statusEx(response) {
|
statusEx(response) {
|
||||||
//Handle expected api errors
|
//Handle expected api errors
|
||||||
if (response.status == 401) {
|
if (response.status == 401) {
|
||||||
//must reject if not Authenticated
|
|
||||||
throw new Error("[ErrorUserNotAuthenticated]");
|
throw new Error("[ErrorUserNotAuthenticated]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status == 403) {
|
if (response.status == 403) {
|
||||||
//must reject if not Authorized
|
|
||||||
throw new Error("[ErrorUserNotAuthorized]");
|
throw new Error("[ErrorUserNotAuthorized]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,7 +415,7 @@ export default {
|
|||||||
return r;
|
return r;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//fundamental error, can't proceed with this call
|
//fundamental error, can't proceed with this call
|
||||||
handleError("GET", error, route, reject);
|
handleError("GET", error, route);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -534,7 +517,7 @@ export default {
|
|||||||
r = await that.extractBodyEx(r);
|
r = await that.extractBodyEx(r);
|
||||||
return r;
|
return r;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError("POSTATTACHMENT", error, route, reject);
|
handleError("POSTATTACHMENT", error, route);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//---------------
|
//---------------
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ export default {
|
|||||||
//
|
//
|
||||||
required(vm, ref) {
|
required(vm, ref) {
|
||||||
if (vm.formState.loading) {
|
if (vm.formState.loading) {
|
||||||
// console.log("gzform:required rule - bailing due to loading", ref);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -736,8 +735,7 @@ export default {
|
|||||||
setFormState(newState) {
|
setFormState(newState) {
|
||||||
//this returns a promise so any function that needs to wait for this can utilize that
|
//this returns a promise so any function that needs to wait for this can utilize that
|
||||||
// if (newState.valid != null && newState.valid == false) {
|
// if (newState.valid != null && newState.valid == false) {
|
||||||
// console.trace();
|
// console.trace(newState);
|
||||||
// console.log(newState);
|
|
||||||
// // debugger;
|
// // debugger;
|
||||||
// }
|
// }
|
||||||
return Vue.nextTick(function() {
|
return Vue.nextTick(function() {
|
||||||
@@ -758,7 +756,6 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newState.ready != null) {
|
if (newState.ready != null) {
|
||||||
console.log("gzform setting newstate ready to ", newState.ready);
|
|
||||||
newState.vm.formState.ready = newState.ready;
|
newState.vm.formState.ready = newState.ready;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-container fluid>
|
<v-container fluid>
|
||||||
<gz-report-selector ref="reportSelector"></gz-report-selector>
|
<gz-report-selector ref="reportSelector"></gz-report-selector>
|
||||||
{{ formState }}
|
|
||||||
{{ obj }}
|
|
||||||
<h2 class="red--text">
|
<h2 class="red--text">
|
||||||
todo: revisit after add customer, ho, vendor to support usertypes
|
todo: revisit after add customer, ho, vendor to support usertypes
|
||||||
customer,headoffice,contractor
|
customer,headoffice,contractor
|
||||||
@@ -239,7 +237,6 @@ const FORM_CUSTOM_TEMPLATE_KEY = "User";
|
|||||||
export default {
|
export default {
|
||||||
async created() {
|
async created() {
|
||||||
//created is called when the route is updated to show a new record even though we don't need to re-init again
|
//created is called when the route is updated to show a new record even though we don't need to re-init again
|
||||||
|
|
||||||
let vm = this;
|
let vm = this;
|
||||||
try {
|
try {
|
||||||
await initForm(vm);
|
await initForm(vm);
|
||||||
@@ -254,16 +251,18 @@ export default {
|
|||||||
if (this.$route.params.obj) {
|
if (this.$route.params.obj) {
|
||||||
//yes, no need to fetch it
|
//yes, no need to fetch it
|
||||||
this.obj = this.$route.params.obj;
|
this.obj = this.$route.params.obj;
|
||||||
|
vm.formState.loading = false; //here we handle it immediately
|
||||||
} else {
|
} else {
|
||||||
vm.getDataFromApi(vm.$route.params.recordid);
|
vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vm.formState.loading = false; //here we handle it immediately
|
||||||
}
|
}
|
||||||
//set initial form status
|
//set initial form status
|
||||||
window.$gz.form.setFormState({
|
window.$gz.form.setFormState({
|
||||||
vm: vm,
|
vm: vm,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
valid: true,
|
valid: true
|
||||||
loading: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
generateMenu(vm);
|
generateMenu(vm);
|
||||||
@@ -387,10 +386,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async getDataFromApi(recordId) {
|
async getDataFromApi(recordId) {
|
||||||
let vm = this;
|
let vm = this;
|
||||||
window.$gz.form.setFormState({
|
vm.formState.loading = true;
|
||||||
vm: vm,
|
|
||||||
loading: true
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!recordId) {
|
if (!recordId) {
|
||||||
throw FORM_KEY + "::getDataFromApi -> Missing recordID!";
|
throw FORM_KEY + "::getDataFromApi -> Missing recordID!";
|
||||||
@@ -414,6 +410,9 @@ export default {
|
|||||||
window.$gz.form.setErrorBoxErrors(vm);
|
window.$gz.form.setErrorBoxErrors(vm);
|
||||||
} else {
|
} else {
|
||||||
vm.obj = res.data;
|
vm.obj = res.data;
|
||||||
|
//modify the menu as necessary
|
||||||
|
generateMenu(vm);
|
||||||
|
|
||||||
//Update the form status
|
//Update the form status
|
||||||
window.$gz.form.setFormState({
|
window.$gz.form.setFormState({
|
||||||
vm: vm,
|
vm: vm,
|
||||||
@@ -421,17 +420,11 @@ export default {
|
|||||||
valid: true,
|
valid: true,
|
||||||
loading: false
|
loading: false
|
||||||
});
|
});
|
||||||
|
|
||||||
//modify the menu as necessary
|
|
||||||
generateMenu(vm);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//Update the form status
|
|
||||||
window.$gz.form.setFormState({
|
|
||||||
vm: vm,
|
|
||||||
loading: false
|
|
||||||
});
|
|
||||||
window.$gz.errorHandler.handleFormError(error, vm);
|
window.$gz.errorHandler.handleFormError(error, vm);
|
||||||
|
} finally {
|
||||||
|
vm.formState.loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async submit() {
|
async submit() {
|
||||||
@@ -441,10 +434,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
window.$gz.form.setFormState({
|
vm.formState.loading = true;
|
||||||
vm: vm,
|
|
||||||
loading: true
|
|
||||||
});
|
|
||||||
let url = API_BASE_URL;
|
let url = API_BASE_URL;
|
||||||
//clear any errors vm might be around from previous submit
|
//clear any errors vm might be around from previous submit
|
||||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||||
@@ -469,16 +459,14 @@ export default {
|
|||||||
if (res.data.id) {
|
if (res.data.id) {
|
||||||
//POST - whole new object returned
|
//POST - whole new object returned
|
||||||
vm.obj = res.data;
|
vm.obj = res.data;
|
||||||
//change url to new record in history
|
//Change URL to new record
|
||||||
//NOTE: will not cause a page re-render, almost nothing does unless forced with a KEY property or using router.GO()
|
//NOTE: will not cause a page re-render, almost nothing does unless forced with a KEY property or using router.GO()
|
||||||
//but will trigger navigation guard beforeRouteUpdate which we use here in this form to fetch data freshly so need a flag to prevent redundant fetch of record
|
|
||||||
|
|
||||||
// vm.$router.replace(vm.$route.fullPath.slice(0, -1) + res.data.id);
|
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
name: "adm-user",
|
name: "adm-user",
|
||||||
params: {
|
params: {
|
||||||
recordid: res.data.id,
|
recordid: res.data.id,
|
||||||
obj: res.data // Hidden data/state
|
obj: res.data //Pass data object to new form
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -497,14 +485,7 @@ export default {
|
|||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
window.$gz.errorHandler.handleFormError(ex, vm);
|
window.$gz.errorHandler.handleFormError(ex, vm);
|
||||||
} finally {
|
} finally {
|
||||||
vm.formState.ready = true;
|
|
||||||
vm.formState.loading = false;
|
vm.formState.loading = false;
|
||||||
|
|
||||||
// window.$gz.form.setFormState({
|
|
||||||
// vm: vm,
|
|
||||||
// loading: false,
|
|
||||||
// ready: true
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async remove() {
|
async remove() {
|
||||||
@@ -516,10 +497,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//do the delete
|
//do the delete
|
||||||
window.$gz.form.setFormState({
|
vm.formState.loading = true;
|
||||||
vm: vm,
|
|
||||||
loading: true
|
|
||||||
});
|
|
||||||
//No need to delete a new record, just abandon it...
|
//No need to delete a new record, just abandon it...
|
||||||
if (vm.$route.params.recordid == 0) {
|
if (vm.$route.params.recordid == 0) {
|
||||||
//this should not get offered for delete but to be safe and clear just in case:
|
//this should not get offered for delete but to be safe and clear just in case:
|
||||||
@@ -545,11 +523,7 @@ export default {
|
|||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
window.$gz.errorHandler.handleFormError(ex, vm);
|
window.$gz.errorHandler.handleFormError(ex, vm);
|
||||||
} finally {
|
} finally {
|
||||||
window.$gz.form.setFormState({
|
vm.formState.loading = false;
|
||||||
vm: vm,
|
|
||||||
loading: false,
|
|
||||||
ready: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async duplicate() {
|
async duplicate() {
|
||||||
@@ -557,36 +531,29 @@ export default {
|
|||||||
if (!vm.canDuplicate || vm.$route.params.recordid == 0) {
|
if (!vm.canDuplicate || vm.$route.params.recordid == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.$gz.form.setFormState({
|
vm.formState.loading = true;
|
||||||
vm: vm,
|
|
||||||
loading: true
|
|
||||||
});
|
|
||||||
let url = API_BASE_URL + "duplicate/" + vm.$route.params.recordid;
|
let url = API_BASE_URL + "duplicate/" + vm.$route.params.recordid;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||||
let res = await window.$gz.api.upsert(url);
|
let res = await window.$gz.api.upsert(url);
|
||||||
vm.formState.loading = false;
|
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
vm.formState.serverError = res.error;
|
vm.formState.serverError = res.error;
|
||||||
window.$gz.form.setErrorBoxErrors(vm);
|
window.$gz.form.setErrorBoxErrors(vm);
|
||||||
} else {
|
} else {
|
||||||
//Navigate to new record
|
//Navigate to new record
|
||||||
vm.$router.push(
|
this.$router.push({
|
||||||
window.$gz.api.replaceAfterLastSlash(
|
name: "adm-user",
|
||||||
vm.$route.fullPath,
|
params: {
|
||||||
res.data.id
|
recordid: res.data.id,
|
||||||
)
|
obj: res.data // pass data object to new form
|
||||||
);
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
window.$gz.errorHandler.handleFormError(ex, vm);
|
window.$gz.errorHandler.handleFormError(ex, vm);
|
||||||
} finally {
|
} finally {
|
||||||
window.$gz.form.setFormState({
|
vm.formState.loading = false;
|
||||||
vm: vm,
|
|
||||||
loading: false,
|
|
||||||
ready: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -718,7 +685,7 @@ function generateMenu(vm) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.rights.change) {
|
if (vm.rights.change && vm.$route.params.recordid != 0) {
|
||||||
menuOptions.menuItems.push({
|
menuOptions.menuItems.push({
|
||||||
title: vm.$ay.t("Duplicate"),
|
title: vm.$ay.t("Duplicate"),
|
||||||
icon: "fa-clone",
|
icon: "fa-clone",
|
||||||
|
|||||||
@@ -273,37 +273,33 @@ export default {
|
|||||||
vm.rights = window.$gz.role.getRights(window.$gz.type.Widget);
|
vm.rights = window.$gz.role.getRights(window.$gz.type.Widget);
|
||||||
vm.formState.readOnly = !vm.rights.change;
|
vm.formState.readOnly = !vm.rights.change;
|
||||||
window.$gz.eventBus.$on("menu-click", clickHandler);
|
window.$gz.eventBus.$on("menu-click", clickHandler);
|
||||||
|
|
||||||
//id 0 means create a new record don't load one
|
//id 0 means create a new record don't load one
|
||||||
if (vm.$route.params.recordid != 0) {
|
if (vm.$route.params.recordid != 0) {
|
||||||
vm.getDataFromApi(vm.$route.params.recordid);
|
//is there already an obj from a prior operation?
|
||||||
|
if (this.$route.params.obj) {
|
||||||
|
//yes, no need to fetch it
|
||||||
|
this.obj = this.$route.params.obj;
|
||||||
|
vm.formState.loading = false; //here we handle it immediately
|
||||||
} else {
|
} else {
|
||||||
//setup for new record
|
vm.getDataFromApi(vm.$route.params.recordid); //let getdata handle loading
|
||||||
//Update the form status
|
}
|
||||||
|
} else {
|
||||||
|
vm.formState.loading = false; //here we handle it immediately
|
||||||
|
}
|
||||||
window.$gz.form.setFormState({
|
window.$gz.form.setFormState({
|
||||||
vm: vm,
|
vm: vm,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
valid: true,
|
valid: true
|
||||||
loading: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
generateMenu(vm);
|
generateMenu(vm);
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
window.$gz.errorHandler.handleFormError(error, vm);
|
window.$gz.errorHandler.handleFormError(error, vm);
|
||||||
} finally {
|
} finally {
|
||||||
vm.formState.ready = true;
|
vm.formState.ready = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeRouteUpdate(to, from, next) {
|
|
||||||
//This triggers a fetch of the data when the ID value changes on the route
|
|
||||||
//which happens on duplicate, submit new record and change of active record id (backward nav/forward nav etc)
|
|
||||||
if (to.params.recordid != 0) {
|
|
||||||
this.getDataFromApi(to.params.recordid);
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
// react to route changes...
|
|
||||||
// don't forget to call next()
|
|
||||||
},
|
|
||||||
async beforeRouteLeave(to, from, next) {
|
async beforeRouteLeave(to, from, next) {
|
||||||
if (!this.formState.dirty || JUST_DELETED) {
|
if (!this.formState.dirty || JUST_DELETED) {
|
||||||
next();
|
next();
|
||||||
@@ -442,6 +438,8 @@ export default {
|
|||||||
window.$gz.form.setErrorBoxErrors(vm);
|
window.$gz.form.setErrorBoxErrors(vm);
|
||||||
} else {
|
} else {
|
||||||
vm.obj = res.data;
|
vm.obj = res.data;
|
||||||
|
//modify the menu as necessary
|
||||||
|
generateMenu(vm);
|
||||||
//Update the form status
|
//Update the form status
|
||||||
window.$gz.form.setFormState({
|
window.$gz.form.setFormState({
|
||||||
vm: vm,
|
vm: vm,
|
||||||
@@ -449,55 +447,61 @@ export default {
|
|||||||
valid: true,
|
valid: true,
|
||||||
loading: false
|
loading: false
|
||||||
});
|
});
|
||||||
|
|
||||||
//modify the menu as necessary
|
|
||||||
generateMenu(vm);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//Update the form status
|
|
||||||
window.$gz.form.setFormState({
|
|
||||||
vm: vm,
|
|
||||||
loading: false
|
|
||||||
});
|
|
||||||
window.$gz.errorHandler.handleFormError(error, vm);
|
window.$gz.errorHandler.handleFormError(error, vm);
|
||||||
|
} finally {
|
||||||
|
vm.formState.loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async submit() {
|
async submit() {
|
||||||
let vm = this;
|
let vm = this;
|
||||||
if (vm.canSave) {
|
if (vm.canSave == false) {
|
||||||
vm.formState.loading = true;
|
return;
|
||||||
let url = API_BASE_URL; // + vm.$route.params.recordid;
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
vm.formState.loading = true;
|
||||||
|
let url = API_BASE_URL; // + vm.$route.params.recordid;
|
||||||
//clear any errors vm might be around from previous submit
|
//clear any errors vm might be around from previous submit
|
||||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||||
|
|
||||||
let res = await window.$gz.api.upsert(url, vm.obj);
|
let res = await window.$gz.api.upsert(url, vm.obj);
|
||||||
vm.formState.loading = false;
|
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
vm.formState.serverError = res.error;
|
vm.formState.serverError = res.error;
|
||||||
window.$gz.form.setErrorBoxErrors(vm);
|
window.$gz.form.setErrorBoxErrors(vm);
|
||||||
} else {
|
} else {
|
||||||
//Logic for detecting if a post or put: if id then it was a post, if no id then it was a put
|
//Logic for detecting if a post or put: if id then it was a post, if no id then it was a put
|
||||||
if (res.data.id) {
|
if (res.data.id) {
|
||||||
//Handle "post" of new record (CREATE)
|
//POST - whole new object returned
|
||||||
|
vm.obj = res.data;
|
||||||
//change url to new record in history
|
//Change URL to new record
|
||||||
//NOTE: will not cause a page re-render, almost nothing does unless forced with a KEY property or using router.GO()
|
//NOTE: will not cause a page re-render, almost nothing does unless forced with a KEY property or using router.GO()
|
||||||
//but will trigger navigation guard beforeRouteUpdate which we use here in this form to fetch data freshly
|
|
||||||
vm.$router.replace(vm.$route.fullPath.slice(0, -1) + res.data.id);
|
this.$router.push({
|
||||||
|
name: "widget-edit",
|
||||||
|
params: {
|
||||||
|
recordid: res.data.id,
|
||||||
|
obj: res.data // Pass data object to new form
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
|
//PUT - only concurrency token is returned (**warning, if server changes object other fields then this needs to act more like POST above but is more efficient this way**)
|
||||||
//Handle "put" of an existing record (UPDATE)
|
//Handle "put" of an existing record (UPDATE)
|
||||||
vm.obj.concurrency = res.data.concurrency;
|
vm.obj.concurrency = res.data.concurrency;
|
||||||
|
}
|
||||||
|
//Update the form status
|
||||||
window.$gz.form.setFormState({
|
window.$gz.form.setFormState({
|
||||||
vm: vm,
|
vm: vm,
|
||||||
dirty: false
|
dirty: false,
|
||||||
|
valid: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
} catch (ex) {
|
||||||
} catch (error) {
|
window.$gz.errorHandler.handleFormError(ex, vm);
|
||||||
|
} finally {
|
||||||
vm.formState.loading = false;
|
vm.formState.loading = false;
|
||||||
window.$gz.errorHandler.handleFormError(error, vm);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async remove() {
|
async remove() {
|
||||||
@@ -552,22 +556,23 @@ export default {
|
|||||||
try {
|
try {
|
||||||
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
window.$gz.form.deleteAllErrorBoxErrors(vm);
|
||||||
let res = await window.$gz.api.upsert(url);
|
let res = await window.$gz.api.upsert(url);
|
||||||
vm.formState.loading = false;
|
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
vm.formState.serverError = res.error;
|
vm.formState.serverError = res.error;
|
||||||
window.$gz.form.setErrorBoxErrors(vm);
|
window.$gz.form.setErrorBoxErrors(vm);
|
||||||
} else {
|
} else {
|
||||||
//Navigate to new record
|
//Navigate to new record
|
||||||
vm.$router.push(
|
this.$router.push({
|
||||||
window.$gz.api.replaceAfterLastSlash(
|
name: "widget-edit",
|
||||||
vm.$route.fullPath,
|
params: {
|
||||||
res.data.id
|
recordid: res.data.id,
|
||||||
)
|
obj: res.data // Pass data object to new form
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
});
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
window.$gz.errorHandler.handleFormError(ex, vm);
|
||||||
|
} finally {
|
||||||
vm.formState.loading = false;
|
vm.formState.loading = false;
|
||||||
window.$gz.errorHandler.handleFormError(error, vm);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user