This commit is contained in:
2019-04-22 21:15:30 +00:00
parent c2f84bd5c4
commit 962522a2c4
2 changed files with 30 additions and 27 deletions

View File

@@ -132,7 +132,8 @@ export default {
owner: keyparts[0], owner: keyparts[0],
key: keyparts[1], key: keyparts[1],
data: menuItem.data, data: menuItem.data,
disabled: menuItem.disabled disabled: menuItem.disabled,
vm: menuItem.vm ? menuItem.vm : null
}; };
} }
//new functions above here //new functions above here

View File

@@ -134,25 +134,24 @@ function clickHandler(menuItem) {
if (!menuItem) { if (!menuItem) {
return; return;
} }
var item = this.$gzmenu.parseMenuItem(menuItem); var m = this.$gzmenu.parseMenuItem(menuItem);
if (item.owner == "inventory-widget-edit" && !item.disabled) { if (m.owner == "inventory-widget-edit" && !m.disabled) {
switch (item.key) { switch (m.key) {
case "save": case "save":
this.submit(); m.vm.submit();
break; break;
case "delete": case "delete":
this.remove(); m.vm.remove();
break; break;
case "duplicate": case "duplicate":
this.duplicate(); m.vm.duplicate();
break; break;
default: default:
alert( alert("inventory-widget-edit.vue::context click: [" + m.key + "]");
"inventory-widget-edit.vue::context click: [" + menuItem.key + "]"
);
} }
} }
} }
export default { export default {
beforeCreate() { beforeCreate() {
//Cache all required lt keys //Cache all required lt keys
@@ -183,13 +182,13 @@ export default {
"WidgetCustom15", "WidgetCustom15",
"WidgetCustom16" "WidgetCustom16"
]; ];
var that = this; var vm = this;
this.$gzlocale this.$gzlocale
.fetch(ltKeysRequired) .fetch(ltKeysRequired)
.then(() => (this.formReady = true)) .then(() => (this.formReady = true))
.catch(err => { .catch(err => {
this.formReady = true; this.formReady = true;
that.$gzHandleFormError(err); vm.$gzHandleFormError(err);
}); });
}, },
created() { created() {
@@ -198,25 +197,28 @@ export default {
icon: "fa-splotch", icon: "fa-splotch",
title: this.$gzlocale.get("Widget"), title: this.$gzlocale.get("Widget"),
helpUrl: "intro/#searching", helpUrl: "intro/#searching",
menuItems: [ menuItems: [
{ {
title: this.$gzlocale.get("Save"), title: this.$gzlocale.get("Save"),
icon: "save", icon: "save",
surface: true, surface: true,
key: "inventory-widget-edit:save", key: "inventory-widget-edit:save",
method: this.submit vm: this
}, },
{ {
title: this.$gzlocale.get("Delete"), title: this.$gzlocale.get("Delete"),
icon: "trash-alt", icon: "trash-alt",
surface: true, surface: true,
key: "inventory-widget-edit:delete" key: "inventory-widget-edit:delete",
vm: this
}, },
{ divider: true, inset: false }, { divider: true, inset: false },
{ {
title: this.$gzlocale.get("Duplicate"), title: this.$gzlocale.get("Duplicate"),
icon: "clone", icon: "clone",
key: "inventory-widget-edit:duplicate" key: "inventory-widget-edit:duplicate",
vm: this
} }
] ]
}); });
@@ -243,50 +245,50 @@ export default {
}, },
getDataFromApi() { getDataFromApi() {
var url = "Widget/" + this.$route.params.id; var url = "Widget/" + this.$route.params.id;
var that = this; var vm = this;
this.$gzv.deleteAllErrorBoxErrors(this); this.$gzv.deleteAllErrorBoxErrors(this);
this.$gzapi this.$gzapi
.get(url) .get(url)
.then(res => { .then(res => {
if (res.error) { if (res.error) {
that.serverError = res.error; vm.serverError = res.error;
that.$gzv.setErrorBoxErrors(that); vm.$gzv.setErrorBoxErrors(vm);
} else { } else {
that.obj = res.data; vm.obj = res.data;
} }
}) })
.catch(function handleGetDataFromAPIError(error) { .catch(function handleGetDataFromAPIError(error) {
that.$gzHandleFormError(error, that); vm.$gzHandleFormError(error, vm);
}); });
}, },
submit() { submit() {
//check if form is valid, as far as I know this is the way you're supposed to do it and in testing it does not force all fields to revalidate individually //check if form is valid, as far as I know this is the way you're supposed to do it and in testing it does not force all fields to revalidate individually
if (this.$refs.form.validate()) { if (this.$refs.form.validate()) {
var that = this; var vm = this;
var url = "Widget/" + this.$route.params.id; var url = "Widget/" + this.$route.params.id;
//clear any errors that might be around from previous submit //clear any errors vm might be around from previous submit
this.$gzv.deleteAllErrorBoxErrors(this); this.$gzv.deleteAllErrorBoxErrors(this);
this.$gzapi this.$gzapi
.upsert(url, this.obj) .upsert(url, this.obj)
.then(res => { .then(res => {
if (res.error) { if (res.error) {
that.serverError = res.error; vm.serverError = res.error;
that.$gzv.setErrorBoxErrors(that); vm.$gzv.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.id) {
//Handle "post" of new record //Handle "post" of new record
that.obj = res.data; vm.obj = res.data;
} else { } else {
//Handle "put" of an existing record //Handle "put" of an existing record
that.obj.concurrencyToken = res.data.concurrencyToken; vm.obj.concurrencyToken = res.data.concurrencyToken;
} }
} }
}) })
.catch(function handleSubmitError(error) { .catch(function handleSubmitError(error) {
that.$gzHandleFormError(error, that); vm.$gzHandleFormError(error, vm);
}); });
} }
}, },