Module: check_mk
Branch: master
Commit: df5981f3dd71de50aadfebd74d641bf9898adc91
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=df5981f3dd71de…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Oct 22 12:03:24 2015 +0200
ListOf(): Allow to specify render text for empty list
---
web/htdocs/valuespec.py | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 42272b5..ff5b17e 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -837,15 +837,16 @@ class ListOfIntegers(ListOfStrings):
class ListOf(ValueSpec):
def __init__(self, valuespec, **kwargs):
ValueSpec.__init__(self, **kwargs)
- self._valuespec = valuespec
- self._magic = kwargs.get("magic", "@!@")
- self._rowlabel = kwargs.get("row_label")
- self._add_label = kwargs.get("add_label", _("Add new
element"))
- self._del_label = kwargs.get("del_label", _("Delete this
entry"))
- self._movable = kwargs.get("movable", True)
- self._totext = kwargs.get("totext")
- self._allow_empty = kwargs.get("allow_empty", True)
- self._empty_text = kwargs.get("empty_text")
+ self._valuespec = valuespec
+ self._magic = kwargs.get("magic", "@!@")
+ self._rowlabel = kwargs.get("row_label")
+ self._add_label = kwargs.get("add_label", _("Add new
element"))
+ self._del_label = kwargs.get("del_label", _("Delete this
entry"))
+ self._movable = kwargs.get("movable", True)
+ self._totext = kwargs.get("totext") # pattern with option %d
+ self._text_if_empty = kwargs.get("text_if_empty", _("No
entries"))
+ self._allow_empty = kwargs.get("allow_empty", True)
+ self._empty_text = kwargs.get("empty_text") # complain text if
empty
if not self._empty_text:
self._empty_text = _("Please specify at least one entry")
@@ -930,21 +931,26 @@ class ListOf(ValueSpec):
"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 []
+
def value_to_text(self, value):
if self._totext:
if "%d" in self._totext:
return self._totext % len(value)
else:
return self._totext
+ elif not value:
+ return self._text_if_empty
else:
s = '<table>'
for v in value:
s += '<tr><td>%s</td></tr>' %
self._valuespec.value_to_text(v)
return s + '</table>'
+
def get_indexes(self, varprefix):
count = int(html.var(varprefix + "_count"))
n = 1