summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-base/htdocs')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/form.js32
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/ui.js46
2 files changed, 67 insertions, 11 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js
index 8d673a877e..4ce5e45ebe 100644
--- a/modules/luci-base/htdocs/luci-static/resources/form.js
+++ b/modules/luci-base/htdocs/luci-static/resources/form.js
@@ -403,11 +403,12 @@ var CBIMap = CBINode.extend({
for (var i = 0; i < depends.length; i++) {
var istat = true,
- reverse = false;
+ reverse = depends[i]['!reverse'],
+ contains = depends[i]['!contains'];
for (var dep in depends[i]) {
- if (dep == '!reverse') {
- reverse = true;
+ if (dep == '!reverse' || dep == '!contains') {
+ continue;
}
else if (dep == '!default') {
def = true;
@@ -417,7 +418,11 @@ var CBIMap = CBINode.extend({
var res = this.lookupOption(dep, section_id, config_name),
val = (res && res[0].isActive(res[1])) ? res[0].formvalue(res[1]) : null;
- istat = (istat && isEqual(val, depends[i][dep]));
+ var equal = contains
+ ? isContained(val, depends[i][dep])
+ : isEqual(val, depends[i][dep]);
+
+ istat = (istat && equal);
}
}
@@ -633,6 +638,23 @@ var isEqual = function(x, y) {
return true;
};
+var isContained = function(x, y) {
+ if (Array.isArray(x)) {
+ for (var i = 0; i < x.length; i++)
+ if (x[i] == y)
+ return true;
+ }
+ else if (L.isObject(x)) {
+ if (x.hasOwnProperty(y) && x[y] != null)
+ return true;
+ }
+ else if (typeof(x) == 'string') {
+ return (x.indexOf(y) > -1);
+ }
+
+ return false;
+};
+
var CBIAbstractValue = CBINode.extend({
__init__: function(map, section, option /*, ... */) {
this.super('__init__', this.varargs(arguments, 3));
@@ -1572,7 +1594,7 @@ var CBIValue = CBIAbstractValue.extend({
this.keylist.push(String(key));
this.vallist = this.vallist || [];
- this.vallist.push(String(val != null ? val : key));
+ this.vallist.push(L.dom.elem(val) ? val : String(val != null ? val : key));
},
render: function(option_index, section_id, in_table) {
diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js
index 774d4a6654..08edaa1475 100644
--- a/modules/luci-base/htdocs/luci-static/resources/ui.js
+++ b/modules/luci-base/htdocs/luci-static/resources/ui.js
@@ -442,11 +442,17 @@ var UIDropdown = UIElement.extend({
if (!this.choices.hasOwnProperty(this.values[i]))
keys.push(this.values[i]);
- for (var i = 0; i < keys.length; i++)
+ for (var i = 0; i < keys.length; i++) {
+ var label = this.choices[keys[i]];
+
+ if (L.dom.elem(label))
+ label = label.cloneNode(true);
+
sb.lastElementChild.appendChild(E('li', {
'data-value': keys[i],
'selected': (this.values.indexOf(keys[i]) > -1) ? '' : null
- }, this.choices[keys[i]] || keys[i]));
+ }, [ label || keys[i] ]));
+ }
if (this.options.create) {
var createEl = E('input', {
@@ -1320,7 +1326,11 @@ var UIDynamicList = UIElement.extend({
}, E('div', { 'class': 'add-item' }));
if (this.choices) {
+ if (this.options.placeholder != null)
+ this.options.select_placeholder = this.options.placeholder;
+
var cbox = new UICombobox(null, this.choices, this.options);
+
dl.lastElementChild.appendChild(cbox.render());
}
else {
@@ -1339,9 +1349,14 @@ var UIDynamicList = UIElement.extend({
true, this.options.validate, 'blur', 'keyup');
}
- for (var i = 0; i < this.values.length; i++)
- this.addItem(dl, this.values[i],
- this.choices ? this.choices[this.values[i]] : null);
+ for (var i = 0; i < this.values.length; i++) {
+ var label = this.choices ? this.choices[this.values[i]] : null;
+
+ if (L.dom.elem(label))
+ label = label.cloneNode(true);
+
+ this.addItem(dl, this.values[i], label);
+ }
return this.bind(dl);
},
@@ -1458,7 +1473,16 @@ var UIDynamicList = UIElement.extend({
sbVal.element.setAttribute('dynlistcustom', '');
}
- this.addItem(dl, sbVal.value, sbVal.text, true);
+ var label = sbVal.text;
+
+ if (sbVal.element) {
+ label = E([]);
+
+ for (var i = 0; i < sbVal.element.childNodes.length; i++)
+ label.appendChild(sbVal.element.childNodes[i].cloneNode(true));
+ }
+
+ this.addItem(dl, sbVal.value, label, true);
},
handleKeydown: function(ev) {
@@ -1531,6 +1555,16 @@ var UIDynamicList = UIElement.extend({
for (var i = 0; i < values.length; i++)
this.addItem(this.node, values[i],
this.choices ? this.choices[values[i]] : null);
+ },
+
+ addChoices: function(values, labels) {
+ var dl = this.node.lastElementChild.firstElementChild;
+ L.dom.callClassMethod(dl, 'addChoices', values, labels);
+ },
+
+ clearChoices: function() {
+ var dl = this.node.lastElementChild.firstElementChild;
+ L.dom.callClassMethod(dl, 'clearChoices');
}
});