From fba53b438540eb544c43adf4598e07320a910347 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Sun, 19 Mar 2017 11:21:31 +0545 Subject: Redmine #7318 None button for widget filters --- src/usr/local/www/index.php | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/usr/local/www/index.php') diff --git a/src/usr/local/www/index.php b/src/usr/local/www/index.php index cfd4578..2b74a9e 100644 --- a/src/usr/local/www/index.php +++ b/src/usr/local/www/index.php @@ -445,6 +445,53 @@ function updateWidgets(newWidget) { $('input[name=sequence]', $('#widgetSequence_form')).val(sequence); } +// Determine if all the checkboxes are checked +function are_all_checked(checkbox_panel_ref) { + var allBoxesChecked = true; + $(checkbox_panel_ref).each(function() { + if ((this.type == 'checkbox') && !this.checked) { + allBoxesChecked = false; + } + }); + return allBoxesChecked; +} + +// If the checkboxes are all checked, then clear them all. +// Otherwise set them all. +function set_clear_checkboxes(checkbox_panel_ref) { + checkTheBoxes = !are_all_checked(checkbox_panel_ref); + + $(checkbox_panel_ref).each(function() { + $(this).prop("checked", checkTheBoxes); + }); +} + +// Set the given id to All or None button depending if the checkboxes are all checked. +function set_all_none_button(checkbox_panel_ref, all_none_button_id) { + if (are_all_checked(checkbox_panel_ref)) { + text = ""; + } else { + text = ""; + } + + $("#" + all_none_button_id).html('' + text); +} + +// Setup the necessary events to manage the All/None button and included checkboxes +// used for selecting the items to show on a widget. +function set_widget_checkbox_events(checkbox_panel_ref, all_none_button_id) { + set_all_none_button(checkbox_panel_ref, all_none_button_id); + + $(checkbox_panel_ref).change(function() { + set_all_none_button(checkbox_panel_ref, all_none_button_id); + }); + + $("#" + all_none_button_id).click(function() { + set_clear_checkboxes(checkbox_panel_ref); + set_all_none_button(checkbox_panel_ref, all_none_button_id); + }); +} + events.push(function() { // Make panels destroyable -- cgit v1.1