Module: check_mk
Branch: master
Commit: 7edbc603f9dcd889045e05bd291969eda509ce50
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7edbc603f9dcd8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Nov 5 11:33:05 2014 +0100
DualListChoice now deals totally correct with multiple selected elements
---
web/htdocs/js/checkmk.js | 58 +++++++++++++++++++++++++++-------------------
web/htdocs/valuespec.py | 2 ++
2 files changed, 36 insertions(+), 24 deletions(-)
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 5e9d4b9..2b0fcfb 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1746,35 +1746,45 @@ function vs_duallist_switch(field_suffix, varprefix, keeporder) {
if (!helper)
return;
- // 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,
- // then new elements will aways be appended. That way the user can
- // create an order of his choice. This is being used if DualListChoice
- // has the option custom_order = True
- var sibling = false;
-
- if (!keeporder) {
- sibling = other_field.firstChild;
- while (sibling != null) {
- if (sibling.nodeType == 1 && sibling.label.toLowerCase() >
selected.label.toLowerCase())
- break;
- sibling = sibling.nextSibling
+ // Move the selected options to the other select field
+ var selected = [];
+ for (var i = 0; i < field.options.length; i++) {
+ if (field.options[i].selected) {
+ selected.push(field.options[i]);
}
}
+ if (selected.length == 0)
+ return; // when add/remove clicked, but none selected
- if (sibling)
- other_field.insertBefore(selected, sibling);
- else
- other_field.appendChild(selected);
+ // Now loop over all selected elements and add them to the other field
+ for (var i = 0; i < selected.length; i++) {
+ // remove option from origin
+ field.removeChild(selected[i]);
+
+ // Determine the correct child to insert. If keeporder is being set,
+ // then new elements will aways be appended. That way the user can
+ // create an order of his choice. This is being used if DualListChoice
+ // has the option custom_order = True
+ var sibling = false;
+
+ if (!keeporder) {
+ sibling = other_field.firstChild;
+ while (sibling != null) {
+ if (sibling.nodeType == 1 && sibling.label.toLowerCase() >
selected[i].label.toLowerCase())
+ break;
+ sibling = sibling.nextSibling
+ }
+ }
+
+ if (sibling)
+ other_field.insertBefore(selected[i], sibling);
+ else
+ other_field.appendChild(selected[i]);
- selected.selected = false;
+ selected[i].selected = false;
+ }
- // add remove from internal helper field
+ // Update internal helper field which contains a list of all selected keys
if (positive)
var pos_field = other_field;
else
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index dc72c4d..10088d8 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1597,6 +1597,7 @@ class DualListChoice(ListChoice):
html.sorted_select(varprefix + '_unselected', unselected,
attrs = {
'size' : 5,
+ 'multiple' : 'multiple',
'style' : self._autoheight and
'height:auto' or '',
'ondblclick' : not self._instant_add and
select_func or '',
},
@@ -1606,6 +1607,7 @@ class DualListChoice(ListChoice):
func(varprefix + '_selected', selected,
attrs = {
'size' : 5,
+ 'multiple' : 'multiple',
'style' : self._autoheight and
'height:auto' or '',
'ondblclick' : not self._instant_add and
unselect_func or '',
},