Module: check_mk
Branch: master
Commit: 83eb80f74057a1e2f54e44a2d159b6367d5ff8cd
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=83eb80f74057a1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 10 14:42:57 2013 +0100
Improved view row selection handling
* When having row selections enabled and no selected and performing
actions an error message is displayed instead of performing the action on
all rows
---
.bugs/788 | 7 +++++--
ChangeLog | 3 +++
web/htdocs/js/checkmk.js | 32 ++++++++++++++++++++++++++------
web/htdocs/views.py | 17 +++++++++++------
4 files changed, 45 insertions(+), 14 deletions(-)
diff --git a/.bugs/788 b/.bugs/788
index 0d1f9bd..894d7ab 100644
--- a/.bugs/788
+++ b/.bugs/788
@@ -1,11 +1,14 @@
Title: Command while no row selected show not do any command
Component: multisite
-State: open
+Class: nastiness
+State: done
Date: 2012-07-29 23:00:06
Targetversion: 1.2.2
-Class: nastiness
Currently if no row is checked then it behaves like *all*
rows are selected. Better would be a warning message
that no row is selected. An no command executed.
+
+2013-01-10 14:42:01: changed state open -> done
+Has been implemented like written here.
diff --git a/ChangeLog b/ChangeLog
index 4df185b..44cb12c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,9 @@
Multisite:
* FIX: Fixed rendering of dashboard globes in opera
+ * When having row selections enabled and no selected and performing
+ actions an error message is displayed instead of performing the action on
+ all rows
1.2.1i4:
Core:
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 1f135e6..7c99fea 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1004,6 +1004,8 @@ function toggle_foldable_container(treename, id) {
* +----------------------------------------------------------------------+
*/
+// Tells us if the row selection is enabled at the moment
+var g_selection_enabled = false;
// Holds the row numbers of all selected rows
var g_selected_rows = [];
@@ -1362,18 +1364,31 @@ function init_rowselect() {
// Adds a hidden field with the selected rows to the form if
// some are selected
+// Send an empty field to tell the server code that the checkbox
+// handling is enabled in GUI but no row has been selected
function add_row_selections(form) {
- var num_selected = g_selected_rows.length;
- // Skip when none selected
- if(num_selected == 0)
+ // Skip when selection is not enabled
+ if(!g_selection_enabled) {
+ // Remove var from form before submission
+ if(form.elements['selected_rows'] !== undefined) {
+ form.removeChild(form.elements['selected_rows']);
+ }
return true;
+ }
+
+ var num_selected = g_selected_rows.length;
+
+ if(form.elements['selected_rows'] === undefined) {
+ var field = document.createElement('input');
+ form.appendChild(field);
+ } else {
+ var field = form.elements['selected_rows'];
+ }
- var field = document.createElement('input');
field.name = 'selected_rows';
field.type = 'hidden';
field.value = g_selected_rows.join(',');
- form.appendChild(field);
field = null;
}
@@ -1814,7 +1829,12 @@ function view_switch_option(oDiv, viewname, option, choices) {
get_url_sync("ajax_set_viewoption.py?view_name=" + viewname +
"&option=" + option + "&value=" +
new_choice[0]);
- if (option == "refresh")
+
+ if (option == "refresh") {
setReload(new_choice[0]);
+ } else if (option == "show_checkboxes") {
+ g_selection_enabled = new_value;
+ }
+
handleReload('');
}
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index b6a0dbe..0b50323 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1370,7 +1370,7 @@ def render_view(view, rows, datasource, group_painters, painters,
if command_form:
# If we are currently within an action (confirming or executing), then
# we display only the selected rows (if checkbox mode is active)
- if html.var("selected_rows", "") and html.do_actions():
+ if html.var("selected_rows", None) != None and html.do_actions():
rows = get_selected_rows(view, rows, html.var("selected_rows"))
if html.do_actions() and html.transaction_valid(): # submit button pressed, no
reload
@@ -1614,7 +1614,7 @@ def view_optiondial(view, option, choices, help):
html.begin_context_buttons() # just to be sure
# Remove unicode strings
choices = [ [c[0], str(c[1])] for c in choices ]
- html.write('<div title="%s" id="optiondial_%s"
class="optiondial %s val_%s"'
+ html.write('<div title="%s" id="optiondial_%s"
class="optiondial %s val_%s" '
'onclick="view_dial_option(this, \'%s\', \'%s\',
%r);"><div>%s</div></div>' % (
help, option, option, value, view["name"], option, choices, title))
html.final_javascript("init_optiondial('optiondial_%s');" %
option)
@@ -1628,7 +1628,7 @@ def view_option_toggler(id, view, option, icon, help, hidden =
False):
value = vo.get(option, view.get(option, False))
html.begin_context_buttons() # just to be sure
hide = hidden and ' style="display:none"' or ''
- html.write('<div id="%s_on" title="%s"
class="togglebutton %s %s"'
+ html.write('<div id="%s_on" title="%s"
class="togglebutton %s %s" '
'onclick="view_switch_option(this, \'%s\',
\'%s\');"%s></div>' % (
id, help, icon, value and "down" or "up",
view["name"], option, hide))
@@ -1699,10 +1699,12 @@ def show_context_links(thisview, active_filters, show_filters,
display_options,
hidden = not enable_commands)
togglebutton_off("commands", "commands", hidden =
enable_commands)
+ selection_enabled = enable_commands and enable_checkboxes
view_option_toggler("checkbox", thisview, "show_checkboxes",
"checkbox",
_("Enable/Disable checkboxes for selecting rows for
commands"),
- hidden = not enable_commands or not enable_checkboxes)
- togglebutton_off("checkbox", "checkbox", hidden =
enable_commands and enable_checkboxes)
+ hidden = not selection_enabled)
+ togglebutton_off("checkbox", "checkbox", hidden =
selection_enabled)
+ html.javascript('g_selection_enabled = %s;' % (selection_enabled and
'true' or 'false'))
if 'O' in display_options:
if config.may("general.view_option_columns"):
@@ -2162,7 +2164,10 @@ def do_actions(view, what, action_rows, backurl):
return False # no actions done
if not action_rows:
- html.show_error(_("No rows selected to perform actions for."))
+ message = _("No rows selected to perform actions for.")
+ if html.output_format == "html": # sorry for this hack
+ message += '<br><a href="%s">%s</a>' %
(backurl, _('Back to view'))
+ html.show_error(message)
return False # no actions done
command = None