From f8e6caf5525b802dfbaf150ca3d64f92620b2d50 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 7 Jul 2019 19:08:03 +0200 Subject: luci-base: widgets.js: add textvalude representation for network select Signed-off-by: Jo-Philipp Wich --- .../htdocs/luci-static/resources/tools/widgets.js | 60 ++++++++++++++++------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js b/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js index b1917eb356..669689449f 100644 --- a/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js +++ b/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js @@ -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; + }, }); -- cgit v1.2.3