Module: check_mk
Branch: master
Commit: 1aa55a11b885d3a539237ec4739229f1b7c6939f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1aa55a11b885d3…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Mar 8 17:26:56 2012 +0100
WATO: ListOf: move-buttons work, still not persist
---
web/htdocs/htmllib.py | 4 +-
web/htdocs/js/checkmk.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++
web/htdocs/pages.css | 4 +++
web/htdocs/valuespec.py | 14 +++++++-----
web/htdocs/wato.css | 3 +-
5 files changed, 65 insertions(+), 9 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 0576c16..bad1ee9 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -350,10 +350,10 @@ class html:
'src="images/button_%s_lo.png" '
'onmouseover=\"hilite_icon(this, 1)\" '
'onmouseout=\"hilite_icon(this, 0)\">'
- '</a>\n' % (url, onclick, style, help, icon))
+ '</a>' % (url, onclick, style, help, icon))
def empty_icon_button(self):
- self.write('<img class="iconbutton trans"
src="images/trans.png">\n')
+ self.write('<img class="iconbutton trans"
src="images/trans.png">')
def jsbutton(self, varname, text, onclick, style=''):
if style:
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 20abfaf..20aab3a 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1458,12 +1458,14 @@ function valuespec_listof_add(varprefix, magic) {
var oTable = document.getElementById(varprefix + "_table");
if (count == 0) { // first: no <tbody> present!
oTable.innerHTML = "<tbody><tr>" + htmlcode +
"</tr></tbody>";
+ valuespec_listof_fixarrows(oTable.childNodes[0]);
}
else {
var oTbody = oTable.childNodes[0];
var oTr = document.createElement("tr")
oTr.innerHTML = htmlcode;
oTbody.appendChild(oTr);
+ valuespec_listof_fixarrows(oTbody);
}
}
@@ -1476,3 +1478,50 @@ function valuespec_listof_delete(oA, varprefix, nr) {
oTdContent.innerHTML = '<input type=hidden name="_' + varprefix +
'_deleted_' + nr + '" value=1>'
oTr.style.display = "none";
}
+
+function valuespec_listof_move(oA, varprefix, nr, where) {
+ var oTr = oA.parentNode.parentNode; // TR to move
+ var oTbody = oTr.parentNode;
+
+ if (where == "up") {
+ var sib = oTr.previousSibling;
+ oTbody.removeChild(oTr);
+ oTbody.insertBefore(oTr, sib);
+ }
+ else /* down */ {
+ var sib = oTr.nextSibling;
+ oTbody.removeChild(oTr);
+ if (sib == oTbody.lastChild)
+ oTbody.appendChild(oTr);
+ else
+ oTbody.insertBefore(oTr, sib.nextSibling);
+ }
+ valuespec_listof_fixarrows(oTbody);
+}
+
+
+function valuespec_listof_fixarrows(oTbody) {
+ for (var i in oTbody.childNodes) {
+ var oTd = oTbody.childNodes[i].childNodes[0]; /* TD with buttons */
+ var oUpTrans = oTd.childNodes[1];
+ var oUp = oTd.childNodes[2];
+ if (i == 0) {
+ oUpTrans.style.display = "";
+ oUp.style.display = "none";
+ }
+ else {
+ oUpTrans.style.display = "none";
+ oUp.style.display = "";
+ }
+ var oDownTrans = oTd.childNodes[3];
+ var oDown = oTd.childNodes[4];
+ if (i >= oTbody.childNodes.length - 1) {
+ oDownTrans.style.display = "";
+ oDown.style.display = "none";
+ }
+ else {
+ oDownTrans.style.display = "none";
+ oDown.style.display = "";
+ }
+ }
+}
diff --git a/web/htdocs/pages.css b/web/htdocs/pages.css
index 6a4915b..a3e4d48 100644
--- a/web/htdocs/pages.css
+++ b/web/htdocs/pages.css
@@ -324,6 +324,10 @@ tr.groupheader a:hover {
img.iconbutton {
width: 20px;
height: 20px;
+ padding: 0px 2px;
+}
+img.iconbutton.trans {
+ width: 100px;
}
/*-------------------------------------------------------------------------.
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 7622d1f..e630346 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -503,14 +503,15 @@ class ListOf(ValueSpec):
js = "valuespec_listof_delete(this, '%s', '%s')" % (vp,
nr)
html.icon_button("#", _("Delete this entry"),
"delete", onclick=js)
- def move_button(self, vp, nr, where, visible):
+ def move_button(self, vp, nr, where):
js = "valuespec_listof_move(this, '%s', '%s',
'%s')" % (vp, nr, where)
where_name = {
"up" : _("up"),
"down" : _("down"),
}
+ html.empty_icon_button() # needed as placeholder
html.icon_button("#", _("Move this entry %s") %
where_name[where],
- where, onclick=js, style = not visible and "display: none;" or
"")
+ where, onclick=js)
# Implementation idea: we render our element-valuespec
# once in a hidden div that is not evaluated. All occurances
@@ -526,8 +527,8 @@ class ListOf(ValueSpec):
html.write('<table style="display:none"
id="%s_prototype">' % varprefix)
html.write('<tr><td class=vlof_buttons>')
self.del_button(varprefix, self._magic)
- self.move_button(varprefix, self._magic, "up", True)
- self.move_button(varprefix, self._magic, "down", True)
+ self.move_button(varprefix, self._magic, "up")
+ self.move_button(varprefix, self._magic, "down")
html.write('</td><td class=vlof_content>')
self._valuespec.render_input(
varprefix + "_" + self._magic,
@@ -539,8 +540,8 @@ class ListOf(ValueSpec):
for nr, v in enumerate(value):
html.write('<tr><td class=vlof_buttons>')
self.del_button(varprefix, nr+1)
- self.move_button(varprefix, self._magic, "up", nr > 0)
- self.move_button(varprefix, self._magic, "down", nr < len(value)
- 1)
+ self.move_button(varprefix, self._magic, "up") # visibility fixed
by javascript
+ self.move_button(varprefix, self._magic, "down")
html.write("</td><td class=vlof_content>")
self._valuespec.render_input(varprefix + "_%d" % (nr+1), v)
html.write("</td></tr>")
@@ -548,6 +549,7 @@ class ListOf(ValueSpec):
html.write("<br>")
html.jsbutton(varprefix + "_add", self._add_label,
"valuespec_listof_add('%s', '%s')" % (varprefix,
self._magic));
+
html.javascript("valuespec_listof_fixarrows(document.getElementById('%s_table').childNodes[0]);"
% varprefix)
def canonical_value(self):
return []
diff --git a/web/htdocs/wato.css b/web/htdocs/wato.css
index 71862de..0611f5a 100644
--- a/web/htdocs/wato.css
+++ b/web/htdocs/wato.css
@@ -306,7 +306,8 @@ table.validationerror img {
}
.wato img.trans {
- width: 24px;
+ width: 16px;
+ height: 16px;
}
.wato td.value img {
width: 20px;