From dbc0971b99f044abdea529e7e1639e2c002c5d73 Mon Sep 17 00:00:00 2001 From: Guillaume Lajarige Date: Fri, 6 Apr 2018 10:06:03 +0000 Subject: [PATCH] Advanced search: Widget refactoring to use _computeTitle method. SVN:trunk[5625] --- js/search/search_form_criteria.js | 40 ++++--------------- .../search_form_criteria_date_abstract.js | 4 +- js/search/search_form_criteria_enum.js | 36 ++++++++--------- js/search/search_form_criteria_numeric.js | 10 +---- js/search/search_form_criteria_raw.js | 5 ++- 5 files changed, 30 insertions(+), 65 deletions(-) diff --git a/js/search/search_form_criteria.js b/js/search/search_form_criteria.js index 127d37552..99bb8c3db 100644 --- a/js/search/search_form_criteria.js +++ b/js/search/search_form_criteria.js @@ -480,47 +480,23 @@ $(function() me[sCallback]($(this), me.options.values); }); }, - // - compture the title element + // - Compute the title string _computeTitle: function(sTitle) { if(sTitle === undefined) { var sValueAsText = this._getValuesAsText(); - var sOperator = this.operators[this.options.operator].code; + var sOperator = (sValueAsText !== '') ? this.operators[this.options.operator].code : 'Any'; + var sDictEntry = 'UI:Search:Criteria:Title:' + this._toCamelCase(this.options.field.widget) + ':' + this._toCamelCase(sOperator); - if ('' == sValueAsText) + // Fallback to default widget dict entry if none exists for the current widget + if(Dict.S(sDictEntry) === sDictEntry) { - var sDictEntry = 'UI:Search:Criteria:Title:' + this._toCamelCase(this.options.field.widget) + ':Any'+ ':' + this._toCamelCase(sOperator); - var sTitle = Dict.Format(sDictEntry, this.options.field.label); - if(sTitle === sDictEntry) - { - var sDictEntry = 'UI:Search:Criteria:Title:Default:Any'+ ':' + this._toCamelCase(sOperator); - var sTitle = Dict.Format(sDictEntry, this.options.field.label); - } - - if(sTitle === sDictEntry) - { - var sDictEntry = 'UI:Search:Criteria:Title:' + this._toCamelCase(this.options.field.widget) + ':Any'; - var sTitle = Dict.Format(sDictEntry, this.options.field.label); - } - - if(sTitle === sDictEntry) - { - var sTitle = Dict.Format('UI:Search:Criteria:Title:Default:Any', this.options.field.label); - } - } - else - { - var sDictEntry = 'UI:Search:Criteria:Title:' + this._toCamelCase(this.options.field.widget) + ':' + this._toCamelCase(sOperator); - var sTitle = Dict.Format(sDictEntry, this.options.field.label, sValueAsText); - // Fallback to default widget dict entry if none exists for the current widget - if(sTitle === sDictEntry) - { - sDictEntry = 'UI:Search:Criteria:Title:Default:' + this._toCamelCase(sOperator); - sTitle = Dict.Format(sDictEntry, this.options.field.label, sValueAsText); - } + sDictEntry = 'UI:Search:Criteria:Title:Default:' + this._toCamelCase(sOperator); } + sTitle = Dict.Format(sDictEntry, this.options.field.label, this._getValuesAsText()); + // Last chande fallback if(sTitle === sDictEntry) { diff --git a/js/search/search_form_criteria_date_abstract.js b/js/search/search_form_criteria_date_abstract.js index e52399675..b1e84c67a 100644 --- a/js/search/search_form_criteria_date_abstract.js +++ b/js/search/search_form_criteria_date_abstract.js @@ -294,8 +294,7 @@ $(function() //------------------ // Inherited methods //------------------ - - _setTitle: function(sTitle) + _computeTitle: function(sTitle) { var me = this; if (sTitle === undefined && me.options.operator == 'between_dates') @@ -334,7 +333,6 @@ $(function() sTitle = Dict.Format(sDictEntry, this.options.field.label, this._getValuesAsText()); } - } return me._super(sTitle); diff --git a/js/search/search_form_criteria_enum.js b/js/search/search_form_criteria_enum.js index d29abe4d1..401b7b9bc 100644 --- a/js/search/search_form_criteria_enum.js +++ b/js/search/search_form_criteria_enum.js @@ -120,7 +120,7 @@ $(function() var sTogglerId = 'toggle_' + sOpId; var oTogglerElem = $('
') .addClass('sfc_opc_mc_toggler') - .append('') + .append('') .appendTo(oOpContentElem); // - Filter @@ -177,7 +177,7 @@ $(function() oTogglerElem.on('click', function(oEvent){ // Check / uncheck all allowed values var bChecked = $(this).closest('.sfc_opc_mc_toggler').find('input:checkbox').prop('checked'); - oOpContentElem.find('.sfc_opc_mc_item input:checkbox').prop('checked', bChecked); + oOpContentElem.find('.sfc_opc_mc_item:visible input:checkbox').prop('checked', bChecked); // Apply criteria //me._apply(); @@ -191,7 +191,6 @@ $(function() { this._prepareInOperatorWithoutAutocomplete(oOpElem, sOpIdx, oOp); } - }, _prepareInOperatorWithoutAutocomplete: function(oOpElem, sOpIdx, oOp) { @@ -229,12 +228,12 @@ $(function() oFilterElem.find('input').on('keyup focus', function(oEvent){ // TODO: Move on values with up and down arrow keys; select with space or enter. var sQuery = $(this).val(); - if(sQuery === '') { oOpContentElem.find('.sfc_opc_mc_item').show(); oFilterElem.find('.sff_filter').show(); oFilterElem.find('.sff_reset').hide(); + oFilterElem.find() } else { @@ -255,6 +254,8 @@ $(function() oFilterElem.find('.sff_filter').hide(); oFilterElem.find('.sff_reset').show(); } + + me._updateTogglerLabel(); }); oFilterElem.find('.sff_filter').on('click', function(){ oFilterElem.find('input').trigger('focus'); @@ -362,6 +363,8 @@ $(function() oFilterElem.find('.sff_reset').show(); }, me.options.autocomplete.xhr_throttle); } + + me._updateTogglerLabel(); }); // - Apply on check @@ -411,10 +414,9 @@ $(function() oForeignKeysWidgetCurrent.ShowModalSearchForeignKeys(); }); }, - _setTitle: function(sTitle) + _computeTitle: function(sTitle) { - var iValLimit = 2; - var iStrLenLimit = 30; + var iValLimit = 3; var iValCount = Object.keys(this.options.values).length; var iAllowedValuesCount = Object.keys(this._getPreloadedAllowedValues()).length; @@ -439,19 +441,8 @@ $(function() sTitle = Dict.Format('UI:Search:Criteria:Title:Enum:In:Many', this.options.field.label, aFirstValues.join(', '), (iValCount - iValLimit+1)); } - else - { - sTitle = this._computeTitle(sTitle); - } - if (typeof sTitle == "string" && sTitle.length > iStrLenLimit) - { - sTitle = Dict.Format('UI:Search:Criteria:Title:Enum:In:Many:Shortened', this.options.field.label, iValCount); - } - - - - this._super(sTitle); + return this._super(sTitle); }, // Operators helpers @@ -508,6 +499,13 @@ $(function() return true; }, + _updateTogglerLabel: function() + { + var oTogglerTextElem = this.element.find('.sfc_opc_mc_toggler label span'); + var sFilterVal = this.element.find('.sf_filter input[type="text"]').val(); + + oTogglerTextElem.text( oTogglerTextElem.attr('data-label-' + (sFilterVal === '' ? 'regular' : 'filtered')) ); + }, // Autocomplete helpers diff --git a/js/search/search_form_criteria_numeric.js b/js/search/search_form_criteria_numeric.js index 11b99eb58..364b7a944 100644 --- a/js/search/search_form_criteria_numeric.js +++ b/js/search/search_form_criteria_numeric.js @@ -186,9 +186,7 @@ $(function() //------------------ // Inherited methods //------------------ - - - _setTitle: function(sTitle) + _computeTitle: function(sTitle) { var me = this; if (sTitle === undefined && me.options.operator == 'between') @@ -245,7 +243,6 @@ $(function() return me._super(sTitle); }, - // - Convert values to a standard string _getValuesAsText: function(aRawValues) { @@ -270,9 +267,6 @@ $(function() return me._super(aRawValues); }, - - - // Prepare operator's DOM element // - Base preparation, always called _prepareOperator: function(oOpElem, sOpIdx, oOp) @@ -330,7 +324,5 @@ $(function() .data('oOp', oOp) ; }, - - }); }); diff --git a/js/search/search_form_criteria_raw.js b/js/search/search_form_criteria_raw.js index ca7f27244..9502c5c3f 100644 --- a/js/search/search_form_criteria_raw.js +++ b/js/search/search_form_criteria_raw.js @@ -68,13 +68,14 @@ $(function() { // Overloading function and doing nothing for this special kind of criteria. }, - _setTitle: function(sTitle) + _computeTitle: function(sTitle) { if(sTitle === undefined) { sTitle = this.options.label; } - this._super(sTitle); + + return this._super(sTitle); }, }); });