luci-base: widgets.js: add textvalude representation for network select
authorJo-Philipp Wich <jo@mein.io>
Sun, 7 Jul 2019 17:08:03 +0000 (19:08 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sun, 7 Jul 2019 17:12:59 +0000 (19:12 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/tools/widgets.js

index b1917eb356edd054da63ba8d21d5ab437c25de5d..669689449f0d3a0d0294548fde9c324840c7ded5 100644 (file)
@@ -241,6 +241,25 @@ var CBINetworkSelect = form.ListValue.extend({
                return true;
        },
 
+       renderIfaceBadge: function(network) {
+               var span = E('span', { 'class': 'ifacebadge' }, network.getName() + ': '),
+                   devices = network.isBridge() ? network.getDevices() : toArray(network.getDevice());
+
+               for (var j = 0; j < devices.length && devices[j]; j++) {
+                       span.appendChild(E('img', {
+                               'title': devices[j].getI18n(),
+                               'src': L.resource('icons/%s%s.png'.format(devices[j].getType(), devices[j].isUp() ? '' : '_disabled'))
+                       }));
+               }
+
+               if (!devices.length) {
+                       span.appendChild(E('em', { 'class': 'hide-close' }, _('(no interfaces attached)')));
+                       span.appendChild(E('em', { 'class': 'hide-open' }, '-'));
+               }
+
+               return span;
+       },
+
        renderWidget: function(section_id, option_index, cfgvalue) {
                var values = toArray((cfgvalue != null) ? cfgvalue : this.default),
                    choices = {},
@@ -264,25 +283,10 @@ var CBINetworkSelect = form.ListValue.extend({
                        if (this.novirtual && network.isVirtual())
                                continue;
 
-                       var span = E('span', { 'class': 'ifacebadge' }, network.getName() + ': '),
-                           devices = network.isBridge() ? network.getDevices() : toArray(network.getDevice());
-
-                       for (var j = 0; j < devices.length && devices[j]; j++) {
-                               span.appendChild(E('img', {
-                                       'title': devices[j].getI18n(),
-                                       'src': L.resource('icons/%s%s.png'.format(devices[j].getType(), devices[j].isUp() ? '' : '_disabled'))
-                               }));
-                       }
-
-                       if (!devices.length) {
-                               span.appendChild(E('em', { 'class': 'hide-close' }, _('(no interfaces attached)')));
-                               span.appendChild(E('em', { 'class': 'hide-open' }, '-'));
-                       }
-
                        if (checked[name])
                                values.push(name);
 
-                       choices[name] = span;
+                       choices[name] = this.renderIfaceBadge(network);
                }
 
                var widget = new ui.Dropdown(this.multiple ? values : values[0], choices, {
@@ -305,6 +309,30 @@ var CBINetworkSelect = form.ListValue.extend({
 
                return widget.render();
        },
+
+       textvalue: function(section_id) {
+               var cfgvalue = this.cfgvalue(section_id),
+                   values = toArray((cfgvalue != null) ? cfgvalue : this.default),
+                   rv = E([]);
+
+               for (var i = 0; i < (this.networks || []).length; i++) {
+                       var network = this.networks[i],
+                           name = network.getName();
+
+                       if (values.indexOf(name) == -1)
+                               continue;
+
+                       if (rv.length)
+                               L.dom.append(rv, ' ');
+
+                       L.dom.append(rv, this.renderIfaceBadge(network));
+               }
+
+               if (!rv.firstChild)
+                       rv.appendChild(E('em', _('unspecified')));
+
+               return rv;
+       },
 });