-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidgets.js
More file actions
67 lines (61 loc) · 1.48 KB
/
widgets.js
File metadata and controls
67 lines (61 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var MultiSelect = function (node, varname, count, choices) {
this.node = node;
this.varname = varname;
this.count = count;
this.choices = choices;
// init
window[this.varname] = [];
for (var i = 0; i < this.count; i++) {
this.newEmptySelect();
}
this.onchange();
var obj = this;
node.change(function () {
obj.onchange();
});
}
MultiSelect.prototype.onchange = function () {
window[this.varname] = [];
// extract selected values
// delete all options except the selected and the __NULL__ option
// delete all unused (__NULL__ selected) selects except the last
var obj = this;
var nullAtEnd = false;
var selects = this.node.children();
selects.each(function (i) {
var value = $(this).val();
if (value != "__NULL__") {
window[obj.varname].push(value);
} else if (this.count) {
if (i == selects.length - 1) {
nullAtEnd = true;
} else {
$(this).remove();
return true;
}
}
$(this).children('[value!="__NULL__"]')
.not(':selected').remove();
});
// append new unused select if needed
if (this.count == 0 && !nullAtEnd) {
this.newEmptySelect();
}
// reappend all options that are not yet choosen
var selects = this.node.children();
for (var i in this.choices) {
if (window[this.varname].indexOf(i) == -1) {
selects.append($('<option>')
.text(this.choices[i])
.val(i));
}
}
}
MultiSelect.prototype.newEmptySelect = function () {
this.node.append($('<select>')
.append($('<option>')
.text("(Nichts)")
.val('__NULL__')
)
);
}