X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci2%2Fui.git;a=blobdiff_plain;f=luci2%2Fhtdocs%2Fluci2%2Fluci2.js;h=6481c0bd90416c989d2f6e092e8c482527bc53da;hp=e401c7c41b701b96d86ead02edcbff0a7ab245d0;hb=5c515935eec07a2ca50d539da1c43bfceae5acc9;hpb=cc66f6160f8e44d07bf92b9321144fdc0c1cf473 diff --git a/luci2/htdocs/luci2/luci2.js b/luci2/htdocs/luci2/luci2.js index e401c7c..6481c0b 100644 --- a/luci2/htdocs/luci2/luci2.js +++ b/luci2/htdocs/luci2/luci2.js @@ -387,7 +387,7 @@ function LuCI2() }; this.globals = { - timeout: 3000, + timeout: 15000, resource: '/luci2', sid: '00000000000000000000000000000000' }; @@ -584,13 +584,44 @@ function LuCI2() }, - changes: _luci2.rpc.declare({ + configs: _luci2.rpc.declare({ + object: 'uci', + method: 'configs', + expect: { configs: [ ] } + }), + + _changes: _luci2.rpc.declare({ object: 'uci', method: 'changes', params: [ 'config' ], expect: { changes: [ ] } }), + changes: function(config) + { + if (typeof(config) == 'string') + return this._changes(config); + + var configlist; + return this.configs().then(function(configs) { + _luci2.rpc.batch(); + configlist = configs; + + for (var i = 0; i < configs.length; i++) + _luci2.uci._changes(configs[i]); + + return _luci2.rpc.flush(); + }).then(function(changes) { + var rv = { }; + + for (var i = 0; i < configlist.length; i++) + if (changes[i].length) + rv[configlist[i]] = changes[i]; + + return rv; + }); + }, + commit: _luci2.rpc.declare({ object: 'uci', method: 'commit', @@ -757,13 +788,13 @@ function LuCI2() var net = nets[i] = networks[i]; var dev = net.l3_device || net.l2_device; if (dev) - net.device = devs[dev] = { }; + net.device = devs[dev] || (devs[dev] = { }); } _luci2.rpc.batch(); for (var dev in devs) - _luci2.network.listDeviceNamestatus(dev); + _luci2.network.getDeviceStatus(dev); return _luci2.rpc.flush(); }).then(function(devices) { @@ -786,7 +817,7 @@ function LuCI2() if (!devs[brm[j]]) { devs[brm[j]] = { }; - _luci2.network.listDeviceNamestatus(brm[j]); + _luci2.network.getDeviceStatus(brm[j]); } devs[devices[i]['device']].subdevices[j] = devs[brm[j]]; @@ -836,6 +867,9 @@ function LuCI2() for (var i = 0; i < interfaces.length; i++) { + if (!interfaces[i].route) + continue; + for (var j = 0; j < interfaces[i].route.length; j++) { var rt = interfaces[i].route[j]; @@ -897,7 +931,7 @@ function LuCI2() } }), - listDeviceNamestatus: _luci2.rpc.declare({ + getDeviceStatus: _luci2.rpc.declare({ object: 'network.device', method: 'status', params: [ 'name' ], @@ -912,6 +946,88 @@ function LuCI2() object: 'luci2.network', method: 'conntrack_count', expect: { '': { count: 0, limit: 0 } } + }), + + listSwitchNames: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'switch_list', + expect: { switches: [ ] } + }), + + getSwitchInfo: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'switch_info', + params: [ 'switch' ], + expect: { info: { } }, + filter: function(data, params) { + data['attrs'] = data['switch']; + data['vlan_attrs'] = data['vlan']; + data['port_attrs'] = data['port']; + data['switch'] = params['switch']; + + delete data.vlan; + delete data.port; + + return data; + } + }), + + getSwitchStatus: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'switch_status', + params: [ 'switch' ], + expect: { ports: [ ] } + }), + + + runPing: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'ping', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + runPing6: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'ping6', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + runTraceroute: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'traceroute', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + runTraceroute6: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'traceroute6', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + runNslookup: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'nslookup', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + + setUp: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'ifup', + params: [ 'data' ], + expect: { '': { code: -1 } } + }), + + setDown: _luci2.rpc.declare({ + object: 'luci2.network', + method: 'ifdown', + params: [ 'data' ], + expect: { '': { code: -1 } } }) }; @@ -1072,6 +1188,57 @@ function LuCI2() } }; + this.firewall = { + getZoneColor: function(zone) + { + if ($.isPlainObject(zone)) + zone = zone.name; + + if (zone == 'lan') + return '#90f090'; + else if (zone == 'wan') + return '#f09090'; + + for (var i = 0, hash = 0; + i < zone.length; + hash = zone.charCodeAt(i++) + ((hash << 5) - hash)); + + for (var i = 0, color = '#'; + i < 3; + color += ('00' + ((hash >> i++ * 8) & 0xFF).tozoneing(16)).slice(-2)); + + return color; + }, + + findZoneByNetwork: function(network) + { + var self = this; + var zone = undefined; + + return _luci2.uci.foreach('firewall', 'zone', function(z) { + if (!z.name || !z.network) + return; + + if (!$.isArray(z.network)) + z.network = z.network.split(/\s+/); + + for (var i = 0; i < z.network.length; i++) + { + if (z.network[i] == network) + { + zone = z; + break; + } + } + }).then(function() { + if (zone) + zone.color = self.getZoneColor(zone); + + return zone; + }); + } + }; + this.system = { getSystemInfo: _luci2.rpc.declare({ object: 'system', @@ -1292,6 +1459,18 @@ function LuCI2() }), + testReset: _luci2.rpc.declare({ + object: 'luci2.system', + method: 'reset_test', + expect: { supported: false } + }), + + startReset: _luci2.rpc.declare({ + object: 'luci2.system', + method: 'reset_start' + }), + + performReboot: _luci2.rpc.declare({ object: 'luci2.system', method: 'reboot' @@ -1452,137 +1631,117 @@ function LuCI2() this.ui = { + saveScrollTop: function() + { + this._scroll_top = $(document).scrollTop(); + }, + + restoreScrollTop: function() + { + if (typeof(this._scroll_top) == 'undefined') + return; + + $(document).scrollTop(this._scroll_top); + + delete this._scroll_top; + }, + loading: function(enable) { var win = $(window); var body = $('body'); - var div = _luci2._modal || ( - _luci2._modal = $('
') - .addClass('cbi-modal-loader') - .append($('
').text(_luci2.tr('Loading data...'))) + + var state = _luci2.ui._loading || (_luci2.ui._loading = { + modal: $('
') + .addClass('modal fade') + .append($('
') + .addClass('modal-dialog') + .append($('
') + .addClass('modal-content luci2-modal-loader') + .append($('
') + .addClass('modal-body') + .text(_luci2.tr('Loading data…'))))) .appendTo(body) - ); + .modal({ + backdrop: 'static', + keyboard: false + }) + }); - if (enable) - { - body.css('overflow', 'hidden'); - body.css('padding', 0); - body.css('width', win.width()); - body.css('height', win.height()); - div.css('width', win.width()); - div.css('height', win.height()); - div.show(); - } - else - { - div.hide(); - body.css('overflow', ''); - body.css('padding', ''); - body.css('width', ''); - body.css('height', ''); - } + state.modal.modal(enable ? 'show' : 'hide'); }, dialog: function(title, content, options) { var win = $(window); var body = $('body'); - var div = _luci2._dialog || ( - _luci2._dialog = $('
') - .addClass('cbi-modal-dialog') + + var state = _luci2.ui._dialog || (_luci2.ui._dialog = { + dialog: $('
') + .addClass('modal fade') .append($('
') + .addClass('modal-dialog') .append($('
') - .addClass('cbi-modal-dialog-header')) - .append($('
') - .addClass('cbi-modal-dialog-body')) - .append($('
') - .addClass('cbi-modal-dialog-footer') - .append($('