Module: check_mk
Branch: master
Commit: 700212a2c513f58b749c22b88f0bfe3a247be57f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=700212a2c513f5…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Nov 18 21:50:33 2011 +0100
WATO: dependent attributes for checkbox elements
---
web/htdocs/htmllib.py | 6 +++---
web/htdocs/js/wato.js | 14 +++++++++-----
web/htdocs/wato.py | 14 +++++++++-----
3 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index bfdae94..8d83daa 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -440,7 +440,7 @@ class html:
(varname, value, checked_text, text))
self.form_vars.append(varname)
- def checkbox(self, varname, deflt=False, cssclass = '', onclick = None):
+ def checkbox(self, varname, deflt=False, cssclass = '', onclick = None,
add_attr = []):
error = self.user_errors.get(varname)
if error:
html = "<x class=inputerror>"
@@ -457,8 +457,8 @@ class html:
if cssclass:
cssclass = ' class="%s"' % cssclass
onclick_code = onclick and " onclick=\"%s\"" % (onclick) or
""
- self.write("<input type=checkbox name=\"%s\"%s%s%s>" %
- (varname, checked, cssclass, onclick_code))
+ self.write("<input type=checkbox name=\"%s\"%s%s%s%s>"
%
+ (varname, checked, cssclass, onclick_code, "
".join(add_attr)))
self.form_vars.append(varname)
if error:
html += "</x>"
diff --git a/web/htdocs/js/wato.js b/web/htdocs/js/wato.js
index cef4bb1..ae99f42 100644
--- a/web/htdocs/js/wato.js
+++ b/web/htdocs/js/wato.js
@@ -76,11 +76,15 @@ function wato_fix_visibility() {
for (var i in oTable.childNodes) {
var oTr = oTable.childNodes[i];
if (oTr.nodeName == 'TR') {
- /* Find the <select> object in this tr */
- /* td.content div select */
- var oSelect = oTr.childNodes[2].childNodes[0].childNodes[0];
- tags = oSelect.value.split("|");
- currentTags = currentTags.concat(tags);
+ /* Find the <select>/<checkbox> object in this tr */
+ /* td.content div select/checkbox */
+ var oElement = oTr.childNodes[2].childNodes[0].childNodes[0];
+ if( oElement.type == 'checkbox' && oElement.checked ){ //
<checkbox>
+ currentTags =
currentTags.concat(oElement.getAttribute('tags').split("|"));
+ }
+ else{ // <select>
+ currentTags = currentTags.concat(oElement.value.split("|"));
+ }
}
}
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 929d2aa..91cd94e 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -3445,11 +3445,10 @@ class HostTagAttribute(Attribute):
secondary_tags = e[2]
else:
secondary_tags = []
- value = "|".join([ tagvalue ] + secondary_tags)
- choices.append((value, e[1]))
+ choices.append(("|".join([ tagvalue ] + secondary_tags), e[1]))
varname = "attr_" + self.name()
if len(choices) == 1:
- html.checkbox(varname, value != None,
onchange='wato_fix_visibility();')
+ html.checkbox(varname, value != None, cssclass = '',
onclick='wato_fix_visibility();', add_attr = ["tags=%s"%choices[0][0]])
html.write(" " + choices[0][1])
else:
html.select(varname, choices, value,
onchange='wato_fix_visibility();')
@@ -7947,7 +7946,9 @@ def mode_edit_hosttag(phase):
raise MKUserError("tag_id", _("Please specify an ID
for your tag group."))
if not re.match("^[-a-z0-9A-Z_]*$", tag_id):
raise MKUserError("tag_id", _("Invalid tag group ID.
Only the characters a-z, A-Z, 0-9, _ and - are allowed."))
- for tgid, tit, ch in config.wato_host_tags:
+ for entry in config.wato_host_tags:
+ tgid = entry[0]
+ tit = entry[1]
if tgid == tag_id:
raise MKUserError("tag_id", _("The tag group ID %s
is already used by the tag group '%s'.") % (tag_id, tit))
@@ -7974,7 +7975,10 @@ def mode_edit_hosttag(phase):
new_choices.append((id, descr))
if id:
# Make sure this ID is not used elsewhere
- for tgid, tit, ch in config.wato_host_tags:
+ for entry in config.wato_host_tags:
+ tgid = entry[0]
+ tit = entry[1]
+ ch = entry[2]
if tgid != tag_id:
for e in ch:
# Check primary and secondary tags