diff --git a/css/light-grey.css b/css/light-grey.css index 115b541c3..69c432ddf 100644 --- a/css/light-grey.css +++ b/css/light-grey.css @@ -849,10 +849,10 @@ div.HRDrawer { margin: 0px; margin-right: 7px; } -.search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_contains .sfc_op_name, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_starts_with .sfc_op_name, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_ends_with .sfc_op_name { +.search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_equals .sfc_op_name, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_contains .sfc_op_name, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_starts_with .sfc_op_name, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_ends_with .sfc_op_name { width: 90px; } -.search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_contains .sfc_op_content input, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_starts_with .sfc_op_content input, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_ends_with .sfc_op_content input { +.search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_equals .sfc_op_content input, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_contains .sfc_op_content input, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_starts_with .sfc_op_content input, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_operators .sfc_fg_operator.sfc_fg_operator_ends_with .sfc_op_content input { width: 130px; } .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_apply, .search_form_handler .sf_criterion_area .search_form_criteria .sfc_form_group.opened .sfc_fg_cancel { diff --git a/css/light-grey.scss b/css/light-grey.scss index 6d222cc82..95572abb5 100644 --- a/css/light-grey.scss +++ b/css/light-grey.scss @@ -937,6 +937,7 @@ div.HRDrawer { } /* Common operators for most criteria types processing*/ + &.sfc_fg_operator_equals, &.sfc_fg_operator_contains, &.sfc_fg_operator_starts_with, &.sfc_fg_operator_ends_with{ diff --git a/js/search/search_form_criteria.js b/js/search/search_form_criteria.js index 355306dd4..7c8eac777 100644 --- a/js/search/search_form_criteria.js +++ b/js/search/search_form_criteria.js @@ -155,6 +155,35 @@ $(function() } }); }, + _apply: function() + { + this._trace('TODO: Apply button (call selected operator callback)'); + // Find active operator + var oActiveOpElem = this.element.find('.sfc_op_radio:checked').closest('.sfc_fg_operator'); + if(oActiveOpElem.length === 0) + { + this._trace('Could not apply new value as there seems to be no active operator.'); + return false; + } + + // Get value from operator (polymorphic method) + var sCallback = '_get' + this._toCamelCase(oActiveOpElem.attr('data-operator-code')) + 'OperatorValues'; + if(this[sCallback] === undefined) + { + this._trace('Callback ' + sCallback + ' is undefined, using _getOperatorValues instead.'); + sCallback = '_getOperatorValues'; + } + var aValues = this[sCallback](oActiveOpElem); + + // Update widget + this.options.operator = oActiveOpElem.find('.sfc_op_radio').val(); + this.options.values = aValues; + // TODO: Update title + this._setTitle(); + + // Trigger event to handler + this.handler.triggerHandler('itop.search.criteria.value_changed'); + }, _remove: function() { this.element.remove(); @@ -166,8 +195,7 @@ $(function() // - Internal events _onButtonApply: function() { - this._trace('TODO: Apply button (call selected operator callback)'); - this.handler.triggerHandler('itop.search.criteria.value_changed'); + this._apply(); }, _onButtonCancel: function() { @@ -318,7 +346,7 @@ $(function() // - Return a HTML template for operators _getOperatorTemplate: function() { - return '
'; + return '
'; }, // Operators helpers @@ -328,17 +356,15 @@ $(function() // Set radio oOpElem.find('.sfc_op_radio').val(sOpIdx); + oOpElem.find('.sfc_op_radio').attr('id', sInputId); // Set label oOpElem.find('.sfc_op_name').text(oOp.label); oOpElem.find('> label').attr('for', sInputId); - // Set value - oOpElem.find('.sfc_op_radio').val(oOpElem.id); - oOpElem.find('.sfc_op_radio').attr('id', sInputId); - // Set helper classes - oOpElem.addClass('sfc_fg_operator_' + oOp.code); + oOpElem.addClass('sfc_fg_operator_' + oOp.code) + .attr('data-operator-code', oOp.code); // Bind events // - Check radio button on click @@ -369,6 +395,19 @@ $(function() { // Do nothing as only the label is necessary }, + // - Fallback for operators without a specific callback + _getOperatorValues: function(oOpElem) + { + var aValues = []; + + oOpElem.find('.sfc_op_content input').each(function(){ + var sValue = $(this).val(); + aValues.push({value: sValue, label: sValue}); + }); + + return aValues; + }, + // Values helpers // - Convert values to a standard string