From 8054344747e63d78b79cc3ba58287febf4b78e46 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 1 Feb 2014 18:07:47 +0000 Subject: [PATCH] luci2: Implement LuCI2.cbi.DeviceList widget --- luci2/htdocs/luci2/luci2.js | 162 ++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/luci2/htdocs/luci2/luci2.js b/luci2/htdocs/luci2/luci2.js index 887aec8..996c18d 100644 --- a/luci2/htdocs/luci2/luci2.js +++ b/luci2/htdocs/luci2/luci2.js @@ -6126,6 +6126,168 @@ function LuCI2() } }); + this.cbi.DeviceList = this.cbi.NetworkList.extend({ + _ev_focus: function(ev) + { + var self = ev.data.self; + var input = $(this); + + input.parent().prev().prop('checked', true); + }, + + _ev_blur: function(ev) + { + ev.which = 10; + ev.data.self._ev_keydown.call(this, ev); + }, + + _ev_keydown: function(ev) + { + if (ev.which != 10 && ev.which != 13) + return; + + var sid = ev.data.sid; + var self = ev.data.self; + var input = $(this); + var ifnames = _luci2.toArray(input.val()); + + if (!ifnames.length) + return; + + _luci2.NetworkModel.createDevice(ifnames[0]); + + self._redraw(sid, $('#' + self.id(sid)), ifnames[0]); + }, + + load: function(sid) + { + return _luci2.NetworkModel.init(); + }, + + _redraw: function(sid, ul, sel) + { + var id = ul.attr('id'); + var devs = _luci2.NetworkModel.getDevices(); + var iface = _luci2.NetworkModel.getInterface(sid); + var itype = this.options.multiple ? 'checkbox' : 'radio'; + var check = { }; + + if (!sel) + { + for (var i = 0; i < devs.length; i++) + if (devs[i].isInNetwork(iface)) + check[devs[i].name()] = true; + } + else + { + if (this.options.multiple) + check = _luci2.toObject(this.formvalue(sid)); + + check[sel] = true; + } + + ul.empty(); + + for (var i = 0; i < devs.length; i++) + { + var dev = devs[i]; + + if (dev.isBridge() && this.options.bridges === false) + continue; + + if (!dev.isBridgeable() && this.options.multiple) + continue; + + var badge = $('') + .addClass('badge') + .append($('').attr('src', dev.icon())) + .append(' %s: %s'.format(dev.name(), dev.description())); + + //var ifcs = dev.getInterfaces(); + //if (ifcs.length) + //{ + // for (var j = 0; j < ifcs.length; j++) + // badge.append((j ? ', ' : ' (') + ifcs[j].name()); + // + // badge.append(')'); + //} + + $('
  • ') + .append($('
  • ') + .append($('
  • ') + .append($('