From f6527cd1e850286708787c6a98fcd5c1cfc417d9 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 13 Apr 2014 22:42:10 +0200 Subject: [PATCH] luci2: add L.NetworkModel.Interface.renderBadge() and use it in L.cbi.NetworkList widget --- luci2/htdocs/luci2/luci2.js | 44 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/luci2/htdocs/luci2/luci2.js b/luci2/htdocs/luci2/luci2.js index 5947791..5e95105 100644 --- a/luci2/htdocs/luci2/luci2.js +++ b/luci2/htdocs/luci2/luci2.js @@ -2737,6 +2737,30 @@ function LuCI2() return dev.getTrafficHistory(); }, + renderBadge: function() + { + var badge = $('') + .addClass('badge') + .text('%s: '.format(this.name())); + + var dev = this.getDevice(); + var subdevs = this.getSubdevices(); + + if (subdevs.length) + for (var j = 0; j < subdevs.length; j++) + badge.append($('') + .attr('src', subdevs[j].icon()) + .attr('title', '%s (%s)'.format(subdevs[j].description(), subdevs[j].name() || '?'))); + else if (dev) + badge.append($('') + .attr('src', dev.icon()) + .attr('title', '%s (%s)'.format(dev.description(), dev.name() || '?'))); + else + badge.append($('').text(L.tr('(No devices attached)'))); + + return badge; + }, + setDevices: function(devs) { var dev = this.getPhysdev(); @@ -6010,30 +6034,16 @@ function LuCI2() for (var i = 0; i < interfaces.length; i++) { var iface = interfaces[i]; - var badge = $('') - .addClass('badge') - .text('%s: '.format(iface.name())); - - var dev = iface.getDevice(); - var subdevs = iface.getSubdevices(); - - if (subdevs.length) - for (var j = 0; j < subdevs.length; j++) - badge.append(this._device_icon(subdevs[j])); - else if (dev) - badge.append(this._device_icon(dev)); - else - badge.append($('').text(L.tr('(No devices attached)'))); $('
  • ') .append($('