From f970c485cfb2571dd6d4ee6a1ad36958f1410b6a Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 7 Jul 2019 20:11:35 +0200 Subject: treewide: switch to shared isObject(), toArray() and sortedKeys() helpers Signed-off-by: Jo-Philipp Wich --- .../htdocs/luci-static/resources/tools/widgets.js | 28 +++++----------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'modules/luci-base/htdocs/luci-static/resources/tools/widgets.js') 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 669689449f..7f2997f173 100644 --- a/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js +++ b/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js @@ -4,22 +4,6 @@ 'require network'; 'require firewall'; -function toArray(x) { - if (x == null) - return []; - else if (Array.isArray(x)) - return x.map(String); - else if (typeof(x) == 'object') - return [ x ]; - - var s = String(x).trim(); - - if (s == '') - return []; - - return s.split(/\s+/); -} - var CBIZoneSelect = form.ListValue.extend({ __name__: 'CBI.ZoneSelect', @@ -45,7 +29,7 @@ var CBIZoneSelect = form.ListValue.extend({ }, renderWidget: function(section_id, option_index, cfgvalue) { - var values = toArray((cfgvalue != null) ? cfgvalue : this.default), + var values = L.toArray((cfgvalue != null) ? cfgvalue : this.default), choices = {}; if (this.allowlocal) { @@ -94,7 +78,7 @@ var CBIZoneSelect = form.ListValue.extend({ 'class': 'ifacebadge' + (network.getName() == this.network ? ' ifacebadge-active' : '') }, network.getName() + ': '); - var devices = network.isBridge() ? network.getDevices() : toArray(network.getDevice()); + var devices = network.isBridge() ? network.getDevices() : L.toArray(network.getDevice()); for (var k = 0; k < devices.length; k++) { span.appendChild(E('img', { @@ -168,7 +152,7 @@ var CBIZoneForwards = form.DummyValue.extend({ 'class': 'ifacebadge' + (network.getName() == this.network ? ' ifacebadge-active' : '') }, network.getName() + ': '); - var devices = network.isBridge() ? network.getDevices() : toArray(network.getDevice()); + var devices = network.isBridge() ? network.getDevices() : L.toArray(network.getDevice()); for (var k = 0; k < devices.length && devices[k]; k++) { span.appendChild(E('img', { @@ -243,7 +227,7 @@ var CBINetworkSelect = form.ListValue.extend({ renderIfaceBadge: function(network) { var span = E('span', { 'class': 'ifacebadge' }, network.getName() + ': '), - devices = network.isBridge() ? network.getDevices() : toArray(network.getDevice()); + devices = network.isBridge() ? network.getDevices() : L.toArray(network.getDevice()); for (var j = 0; j < devices.length && devices[j]; j++) { span.appendChild(E('img', { @@ -261,7 +245,7 @@ var CBINetworkSelect = form.ListValue.extend({ }, renderWidget: function(section_id, option_index, cfgvalue) { - var values = toArray((cfgvalue != null) ? cfgvalue : this.default), + var values = L.toArray((cfgvalue != null) ? cfgvalue : this.default), choices = {}, checked = {}; @@ -312,7 +296,7 @@ var CBINetworkSelect = form.ListValue.extend({ textvalue: function(section_id) { var cfgvalue = this.cfgvalue(section_id), - values = toArray((cfgvalue != null) ? cfgvalue : this.default), + values = L.toArray((cfgvalue != null) ? cfgvalue : this.default), rv = E([]); for (var i = 0; i < (this.networks || []).length; i++) { -- cgit v1.2.3