Module: check_mk
Branch: master
Commit: ac51262fba3cc16143061e0d1e0cfb999508e6d5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ac51262fba3cc1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Sep 5 10:07:15 2011 +0200
Added select/deselect all button ("x") to view action row
---
web/htdocs/js/check_mk.js | 31 ++++++++++++++++++++++++++++++-
web/htdocs/views.py | 14 +++++++++++---
2 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/web/htdocs/js/check_mk.js b/web/htdocs/js/check_mk.js
index c1b0321..588b105 100644
--- a/web/htdocs/js/check_mk.js
+++ b/web/htdocs/js/check_mk.js
@@ -961,9 +961,17 @@ function highlight_elem(elem, on, ty) {
highlight_elem(childs[i], on, ty);
}
+function select_all_rows(elems) {
+ for(var i = 0; i < elems.length; i++) {
+ highlight_elem(elems[i], true, 'click');
+ if(g_selected_rows.indexOf(elems[i].row_num) === -1)
+ g_selected_rows.push(elems[i].row_num);
+ }
+}
+
function remove_selected_rows(row_num) {
for(var i = g_selected_rows.length - 1; i >= 0; i--) {
- if(g_selected_rows[i] != row_num) {
+ if(g_selected_rows[i] !== row_num) {
highlight_row(g_selected_rows[i], false, 'click');
highlight_row(g_selected_rows[i], false, 'hover');
g_selected_rows.splice(i, 1);
@@ -1031,6 +1039,27 @@ function disable_selection(e) {
return false;
}
+// Is used to select/deselect all rows in the current view
+function toggle_all_rows() {
+ var elems = document.getElementsByClassName('dr');
+
+ var all_selected = true;
+ for(var i = 0; i < elems.length && all_selected == true; i++) {
+ if(elems[i].tagName != 'TD' && elems[i].tagName !=
'DIV')
+ continue;
+
+ if(g_selected_rows.indexOf(elems[i].row_num) === -1)
+ all_selected = false;
+ }
+
+ // Now set the new state
+ if(all_selected) {
+ remove_selected_rows('');
+ } else {
+ select_all_rows(elems);
+ }
+}
+
function get_row_num(elem) {
// FIXME: Maybe performance problem. Would be better to have a
// dedicated attribute for the data row number
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 845d6c0..c6a16db 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1275,6 +1275,12 @@ def show_view(view, show_heading = False, show_buttons = True,
show_footer = Tru
# Buttons for view options
if 'O' in display_options:
+ # Link for selecting/deselecting all rows
+ if 'C' in display_options and len(rows) > 0 and
config.may("act") and not html.do_actions():
+ html.write('<td class="left w30"><a
href="javascript:toggle_all_rows()" '
+ 'title="%s">%s</a></td>\n' %
(_('Toggle all row selections'), _('x')))
+ html.write("<td class=minigap></td>\n")
+
if config.user_may(config.user, "view_option_columns"):
for col in config.view_option_columns:
uri = html.makeuri([("num_columns", col)])
@@ -1282,7 +1288,8 @@ def show_view(view, show_heading = False, show_buttons = True,
show_footer = Tru
addclass = " selected"
else:
addclass = ""
- html.write('<td class="left w30%s"><a
href="%s">%s</a></td>\n' % (addclass, uri, col))
+ html.write('<td class="left w30%s"><a
href="%s" title="%s">%s</a></td>\n' %
+ (addclass, uri, _('%d column layout') %
col, col))
html.write("<td class=minigap></td>\n")
if 'R' in display_options and config.user_may(config.user,
"view_option_refresh"):
@@ -1296,8 +1303,9 @@ def show_view(view, show_heading = False, show_buttons = True,
show_footer = Tru
reftext = "%d s" % ref
else:
reftext = "∞"
- html.write('<td class="left w40%s"
id="button-refresh-%s"><a
href="%s">%s</a></td>\n' %
- (addclass,
ref, uri, reftext))
+ html.write('<td class="left w40%s"
id="button-refresh-%s">'
+ '<a href="%s"
title="%s">%s</a></td>\n' %
+ (addclass, ref, uri, _('refresh every %d seconds')
% ref, reftext))
html.write("<td class=minigap></td>\n")
html.write("<td class=gap> </td>\n")