Module: check_mk
Branch: master
Commit: da20f198d5dd932b5a4247932d8613c8800f6a21
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=da20f198d5dd93…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Mar 8 16:19:21 2012 +0100
ListOf(): add buttns for moving up and done
still not functional, though
---
web/htdocs/check_mk.css | 1 +
web/htdocs/htmllib.py | 16 +++++++++++-----
web/htdocs/pages.css | 6 +++++-
web/htdocs/valuespec.py | 13 +++++++++++++
4 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/web/htdocs/check_mk.css b/web/htdocs/check_mk.css
index fc3215e..5017605 100644
--- a/web/htdocs/check_mk.css
+++ b/web/htdocs/check_mk.css
@@ -318,6 +318,7 @@ table.vs_date th {
table.valuespec_listof td.vlof_buttons {
margin-right: 5px;
+ white-space: nowrap;
}
table.valuespec_listof td.vlof_content {
border: 1px solid white;
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index c3e8c33..0576c16 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -337,17 +337,20 @@ class html:
def empty_icon(self):
self.write('<img class=icon src="images/trans.png">')
- def icon_button(self, url, help, icon, onclick=None):
+ def icon_button(self, url, help, icon, onclick=None, style=""):
if onclick:
onclick = " onclick=\"%s\"" % onclick
url = "#"
- self.write('<a href="%s"%s>'
+ if style:
+ style = ' style="%s"' % style
+
+ self.write('<a href="%s"%s%s>'
'<img align=absmiddle class=iconbutton title="%s"
'
'src="images/button_%s_lo.png" '
'onmouseover=\"hilite_icon(this, 1)\" '
'onmouseout=\"hilite_icon(this, 0)\">'
- '</a>\n' % (url, onclick, help, icon))
+ '</a>\n' % (url, onclick, style, help, icon))
def empty_icon_button(self):
self.write('<img class="iconbutton trans"
src="images/trans.png">\n')
@@ -532,7 +535,9 @@ class html:
add_attr = [] # do not use [] as default element, it will be a global
variable!
error = self.user_errors.get(varname)
if error:
- self.write("<x class=inputerror><span
class=checkbox>")
+ self.write("<x class=inputerror>")
+
+ self.write("<span class=checkbox>")
# Problem with checkboxes: The browser will add the variable
# only to the URL if the box is checked. So in order to detect
# wether we should add the default value, we need to detect
@@ -555,8 +560,9 @@ class html:
self.form_vars.append(varname)
if label:
self.write('<label for="%s">%s</label>\n' %
(id, label))
+ self.write("</span>")
if error:
- self.write("</span></x>")
+ self.write("</x>")
# Check if the current form is currently filled in (i.e. we display
# the form a second time while showing value typed in at the first
diff --git a/web/htdocs/pages.css b/web/htdocs/pages.css
index cec1284..6a4915b 100644
--- a/web/htdocs/pages.css
+++ b/web/htdocs/pages.css
@@ -475,7 +475,7 @@ input.date, input.time {
font-family: monospace;
}
-.inputerror input, .inputerror textarea, span.checkbox {
+.inputerror input, .inputerror textarea, .inputerror span.checkbox {
background-color: #f84;
}
@@ -490,6 +490,10 @@ input.date, input.time {
margin: 1px;
}
+span.checkbox {
+ white-space: nowrap;
+}
+
/*-------------------------------------------------------------------------.
| _ _ _ |
| / \ ___| |_(_) ___ _ __ ___ |
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 3291e5b..7622d1f 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -503,6 +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):
+ js = "valuespec_listof_move(this, '%s', '%s',
'%s')" % (vp, nr, where)
+ where_name = {
+ "up" : _("up"),
+ "down" : _("down"),
+ }
+ html.icon_button("#", _("Move this entry %s") %
where_name[where],
+ where, onclick=js, style = not visible and "display: none;" or
"")
+
# Implementation idea: we render our element-valuespec
# once in a hidden div that is not evaluated. All occurances
# of a magic string are replaced with the actual number
@@ -517,6 +526,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)
html.write('</td><td class=vlof_content>')
self._valuespec.render_input(
varprefix + "_" + self._magic,
@@ -528,6 +539,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)
html.write("</td><td class=vlof_content>")
self._valuespec.render_input(varprefix + "_%d" % (nr+1), v)
html.write("</td></tr>")