details: https://code.openbravo.com/erp/devel/pi/rev/7bf022753248 changeset: 28619:7bf022753248 user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Fri Feb 19 10:44:55 2016 +0100 summary: fixes issue 32193: Fix selection in P&E grids having filter on change disabled
Having filter on change disabled, the filtering is not performed until enter is pressed or the focus is moved out of the text filter. In this second case, there could be problems if the focus is lost when checking a pick and edit grid record: the filtering request is performed and at the same time the actions related to the record selection are fired. This can cause the selection actions not work as expected. This problem also affects to numeric and date filters, because they always perform the filtering after losing the focus. To avoid this problem a new mechanism has been included for pick and edit grids, the blur method for the filter elements is overridden to prevent the selection immediately after losing the focus. diffstat: modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js | 2 + modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js | 2 + modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-text.js | 2 + modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js | 104 ++++++++++ 4 files changed, 110 insertions(+), 0 deletions(-) diffs (171 lines): diff -r 429009e5662e -r 7bf022753248 modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js Fri Feb 19 08:52:30 2016 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js Fri Feb 19 10:44:55 2016 +0100 @@ -389,6 +389,8 @@ singleDateMode: false, singleDateValue: null, singleDateDisplayValue: null, + // In P&E grids, on blur will be overridden to ensure correct record selection having filter on change disabled + canOverrideOnBlur: true, init: function () { this.addAutoChild('rangeDialog', { diff -r 429009e5662e -r 7bf022753248 modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js Fri Feb 19 08:52:30 2016 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js Fri Feb 19 10:44:55 2016 +0100 @@ -536,6 +536,8 @@ doBlurLogic: false, operator: 'equals', validOperators: ['equals', 'lessThan', 'greaterThan', 'notEqual', 'lessThan', 'lessOrEqual', 'greaterOrEqual', 'between', 'betweenInclusive', 'isNull', 'isNotNull', 'equalsField', 'notEqualField', 'greaterThanField', 'lessThanField', 'greaterOrEqualField', 'lessOrEqualField'], + // In P&E grids, on blur will be overridden to ensure correct record selection having filter on change disabled + canOverrideOnBlur: true, // prevent handling of equal symbol in filteritem keyDownAction: function (item, form, keyName) { diff -r 429009e5662e -r 7bf022753248 modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-text.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-text.js Fri Feb 19 08:52:30 2016 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-text.js Fri Feb 19 10:44:55 2016 +0100 @@ -125,6 +125,8 @@ isc.OBTextFilterItem.addProperties({ allowExpressions: true, validateAgainstMask: false, + // In P&E grids, on blur will be overridden to ensure correct record selection having filter on change disabled + canOverrideOnBlur: true, init: function () { var field = this.grid.getField(this.name); diff -r 429009e5662e -r 7bf022753248 modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js Fri Feb 19 08:52:30 2016 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js Fri Feb 19 10:44:55 2016 +0100 @@ -38,6 +38,7 @@ autoSaveEdits: false, selectionAppearance: 'checkbox', + canSelectOnFilterBlur: true, autoFitFieldWidths: true, autoFitWidthApproach: 'title', canAutoFitFields: false, @@ -221,6 +222,11 @@ OB.TestRegistry.register('org.openbravo.client.application.ParameterWindow_Grid_' + this.parameterName + '_' + this.contentView.view.processId, this); }, + draw: function () { + this.Super('draw', arguments); + this.overrideFilterItemOnBlur(); + }, + redraw: function () { var ret = this.Super('redraw', arguments); if (this.autoFitFieldWidths && this.view && this.view.isExpandedRecord && !this.isExpandedRecordAutoFitRedrawAlreadyAplied) { @@ -235,6 +241,103 @@ return ret; }, + overrideFilterItemOnBlur: function () { + var i, filterFields, filterItem, me = this, + updatedBlur; + if (me.filterEditor && me.filterEditor.getEditForm()) { + updatedBlur = function () { + var field = this.grid.getField(this.name), + pickAndEditGrid = field.grid; + if (this.actOnKeypress === false && pickAndEditGrid) { + if (pickAndEditGrid.isFieldCriterionChanged(this.name)) { + // Prevent selection until the filtering request is completed + pickAndEditGrid.canSelectOnFilterBlur = false; + } else { + // Filter content has not changed, not necessary to perform filtering on blur + return; + } + } + this.originalBlur(); + }; + filterFields = me.filterEditor.getEditForm().getItems() || []; + for (i = 0; i < filterFields.length; i++) { + filterItem = filterFields[i]; + if (filterItem.canOverrideOnBlur && !filterItem.originalBlur) { + filterItem.originalBlur = filterItem.blur; + filterItem.blur = updatedBlur; + } + } + } + }, + + isFieldCriterionChanged: function (fieldName) { + var gridCriteria, currentGridCriteria = [], + fieldCriterion, currentFieldCriterion, values = [], + valuesAsCriteria; + // Get field criterion currently applied into the grid + gridCriteria = this.getGridCriteria(); + fieldCriterion = gridCriteria.find('fieldName', fieldName); + // Get field criterion currently present into the filter + if (this.getFilterEditor() && this.getFilterEditor().getEditForm()) { + values = this.getFilterEditor().getEditForm().getValues() || []; + if (!fieldCriterion && values[fieldName]) { + // criteria is changing from empty to some value + // handle special case: not formatted dates are not present in the criteria + return true; + } + valuesAsCriteria = this.getFilterEditor().getEditForm().getValuesAsCriteria(); + if (valuesAsCriteria) { + currentGridCriteria = valuesAsCriteria.criteria || []; + } + } + currentFieldCriterion = currentGridCriteria.find('fieldName', fieldName); + if (this.isSameCriterion(fieldCriterion, currentFieldCriterion)) { + return false; + } + return true; + }, + + getGridCriteria: function () { + var crit; + if (!this.getCriteria()) { + return []; + } + crit = this.getCriteria().criteria || []; + // remove criteria for selected records + crit.removeList(crit.findAll('fieldName', 'id')); + if (crit[0] && crit[0].criteria) { + return crit[0].criteria; + } + return crit; + }, + + isSameCriterion: function (criterion1, criterion2) { + var value1 = '', + value2 = '', + operator1, operator2; + if (criterion1) { + value1 = criterion1.value || value1; + operator1 = criterion1.operator; + } + if (criterion2) { + value2 = criterion2.value || value2; + operator2 = criterion2.operator; + } + return value1.toString() === value2.toString() && operator1 === operator2; + }, + + canSelectRecords: function () { + return this.isDataLoaded() && this.canSelectOnFilterBlur; + }, + + selectOnMouseDown: function (record, rowNum, colNum) { + // If filter on change is disabled, the selection of records is prevented until the request fired after on blur is completed + if (!this.canSelectRecords()) { + return; + } + this.Super('selectOnMouseDown', arguments); + }, + evaluateDisplayLogicForGridColumns: function () { var currentValues = (this.contentView.view.theForm && this.contentView.view.theForm.getValues()) || {}, contextInfo = this.view.getUnderLyingRecordContext(false, true, true, true), @@ -507,6 +610,7 @@ }, handleFilterEditorSubmit: function (criteria, context) { + this.canSelectOnFilterBlur = true; var crit = this.addSelectedIDsToCriteria(criteria); this.Super('handleFilterEditorSubmit', [crit, context]); ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits