Redmine #7318 None button for widget filters

This commit is contained in:
Phil Davis 2017-03-19 11:21:31 +05:45
parent 405dfaad14
commit fba53b4385
No known key found for this signature in database
GPG Key ID: 340A5689A513CA23
10 changed files with 56 additions and 50 deletions

View File

@ -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 = "<?=gettext('None')?>";
} else {
text = "<?=gettext('All')?>";
}
$("#" + all_none_button_id).html('<i class="fa fa-undo icon-embed-btn"></i>' + 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

View File

@ -285,12 +285,7 @@ function get_dyndns_service_text($dyndns_type) {
setTimeout('dyndns_getstatus()', 5*60*1000);
}
events.push(function(){
$("#showalldyndns").click(function() {
$("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() {
$(this).prop("checked", true);
});
});
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showalldyndns");
});
// Do the first status check 2 seconds after the dashboard opens
setTimeout('dyndns_getstatus()', 2000);

View File

@ -188,11 +188,7 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period
}
events.push(function(){
$("#showallgateways").click(function() {
$("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() {
$(this).prop("checked", true);
});
});
set_widget_checkbox_events("#widget-<?=$widgetname?>_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)

View File

@ -185,11 +185,7 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period
}
events.push(function(){
$("#showallinterfacesforstats").click(function() {
$("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() {
$(this).prop("checked", true);
});
});
set_widget_checkbox_events("#widget-<?=$widgetname?>_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)

View File

@ -188,12 +188,7 @@ endif;
<script>
//<![CDATA[
events.push(function(){
$("#showallinterfaces").click(function() {
$("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() {
$(this).prop("checked", true);
});
});
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallinterfaces");
});
//]]>
</script>

View File

@ -364,11 +364,7 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period
}
events.push(function(){
$("#showallovpns").click(function() {
$("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() {
$(this).prop("checked", true);
});
});
set_widget_checkbox_events("#widget-<?=$widgetname?>_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)

View File

@ -164,12 +164,7 @@ if (count($services) > 0) {
<script type="text/javascript">
//<![CDATA[
events.push(function(){
$("#showallservices").click(function() {
$("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() {
$(this).prop("checked", true);
});
});
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallservices");
});
//]]>
</script>

View File

@ -162,12 +162,7 @@ if (count($devs) > 0) {
<script type="text/javascript">
//<![CDATA[
events.push(function(){
$("#showallsmartdrives").click(function() {
$("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() {
$(this).prop("checked", true);
});
});
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallsmartdrives");
});
//]]>
</script>

View File

@ -487,11 +487,7 @@ function updateMeters() {
}
events.push(function(){
$("#showallsysinfoitems").click(function() {
$("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() {
$(this).prop("checked", true);
});
});
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallsysinfoitems");
});
var update_interval = "<?=$widgetperiod?>";

View File

@ -183,12 +183,7 @@ if (is_array($config['dhcpd'])) {
<script>
//<![CDATA[
events.push(function(){
$("#showallwols").click(function() {
$("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() {
$(this).prop("checked", true);
});
});
set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallwols");
});
//]]>
</script>