This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
/* Xeslint-disable */
|
/* Xeslint-disable */
|
||||||
|
import _ from "../libs/lodash.min.js";
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
import router from "../router";
|
import router from "../router";
|
||||||
import auth from "./auth";
|
import auth from "./auth";
|
||||||
@@ -284,9 +285,15 @@ export default {
|
|||||||
//determine if this is a new or existing record
|
//determine if this is a new or existing record
|
||||||
var fetchOptions = undefined;
|
var fetchOptions = undefined;
|
||||||
if (data.concurrencyToken) {
|
if (data.concurrencyToken) {
|
||||||
|
//has concurrency token, so this is a PUT as it's updating an existing record
|
||||||
fetchOptions = that.fetchPutOptions(data);
|
fetchOptions = that.fetchPutOptions(data);
|
||||||
} else {
|
} 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);
|
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)
|
fetch(that.APIUrl(route), fetchOptions)
|
||||||
.then(that.status)
|
.then(that.status)
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export default function initialize() {
|
|||||||
api
|
api
|
||||||
.get("UserOptions/" + store.state.userId)
|
.get("UserOptions/" + store.state.userId)
|
||||||
.then(res => {
|
.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:
|
//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
|
//convert error to human readable string for display and popup a notification to user
|
||||||
var msg = api.apiErrorToHumanString(res.error);
|
var msg = api.apiErrorToHumanString(res.error);
|
||||||
|
|||||||
@@ -137,7 +137,6 @@
|
|||||||
></v-text-field>
|
></v-text-field>
|
||||||
</v-flex>
|
</v-flex>
|
||||||
</v-layout>
|
</v-layout>
|
||||||
|
|
||||||
<!-- <v-layout align-left justify-center row wrap mt-5>
|
<!-- <v-layout align-left justify-center row wrap mt-5>
|
||||||
<v-flex xs6 sm4>
|
<v-flex xs6 sm4>
|
||||||
READY: {{ formState.ready }}
|
READY: {{ formState.ready }}
|
||||||
@@ -158,7 +157,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
/* xeslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -192,6 +191,9 @@ function clickHandler(menuItem) {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
function generateMenu(vm) {
|
function generateMenu(vm) {
|
||||||
|
// console.log("Generating menu");
|
||||||
|
// console.log("GENERATE MENU: Rights currently are:");
|
||||||
|
// console.log(vm.rights);
|
||||||
var menuOptions = {
|
var menuOptions = {
|
||||||
isMain: false,
|
isMain: false,
|
||||||
icon: "fa-splotch",
|
icon: "fa-splotch",
|
||||||
@@ -237,6 +239,8 @@ var JUST_DELETED = false;
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
beforeCreate() {
|
beforeCreate() {
|
||||||
|
//console.log("BEFORECREATE: TOP");
|
||||||
|
|
||||||
//Cache all required lt keys
|
//Cache all required lt keys
|
||||||
var ltKeysRequired = [
|
var ltKeysRequired = [
|
||||||
"Widget",
|
"Widget",
|
||||||
@@ -270,7 +274,8 @@ export default {
|
|||||||
.fetch(ltKeysRequired)
|
.fetch(ltKeysRequired)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
//don't have access to local data object until here
|
//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;
|
vm.formState.ready = true;
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
@@ -279,13 +284,21 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
created() {
|
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);
|
this.$gzevent.$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 (this.$route.params.id != 0) {
|
if (this.$route.params.id != 0) {
|
||||||
this.getDataFromApi();
|
this.getDataFromApi();
|
||||||
} else {
|
} else {
|
||||||
|
// console.log("CREATED: setting up for new record");
|
||||||
|
// console.log("CREATED: Rights are:");
|
||||||
|
// console.log(this.rights);
|
||||||
|
|
||||||
//setup for new record
|
//setup for new record
|
||||||
var readOnly = this.rights.change;
|
var readOnly = !this.rights.change;
|
||||||
//Update the form status
|
//Update the form status
|
||||||
this.$gzform.setFormState({
|
this.$gzform.setFormState({
|
||||||
vm: this,
|
vm: this,
|
||||||
@@ -295,6 +308,8 @@ export default {
|
|||||||
readOnly: readOnly
|
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...
|
//it's a new record so it can't be deleted so...
|
||||||
this.rights.delete = false;
|
this.rights.delete = false;
|
||||||
|
|
||||||
@@ -378,7 +393,7 @@ export default {
|
|||||||
this.$gzapi
|
this.$gzapi
|
||||||
.get(url)
|
.get(url)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.error) {
|
if (res.error != undefined) {
|
||||||
//Not found?
|
//Not found?
|
||||||
if (res.error.code == "2010") {
|
if (res.error.code == "2010") {
|
||||||
//notify not found error then navigate backwards
|
//notify not found error then navigate backwards
|
||||||
@@ -423,17 +438,17 @@ export default {
|
|||||||
|
|
||||||
//clear any errors vm might be around from previous submit
|
//clear any errors vm might be around from previous submit
|
||||||
this.$gzform.deleteAllErrorBoxErrors(this);
|
this.$gzform.deleteAllErrorBoxErrors(this);
|
||||||
|
|
||||||
this.$gzapi
|
this.$gzapi
|
||||||
.upsert(url, this.obj)
|
.upsert(url, this.obj)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.formState.loading = false;
|
debugger;
|
||||||
if (res.error) {
|
vm.formState.loading = false;
|
||||||
|
if (res.error != undefined) {
|
||||||
vm.formState.serverError = res.error;
|
vm.formState.serverError = res.error;
|
||||||
vm.$gzform.setErrorBoxErrors(vm);
|
vm.$gzform.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.id) {
|
if (res.data.id) {
|
||||||
//Handle "post" of new record (CREATE)
|
//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??
|
//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;
|
vm.obj = res.data;
|
||||||
@@ -442,6 +457,9 @@ export default {
|
|||||||
dirty: false,
|
dirty: false,
|
||||||
readOnly: res.readOnly ? true : 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 {
|
} else {
|
||||||
//Handle "put" of an existing record (UPDATE)
|
//Handle "put" of an existing record (UPDATE)
|
||||||
vm.obj.concurrencyToken = res.data.concurrencyToken;
|
vm.obj.concurrencyToken = res.data.concurrencyToken;
|
||||||
@@ -471,7 +489,7 @@ export default {
|
|||||||
vm.$gzapi
|
vm.$gzapi
|
||||||
.remove(url)
|
.remove(url)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.error) {
|
if (res.error != undefined) {
|
||||||
vm.formState.serverError = res.error;
|
vm.formState.serverError = res.error;
|
||||||
vm.$gzform.setErrorBoxErrors(vm);
|
vm.$gzform.setErrorBoxErrors(vm);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user