From 23f0d154395cfcfdd73cd1107f7edbd1a6d5547b Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Thu, 24 Feb 2011 15:14:59 +0100 Subject: [PATCH] attach to filters with dependents. the controller action is basically what it should be, the missing link is the Reporting.Filters.narrow_values function, where we have to call the controller action, give it the dependency from which it is called and the dependent name on which it should return values. the controller will (as already implemented) return the list of available values as json, so the JS then has to update the selectbox --- assets/javascripts/reporting/filters.js | 12 ++++++++++++ lib/report/controller.rb | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index 3cb86059bb..bdffd082d0 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -142,6 +142,10 @@ Reporting.Filters = { Reporting.Filters.visible_filters().each(function (filter) { Reporting.Filters.remove_filter(filter); }); + }, + + narrow_values: function (dependent_name) { + console.log("Narrowing values not implemented"); } }; @@ -172,4 +176,12 @@ Reporting.onload(function () { }).size(); s.multiple = (selected_size > 1); }); + $$('.filters-select[data-dependent]').each(function (dependency) { + dependency.observe("change", function () { + var dependent_name = this.getAttribute("data-dependent"); + $("add_filter_select").select("option[value='" + dependent_name + "']").first().selected = true; + Reporting.Filters.add_filter($("add_filter_select")); + Reporting.Filters.narrow_values(dependent_name); + }); + }); }); diff --git a/lib/report/controller.rb b/lib/report/controller.rb index 9159fd3dc2..9c7a726136 100644 --- a/lib/report/controller.rb +++ b/lib/report/controller.rb @@ -100,6 +100,22 @@ module Report::Controller end end + ## + # Determine the available values for the specified filter and return them as + # json + def values + dependency = params[:dependency].to_sym + dependent = params[:dependent] + + query = CostQuery.new + query.filter(dependency, + :operator => params[:operators][dependency], + :values => params[:values][dependency]) + query.column(dependent) + values = query.result.collect {|r| r.fields[dependent] } + render :text => values.to_json + end + ## # Determine the requested engine by constantizing from the :engine parameter # Sets @report_engine and @title based on that, and makes the engine available