diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-11-22 12:56:05 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-11-22 12:58:34 +0100 |
commit | a03ec606967434182450cdbad81d25474eb5cd51 (patch) | |
tree | 6d8cbe0c9dfc7b4a501abb85a6e08dfda3159adb /modules/luci-mod-network/htdocs | |
parent | f598b10c49ff5d196baea7c92a2859da70869a5f (diff) |
luci-mod-network: move wifi overview markup and JS code into external files
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-mod-network/htdocs')
-rw-r--r-- | modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js new file mode 100644 index 0000000000..bdeb23d235 --- /dev/null +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js @@ -0,0 +1,93 @@ +function wifi_delete(ev) { + if (!confirm(_('Really delete this wireless network? The deletion cannot be undone! You might lose access to this device if you are connected via this network.'))) { + ev.preventDefault(); + return false; + } + + ev.target.previousElementSibling.value = '1'; + return true; +} + +function wifi_restart(ev) { + L.halt(); + + findParent(ev.target, '.table').querySelectorAll('[data-disabled="false"]').forEach(function(s) { + L.dom.content(s, E('em', _('Wireless is restarting...'))); + }); + + L.post(L.url('admin/network/wireless_reconnect', ev.target.getAttribute('data-radio')), L.run); +} + +var networks = [ ]; + +document.querySelectorAll('[data-network]').forEach(function(n) { + networks.push(n.getAttribute('data-network')); +}); + +L.poll(5, L.url('admin/network/wireless_status', networks.join(',')), null, + function(x, st) { + if (st) { + var rowstyle = 1; + var radiostate = { }; + + st.forEach(function(s) { + var r = radiostate[s.device.device] || (radiostate[s.device.device] = {}); + + s.is_assoc = (s.bssid && s.bssid != '00:00:00:00:00:00' && s.channel && s.mode != 'Unknown' && !s.disabled); + + r.up = r.up || s.is_assoc; + r.channel = r.channel || s.channel; + r.bitrate = r.bitrate || s.bitrate; + r.frequency = r.frequency || s.frequency; + }); + + for (var i = 0; i < st.length; i++) { + var iw = st[i], + sig = document.getElementById(iw.id + '-iw-signal'), + info = document.getElementById(iw.id + '-iw-status'), + disabled = (info && info.getAttribute('data-disabled') === 'true'); + + var p = iw.quality; + var q = disabled ? -1 : p; + + var icon; + if (q < 0) + icon = L.resource('icons/signal-none.png'); + else if (q == 0) + icon = L.resource('icons/signal-0.png'); + else if (q < 25) + icon = L.resource('icons/signal-0-25.png'); + else if (q < 50) + icon = L.resource('icons/signal-25-50.png'); + else if (q < 75) + icon = L.resource('icons/signal-50-75.png'); + else + icon = L.resource('icons/signal-75-100.png'); + + L.dom.content(sig, E('span', { + class: 'ifacebadge', + title: '%s %d %s / %s: %d %s'.format(_('Signal'), iw.signal, _('dBm'), _('Noise'), iw.noise, _('dBm')) + }, [ E('img', { src: icon }), ' %d%%'.format(p) ])); + + L.itemlist(info, [ + _('SSID'), '%h'.format(iw.ssid || '?'), + _('Mode'), iw.mode, + _('BSSID'), iw.is_assoc ? iw.bssid : null, + _('Encryption'), iw.is_assoc ? iw.encryption || _('None') : null, + null, iw.is_assoc ? null : E('em', disabled ? _('Wireless is disabled') : _('Wireless is not associated')) + ], [ ' | ', E('br') ]); + } + + for (var dev in radiostate) { + var img = document.getElementById(dev + '-iw-upstate'); + if (img) img.src = L.resource('icons/wifi' + (radiostate[dev].up ? '' : '_disabled') + '.png'); + + var stat = document.getElementById(dev + '-iw-devinfo'); + L.itemlist(stat, [ + _('Channel'), '%s (%s %s)'.format(radiostate[dev].channel || '?', radiostate[dev].frequency || '?', _('GHz')), + _('Bitrate'), '%s %s'.format(radiostate[dev].bitrate || '?', _('Mbit/s')) + ], ' | '); + } + } + } +); |