Module: check_mk
Branch: master
Commit: 8976c77dbeee44370c08e1dab63d0502bcca1f11
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8976c77dbeee44…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Aug 31 09:45:03 2018 +0200
6518 FIX Fixed sorting of dual list choices (like network interface types)
When e.g. editing the network interface port types to discovery in the "Network
Interface and Switch Port Discovery" ruleset,
the list of port types was initially not sorted correctly. Even when the list was sorted
correctly, the sorting was not kept
when moving options between both fields. Both issues have now been fixed.
Change-Id: Id4a44498c156dbe1fde70dcdb3dba43583c68831
---
.werks/6518 | 13 ++++++++++++
web/htdocs/js/checkmk.js | 52 +++++++++++++++++++++++++++++-------------------
2 files changed, 45 insertions(+), 20 deletions(-)
diff --git a/.werks/6518 b/.werks/6518
new file mode 100644
index 0000000..a7935af
--- /dev/null
+++ b/.werks/6518
@@ -0,0 +1,13 @@
+Title: Fixed sorting of dual list choices (like network interface types)
+Level: 1
+Component: wato
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1535701338
+
+When e.g. editing the network interface port types to discovery in the "Network
Interface and Switch Port Discovery" ruleset,
+the list of port types was initially not sorted correctly. Even when the list was sorted
correctly, the sorting was not kept
+when moving options between both fields. Both issues have now been fixed.
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 6a781c4..2238a60 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -235,6 +235,28 @@ function mouse_offset_to_middle(obj, event){
};
}
+function sort_select(select, cmp_func) {
+ var choices = [];
+ for (var i = 0; i < select.options.length;i++) {
+ choices[i] = [];
+ choices[i][0] = select.options[i].text;
+ choices[i][1] = select.options[i].value;
+ }
+
+ choices.sort(cmp_func);
+ while (select.options.length > 0) {
+ select.options[0] = null;
+ }
+
+ for (var i = 0; i < choices.length;i++) {
+ var op = new Option(choices[i][0], choices[i][1]);
+ select.options[i] = op;
+ }
+
+ return;
+}
+
+
//#.
//# .-Events-------------------------------------------------------------.
//# | _____ _ |
@@ -2408,30 +2430,20 @@ function vs_duallist_switch(field_suffix, varprefix, keeporder) {
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.children[0];
- 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]);
+ other_field.appendChild(selected[i]);
selected[i].selected = false;
}
+ // 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
+ if (!keeporder) {
+ var collator = new Intl.Collator(undefined, {numeric: true, sensitivity:
'base'});
+ sort_select(other_field, collator.compare);
+ }
+
// Update internal helper field which contains a list of all selected keys
var pos_field = positive ? other_field : field;