diff --git a/ayanova/src/api/gzmenu.js b/ayanova/src/api/gzmenu.js index 8a951897..442309bb 100644 --- a/ayanova/src/api/gzmenu.js +++ b/ayanova/src/api/gzmenu.js @@ -132,7 +132,8 @@ export default { owner: keyparts[0], key: keyparts[1], data: menuItem.data, - disabled: menuItem.disabled + disabled: menuItem.disabled, + vm: menuItem.vm ? menuItem.vm : null }; } //new functions above here diff --git a/ayanova/src/views/inventory-widget-edit.vue b/ayanova/src/views/inventory-widget-edit.vue index ab28c426..5db3f7c4 100644 --- a/ayanova/src/views/inventory-widget-edit.vue +++ b/ayanova/src/views/inventory-widget-edit.vue @@ -134,25 +134,24 @@ function clickHandler(menuItem) { if (!menuItem) { return; } - var item = this.$gzmenu.parseMenuItem(menuItem); - if (item.owner == "inventory-widget-edit" && !item.disabled) { - switch (item.key) { + var m = this.$gzmenu.parseMenuItem(menuItem); + if (m.owner == "inventory-widget-edit" && !m.disabled) { + switch (m.key) { case "save": - this.submit(); + m.vm.submit(); break; case "delete": - this.remove(); + m.vm.remove(); break; case "duplicate": - this.duplicate(); + m.vm.duplicate(); break; default: - alert( - "inventory-widget-edit.vue::context click: [" + menuItem.key + "]" - ); + alert("inventory-widget-edit.vue::context click: [" + m.key + "]"); } } } + export default { beforeCreate() { //Cache all required lt keys @@ -183,13 +182,13 @@ export default { "WidgetCustom15", "WidgetCustom16" ]; - var that = this; + var vm = this; this.$gzlocale .fetch(ltKeysRequired) .then(() => (this.formReady = true)) .catch(err => { this.formReady = true; - that.$gzHandleFormError(err); + vm.$gzHandleFormError(err); }); }, created() { @@ -198,25 +197,28 @@ export default { icon: "fa-splotch", title: this.$gzlocale.get("Widget"), helpUrl: "intro/#searching", + menuItems: [ { title: this.$gzlocale.get("Save"), icon: "save", surface: true, key: "inventory-widget-edit:save", - method: this.submit + vm: this }, { title: this.$gzlocale.get("Delete"), icon: "trash-alt", surface: true, - key: "inventory-widget-edit:delete" + key: "inventory-widget-edit:delete", + vm: this }, { divider: true, inset: false }, { title: this.$gzlocale.get("Duplicate"), icon: "clone", - key: "inventory-widget-edit:duplicate" + key: "inventory-widget-edit:duplicate", + vm: this } ] }); @@ -243,50 +245,50 @@ export default { }, getDataFromApi() { var url = "Widget/" + this.$route.params.id; - var that = this; + var vm = this; this.$gzv.deleteAllErrorBoxErrors(this); this.$gzapi .get(url) .then(res => { if (res.error) { - that.serverError = res.error; - that.$gzv.setErrorBoxErrors(that); + vm.serverError = res.error; + vm.$gzv.setErrorBoxErrors(vm); } else { - that.obj = res.data; + vm.obj = res.data; } }) .catch(function handleGetDataFromAPIError(error) { - that.$gzHandleFormError(error, that); + vm.$gzHandleFormError(error, vm); }); }, 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 if (this.$refs.form.validate()) { - var that = this; + var vm = this; 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.$gzapi .upsert(url, this.obj) .then(res => { if (res.error) { - that.serverError = res.error; - that.$gzv.setErrorBoxErrors(that); + vm.serverError = res.error; + vm.$gzv.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) { //Handle "post" of new record - that.obj = res.data; + vm.obj = res.data; } else { //Handle "put" of an existing record - that.obj.concurrencyToken = res.data.concurrencyToken; + vm.obj.concurrencyToken = res.data.concurrencyToken; } } }) .catch(function handleSubmitError(error) { - that.$gzHandleFormError(error, that); + vm.$gzHandleFormError(error, vm); }); } },