From 14c6cfa0ba499c695d7da58e22cb2215541bddea 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 (cherry picked from commit fba53b438540eb544c43adf4598e07320a910347) --- src/usr/local/www/index.php | 47 ++++++++++++++++++++++ .../www/widgets/widgets/dyn_dns_status.widget.php | 7 +--- .../local/www/widgets/widgets/gateways.widget.php | 6 +-- .../widgets/interface_statistics.widget.php | 6 +-- .../www/widgets/widgets/interfaces.widget.php | 7 +--- .../local/www/widgets/widgets/openvpn.widget.php | 6 +-- .../www/widgets/widgets/services_status.widget.php | 7 +--- .../www/widgets/widgets/smart_status.widget.php | 7 +--- .../widgets/widgets/system_information.widget.php | 6 +-- .../www/widgets/widgets/wake_on_lan.widget.php | 7 +--- 10 files changed, 56 insertions(+), 50 deletions(-) (limited to 'src/usr/local/www') diff --git a/src/usr/local/www/index.php b/src/usr/local/www/index.php index 4d9535e..a7dde79 100644 --- a/src/usr/local/www/index.php +++ b/src/usr/local/www/index.php @@ -482,6 +482,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 diff --git a/src/usr/local/www/widgets/widgets/dyn_dns_status.widget.php b/src/usr/local/www/widgets/widgets/dyn_dns_status.widget.php index 0ca13de..b8f7ba1 100644 --- a/src/usr/local/www/widgets/widgets/dyn_dns_status.widget.php +++ b/src/usr/local/www/widgets/widgets/dyn_dns_status.widget.php @@ -317,12 +317,7 @@ function get_dyndns_service_text($dyndns_type) { setTimeout('dyndns_getstatus()', 5*60*1000); } events.push(function(){ - $("#showalldyndns").click(function() { - $("#widget-_panel-footer [id^=show]").each(function() { - $(this).prop("checked", true); - }); - }); - + set_widget_checkbox_events("#widget-_panel-footer [id^=show]", "showalldyndns"); }); // Do the first status check 2 seconds after the dashboard opens setTimeout('dyndns_getstatus()', 2000); diff --git a/src/usr/local/www/widgets/widgets/gateways.widget.php b/src/usr/local/www/widgets/widgets/gateways.widget.php index 41b7094..f4408b8 100644 --- a/src/usr/local/www/widgets/widgets/gateways.widget.php +++ b/src/usr/local/www/widgets/widgets/gateways.widget.php @@ -220,11 +220,7 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period } events.push(function(){ - $("#showallgateways").click(function() { - $("#widget-_panel-footer [id^=show]").each(function() { - $(this).prop("checked", true); - }); - }); + set_widget_checkbox_events("#widget-_panel-footer [id^=show]", "showallgateways"); // Start polling for updates some small random number of seconds from now (so that all the widgets don't // hit the server at exactly the same time) diff --git a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php index 8cd03fc..1c87c5f 100644 --- a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php +++ b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php @@ -216,11 +216,7 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period } events.push(function(){ - $("#showallinterfacesforstats").click(function() { - $("#widget-_panel-footer [id^=show]").each(function() { - $(this).prop("checked", true); - }); - }); + set_widget_checkbox_events("#widget-_panel-footer [id^=show]", "showallinterfacesforstats"); // Start polling for updates some small random number of seconds from now (so that all the widgets don't // hit the server at exactly the same time) diff --git a/src/usr/local/www/widgets/widgets/interfaces.widget.php b/src/usr/local/www/widgets/widgets/interfaces.widget.php index e8954a4..df3b717 100644 --- a/src/usr/local/www/widgets/widgets/interfaces.widget.php +++ b/src/usr/local/www/widgets/widgets/interfaces.widget.php @@ -220,12 +220,7 @@ endif; diff --git a/src/usr/local/www/widgets/widgets/openvpn.widget.php b/src/usr/local/www/widgets/widgets/openvpn.widget.php index bc7ddd2..35a7865 100644 --- a/src/usr/local/www/widgets/widgets/openvpn.widget.php +++ b/src/usr/local/www/widgets/widgets/openvpn.widget.php @@ -384,11 +384,7 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period } events.push(function(){ - $("#showallovpns").click(function() { - $("#widget-_panel-footer [id^=show]").each(function() { - $(this).prop("checked", true); - }); - }); + set_widget_checkbox_events("#widget-_panel-footer [id^=show]", "showallovpns"); // Start polling for updates some small random number of seconds from now (so that all the widgets don't // hit the server at exactly the same time) diff --git a/src/usr/local/www/widgets/widgets/services_status.widget.php b/src/usr/local/www/widgets/widgets/services_status.widget.php index 2d04a93..f28a1ed 100644 --- a/src/usr/local/www/widgets/widgets/services_status.widget.php +++ b/src/usr/local/www/widgets/widgets/services_status.widget.php @@ -164,12 +164,7 @@ if (count($services) > 0) { diff --git a/src/usr/local/www/widgets/widgets/smart_status.widget.php b/src/usr/local/www/widgets/widgets/smart_status.widget.php index fa309a9..9707e94 100644 --- a/src/usr/local/www/widgets/widgets/smart_status.widget.php +++ b/src/usr/local/www/widgets/widgets/smart_status.widget.php @@ -194,12 +194,7 @@ if (count($devs) > 0) { diff --git a/src/usr/local/www/widgets/widgets/system_information.widget.php b/src/usr/local/www/widgets/widgets/system_information.widget.php index b6275c1..a04da18 100644 --- a/src/usr/local/www/widgets/widgets/system_information.widget.php +++ b/src/usr/local/www/widgets/widgets/system_information.widget.php @@ -590,11 +590,7 @@ function updateMeters() { } events.push(function(){ - $("#showallsysinfoitems").click(function() { - $("#widget-_panel-footer [id^=show]").each(function() { - $(this).prop("checked", true); - }); - }); + set_widget_checkbox_events("#widget-_panel-footer [id^=show]", "showallsysinfoitems"); }); var update_interval = ""; diff --git a/src/usr/local/www/widgets/widgets/wake_on_lan.widget.php b/src/usr/local/www/widgets/widgets/wake_on_lan.widget.php index 21e7efe..e650114 100644 --- a/src/usr/local/www/widgets/widgets/wake_on_lan.widget.php +++ b/src/usr/local/www/widgets/widgets/wake_on_lan.widget.php @@ -217,12 +217,7 @@ if (is_array($config['dhcpd'])) { -- cgit v1.1