Advanced search: Widget refactoring to use _computeTitle method.

SVN:trunk[5625]
This commit is contained in:
Guillaume Lajarige
2018-04-06 10:06:03 +00:00
parent 26127c8218
commit dbc0971b99
5 changed files with 30 additions and 65 deletions

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -120,7 +120,7 @@ $(function()
var sTogglerId = 'toggle_' + sOpId;
var oTogglerElem = $('<div></div>')
.addClass('sfc_opc_mc_toggler')
.append('<label for="' + sTogglerId + '"><input type="checkbox" id="' + sTogglerId + '" />' + Dict.S('UI:Search:Value:Toggler:CheckAllNone') + '</label>')
.append('<label for="' + sTogglerId + '"><input type="checkbox" id="' + sTogglerId + '" /><span data-label-regular="' + Dict.S('UI:Search:Value:Toggler:CheckAllNone') + '" data-label-filtered="' + Dict.S('UI:Search:Value:Toggler:CheckAllNoneFiltered') + '">' + Dict.S('UI:Search:Value:Toggler:CheckAllNone') + '</span></label>')
.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

View File

@@ -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)
;
},
});
});

View File

@@ -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);
},
});
});