From bfe43c4936b729af182f379f657ef214a1354861 Mon Sep 17 00:00:00 2001 From: jwollert Date: Wed, 7 Sep 2011 15:41:40 +0200 Subject: [PATCH 01/14] don't swallow errors in Controller#available_values --- lib/report/controller.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/report/controller.rb b/lib/report/controller.rb index 0da1a08eb0..d920f10fa6 100644 --- a/lib/report/controller.rb +++ b/lib/report/controller.rb @@ -340,15 +340,12 @@ module Report::Controller # renders option tags for each available value for a single filter def available_values if name = params[:filter_name] - begin - f_cls = report_engine::Filter.const_get(name.to_s.camelcase) - filter = f_cls.new.tap do |f| - f.values = JSON.parse(params[:values].gsub("'", '"')) if params[:values].present? and params[:values] - end - render_widget Widget::Filters::Option, filter, :to => canvas = "" - render :text => canvas, :layout => !request.xhr? - rescue NameError + f_cls = report_engine::Filter.const_get(name.to_s.camelcase) + filter = f_cls.new.tap do |f| + f.values = JSON.parse(params[:values].gsub("'", '"')) if params[:values].present? and params[:values] end + render_widget Widget::Filters::Option, filter, :to => canvas = "" + render :text => canvas, :layout => !request.xhr? end end From 47de452ad6465ad359a2ca8fe7c1488b5afd9993 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 9 Sep 2011 19:13:59 +0200 Subject: [PATCH 02/14] in principle working, though a bit too much perhaps --- assets/javascripts/reporting/filters.js | 21 ++++++---- assets/javascripts/reporting/restore_query.js | 39 +++++++++++++++++-- lib/widget/filters/multi_values.rb | 2 +- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index 64cf73e423..dc782804cd 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -8,6 +8,9 @@ Reporting.Filters = { if (select === null || select === undefined) { return; } + if (filter_name == "sector_id") { + console.log("UPDATE SECTOR ID VALUES"); + } url = select.readAttribute("data-remote-url"); json_post_select_values = select.readAttribute('data-initially-selected') if (json_post_select_values !== null && json_post_select_values !== undefined) { @@ -213,10 +216,12 @@ Reporting.Filters = { add_filter: function (select) { var field; field = select.value; - Reporting.Filters.show_filter(field, { slowly: true }); - select.selectedIndex = 0; - Reporting.Filters.select_option_enabled(select, field, false); - Reporting.Filters.activate_dependents($(field + "_arg_1_val")) + Reporting.Filters.show_filter(field, { slowly: true, callback_func: function() { + select.selectedIndex = 0; + Reporting.Filters.select_option_enabled(select, field, false); + Reporting.Filters.activate_dependents($(field + "_arg_1_val")) + } + }); }, select_option_enabled: function (box, value, state) { @@ -333,7 +338,7 @@ Reporting.Filters = { // return an array of all filters that depend on the given filter plus the given filter dependent_for: function(field) { var deps = $$('.filters-select[data-all-dependents]').findAll(function(selectBox) { - return selectBox.up('tr').visible() && Reporting.Filters.get_dependents(selectBox).include(field) + return (selectBox.up('tr').visible()) && Reporting.Filters.get_dependents(selectBox).include(field) }).map(function(selectBox) { return selectBox.getAttribute("data-filter-name"); }); @@ -474,15 +479,15 @@ Reporting.onload(function () { }).size(); s.multiple = (selected_size > 1); s.observe("change", function (evt) { - var filter_name = this.up('tr').getAttribute("data-filter-name"); - Reporting.Filters.value_changed(filter_name); + var filter_name = this.up('tr').getAttribute("data-filter-name"); + Reporting.Filters.value_changed(filter_name); }); }); $$('.filters-select[data-all-dependents]').each(function (dependency) { dependency.observe("change", Reporting.Filters.activate_dependents); }); Reporting.Filters.visible_filters().each(function (filter) { - Reporting.Filters.load_available_values_for_filter(filter, function () {}); + // Reporting.Filters.load_available_values_for_filter(filter, function () {}); }); }); diff --git a/assets/javascripts/reporting/restore_query.js b/assets/javascripts/reporting/restore_query.js index b3a742ac9e..d9845d92d5 100644 --- a/assets/javascripts/reporting/restore_query.js +++ b/assets/javascripts/reporting/restore_query.js @@ -75,10 +75,31 @@ Reporting.RestoreQuery = { // correctly display number of arguments of filters depending on their arity Reporting.Filters.operator_changed(filter_name, $("operators[" + filter_name + "]")); }); - // restore values of dependent filters - Reporting.RestoreQuery.initialize_load_dependent_filters($$('.filters-select[data-all-dependents]').findAll(function(select) { - return select.up('tr').visible() - })); + var deps = $$('.filters-select').partition(function(select) { + return select.readAttribute("data-all-dependents") !== undefined && select.up('tr').visible(); + }); + var dependents = deps[0]; + var independents = deps[1].select(function(select) { + return select.up("tr").visible(); + }); + var semaphore = dependents.length; + dependents.each(function(dep) { + filter_name = dep.up("tr").getAttribute("data-filter-name"); + if (filter_name == "sector_id") { + console.log("[id=" + dep.readAttribute("id") + ", data-filter-name=" + filter_name + "]"); + } + Reporting.Filters.load_available_values_for_filter(filter_name, function () { + semaphore -= 1; + if (semaphore <= 0) { + Reporting.RestoreQuery.initialize_load_dependent_filters(dependents); + } + console.log("loaded available values for " + filter_name); + }); + }); + /*independents.each(function (e) { + filter_name = e.up("tr").getAttribute("data-filter-name"); + Reporting.Filters.load_available_values_for_filter(filter_name, function () {}); + });*/ }, restore_group_bys: function () { @@ -101,4 +122,14 @@ Reporting.RestoreQuery = { Reporting.onload(function () { Reporting.RestoreQuery.restore_group_bys(); Reporting.RestoreQuery.restore_filters(); + }); + + + + + + + + + diff --git a/lib/widget/filters/multi_values.rb b/lib/widget/filters/multi_values.rb index bbf24c8d2e..b7220f535d 100644 --- a/lib/widget/filters/multi_values.rb +++ b/lib/widget/filters/multi_values.rb @@ -25,7 +25,7 @@ class Widget::Filters::MultiValues < Widget::Filters::Base if (filter_class.is_dependent? || @options[:lazy]) && !Array(filter.values).empty? select_options.merge! :"data-initially-selected" => filter.values.to_json.gsub!('"', "'") end - box_content = "" + box_content = "".html_safe box = content_tag :select, select_options do render_widget Widget::Filters::Option, filter, :to => box_content unless @options[:lazy] end From c1611b1c80bc7706092c94794d0653fbe3c88c30 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Tue, 13 Sep 2011 15:02:12 +0200 Subject: [PATCH 03/14] fixed multi_choice filter value restoration --- lib/widget/filters/multi_choice.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widget/filters/multi_choice.rb b/lib/widget/filters/multi_choice.rb index a7864120b2..c73f9b9e9c 100644 --- a/lib/widget/filters/multi_choice.rb +++ b/lib/widget/filters/multi_choice.rb @@ -12,7 +12,7 @@ class Widget::Filters::MultiChoice < Widget::Filters::Base :id => "#{filterName}_radio_option_#{i}", :value => value } - opts[:checked] = "checked" if filter.values == value + opts[:checked] = "checked" if filter.values == [value].flatten radio_button = tag :input, opts content_tag :label, radio_button + translate(label), :for => "#{filterName}_radio_option_#{i}", From 5690b5274e6b27ba867de5bf4c6242eb218ec7ec Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Tue, 13 Sep 2011 15:52:05 +0200 Subject: [PATCH 04/14] Values expected as ["1", "2"], sector_id yields [1, 2] which when combined with that gsub! stuff equals BOOOM! long story short: data-initially-selected now works for sector_id too --- lib/widget/filters/multi_values.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/widget/filters/multi_values.rb b/lib/widget/filters/multi_values.rb index b7220f535d..9f92e5e975 100644 --- a/lib/widget/filters/multi_values.rb +++ b/lib/widget/filters/multi_values.rb @@ -23,7 +23,8 @@ class Widget::Filters::MultiValues < Widget::Filters::Base # store selected value(s) in data-initially-selected if this filter is a dependent # of another filter, as we have to restore values manually in the client js if (filter_class.is_dependent? || @options[:lazy]) && !Array(filter.values).empty? - select_options.merge! :"data-initially-selected" => filter.values.to_json.gsub!('"', "'") + select_options.merge! :"data-initially-selected" => + filter.values.to_json.gsub!('"', "'") || "[" + filter.values.map { |v| "'#{v}'" }.join(',') + "]" end box_content = "".html_safe box = content_tag :select, select_options do From 5b487766ad2bc25cda93aa1944a2e8a4e725f3ca Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Tue, 13 Sep 2011 18:04:55 +0200 Subject: [PATCH 05/14] let the js know when a filter is a dependent one --- lib/widget/filters/multi_values.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/widget/filters/multi_values.rb b/lib/widget/filters/multi_values.rb index 9f92e5e975..6ec8d9865b 100644 --- a/lib/widget/filters/multi_values.rb +++ b/lib/widget/filters/multi_values.rb @@ -26,6 +26,7 @@ class Widget::Filters::MultiValues < Widget::Filters::Base select_options.merge! :"data-initially-selected" => filter.values.to_json.gsub!('"', "'") || "[" + filter.values.map { |v| "'#{v}'" }.join(',') + "]" end + select_options.merge! :"data-dependent" => true if filter_class.is_dependent? box_content = "".html_safe box = content_tag :select, select_options do render_widget Widget::Filters::Option, filter, :to => box_content unless @options[:lazy] From 095dead9575325b3c8170916007ae35063f8cd6c Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 16 Sep 2011 16:51:29 +0200 Subject: [PATCH 06/14] waaaaaah --- assets/javascripts/reporting/filters.js | 67 ++++++++++++------- assets/javascripts/reporting/restore_query.js | 67 ++++++++++++++++--- 2 files changed, 97 insertions(+), 37 deletions(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index dc782804cd..f46ea286b9 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -70,6 +70,9 @@ Reporting.Filters = { if (options.show_filter === undefined) { options.show_filter = true; } + if (options.hide_only === undefined) { + options.hide_only = false; + } var field_el = $('tr_' + field); if (field_el !== null) { if (options.insert_after === undefined) { @@ -77,8 +80,10 @@ Reporting.Filters = { } if (options.insert_after !== undefined && options.show_filter) { // Move the filter down to appear after the last currently visible filter - field_el.remove(); - options.insert_after.insert({after: field_el}); + if (field_el.id !== options.insert_after.id) { + field_el.remove(); + options.insert_after.insert({after: field_el}); + } } // the following command might be included into the callback_function (which is called after the ajax request) later var display_functor; @@ -90,7 +95,9 @@ Reporting.Filters = { Reporting.Filters.set_filter_value_widths(100); } else { (options.slowly ? Effect.Fade : Element.hide)(field_el); - field_el.removeAttribute('data-selected'); + if (!options.hide_only) { // remember that this filter used to be selected + field_el.removeAttribute('data-selected'); + } $('rm_' + field).value = ""; // reset the value, so the serialized form will not return this filter Reporting.Filters.set_filter_value_widths(5000); } @@ -99,6 +106,31 @@ Reporting.Filters = { } }, + /** + * Activates the filter with the given name and loads dependent filters if necessary. + * + * @param filter_name Name of the filter to be activated. + */ + add_filter: function (filter_name) { + var field = filter_name + Reporting.Filters.show_filter(field, { slowly: true, callback_func: function() { + Reporting.Filters.activate_dependents($(field + "_arg_1_val")); + Reporting.Filters.select_option_enabled($("add_filter_select"), filter_name, false); + } + }); + }, + + remove_filter: function (field, hide_only) { + Reporting.Filters.show_filter(field, { show_filter: false, hide_only: hide_only }); + var dependent = Reporting.Filters.get_dependents($(field + '_arg_1_val'), false).find(function(d) { + return Reporting.Filters.visible_filters().include(d); + }); + if (dependent !== undefined) { + Reporting.Filters.remove_filter(dependent); + } + Reporting.Filters.select_option_enabled($("add_filter_select"), field, true); + }, + /* Smoothly sets the width of currently displayed filters. Params: @@ -213,17 +245,6 @@ Reporting.Filters = { } }, - add_filter: function (select) { - var field; - field = select.value; - Reporting.Filters.show_filter(field, { slowly: true, callback_func: function() { - select.selectedIndex = 0; - Reporting.Filters.select_option_enabled(select, field, false); - Reporting.Filters.activate_dependents($(field + "_arg_1_val")) - } - }); - }, - select_option_enabled: function (box, value, state) { var option = box.select("[value='" + value + "']").first(); if (option !== undefined) { @@ -248,17 +269,6 @@ Reporting.Filters = { Reporting.Filters.multi_select(select, !select.multiple); }, - remove_filter: function (field) { - Reporting.Filters.show_filter(field, { show_filter: false }); - var dependent = Reporting.Filters.get_dependents($(field + '_arg_1_val'), false).find(function(d) { - return Reporting.Filters.visible_filters().include(d); - }); - if (dependent !== undefined) { - Reporting.Filters.remove_filter(dependent); - } - Reporting.Filters.select_option_enabled($("add_filter_select"), field, true); - }, - visible_filters: function () { return $("filter_table").select("tr").select(function (tr) { return tr.visible() === true; @@ -405,7 +415,9 @@ Reporting.Filters = { // cannot use .innerhtml due to IE wierdness $(selectBox).insert(new Element('option', {value: value}).update(label.escapeHTML())); }); + 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 @@ -427,9 +439,11 @@ Reporting.Filters = { Reporting.Filters.narrow_values(sources, dependents); } } + callbackWhenFinished(); }, onException: function (response, error) { + console.log(error); Reporting.flash("Loading of filter values failed. Probably, the server is temporary offline for maintenance."); var selectBox = $(currentDependent + "_arg_1_val"); $(selectBox).insert(new Element('option', {value: '<>'}).update('Failed to load values.')); @@ -450,7 +464,8 @@ Reporting.onload(function () { if ($("add_filter_select")) { $("add_filter_select").observe("change", function () { if (!(Reporting.Filters.exists(this.value))) { - Reporting.Filters.add_filter(this); + Reporting.Filters.add_filter(this.value); + this.selectedIndex = 0; }; }); } diff --git a/assets/javascripts/reporting/restore_query.js b/assets/javascripts/reporting/restore_query.js index d9845d92d5..93eae92906 100644 --- a/assets/javascripts/reporting/restore_query.js +++ b/assets/javascripts/reporting/restore_query.js @@ -64,24 +64,70 @@ Reporting.RestoreQuery = { }); }, + restore_dependent_filters: function(selectBox) { + Reporting.Filters.activate_dependents(selectBox, function() { + var sources = Reporting.Filters.get_dependents(selectBox).collect(function(field) { + return $('tr_' + field).select('.filter_values select').first(); + }); + sources.each(function(source) { + if (source.hasAttribute('data-initially-selected')) { + var selected_values = source.readAttribute('data-initially-selected').replace(/'/g, '"').evalJSON(true); + Reporting.Filters.select_values(source, selected_values); + Reporting.Filters.value_changed(source.up('tr').readAttribute("data-filter-name")); + } + }); + if (sources.reject( function (select) { return select.value == '<>' }).size() == 0) { + Reporting.Filters.activate_dependents(selectBox); + } else { + sources.each(function (select) { + Reporting.RestoreQuery.restore_dependent_filters(select); + }); + } + }); + }, + restore_filters: function () { - // FIXME: rm_xxx values for filters have to be set after re-displaying them + console.log("restore filters"); + var deps = $$('.filters-select.filter-value').each(function(select) { + var tr = select.up('tr'); + if (tr.visible()) { + var filter = tr.readAttribute('data-filter-name'); + var dependent = select.readAttribute('data-dependent'); + if (filter && dependent) { + Reporting.Filters.remove_filter(filter, false); + } + } + }); + /*var dependents = deps[0]; + var independents = deps[1].select(function(select) { + return select.up("tr").visible(); + }); + var dependent_filters = deps[0].findAll(function (select) { + return select.getValue() == '<>' || select.select('option[selected]').size()==0 + }); + // Filters which are <> are probably dependents themselfes, so remove and forget them for now. + // This is OK as they get reloaded later + dependent_filters.each(function(select) { + Reporting.Filters.remove_filter(select.up('tr').readAttribute("data-filter-name")); + });*/ $$("tr[data-selected=true]").each(function (e) { - var rm_box, filter_name; + if (e.down(".filter_values select").hasAttribute("data-dependent")) return; + var filter_name = e.getAttribute("data-filter-name"); + console.log("restore: " + filter_name); + Reporting.Filters.add_filter(filter_name); + // Reporting.RestoreQuery.restore_dependent_filters(e.down(".filters-select.filter-value")); + // FIXME: rm_xxx values for filters have to be set after re-displaying them + /*var rm_box, filter_name; rm_box = e.select("input[id^=rm]").first(); filter_name = e.getAttribute("data-filter-name"); rm_box.value = filter_name; Reporting.Filters.select_option_enabled($("add_filter_select"), filter_name, false); // correctly display number of arguments of filters depending on their arity - Reporting.Filters.operator_changed(filter_name, $("operators[" + filter_name + "]")); - }); - var deps = $$('.filters-select').partition(function(select) { - return select.readAttribute("data-all-dependents") !== undefined && select.up('tr').visible(); - }); - var dependents = deps[0]; - var independents = deps[1].select(function(select) { - return select.up("tr").visible(); + Reporting.Filters.operator_changed(filter_name, $("operators[" + filter_name + "]"));*/ }); + + if (true) return; // pull the break + var semaphore = dependents.length; dependents.each(function(dep) { filter_name = dep.up("tr").getAttribute("data-filter-name"); @@ -122,7 +168,6 @@ Reporting.RestoreQuery = { Reporting.onload(function () { Reporting.RestoreQuery.restore_group_bys(); Reporting.RestoreQuery.restore_filters(); - }); From 462768fc6ff6a9bd0b64a0410773da5ae11655c5 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 16 Sep 2011 18:57:37 +0200 Subject: [PATCH 07/14] filter restoration working; there's still a bug though where when adding the sector_id filter the wrong dependent is opened (org unit instead of regional company) --- assets/javascripts/reporting/filters.js | 27 ++-- assets/javascripts/reporting/restore_query.js | 128 +++--------------- 2 files changed, 36 insertions(+), 119 deletions(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index f46ea286b9..b754a42831 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -8,9 +8,6 @@ Reporting.Filters = { if (select === null || select === undefined) { return; } - if (filter_name == "sector_id") { - console.log("UPDATE SECTOR ID VALUES"); - } url = select.readAttribute("data-remote-url"); json_post_select_values = select.readAttribute('data-initially-selected') if (json_post_select_values !== null && json_post_select_values !== undefined) { @@ -111,11 +108,20 @@ Reporting.Filters = { * * @param filter_name Name of the filter to be activated. */ - add_filter: function (filter_name) { + add_filter: function (filter_name, activate_dependent, on_complete) { var field = filter_name + if (activate_dependent === undefined) { + activate_dependent = true; + } + if (on_complete === undefined) { + on_complete = function() { }; + } Reporting.Filters.show_filter(field, { slowly: true, callback_func: function() { - Reporting.Filters.activate_dependents($(field + "_arg_1_val")); + if (activate_dependent) { + Reporting.Filters.activate_dependents($(field + "_arg_1_val")); + } Reporting.Filters.select_option_enabled($("add_filter_select"), filter_name, false); + on_complete(); } }); }, @@ -308,7 +314,7 @@ Reporting.Filters = { selectBox = this; } if (callbackWhenFinished === undefined) { - callbackWhenFinished = function() {}; + callbackWhenFinished = function(dependent) { console.log("Activated " + dependent); }; } source = selectBox.getAttribute("data-filter-name"); all_dependents = Reporting.Filters.get_dependents(selectBox); @@ -341,7 +347,11 @@ Reporting.Filters = { var active_dependents = all_dependents.select(function (d) { return active_filters.include(d); }); - Reporting.Filters.narrow_values(Reporting.Filters.dependent_for(source), active_dependents, callbackWhenFinished); + Reporting.Filters.narrow_values( + Reporting.Filters.dependent_for(source), + active_dependents, + function() { callbackWhenFinished(dependent); } + ); }, 1); }, @@ -501,8 +511,5 @@ Reporting.onload(function () { $$('.filters-select[data-all-dependents]').each(function (dependency) { dependency.observe("change", Reporting.Filters.activate_dependents); }); - Reporting.Filters.visible_filters().each(function (filter) { - // Reporting.Filters.load_available_values_for_filter(filter, function () {}); - }); }); diff --git a/assets/javascripts/reporting/restore_query.js b/assets/javascripts/reporting/restore_query.js index 93eae92906..56941a351e 100644 --- a/assets/javascripts/reporting/restore_query.js +++ b/assets/javascripts/reporting/restore_query.js @@ -27,65 +27,23 @@ Reporting.RestoreQuery = { } }, - // This is called the first time the report loads. - // Params: - // elements: Array of visible filter-select-boxes that have dependents - // (and possibly are dependents themselfes) - initialize_load_dependent_filters: function(elements) { - var filters_to_load, dependent_filters; - dependent_filters = elements.findAll(function (select) { return select.getValue() == '<>' || select.select('option[selected]').size()==0 }); - filters_to_load = elements.reject( function (select) { return select.getValue() == '<>' }); - // Filters which are <> are probably dependents themselfes, so remove and forget them for now. - // This is OK as they get reloaded later - dependent_filters.each(function(select) { - Reporting.Filters.remove_filter(select.up('tr').readAttribute("data-filter-name")); - }); - // For each dependent filter we reload its dependent chain - filters_to_load.each(function(selectBox) { - var sources, selected_values; - Reporting.Filters.activate_dependents(selectBox, function() { - sources = Reporting.Filters.get_dependents(selectBox).collect(function(field) { - return $('tr_' + field).select('.filter_values select').first(); - }); - sources.each(function(source) { - if (source.hasAttribute('data-initially-selected')) { - selected_values = source.readAttribute('data-initially-selected').replace(/'/g, '"').evalJSON(true); - Reporting.Filters.select_values(source, selected_values); - Reporting.Filters.value_changed(source.up('tr').readAttribute("data-filter-name")); - } - }); - if (sources.reject( function (select) { return select.value == '<>' }).size() == 0) { - Reporting.Filters.activate_dependents(selectBox); - } - else { - Reporting.RestoreQuery.initialize_load_dependent_filters(sources); - } - }); + restore_dependent_filters: function(filter_name) { + $$("tr.filter[data-filter-name=" + filter_name + "] select.filter-value").each(function(selectBox) { + console.log("restore dependents of " + filter_name); + var activateNext = function(dependent) { + if (!dependent) return; + console.log("up next: " + dependent); + Reporting.RestoreQuery.restore_dependent_filters(dependent); + }; + if (selectBox.hasAttribute('data-initially-selected')) { + var selected_values = selectBox.readAttribute('data-initially-selected').replace(/'/g, '"').evalJSON(true); + Reporting.Filters.select_values(selectBox, selected_values); + Reporting.Filters.value_changed(filter_name); + } + Reporting.Filters.activate_dependents(selectBox, activateNext); }); }, - restore_dependent_filters: function(selectBox) { - Reporting.Filters.activate_dependents(selectBox, function() { - var sources = Reporting.Filters.get_dependents(selectBox).collect(function(field) { - return $('tr_' + field).select('.filter_values select').first(); - }); - sources.each(function(source) { - if (source.hasAttribute('data-initially-selected')) { - var selected_values = source.readAttribute('data-initially-selected').replace(/'/g, '"').evalJSON(true); - Reporting.Filters.select_values(source, selected_values); - Reporting.Filters.value_changed(source.up('tr').readAttribute("data-filter-name")); - } - }); - if (sources.reject( function (select) { return select.value == '<>' }).size() == 0) { - Reporting.Filters.activate_dependents(selectBox); - } else { - sources.each(function (select) { - Reporting.RestoreQuery.restore_dependent_filters(select); - }); - } - }); - }, - restore_filters: function () { console.log("restore filters"); var deps = $$('.filters-select.filter-value').each(function(select) { @@ -98,54 +56,15 @@ Reporting.RestoreQuery = { } } }); - /*var dependents = deps[0]; - var independents = deps[1].select(function(select) { - return select.up("tr").visible(); - }); - var dependent_filters = deps[0].findAll(function (select) { - return select.getValue() == '<>' || select.select('option[selected]').size()==0 - }); - // Filters which are <> are probably dependents themselfes, so remove and forget them for now. - // This is OK as they get reloaded later - dependent_filters.each(function(select) { - Reporting.Filters.remove_filter(select.up('tr').readAttribute("data-filter-name")); - });*/ + $$("tr[data-selected=true]").each(function (e) { if (e.down(".filter_values select").hasAttribute("data-dependent")) return; var filter_name = e.getAttribute("data-filter-name"); - console.log("restore: " + filter_name); - Reporting.Filters.add_filter(filter_name); - // Reporting.RestoreQuery.restore_dependent_filters(e.down(".filters-select.filter-value")); - // FIXME: rm_xxx values for filters have to be set after re-displaying them - /*var rm_box, filter_name; - rm_box = e.select("input[id^=rm]").first(); - filter_name = e.getAttribute("data-filter-name"); - rm_box.value = filter_name; - Reporting.Filters.select_option_enabled($("add_filter_select"), filter_name, false); - // correctly display number of arguments of filters depending on their arity - Reporting.Filters.operator_changed(filter_name, $("operators[" + filter_name + "]"));*/ + var on_complete = function() { + Reporting.RestoreQuery.restore_dependent_filters(filter_name); + }; + Reporting.Filters.add_filter(filter_name, false, on_complete); }); - - if (true) return; // pull the break - - var semaphore = dependents.length; - dependents.each(function(dep) { - filter_name = dep.up("tr").getAttribute("data-filter-name"); - if (filter_name == "sector_id") { - console.log("[id=" + dep.readAttribute("id") + ", data-filter-name=" + filter_name + "]"); - } - Reporting.Filters.load_available_values_for_filter(filter_name, function () { - semaphore -= 1; - if (semaphore <= 0) { - Reporting.RestoreQuery.initialize_load_dependent_filters(dependents); - } - console.log("loaded available values for " + filter_name); - }); - }); - /*independents.each(function (e) { - filter_name = e.up("tr").getAttribute("data-filter-name"); - Reporting.Filters.load_available_values_for_filter(filter_name, function () {}); - });*/ }, restore_group_bys: function () { @@ -169,12 +88,3 @@ Reporting.onload(function () { Reporting.RestoreQuery.restore_group_bys(); Reporting.RestoreQuery.restore_filters(); }); - - - - - - - - - From 58313287e21a7449dd999d5438e291f63927c9d5 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 21 Sep 2011 12:20:55 +0200 Subject: [PATCH 08/14] don't fail on non-select filter values --- assets/javascripts/reporting/restore_query.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/reporting/restore_query.js b/assets/javascripts/reporting/restore_query.js index 56941a351e..7ce5e3c7ff 100644 --- a/assets/javascripts/reporting/restore_query.js +++ b/assets/javascripts/reporting/restore_query.js @@ -58,7 +58,8 @@ Reporting.RestoreQuery = { }); $$("tr[data-selected=true]").each(function (e) { - if (e.down(".filter_values select").hasAttribute("data-dependent")) return; + var select = e.down(".filter_values select"); + if (select && select.hasAttribute("data-dependent")) return; var filter_name = e.getAttribute("data-filter-name"); var on_complete = function() { Reporting.RestoreQuery.restore_dependent_filters(filter_name); From 397f7e1ffd3dcad3458416e8449a83a1a3701afe Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 21 Sep 2011 12:24:30 +0200 Subject: [PATCH 09/14] fix sector_id bug in FF, it is beyond me how this could work at all before, but hey ... I guess JS is a non-deterministic programming language --- assets/javascripts/reporting/filters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index b754a42831..0b9f1a8b30 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -30,7 +30,6 @@ Reporting.Filters = { }, onComplete: function (a, b) { $$("select[data-filter-name='" + filter_name + "']").each(function (e) { e.enable(); }); - callback_func(); if (select.tagName.toLowerCase() === "select") { if (post_select_values === undefined || post_select_values === null || post_select_values.size() === 0) { select.selectedIndex = 0; @@ -38,6 +37,7 @@ Reporting.Filters = { Reporting.Filters.select_values(select, post_select_values); } } + callback_func(); } }); Reporting.Filters.multi_select(select, false); From f35d186a74a9d58bd7e1b0ab0fcaaf6775f3ccb5 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 21 Sep 2011 12:24:49 +0200 Subject: [PATCH 10/14] remove console.log since it doesn't work in IE --- assets/javascripts/reporting/filters.js | 6 ++++-- assets/javascripts/reporting/restore_query.js | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index 0b9f1a8b30..483baa3353 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -314,7 +314,7 @@ Reporting.Filters = { selectBox = this; } if (callbackWhenFinished === undefined) { - callbackWhenFinished = function(dependent) { console.log("Activated " + dependent); }; + callbackWhenFinished = function(dependent) { }; } source = selectBox.getAttribute("data-filter-name"); all_dependents = Reporting.Filters.get_dependents(selectBox); @@ -453,7 +453,9 @@ Reporting.Filters = { callbackWhenFinished(); }, onException: function (response, error) { - console.log(error); + if (console) { + console.log(error); + } Reporting.flash("Loading of filter values failed. Probably, the server is temporary offline for maintenance."); var selectBox = $(currentDependent + "_arg_1_val"); $(selectBox).insert(new Element('option', {value: '<>'}).update('Failed to load values.')); diff --git a/assets/javascripts/reporting/restore_query.js b/assets/javascripts/reporting/restore_query.js index 7ce5e3c7ff..36a3222a6d 100644 --- a/assets/javascripts/reporting/restore_query.js +++ b/assets/javascripts/reporting/restore_query.js @@ -29,10 +29,8 @@ Reporting.RestoreQuery = { restore_dependent_filters: function(filter_name) { $$("tr.filter[data-filter-name=" + filter_name + "] select.filter-value").each(function(selectBox) { - console.log("restore dependents of " + filter_name); var activateNext = function(dependent) { if (!dependent) return; - console.log("up next: " + dependent); Reporting.RestoreQuery.restore_dependent_filters(dependent); }; if (selectBox.hasAttribute('data-initially-selected')) { @@ -45,7 +43,6 @@ Reporting.RestoreQuery = { }, restore_filters: function () { - console.log("restore filters"); var deps = $$('.filters-select.filter-value').each(function(select) { var tr = select.up('tr'); if (tr.visible()) { From f7b5373f8a780eaf1f3f019fcb44516fba6a840f Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 21 Sep 2011 14:59:42 +0200 Subject: [PATCH 11/14] only activate_dependents if there's actually something selected --- assets/javascripts/reporting/restore_query.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/reporting/restore_query.js b/assets/javascripts/reporting/restore_query.js index 36a3222a6d..e3a4b5d261 100644 --- a/assets/javascripts/reporting/restore_query.js +++ b/assets/javascripts/reporting/restore_query.js @@ -38,7 +38,9 @@ Reporting.RestoreQuery = { Reporting.Filters.select_values(selectBox, selected_values); Reporting.Filters.value_changed(filter_name); } - Reporting.Filters.activate_dependents(selectBox, activateNext); + if (selectBox.getValue() !== '<>') { + Reporting.Filters.activate_dependents(selectBox, activateNext); + } }); }, From fccc1a6d06ea67dd71dcf4f0c8068e7793ab43c8 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 21 Sep 2011 15:00:02 +0200 Subject: [PATCH 12/14] only callback if request actually succeeded --- assets/javascripts/reporting/filters.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index 483baa3353..aa91a27f96 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -448,9 +448,8 @@ Reporting.Filters = { if (continue_narrowing) { Reporting.Filters.narrow_values(sources, dependents); } + callbackWhenFinished(); } - - callbackWhenFinished(); }, onException: function (response, error) { if (console) { From 9f69422ab5c8cd3de197f266baa6b299c1f24fd5 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 21 Sep 2011 16:35:12 +0200 Subject: [PATCH 13/14] fixed initial multi_choice selection --- assets/javascripts/reporting/filters.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index aa91a27f96..ac4d1ec4df 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -5,6 +5,11 @@ Reporting.Filters = { load_available_values_for_filter: function (filter_name, callback_func) { var select, radio_options, post_select_values; select = $$('.filter-value[data-filter-name="' + filter_name + '"]').first(); + // check if we might have a radio-box + radio_options = $$('.' + filter_name + '_radio_option input'); + if (radio_options && radio_options.size() !== 0) { + radio_options.first().checked = true; + } if (select === null || select === undefined) { return; } @@ -44,14 +49,6 @@ Reporting.Filters = { } else { callback_func(); } - // select first option by default - if (select.tagName.toLowerCase() === "div") { - // check if we might have a radio-box - radio_options = $$('.' + filter_name + '_radio_option input'); - if (radio_options && radio_options.size() !== 0) { - radio_options.first().checked = true; - } - } }, show_filter: function (field, options) { From 60ee5b5bb7dd33fe7fb2749df9817cc709c8c84d Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 21 Sep 2011 18:07:37 +0200 Subject: [PATCH 14/14] fixed alumni selection bug (selection not disabled) --- assets/javascripts/reporting/filters.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index ac4d1ec4df..71ce527cbb 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -9,6 +9,7 @@ Reporting.Filters = { radio_options = $$('.' + filter_name + '_radio_option input'); if (radio_options && radio_options.size() !== 0) { radio_options.first().checked = true; + callback_func(); } if (select === null || select === undefined) { return; @@ -307,7 +308,10 @@ Reporting.Filters = { // Param: select [optional] - the select-box of the filter which should activate it's dependents activate_dependents: function (selectBox, callbackWhenFinished) { var all_dependents, next_dependents, dependent, active_filters, source; - if (selectBox === undefined || selectBox.type.toLowerCase() == 'change') { + if (selectBox !== undefined && selectBox.tagName.toLowerCase() !== "select") { + return; // only multi_value filters have dependents + } + if (selectBox === undefined || selectBox.type.toLowerCase() == 'change') { selectBox = this; } if (callbackWhenFinished === undefined) {