This commit is contained in:
2019-06-06 18:15:18 +00:00
parent 629b93295e
commit f894c012b5
3 changed files with 36 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
/* Xeslint-disable */
import _ from "../libs/lodash.min.js";
import store from "../store";
import router from "../router";
import auth from "./auth";
@@ -284,9 +285,15 @@ export default {
//determine if this is a new or existing record
var fetchOptions = undefined;
if (data.concurrencyToken) {
//has concurrency token, so this is a PUT as it's updating an existing record
fetchOptions = that.fetchPutOptions(data);
} else {
//Does not have a concurrency token so this is a POST as it's posting a new record without a concurrency token
fetchOptions = that.fetchPostOptions(data);
//ensure the route doesn't end in /0 which will happen if it's a new record since the edit forms just send the url here with the ID regardless
if (_.endsWith(route, "/0")) {
route = route.slice(0, -2);
}
}
fetch(that.APIUrl(route), fetchOptions)
.then(that.status)

View File

@@ -86,7 +86,7 @@ export default function initialize() {
api
.get("UserOptions/" + store.state.userId)
.then(res => {
if (res.error) {
if (res.error != undefined) {
//In a form this would trigger a bunch of validation or error display code but for here and now:
//convert error to human readable string for display and popup a notification to user
var msg = api.apiErrorToHumanString(res.error);

View File

@@ -137,7 +137,6 @@
></v-text-field>
</v-flex>
</v-layout>
<!-- <v-layout align-left justify-center row wrap mt-5>
<v-flex xs6 sm4>
READY: {{ formState.ready }}
@@ -158,7 +157,7 @@
</template>
<script>
/* xeslint-disable */
/* eslint-disable */
/////////////////////////////
//
@@ -192,6 +191,9 @@ function clickHandler(menuItem) {
//
//
function generateMenu(vm) {
// console.log("Generating menu");
// console.log("GENERATE MENU: Rights currently are:");
// console.log(vm.rights);
var menuOptions = {
isMain: false,
icon: "fa-splotch",
@@ -237,6 +239,8 @@ var JUST_DELETED = false;
export default {
beforeCreate() {
//console.log("BEFORECREATE: TOP");
//Cache all required lt keys
var ltKeysRequired = [
"Widget",
@@ -270,7 +274,8 @@ export default {
.fetch(ltKeysRequired)
.then(() => {
//don't have access to local data object until here
vm.rights = this.$gzrole.getRights(this, this.$gztype.Widget);
// vm.rights = this.$gzrole.getRights(this, this.$gztype.Widget);
// console.log("BEFORECREATE: setting rights");
vm.formState.ready = true;
})
.catch(err => {
@@ -279,13 +284,21 @@ export default {
});
},
created() {
// console.log("CREATED: TOP");
// console.log("CREATED: setting rights");
this.rights = this.$gzrole.getRights(this, this.$gztype.Widget);
this.$gzevent.$on("menu-click", clickHandler);
//id 0 means create a new record don't load one
if (this.$route.params.id != 0) {
this.getDataFromApi();
} else {
// console.log("CREATED: setting up for new record");
// console.log("CREATED: Rights are:");
// console.log(this.rights);
//setup for new record
var readOnly = this.rights.change;
var readOnly = !this.rights.change;
//Update the form status
this.$gzform.setFormState({
vm: this,
@@ -295,6 +308,8 @@ export default {
readOnly: readOnly
});
// console.log("CREATED: Read only is: " + readOnly);
// console.log("CREATED:formstate is: " + this.formState);
//it's a new record so it can't be deleted so...
this.rights.delete = false;
@@ -378,7 +393,7 @@ export default {
this.$gzapi
.get(url)
.then(res => {
if (res.error) {
if (res.error != undefined) {
//Not found?
if (res.error.code == "2010") {
//notify not found error then navigate backwards
@@ -423,17 +438,17 @@ export default {
//clear any errors vm might be around from previous submit
this.$gzform.deleteAllErrorBoxErrors(this);
this.$gzapi
.upsert(url, this.obj)
.then(res => {
this.formState.loading = false;
if (res.error) {
debugger;
vm.formState.loading = false;
if (res.error != undefined) {
vm.formState.serverError = res.error;
vm.$gzform.setErrorBoxErrors(vm);
} else {
//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.id) {
if (res.data.id) {
//Handle "post" of new record (CREATE)
//wouldn't this be cleaner if it just opened the new record directly since the url still has zero in the id field??
vm.obj = res.data;
@@ -442,6 +457,9 @@ export default {
dirty: false,
readOnly: res.readOnly ? true : false
});
//change url to new record but don't actually navigate, replace current url with same url but with the actual id at the end instead of zero:
vm.$router.replace(vm.$route.fullPath.slice(0, -1) + res.data.id);
} else {
//Handle "put" of an existing record (UPDATE)
vm.obj.concurrencyToken = res.data.concurrencyToken;
@@ -471,7 +489,7 @@ export default {
vm.$gzapi
.remove(url)
.then(res => {
if (res.error) {
if (res.error != undefined) {
vm.formState.serverError = res.error;
vm.$gzform.setErrorBoxErrors(vm);
} else {