From dd545b90ff33ca934fc7ce3d68a4f0029e72a7dc Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 26 Nov 2019 20:39:20 +0000 Subject: [PATCH] --- .../src/components/custom-fields-control.vue | 139 +++++++++--------- 1 file changed, 70 insertions(+), 69 deletions(-) diff --git a/ayanova/src/components/custom-fields-control.vue b/ayanova/src/components/custom-fields-control.vue index b70fde23..d292b150 100644 --- a/ayanova/src/components/custom-fields-control.vue +++ b/ayanova/src/components/custom-fields-control.vue @@ -150,6 +150,76 @@ export default { readOnly: Boolean, parentVM: Object }, + + methods: { + lt: function(ltkey) { + return window.$gz.locale.get(ltkey); + }, + ltFormat() { + return window.$gz.locale.format(); + }, + form() { + //nothing + return window.$gz.form; + }, + onChange(ref) { + if ( + !this.parentVM.formState.loading && + !this.parentVM.formState.readOnly + ) { + window.$gz.form.onChange(this.parentVM, ref); + } + }, + GetValueForField: function(dataKey) { + if (!this.value) { + return null; + } + //debugger; + //get the data out of the JSON string value + var cData = JSON.parse(this.value); + + //get the type it *should* be + //TODO: method here + + //coerce it to that type and return it + //TODO: Method here + + return cData[dataKey]; + }, + SetValueForField: function(dataKey, newValue) { + //https://stackoverflow.com/questions/39868963/vue-2-mutating-props-vue-warn + + //Is this a new or empty custom fields object? + if (this.value === null || this.value === undefined) { + this.value = "{}"; //empty json fragment, field will be added later below + } + + //Get the current data out of the json string value + // + var cData = JSON.parse(this.value); + if (!window.$gz._.has(cData, dataKey)) { + cData[dataKey] = null; + } + + //handle null or undefined + if (newValue === null || newValue === undefined) { + cData[dataKey] = null; + } else { + //then set item in the cData + + //TODO: This will likely need also to be converted because dates and stuff + //initial naive attempt: (tostring is suspect) + cData[dataKey] = newValue.toString(); + } + + //emit the new data so it syncs with the parent source + var ret = JSON.stringify(cData); + this.$emit("update:value", ret); + //this triggers the onchange routine in the parent form + //mainly for custom fields purposes so that the dirty checking works + this.$emit("change", ret); + } + }, computed: { c1: { get: function() { @@ -280,75 +350,6 @@ export default { } } }, - methods: { - lt: function(ltkey) { - return window.$gz.locale.get(ltkey); - }, - ltFormat() { - return window.$gz.locale.format(); - }, - form() { - //nothing - return window.$gz.form; - }, - onChange(ref) { - if ( - !this.parentVM.formState.loading && - !this.parentVM.formState.readOnly - ) { - window.$gz.form.onChange(this.parentVM, ref); - } - }, - GetValueForField: function(dataKey) { - if (!this.value) { - return null; - } - //debugger; - //get the data out of the JSON string value - var cData = JSON.parse(this.value); - - //get the type it *should* be - //TODO: method here - - //coerce it to that type and return it - //TODO: Method here - - return cData[dataKey]; - }, - SetValueForField: function(dataKey, newValue) { - //https://stackoverflow.com/questions/39868963/vue-2-mutating-props-vue-warn - - //Is this a new or empty custom fields object? - if (this.value === null || this.value === undefined) { - this.value = "{}"; //empty json fragment, field will be added later below - } - - //Get the current data out of the json string value - // - var cData = JSON.parse(this.value); - if (!window.$gz._.has(cData, dataKey)) { - cData[dataKey] = null; - } - - //handle null or undefined - if (newValue === null || newValue === undefined) { - cData[dataKey] = null; - } else { - //then set item in the cData - - //TODO: This will likely need also to be converted because dates and stuff - //initial naive attempt: (tostring is suspect) - cData[dataKey] = newValue.toString(); - } - - //emit the new data so it syncs with the parent source - var ret = JSON.stringify(cData); - this.$emit("update:value", ret); - //this triggers the onchange routine in the parent form - //mainly for custom fields purposes so that the dirty checking works - this.$emit("change", ret); - } - }, beforeCreate() { //check pre-requisites exist just in case if (window.$gz.errorHandler.devMode()) {