From 537d34a50644cbd1e0b4954f1e679c0f303afe76 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 2 Feb 2011 14:07:28 +0100 Subject: [PATCH] move more code into filter.js --- assets/javascripts/reporting.js | 38 -------------------- assets/javascripts/reporting/filters.js | 46 ++++++++++++++++++------- 2 files changed, 33 insertions(+), 51 deletions(-) diff --git a/assets/javascripts/reporting.js b/assets/javascripts/reporting.js index 2ef5fa79cc..181daa31b4 100644 --- a/assets/javascripts/reporting.js +++ b/assets/javascripts/reporting.js @@ -48,44 +48,6 @@ Reporting.require("restore_query"); // } // } // -// function occupied_category(tr_field) { -// var i, data_label, filters; -// data_label = tr_field.getAttribute("data-label"); -// filters = document.getElementsByClassName('filter'); -// for (i = 0; i < filters.length; i += 1) { -// if (filters[i].visible() && filters[i].getAttribute("data-label") === data_label) { -// return true; -// } -// } -// return false; //not hit -// } -// -// function hide_filter(field, slowly) { -// var field_el, operator_select; -// field_el = $('tr_' + field); -// if (field_el !== null) { -// $('rm_' + field).value = ""; -// if (slowly) { -// new Effect.Fade(field_el); -// } else { -// field_el.hide(); -// } -// operator_select = $("operators_" + field); -// if (operator_select !== null) { -// // in case the filter doesn't have an operator select field' -// operator_changed(field, $("operators_" + field)); -// } -// if (!occupied_category(field_el)) { -// hide_category(field_el); -// } -// } -// } -// -// function remove_filter(field) { -// hide_filter(field, true); -// enable_select_option($("add_filter_select"), field); -// } -// // function show_group_by(group_by, target) { // var source, group_option, i; // source = $("group_by_container"); diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index e83bbcf03c..baaf35f67c 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -1,5 +1,5 @@ /*jslint white: false, nomen: true, devel: true, on: true, debug: false, evil: true, onevar: false, browser: true, white: false, indent: 2 */ -/*global window, $, $$, Reporting, Effect, Ajax */ +/*global window, $, $$, Reporting, Effect, Ajax, Element */ Reporting.Filters = { load_available_values_for_filter: function (filter_name, callback_func) { @@ -26,32 +26,47 @@ Reporting.Filters = { } }, - show_filter: function (field, slowly, callback_func) { - if (callback_func === undefined) { - callback_func = function () {}; + show_filter: function (field, options) { + if (options.callback_func === undefined) { + options.callback_func = function () {}; } - if (slowly === undefined) { - slowly = true; + if (options.slowly === undefined) { + options.slowly = true; + } + if (options.show_filter === undefined) { + options.show_filter = true; } var field_el = $('tr_' + field); if (field_el !== null) { - Reporting.Filters.load_available_values_for_filter(field, callback_func); + Reporting.Filters.load_available_values_for_filter(field, options.callback_func); // the following command might be included into the callback_function (which is called after the ajax request) later $('rm_' + field).value = field; - if (slowly) { - Effect.Appear(field_el); + var display_functor; + if (options.show_filter) { + display_functor = options.slowly ? Effect.Appear : Element.show; } else { - field_el.show(); + display_functor = options.slowly ? Effect.Fade : Element.hide; } + display_functor(field_el); Reporting.Filters.operator_changed(field, $("operators_" + field)); - Reporting.Filters.display_category(field_el); + Reporting.Filters.display_category(field_el, options.show_filter); } }, - display_category: function (tr_field) { + display_category: function (tr_field, show) { + if (show === undefined) { + show = true; + } var label = $(tr_field.getAttribute("data-label")); if (label !== null) { - label.show(); + var filters = $$('.filter'); + for (var i = 0; i < filters.length; i += 1) { + if (filters[i].visible() === show && filters[i].getAttribute("data-label") === label) { + return; // No need to show/hide + } + } + var display_functor = show ? Element.show : Element.hide; + display_functor(label); } }, @@ -105,6 +120,11 @@ Reporting.Filters = { toggle_multi_select: function (select) { Reporting.Filters.multi_select(select, !select.multiple); + }, + + remove_filter: function (field) { + Reporting.Filters.show_filter(field, { show_filter: false }); + Reporting.Filters.select_option_enabled($("add_filter_select"), field, true); } };