Module: check_mk
Branch: master
Commit: 4a4613b4e3d14193572a586cfe7be064322ff5d7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4a4613b4e3d141…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Oct 28 15:09:51 2014 +0100
Reworked duallist choice valuespec to make selection and search possible
---
web/htdocs/check_mk.css | 20 ++++++++++++++++++++
web/htdocs/js/checkmk.js | 5 ++++-
web/htdocs/valuespec.py | 29 ++++++++++++++++++++++-------
3 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/web/htdocs/check_mk.css b/web/htdocs/check_mk.css
index 1863640..34c105c 100644
--- a/web/htdocs/check_mk.css
+++ b/web/htdocs/check_mk.css
@@ -455,6 +455,26 @@ table.valuespec_listof .unused {
display: none;
}
+table.vs_duallist td.head {
+ text-align:center;
+}
+
+table.vs_duallist a.control {
+ display: inline-block;
+ width: 14px;
+ border: 1px solid #fff;
+ text-decoration: none;
+ text-align: center;
+}
+
+table.vs_duallist a.control.add {
+ float: right;
+}
+
+table.vs_duallist a.control.del {
+ float: left;
+}
+
textarea.tt {
font-family: monospace;
}
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index e09073c..56e9e16 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1704,7 +1704,8 @@ function vs_passwordspec_randomize(img) {
oInput.value = password;
}
-function vs_duallist_switch(field, varprefix, keeporder) {
+function vs_duallist_switch(field_suffix, varprefix, keeporder) {
+ var field = document.getElementById(varprefix + '_' + field_suffix);
if (field.id != varprefix + '_selected') {
// The other field is the one without "_unselected" suffix
var other_id = varprefix + '_selected';
@@ -1725,6 +1726,8 @@ function vs_duallist_switch(field, varprefix, keeporder) {
// Move the selected option to the other select field
var selected = field.options[field.selectedIndex];
+ if (typeof selected === 'undefined')
+ return; // when add/remove clicked, but none selected
field.removeChild(selected);
// Determine the correct child to insert. If keeporder is being set,
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 4acb5ab..13d1155 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1539,6 +1539,7 @@ class DualListChoice(ListChoice):
ListChoice.__init__(self, **kwargs)
self._autoheight = kwargs.get("autoheight", True)
self._custom_order = kwargs.get("custom_order", False)
+ self._instant_add = kwargs.get("instant_add", False)
def render_input(self, varprefix, value):
self.load_elements()
@@ -1564,20 +1565,34 @@ class DualListChoice(ListChoice):
else:
unselected.append(e)
-
- html.write('<table><tr><td>')
- html.write(_('Available:'))
- html.write('</td><td>')
- html.write(_('Selected:'))
+ select_func = 'vs_duallist_switch(\'unselected\', \'%s\',
%d);' % (varprefix, self._custom_order and 1 or 0)
+ unselect_func = 'vs_duallist_switch(\'selected\', \'%s\',
1);' % varprefix
+
+ html.write('<table class="vs_duallist"><tr><td
class="head">')
+ html.write(_('Available'))
+ if not self._instant_add:
+ html.write('<a href="javascript:%s" class="control
add">></a>' % select_func)
+ html.write('</td><td class="head">')
+ html.write(_('Selected'))
+ if not self._instant_add:
+ html.write('<a href="javascript:%s" class="control
del"><</a>' % unselect_func)
html.write('</td></tr><tr><td>')
+
+ if self._instant_add:
+ onchange_unselected = select_func
+ onchange_selected = unselect_func
+ else:
+ onchange_unselected = ''
+ onchange_selected = ''
+
html.sorted_select(varprefix + '_unselected', unselected,
attrs = {'size': 5, 'style': self._autoheight
and 'height:auto' or ''},
- onchange = 'vs_duallist_switch(this, \'%s\',
%d);' % (varprefix, self._custom_order and 1 or 0))
+ onchange = onchange_unselected)
html.write('</td><td>')
func = self._custom_order and html.select or html.sorted_select
func(varprefix + '_selected', selected,
attrs = {'size': 5, 'style': self._autoheight
and 'height:auto' or '', 'multiple': 'multiple'},
- onchange = 'vs_duallist_switch(this, \'%s\',
1);' % varprefix)
+ onchange = onchange_selected)
html.write('</td></tr></table>')
html.hidden_field(varprefix, '|'.join([k for k, v in selected]), id =
varprefix, add_var = True)