From 435a3a36a2c4050bf3cb42b07f331365e91004c5 Mon Sep 17 00:00:00 2001 From: Philipp Tessenow Date: Wed, 23 Mar 2011 14:41:00 +0100 Subject: [PATCH] filter.js - let activate_dependents() optionally accept the select-box to handle and a callback-function which is passed to narrow values --- assets/javascripts/reporting/filters.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index aa655e44aa..c54176dc6e 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -234,11 +234,19 @@ Reporting.Filters = { // Activate the first dependent of the changed filter, if it is not already active. // Afterwards, collect the visible filters from the dependents list and start // narrowing down their values. - activate_dependents: function () { - var dependents = Reporting.Filters.get_dependents(this); - var active_filters = Reporting.Filters.visible_filters(); + // Param: select [optional] - the select-box of the filter which should activate it's dependents + activate_dependents: function (selectBox, callbackWhenFinished) { + var dependents, active_filters, source; + if (selectBox === undefined || selectBox.type == 'change') { + selectBox = this; + } + if (callbackWhenFinished === undefined) { + callbackWhenFinished = function() {}; + } + dependents = Reporting.Filters.get_dependents(selectBox); + active_filters = Reporting.Filters.visible_filters(); if (!active_filters.include(dependents.first())) { - Reporting.Filters.show_filter(dependents.first(), { slowly: true, insert_after: $(this.up(".filter")) }); + Reporting.Filters.show_filter(dependents.first(), { slowly: true, insert_after: $(selectBox.up(".filter")) }); // render filter inactive if possible to avoid unintended filtering $(dependents.first() + '_arg_1_val').value = '<>' Reporting.Filters.operator_changed(dependents.first(), $('operators[' + dependents.first() + ']')); @@ -248,12 +256,12 @@ Reporting.Filters = { // Remove border of dependent, so it "merges" with the filter before active_filters.unshift(dependents.first()); } - var source = this.getAttribute("data-filter-name"); + source = selectBox.getAttribute("data-filter-name"); setTimeout(function () { // Make sure the newly shown filters are in the DOM var active_dependents = dependents.select(function (d) { return active_filters.include(d); }); - Reporting.Filters.narrow_values([source], active_dependents); + Reporting.Filters.narrow_values([source], active_dependents, callbackWhenFinished); }, 1); },