Module: check_mk
Branch: master
Commit: 8f18f6296452d459a23c7f631fc8a0a70239ce21
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8f18f6296452d4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Sep 5 12:46:35 2011 +0200
Changed row selection in WATO to new row selection mechanism
---
ChangeLog | 1 +
web/htdocs/htmllib.py | 10 ++++++++++
web/htdocs/js/check_mk.js | 13 ++++++++++---
web/htdocs/wato.py | 29 ++++++++++++++---------------
web/plugins/views/layouts.py | 12 ++----------
5 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0398110..b3ab8c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,7 @@
* Added missing sorters for "service nth service perfdata" painters
* Implemented row selection in views to select only a subset of shown data
for actions
+ * Changed row selection in WATO to new row selection mechanism
1.1.11i3:
Core, Setup, etc.:
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index c9cbc4d..9de3262 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -790,3 +790,13 @@ class html:
def end_foldable_container(self):
self.write("</ul>")
+
+ def init_rowselect(self):
+ selected = []
+ if self.has_var('selected_rows'):
+ selected_rows = self.var('selected_rows', '')
+ if selected_rows or ',' in selected_rows:
+ selected = selected_rows.split(',')
+
+ self.javascript('g_selected_rows = %s;\n'
+ 'init_rowselect();' % repr(selected))
diff --git a/web/htdocs/js/check_mk.js b/web/htdocs/js/check_mk.js
index 18272db..a19595c 100644
--- a/web/htdocs/js/check_mk.js
+++ b/web/htdocs/js/check_mk.js
@@ -915,7 +915,10 @@ function real_style(obj, attr) {
// If elem is a TD and has no background find the backround of the parent
// e.g. the TR and then set this color as background for the TD
- if(obj.tagName == 'TD' && (st == 'transparent' || st ==
'rgba(0, 0, 0, 0)'))
+ // But only do this when the TR is not in the highlight scope
+ if(obj.tagName == 'TD'
+ && obj.parentNode.row_num === undefined
+ && (st == 'transparent' || st == 'rgba(0, 0, 0, 0)'))
st = real_style(obj.parentNode, attr);
return st;
@@ -1046,7 +1049,9 @@ function toggle_all_rows() {
var all_selected = true;
for(var i = 0; i < elems.length && all_selected == true; i++) {
- if(elems[i].tagName != 'TD' && elems[i].tagName !=
'DIV')
+ if(elems[i].tagName != 'TD'
+ && elems[i].tagName != 'TR'
+ && elems[i].tagName != 'DIV')
continue;
if(g_selected_rows.indexOf(elems[i].row_num) === -1)
@@ -1075,7 +1080,9 @@ function table_init_rowselect(oTable) {
var childs = document.getElementsByClassName('dr');
for(var i = 0; i < childs.length; i++) {
- if(childs[i].tagName != 'TD' && childs[i].tagName !=
'DIV')
+ if(childs[i].tagName != 'TD'
+ && childs[i].tagName != 'TR'
+ && childs[i].tagName != 'DIV')
continue;
var elem = childs[i];
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index cd13efa..6f10be4 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -621,10 +621,10 @@ def mode_file(phase):
# Show table of hosts in this file
colspan = 5
- html.begin_form("hosts", None, "POST")
+ html.begin_form("hosts", None, "POST", onsubmit =
'add_row_selections(this);')
html.write("<table class=data>\n")
- html.write("<tr><th
class=left></th><th></th><th>" + _("Hostname") +
"</th>")
-
+ html.write("<tr><th class=left></th><th>" +
_("Hostname") + "</th>")
+
for attr, topic in host_attributes:
if attr.show_in_table():
html.write("<th>%s</th>" % attr.title())
@@ -635,7 +635,6 @@ def mode_file(phase):
odd = "odd"
search_text = html.var("search")
- selected_hosts = get_hostnames_from_checkboxes()
at_least_one_imported = False
for hostname in hostnames:
if search_text and (search_text.lower() not in hostname.lower()):
@@ -645,15 +644,9 @@ def mode_file(phase):
effective = effective_attributes(host, g_file)
# Rows with alternating odd/even styles
- html.write('<tr class="data %s0">' % odd)
+ html.write('<tr class="dr_%s dr data %s0">' %
(hostname, odd))
odd = odd == "odd" and "even" or "odd"
- # Check box (if none is checked, then the default is to check all)
- def_value = selected_hosts == []
- html.write("<td class=select>")
- html.checkbox("sel_%s" % hostname, def_value,
'wato_select')
- html.write("</td>")
-
# Column with actions (buttons)
edit_url = make_link([("mode", "edithost"),
("host", hostname)])
services_url = make_link([("mode", "inventory"),
("host", hostname)])
@@ -697,9 +690,9 @@ def mode_file(phase):
# bulk actions
- html.write('<tr class="data %s0"><td class=select>'
% odd)
- html.jsbutton('_markall', 'X',
'javascript:wato_check_all(\'wato_select\');')
- html.write("</td><td colspan=%d>" % colspan)
+ html.write('<tr class="data %s0">' % odd)
+ html.write("<td colspan=%d>" % colspan)
+ html.jsbutton('_markall', 'X',
'javascript:toggle_all_rows();')
html.write(_("On all selected hosts:\n"))
html.button("_bulk_delete", _("Delete"))
html.button("_bulk_edit", _("Edit"))
@@ -721,16 +714,22 @@ def mode_file(phase):
html.hidden_fields()
html.end_form()
+ html.init_rowselect()
# Create list of all hosts that are select with checkboxes in the current file
def get_hostnames_from_checkboxes():
hostnames = g_hosts.keys()
hostnames.sort()
+
+ selected = []
+ if html.var('selected_rows', '') != '':
+ selected = html.var('selected_rows', '').split(',')
+
selected_hosts = []
search_text = html.var("search")
for name in hostnames:
if (not search_text or (search_text.lower() in name.lower())) \
- and html.var("sel_" + name):
+ and name in selected:
selected_hosts.append(name)
return selected_hosts
diff --git a/web/plugins/views/layouts.py b/web/plugins/views/layouts.py
index 6f17cc5..104f6b4 100644
--- a/web/plugins/views/layouts.py
+++ b/web/plugins/views/layouts.py
@@ -28,15 +28,7 @@ def init_rowselect():
# Don't make rows selectable when no commands can be fired
if not 'C' in html.display_options or not config.may("act"):
return
-
- row_nums = []
- if html.has_var('selected_rows'):
- selected_rows = html.var('selected_rows', '')
- if selected_rows or ',' in selected_rows:
- row_nums = selected_rows.split(',')
-
- html.javascript('g_selected_rows = %s;\n'
- 'init_rowselect();' % repr(row_nums))
+ html.init_rowselect()
# -------------------------------------------------------------------------
# ____ _ _
@@ -253,7 +245,7 @@ def render_tiled(rows, view, group_painters, painters,
_ignore_num_columns):
if not group_open:
html.write("<tr><td class=tiles>")
group_open = True
- html.write('<div class="dr_%d dr tile %s"><table>'
% (row_id(view, row), sclass))
+ html.write('<div class="dr_%s dr tile %s"><table>'
% (row_id(view, row), sclass))
# We need at least five painters.
empty_painter = { "paint" : (lambda row: ("", ""))
}