vertical mode
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 6fdcba30eacee6e82b108dccc8ed91e4e9267afa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6fdcba30eacee6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Apr 28 17:37:54 2012 +0200
Fix ValueSpec ListOfStrings horizontal/vertical mode
---
web/htdocs/check_mk.css | 5 +-
web/htdocs/js/checkmk.js | 67 +++++++++++++++++---------------
web/htdocs/valuespec.py | 20 +++-------
web/plugins/wato/builtin_attributes.py | 16 ++++++++
4 files changed, 61 insertions(+), 47 deletions(-)
diff --git a/web/htdocs/check_mk.css b/web/htdocs/check_mk.css
index 4eed256..f867b5f 100644
--- a/web/htdocs/check_mk.css
+++ b/web/htdocs/check_mk.css
@@ -390,8 +390,9 @@ table.valuespec_listof option[selected] {
font-weight: bold;
}
-table.listofstrings.horizontal td {
- padding-right: 5px;
+div.listofstrings.horizontal > div {
+ float: left;
+ margin-right: 5px;
}
table.listchoice {
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 1990135..4dc5d78 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1408,52 +1408,57 @@ function valuespec_toggle_dropdownn(oDropdown, divid) {
oDiv = null;
}
-function list_of_strings_init(tableid) {
- var oTable = document.getElementById(tableid);
- var oTBody = oTable.childNodes[0];
- var oTr = oTBody.childNodes[oTBody.childNodes.length - 1];
- var oTd = oTr.childNodes[0];
- for (var j in oTd.childNodes) {
- var o = oTd.childNodes[j];
+/* This function is called after the table with of input elements
+ has been rendered. It attaches the onFocus-function to the last
+ of the input elements. The reason is, that ListOfString does not render
+ the input fields itself. This does so other ValueSpec element
+ where we have no access to */
+function list_of_strings_init(divid) {
+ var oContainer = document.getElementById(divid);
+ var numChilds = oContainer.childNodes.length;
+ var oLastChild = oContainer.childNodes[numChilds-1];
+ list_of_strings_add_focus(oLastChild);
+}
+
+function list_of_strings_add_focus(oLastChild) {
+ /* look for <input> in last child node and attach focus handler to it. */
+ for (var j in oLastChild.childNodes) {
+ var o = oLastChild.childNodes[j];
if (o.tagName == "INPUT") {
o.onfocus = function(e) { return list_of_strings_extend(this); };
}
}
}
+/* Is called when the last input field in a ListOfString gets focus.
+ In that case a new input field is being appended. */
function list_of_strings_extend(oInput, j) {
+
+ /* The input field has a unique name like "extra_emails_2" for the field
with
+ the index 2. We need to convert this into "extra_emails_3". */
+
var oldName = oInput.name;
- // Transform e.g extra_emails_12 -> extra_emails_13
var splitted = oldName.split("_");
var num = 1 + parseInt(splitted[splitted.length-1]);
splitted[splitted.length-1] = "" + num;
var newName = splitted.join("_");
- var oTd = oInput.parentNode;
- var oTr = oTd.parentNode;
- var oTBody = oTr.parentNode;
- var oNewTd;
+ /* Now create a new <div> element as a copy from the current one and
+ replace this name. We do this by simply copying the HTML code. The
+ last field is always empty. Remember: ListOfStrings() always renders
+ one exceeding empty element. */
- var horiz = oTBody.parentNode.classList.contains("horizontal");
+ var oDiv = oInput.parentNode;
+ while (!oDiv.parentNode.classList.contains("listofstrings"))
+ oDiv = oDiv.parentNode;
+ var oContainer = oDiv.parentNode;
- if (!horiz) {
- var oNewTr = document.createElement("TR");
- oNewTr.innerHTML = oTr.innerHTML.replace('"' + oldName +
'"', '"' + newName + '"');
- oTBody.appendChild(oNewTr);
- oNewTd = oNewTr.childNodes[0];
- }
- else {
- var oNewTd = document.createElement("TD");
- oNewTd.innerHTML = oTd.innerHTML.replace('"' + oldName +
'"', '"' + newName + '"');
- oTr.appendChild(oNewTd);
- }
- for (var j in oNewTd.childNodes) {
- var o = oNewTd.childNodes[j];
- if (o.tagName == "INPUT") {
- o.onfocus = function(e) { return list_of_strings_extend(this); };
- }
- }
- // Remove handle from old last element
+ var oNewDiv = document.createElement("DIV");
+ oNewDiv.innerHTML = oDiv.innerHTML.replace('"' + oldName +
'"', '"' + newName + '"');
+ oContainer.appendChild(oNewDiv);
+
+ /* Move focus function from old last to new last input field */
+ list_of_strings_add_focus(oNewDiv);
oInput.onfocus = null;
}
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 682ce62..ec9953d 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -499,23 +499,15 @@ class ListOfStrings(ValueSpec):
while html.has_var(vp + "_%d" % nr):
html.del_var(vp + "_%d" % nr)
nr += 1
- html.write('<table class="listofstrings %s" border=0
cellspacing=0 cellpadding=0 id="%s">' % (
- self._vertical and "vertical" or "horizontal", vp))
- if not self._vertical:
- html.write('<tr>')
-
+
+ html.write('<div class="listofstrings %s"
id="%s">' % (self._vertical and 'vertical' or
'horizontal', vp))
+
for nr, s in enumerate(value + [""]):
- if self._vertical:
- html.write('<tr>')
- html.write('<td>')
+ html.write('<div>')
self._valuespec.render_input(vp + "_%d" % nr, s)
- html.write('</td>')
- if self._vertical:
- html.write('</tr>')
+ html.write('</div>')
+ html.write('</div>')
- if not self._vertical:
- html.write('</tr>')
- html.write('</table>')
html.javascript("list_of_strings_init('%s');" % vp);
def canonical_value(self):
diff --git a/web/plugins/wato/builtin_attributes.py
b/web/plugins/wato/builtin_attributes.py
index 3e85bcd..1ec9c75 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -45,3 +45,19 @@ declare_host_attribute(TextAttribute("ipaddress", _("IP
address"),
allow_empty = False),
show_in_table = True,
show_in_folder = False)
+
+class ParentsAttribute(ValueSpecAttribute):
+ def __init__(self):
+ ValueSpecAttribute.__init__(self, "parents",
+ ListOfStrings(
+ title = _("Parents"),
+ help = _("Hier kommt die Hilfe."),
+ orientation = "horizontal"))
+ def to_nagios(self, value):
+ if value:
+ return ",".join(value)
+
+
+declare_host_attribute(ParentsAttribute(),
+ show_in_table = True,
+ show_in_folder = True)