diff --git a/ayanova/src/views/ay-data-list-view.vue b/ayanova/src/views/ay-data-list-view.vue index 135bddaf..4eb1de5a 100644 --- a/ayanova/src/views/ay-data-list-view.vue +++ b/ayanova/src/views/ay-data-list-view.vue @@ -52,12 +52,12 @@ - @@ -495,14 +496,16 @@ export default { }, data() { return { - obj: [], //working copy driving UI - objName: "", - objPublic: true, + obj: { editView: [], name: "", public: true }, + listViewId: undefined, dataListKey: undefined, formKey: undefined, fieldDefinitions: [], effectiveListView: undefined, + editedListView: undefined, + editedName: "", + editedPublic: true, concurrencyToken: undefined, pickLists: { dateFilterOperators: [], @@ -543,12 +546,10 @@ export default { return window.$gz.enums.getPickList(enumKey); }, includeChanged: function(item) { - //Note: stock items can't be changed so no need to take that into account if (item.required && item.visible == false) { item.required = false; } - this.formState.dirty = true; - enableSaveButton(); + updateEditedListView(this); }, toggleSort: function(item) { if (item.sort == null) { @@ -562,9 +563,10 @@ export default { if (item.sort) { item.include = true; } + updateEditedListView(this); }, move: function(direction, index) { - var totalItems = this.obj.length; + var totalItems = this.obj.editView.length; var newIndex = 0; //calculate new index switch (direction) { @@ -589,7 +591,12 @@ export default { break; } - this.obj.splice(newIndex, 0, this.obj.splice(index, 1)[0]); + this.obj.editView.splice( + newIndex, + 0, + this.obj.editView.splice(index, 1)[0] + ); + updateEditedListView(this); }, addFilterCondition(item) { var filterItem = { op: null, value: null, display: null }; @@ -705,12 +712,14 @@ export default { //add only if not already in the collection (accidental double click) if (!window.$gz._.find(item.filter.items, filterItem)) { item.filter.items.push(filterItem); + updateEditedListView(this); } return; } }, removeFilterCondition(item, index) { item.filter.items.splice(index, 1); + updateEditedListView(this); }, form() { return window.$gz.form; @@ -721,84 +730,78 @@ export default { } }, submit() { - var vm = this; - var url = API_BASE_URL + this.formCustomTemplateKey; - - //clear any errors vm might be around from previous submit - window.$gz.form.deleteAllErrorBoxErrors(this); - - //Create template data object here.... - //Note that server expects to see a string array of json template, not actual json - var newObj = { - formKey: this.formCustomTemplateKey, - concurrencyToken: this.concurrencyToken, - template: "[]" - }; - //temporary array to hold template for later stringification - var temp = []; - //Rules: - for (var i = 0; i < this.obj.length; i++) { - var fldItem = this.obj[i]; - if (fldItem.custom == false) { - //Process regular stock field - //If it's *not* set to stockRequired (i.e. built in field with biz rules that can't be hidden or changed) - // and it's also set to hidden or required then it's template-worthy - if ( - !fldItem.stockRequired && - (fldItem.visible == false || fldItem.required == true) - ) { - temp.push({ - fld: fldItem.key, - required: fldItem.required, - hide: !fldItem.visible - }); - } - } else { - //Process custom field - //If it's not visible then don't add it at all - if (fldItem.visible == true) { - temp.push({ - fld: fldItem.key, - required: fldItem.required, - type: fldItem.type - }); - } - } - } - - //now set the template as a json string - newObj.template = JSON.stringify(temp); - - window.$gz.api - .upsert(url, newObj) - .then(res => { - vm.formState.loading = false; - if (res.error != undefined) { - vm.formState.serverError = res.error; - window.$gz.form.setErrorBoxErrors(vm); - } else { - //Handle "put" of an existing record (UPDATE) (there is no POST of a new record for this particular object) - - //Set store values for template and token - window.$gz.formCustomTemplate.set( - vm.formCustomTemplateKey, - res.data.concurrencyToken, - newObj.template - ); - //set our local concurrency token value - vm.concurrencyToken = res.data.concurrencyToken; - - //form is now clean - window.$gz.form.setFormState({ - vm: vm, - dirty: false - }); - } - }) - .catch(function handleSubmitError(error) { - vm.formState.loading = false; - window.$gz.errorHandler.handleFormError(error, vm); - }); + // var vm = this; + // var url = API_BASE_URL + this.formCustomTemplateKey; + // //clear any errors vm might be around from previous submit + // window.$gz.form.deleteAllErrorBoxErrors(this); + // //Create template data object here.... + // //Note that server expects to see a string array of json template, not actual json + // var newObj = { + // formKey: this.formCustomTemplateKey, + // concurrencyToken: this.concurrencyToken, + // template: "[]" + // }; + // //temporary array to hold template for later stringification + // var temp = []; + // //Rules: + // for (var i = 0; i < this.obj.length; i++) { + // var fldItem = this.obj[i]; + // if (fldItem.custom == false) { + // //Process regular stock field + // //If it's *not* set to stockRequired (i.e. built in field with biz rules that can't be hidden or changed) + // // and it's also set to hidden or required then it's template-worthy + // if ( + // !fldItem.stockRequired && + // (fldItem.visible == false || fldItem.required == true) + // ) { + // temp.push({ + // fld: fldItem.key, + // required: fldItem.required, + // hide: !fldItem.visible + // }); + // } + // } else { + // //Process custom field + // //If it's not visible then don't add it at all + // if (fldItem.visible == true) { + // temp.push({ + // fld: fldItem.key, + // required: fldItem.required, + // type: fldItem.type + // }); + // } + // } + // } + // //now set the template as a json string + // newObj.template = JSON.stringify(temp); + // window.$gz.api + // .upsert(url, newObj) + // .then(res => { + // vm.formState.loading = false; + // if (res.error != undefined) { + // vm.formState.serverError = res.error; + // window.$gz.form.setErrorBoxErrors(vm); + // } else { + // //Handle "put" of an existing record (UPDATE) (there is no POST of a new record for this particular object) + // //Set store values for template and token + // window.$gz.formCustomTemplate.set( + // vm.formCustomTemplateKey, + // res.data.concurrencyToken, + // newObj.template + // ); + // //set our local concurrency token value + // vm.concurrencyToken = res.data.concurrencyToken; + // //form is now clean + // window.$gz.form.setFormState({ + // vm: vm, + // dirty: false + // }); + // } + // }) + // .catch(function handleSubmitError(error) { + // vm.formState.loading = false; + // window.$gz.errorHandler.handleFormError(error, vm); + // }); } } }; @@ -1143,7 +1146,7 @@ function setEffectiveListView(vm) { - If listviewid is zero then that's starting with the default list view so need to fetch it and then init the form - If listviewid is -1 then that's starting with an unsaved listview so get that from the saved form store - If listviewid is greater than 0 then it's a saved listview and there sb a cached version of it but ideally maybe fetch it from -objPublic, objName + */ if (vm.listViewId == null) { @@ -1155,7 +1158,7 @@ objPublic, objName if (vm.listViewId == -1) { if (formSettings.saved.dataTable.editedListView != null) { vm.effectiveListView = formSettings.saved.dataTable.editedListView; - vm.objName = vm.lt("FilterUnsaved"); + vm.obj.name = vm.lt("FilterUnsaved"); return Promise.resolve(); } } else if (vm.listViewId == 0) { @@ -1168,7 +1171,7 @@ objPublic, objName throw res.error; } else { vm.effectiveListView = JSON.parse(res.data); - vm.objName = vm.lt("FilterUnsaved"); + vm.obj.name = vm.lt("FilterUnsaved"); } }); } else { @@ -1178,8 +1181,8 @@ objPublic, objName throw res.error; } else { vm.effectiveListView = JSON.parse(res.data.listView); - vm.objPublic = res.data.public; - vm.objName = res.data.name; + vm.obj.public = res.data.public; + vm.obj.name = res.data.name; } }); } @@ -1260,10 +1263,10 @@ function initDataObject(vm) { ret.push(o); } } - vm.obj = ret; + vm.obj.editView = ret; if (window.$gz.errorHandler.devMode) { - if (vm.obj.length != vm.fieldDefinitions.length - 1) { + if (vm.obj.editView.length != vm.fieldDefinitions.length - 1) { throw "ay-data-list-view::initDataObject - working array length not equal to total field definition length"; } } @@ -1293,6 +1296,20 @@ function fetchEnums(vm) { return Promise.resolve(); } +////////////////////////////////////////////////////////// +// +// Convert working object to actual listView +// +function updateEditedListView(vm) { + //turn the obj.editView settings into an actual listview + //compare it with the effectiveListView to see if there are any changes between the two + //set the form to dirty if there are changes and can save + //this.formState.dirty = true; + // enableSaveButton(); + //this way user can build their way back to the same view and then no need to save if no changes + //build an array of all enums then execute method +} + /* public const string OpEquality = "="; public const string OpGreaterThan = ">";