From 90f56ad7c039f7b0761e4cfff014933a25b0c337 Mon Sep 17 00:00:00 2001 From: Philipp Tessenow Date: Wed, 23 Mar 2011 14:42:05 +0100 Subject: [PATCH] extract selecting-values-of-a-select-box-functionality from narrow_values to a separate function --- assets/javascripts/reporting/filters.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index c54176dc6e..27db2278fe 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -265,6 +265,18 @@ Reporting.Filters = { }, 1); }, + // Select the given values of the selectBox. + // Toggle multi-select state of the selectBox depending on how many values were given. + select_values: function(selectBox, values_to_select) { + Reporting.Filters.multi_select(selectBox, values_to_select.size() > 1); + values_to_select.each(function (val) { + var opt = selectBox.select("option[value='" + val + "']"); + if (opt.size() === 1) { + opt.first().selected = true; + } + }); + }, + // Narrow down the available values for the [dependents] of [sources]. // This will narrow down for each dependent separately, adding each finished // dependent to the sources array and removing it from the dependents array. @@ -308,12 +320,7 @@ Reporting.Filters = { // cannot use .innerhtml due to IE wierdness $(selectBox).insert(new Element('option', {value: value}).update(value.escapeHTML())); }); - selected.each(function (val) { - var opt = selectBox.select("option[value='" + val + "']"); - if (opt.size() === 1) { - opt.first().selected = true; - } - }); + Reporting.Filters.select_values(selectBox, selected); sources.push(currentDependent); // Add as last element dependents.splice(0, 1); // Delete first element // if we got no values besides the <> value, do not show this selectBox