treewide: require ui.js explicitly

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-11-03 21:54:40 +01:00
parent b2a46e131b
commit 86f492173d
12 changed files with 98 additions and 86 deletions

View file

@ -1,5 +1,6 @@
'use strict'; 'use strict';
'require fs'; 'require fs';
'require ui';
return L.view.extend({ return L.view.extend({
load: function() { load: function() {
@ -11,10 +12,10 @@ return L.view.extend({
return fs.write('/etc/firewall.user', value).then(function(rc) { return fs.write('/etc/firewall.user', value).then(function(rc) {
document.querySelector('textarea').value = value; document.querySelector('textarea').value = value;
L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info'); ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
fs.exec('/etc/init.d/firewall', ['restart']); fs.exec('/etc/init.d/firewall', ['restart']);
}).catch(function(e) { }).catch(function(e) {
L.ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
}); });
}, },

View file

@ -1,5 +1,6 @@
'use strict'; 'use strict';
'require fs'; 'require fs';
'require ui';
'require uci'; 'require uci';
'require form'; 'require form';
'require network'; 'require network';
@ -7,7 +8,7 @@
'require tools.widgets as widgets'; 'require tools.widgets as widgets';
function count_changes(section_id) { function count_changes(section_id) {
var changes = L.ui.changes.changes, n = 0; var changes = ui.changes.changes, n = 0;
if (!L.isObject(changes)) if (!L.isObject(changes))
return n; return n;
@ -100,7 +101,7 @@ function render_status(node, ifc, with_device) {
_('Error'), errors ? errors[4] : null, _('Error'), errors ? errors[4] : null,
null, changecount ? E('a', { null, changecount ? E('a', {
href: '#', href: '#',
click: L.bind(L.ui.changes.displayChanges, L.ui.changes) click: L.bind(ui.changes.displayChanges, ui.changes)
}, _('Interface has %d pending changes').format(changecount)) : null }, _('Interface has %d pending changes').format(changecount)) : null
]); ]);
} }
@ -166,7 +167,7 @@ function iface_updown(up, id, ev, force) {
Array.isArray(info.inbound_interfaces) && Array.isArray(info.inbound_interfaces) &&
info.inbound_interfaces.filter(function(i) { return i == id })[0]) { info.inbound_interfaces.filter(function(i) { return i == id })[0]) {
L.ui.showModal(_('Confirm disconnect'), [ ui.showModal(_('Confirm disconnect'), [
E('p', _('You appear to be currently connected to the device via the "%h" interface. Do you really want to shut down the interface?').format(id)), E('p', _('You appear to be currently connected to the device via the "%h" interface. Do you really want to shut down the interface?').format(id)),
E('div', { 'class': 'right' }, [ E('div', { 'class': 'right' }, [
E('button', { E('button', {
@ -176,7 +177,7 @@ function iface_updown(up, id, ev, force) {
btns[1].disabled = false; btns[1].disabled = false;
btns[0].disabled = false; btns[0].disabled = false;
L.ui.hideModal(); ui.hideModal();
} }
}, _('Cancel')), }, _('Cancel')),
' ', ' ',
@ -186,7 +187,7 @@ function iface_updown(up, id, ev, force) {
dsc.setAttribute('disconnect', ''); dsc.setAttribute('disconnect', '');
L.dom.content(dsc, E('em', _('Interface is shutting down...'))); L.dom.content(dsc, E('em', _('Interface is shutting down...')));
L.ui.hideModal(); ui.hideModal();
} }
}, _('Disconnect')) }, _('Disconnect'))
]) ])
@ -557,7 +558,7 @@ return L.view.extend({
E('button', { E('button', {
'class': 'cbi-button cbi-button-add', 'class': 'cbi-button cbi-button-add',
'title': _('Setup DHCP Server'), 'title': _('Setup DHCP Server'),
'click': L.ui.createHandlerFn(this, function(section_id, ev) { 'click': ui.createHandlerFn(this, function(section_id, ev) {
this.map.save(function() { this.map.save(function() {
uci.add('dhcp', 'dhcp', section_id); uci.add('dhcp', 'dhcp', section_id);
uci.set('dhcp', section_id, 'interface', section_id); uci.set('dhcp', section_id, 'interface', section_id);
@ -748,16 +749,16 @@ return L.view.extend({
} }
m2.render().then(L.bind(function(nodes) { m2.render().then(L.bind(function(nodes) {
L.ui.showModal(_('Add new interface...'), [ ui.showModal(_('Add new interface...'), [
nodes, nodes,
E('div', { 'class': 'right' }, [ E('div', { 'class': 'right' }, [
E('button', { E('button', {
'class': 'btn', 'class': 'btn',
'click': L.ui.hideModal 'click': ui.hideModal
}, _('Cancel')), ' ', }, _('Cancel')), ' ',
E('button', { E('button', {
'class': 'cbi-button cbi-button-positive important', 'class': 'cbi-button cbi-button-positive important',
'click': L.ui.createHandlerFn(this, function(ev) { 'click': ui.createHandlerFn(this, function(ev) {
var nameval = name.isValid('_new_') ? name.formvalue('_new_') : null, var nameval = name.isValid('_new_') ? name.formvalue('_new_') : null,
protoval = proto.isValid('_new_') ? proto.formvalue('_new_') : null; protoval = proto.isValid('_new_') ? proto.formvalue('_new_') : null;
@ -977,13 +978,13 @@ return L.view.extend({
if (dsc.getAttribute('reconnect') == '') { if (dsc.getAttribute('reconnect') == '') {
dsc.setAttribute('reconnect', '1'); dsc.setAttribute('reconnect', '1');
tasks.push(fs.exec('/sbin/ifup', [section_ids[i]]).catch(function(e) { tasks.push(fs.exec('/sbin/ifup', [section_ids[i]]).catch(function(e) {
L.ui.addNotification(null, E('p', e.message)); ui.addNotification(null, E('p', e.message));
})); }));
} }
else if (dsc.getAttribute('disconnect') == '') { else if (dsc.getAttribute('disconnect') == '') {
dsc.setAttribute('disconnect', '1'); dsc.setAttribute('disconnect', '1');
tasks.push(fs.exec('/sbin/ifdown', [section_ids[i]]).catch(function(e) { tasks.push(fs.exec('/sbin/ifdown', [section_ids[i]]).catch(function(e) {
L.ui.addNotification(null, E('p', e.message)); ui.addNotification(null, E('p', e.message));
})); }));
} }
else if (dsc.getAttribute('reconnect') == '1') { else if (dsc.getAttribute('reconnect') == '1') {

View file

@ -1,4 +1,5 @@
'use strict'; 'use strict';
'require ui';
'require rpc'; 'require rpc';
'require uci'; 'require uci';
'require form'; 'require form';
@ -55,7 +56,7 @@ function update_interfaces(old_ifname, new_ifname) {
if (changed) { if (changed) {
uci.set('network', interfaces[i]['.name'], 'ifname', new_ifnames.join(' ')); uci.set('network', interfaces[i]['.name'], 'ifname', new_ifnames.join(' '));
L.ui.addNotification(null, E('p', _('Interface %q device auto-migrated from %q to %q.') ui.addNotification(null, E('p', _('Interface %q device auto-migrated from %q to %q.')
.replace(/%q/g, '"%s"').format(interfaces[i]['.name'], old_ifname, new_ifname))); .replace(/%q/g, '"%s"').format(interfaces[i]['.name'], old_ifname, new_ifname)));
} }
} }
@ -143,7 +144,7 @@ return L.view.extend({
topology = topologies[switch_name]; topology = topologies[switch_name];
if (!topology) { if (!topology) {
L.ui.addNotification(null, _('Switch %q has an unknown topology - the VLAN settings might not be accurate.').replace(/%q/, switch_name)); ui.addNotification(null, _('Switch %q has an unknown topology - the VLAN settings might not be accurate.').replace(/%q/, switch_name));
topology = { topology = {
features: {}, features: {},

View file

@ -1,5 +1,6 @@
'use strict'; 'use strict';
'require fs'; 'require fs';
'require ui';
'require rpc'; 'require rpc';
'require uci'; 'require uci';
'require form'; 'require form';
@ -8,7 +9,7 @@
'require tools.widgets as widgets'; 'require tools.widgets as widgets';
function count_changes(section_id) { function count_changes(section_id) {
var changes = L.ui.changes.changes, n = 0; var changes = ui.changes.changes, n = 0;
if (!L.isObject(changes)) if (!L.isObject(changes))
return n; return n;
@ -97,7 +98,7 @@ function render_network_status(radioNet) {
if (changecount) if (changecount)
status_text = E('a', { status_text = E('a', {
href: '#', href: '#',
click: L.bind(L.ui.changes.displayChanges, L.ui.changes) click: L.bind(ui.changes.displayChanges, ui.changes)
}, _('Interface has %d pending changes').format(changecount)); }, _('Interface has %d pending changes').format(changecount));
else if (!is_assoc) else if (!is_assoc)
status_text = E('em', disabled ? _('Wireless is disabled') : _('Wireless is not associated')); status_text = E('em', disabled ? _('Wireless is disabled') : _('Wireless is not associated'));
@ -196,7 +197,7 @@ function network_updown(id, map, ev) {
} }
return map.save().then(function() { return map.save().then(function() {
L.ui.changes.apply() ui.changes.apply()
}); });
} }
@ -605,18 +606,18 @@ return L.view.extend({
} }
return Promise.all(tasks) return Promise.all(tasks)
.then(L.bind(L.ui.changes.init, L.ui.changes)) .then(L.bind(ui.changes.init, ui.changes))
.then(L.bind(L.ui.changes.apply, L.ui.changes)); .then(L.bind(ui.changes.apply, ui.changes));
}, },
renderMigration: function() { renderMigration: function() {
L.ui.showModal(_('Wireless configuration migration'), [ ui.showModal(_('Wireless configuration migration'), [
E('p', _('The existing wireless configuration needs to be changed for LuCI to function properly.')), E('p', _('The existing wireless configuration needs to be changed for LuCI to function properly.')),
E('p', _('Upon pressing "Continue", anonymous "wifi-iface" sections will be assigned with a name in the form <em>wifinet#</em> and the network will be restarted to apply the updated configuration.')), E('p', _('Upon pressing "Continue", anonymous "wifi-iface" sections will be assigned with a name in the form <em>wifinet#</em> and the network will be restarted to apply the updated configuration.')),
E('div', { 'class': 'right' }, E('div', { 'class': 'right' },
E('button', { E('button', {
'class': 'btn cbi-button-action important', 'class': 'btn cbi-button-action important',
'click': L.ui.createHandlerFn(this, 'handleMigration') 'click': ui.createHandlerFn(this, 'handleMigration')
}, _('Continue'))) }, _('Continue')))
]); ]);
}, },
@ -691,17 +692,17 @@ return L.view.extend({
E('button', { E('button', {
'class': 'cbi-button cbi-button-neutral', 'class': 'cbi-button cbi-button-neutral',
'title': _('Restart radio interface'), 'title': _('Restart radio interface'),
'click': L.ui.createHandlerFn(this, radio_restart, section_id) 'click': ui.createHandlerFn(this, radio_restart, section_id)
}, _('Restart')), }, _('Restart')),
E('button', { E('button', {
'class': 'cbi-button cbi-button-action important', 'class': 'cbi-button cbi-button-action important',
'title': _('Find and join network'), 'title': _('Find and join network'),
'click': L.ui.createHandlerFn(this, 'handleScan', inst) 'click': ui.createHandlerFn(this, 'handleScan', inst)
}, _('Scan')), }, _('Scan')),
E('button', { E('button', {
'class': 'cbi-button cbi-button-add', 'class': 'cbi-button cbi-button-add',
'title': _('Provide new network'), 'title': _('Provide new network'),
'click': L.ui.createHandlerFn(this, 'handleAdd', inst) 'click': ui.createHandlerFn(this, 'handleAdd', inst)
}, _('Add')) }, _('Add'))
]; ];
} }
@ -713,17 +714,17 @@ return L.view.extend({
E('button', { E('button', {
'class': 'cbi-button cbi-button-neutral enable-disable', 'class': 'cbi-button cbi-button-neutral enable-disable',
'title': isDisabled ? _('Enable this network') : _('Disable this network'), 'title': isDisabled ? _('Enable this network') : _('Disable this network'),
'click': L.ui.createHandlerFn(this, network_updown, section_id, this.map) 'click': ui.createHandlerFn(this, network_updown, section_id, this.map)
}, isDisabled ? _('Enable') : _('Disable')), }, isDisabled ? _('Enable') : _('Disable')),
E('button', { E('button', {
'class': 'cbi-button cbi-button-action important', 'class': 'cbi-button cbi-button-action important',
'title': _('Edit this network'), 'title': _('Edit this network'),
'click': L.ui.createHandlerFn(this, 'renderMoreOptionsModal', section_id) 'click': ui.createHandlerFn(this, 'renderMoreOptionsModal', section_id)
}, _('Edit')), }, _('Edit')),
E('button', { E('button', {
'class': 'cbi-button cbi-button-negative remove', 'class': 'cbi-button cbi-button-negative remove',
'title': _('Delete this network'), 'title': _('Delete this network'),
'click': L.ui.createHandlerFn(this, 'handleRemove', section_id) 'click': ui.createHandlerFn(this, 'handleRemove', section_id)
}, _('Remove')) }, _('Remove'))
]; ];
} }
@ -755,7 +756,7 @@ return L.view.extend({
o = ss.taboption('general', form.Button, '_toggle', isDisabled ? _('Wireless network is disabled') : _('Wireless network is enabled')); o = ss.taboption('general', form.Button, '_toggle', isDisabled ? _('Wireless network is disabled') : _('Wireless network is enabled'));
o.inputstyle = isDisabled ? 'apply' : 'reset'; o.inputstyle = isDisabled ? 'apply' : 'reset';
o.inputtitle = isDisabled ? _('Enable') : _('Disable'); o.inputtitle = isDisabled ? _('Enable') : _('Disable');
o.onclick = L.ui.createHandlerFn(s, network_updown, s.section, s.map); o.onclick = ui.createHandlerFn(s, network_updown, s.section, s.map);
o = ss.taboption('general', CBIWifiFrequencyValue, '_freq', '<br />' + _('Operating frequency')); o = ss.taboption('general', CBIWifiFrequencyValue, '_freq', '<br />' + _('Operating frequency'));
o.ucisection = s.section; o.ucisection = s.section;
@ -1630,7 +1631,7 @@ return L.view.extend({
cbi_update_table(table, [], E('em', { class: 'spinning' }, _('Starting wireless scan...'))); cbi_update_table(table, [], E('em', { class: 'spinning' }, _('Starting wireless scan...')));
var md = L.ui.showModal(_('Join Network: Wireless Scan'), [ var md = ui.showModal(_('Join Network: Wireless Scan'), [
table, table,
E('div', { 'class': 'right' }, E('div', { 'class': 'right' },
E('button', { E('button', {
@ -1710,7 +1711,7 @@ return L.view.extend({
md.style.maxHeight = ''; md.style.maxHeight = '';
} }
L.ui.hideModal(); ui.hideModal();
L.Poll.remove(this.pollFn); L.Poll.remove(this.pollFn);
this.pollFn = null; this.pollFn = null;
@ -1848,16 +1849,16 @@ return L.view.extend({
zone.default = 'wan'; zone.default = 'wan';
return m2.render().then(L.bind(function(nodes) { return m2.render().then(L.bind(function(nodes) {
L.ui.showModal(_('Joining Network: %q').replace(/%q/, '"%h"'.format(bss.ssid)), [ ui.showModal(_('Joining Network: %q').replace(/%q/, '"%h"'.format(bss.ssid)), [
nodes, nodes,
E('div', { 'class': 'right' }, [ E('div', { 'class': 'right' }, [
E('button', { E('button', {
'class': 'btn', 'class': 'btn',
'click': L.ui.hideModal 'click': ui.hideModal
}, _('Cancel')), ' ', }, _('Cancel')), ' ',
E('button', { E('button', {
'class': 'cbi-button cbi-button-positive important', 'class': 'cbi-button cbi-button-positive important',
'click': L.ui.createHandlerFn(this, 'handleJoinConfirm', radioDev, bss, m2) 'click': ui.createHandlerFn(this, 'handleJoinConfirm', radioDev, bss, m2)
}, _('Submit')) }, _('Submit'))
]) ])
], 'cbi-modal').querySelector('[id="%s"] input[class][type]'.format((passphrase || name).cbid('_new_'))).focus(); ], 'cbi-modal').querySelector('[id="%s"] input[class][type]'.format((passphrase || name).cbid('_new_'))).focus();
@ -1919,7 +1920,7 @@ return L.view.extend({
if (dsc.getAttribute('restart') == '') { if (dsc.getAttribute('restart') == '') {
dsc.setAttribute('restart', '1'); dsc.setAttribute('restart', '1');
tasks.push(fs.exec('/sbin/wifi', ['up', section_ids[i]]).catch(function(e) { tasks.push(fs.exec('/sbin/wifi', ['up', section_ids[i]]).catch(function(e) {
L.ui.addNotification(null, E('p', e.message)); ui.addNotification(null, E('p', e.message));
})); }));
} }
else if (dsc.getAttribute('restart') == '1') { else if (dsc.getAttribute('restart') == '1') {

View file

@ -1,4 +1,5 @@
'use strict'; 'use strict';
'require ui';
'require rpc'; 'require rpc';
'require network'; 'require network';
@ -298,7 +299,7 @@ return L.view.extend({
}); });
} }
L.ui.tabs.initTabGroup(v.firstElementChild.childNodes); ui.tabs.initTabGroup(v.firstElementChild.childNodes);
this.pollData(); this.pollData();

View file

@ -1,4 +1,5 @@
'use strict'; 'use strict';
'require ui';
'require rpc'; 'require rpc';
'require network'; 'require network';
@ -326,7 +327,7 @@ return L.view.extend({
}); });
} }
L.ui.tabs.initTabGroup(v.firstElementChild.childNodes); ui.tabs.initTabGroup(v.firstElementChild.childNodes);
this.pollData(); this.pollData();

View file

@ -1,5 +1,6 @@
'use strict'; 'use strict';
'require fs'; 'require fs';
'require ui';
return L.view.extend({ return L.view.extend({
load: function() { load: function() {
@ -11,9 +12,9 @@ return L.view.extend({
return fs.write('/etc/crontabs/root', value).then(function(rc) { return fs.write('/etc/crontabs/root', value).then(function(rc) {
document.querySelector('textarea').value = value; document.querySelector('textarea').value = value;
L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info'); ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
}).catch(function(e) { }).catch(function(e) {
L.ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
}); });
}, },

View file

@ -2,6 +2,7 @@
'require form'; 'require form';
'require rpc'; 'require rpc';
'require fs'; 'require fs';
'require ui';
var callSystemValidateFirmwareImage = rpc.declare({ var callSystemValidateFirmwareImage = rpc.declare({
object: 'system', object: 'system',
@ -89,46 +90,46 @@ return L.view.extend({
if (!confirm(_('Do you really want to erase all settings?'))) if (!confirm(_('Do you really want to erase all settings?')))
return; return;
L.ui.showModal(_('Erasing...'), [ ui.showModal(_('Erasing...'), [
E('p', { 'class': 'spinning' }, _('The system is erasing the configuration partition now and will reboot itself when finished.')) E('p', { 'class': 'spinning' }, _('The system is erasing the configuration partition now and will reboot itself when finished.'))
]); ]);
/* Currently the sysupgrade rpc call will not return, hence no promise handling */ /* Currently the sysupgrade rpc call will not return, hence no promise handling */
fs.exec('/sbin/firstboot', [ '-r', '-y' ]); fs.exec('/sbin/firstboot', [ '-r', '-y' ]);
L.ui.awaitReconnect('192.168.1.1', 'openwrt.lan'); ui.awaitReconnect('192.168.1.1', 'openwrt.lan');
}, },
handleRestore: function(ev) { handleRestore: function(ev) {
return L.ui.uploadFile('/tmp/backup.tar.gz', ev.target) return ui.uploadFile('/tmp/backup.tar.gz', ev.target)
.then(L.bind(function(btn, res) { .then(L.bind(function(btn, res) {
btn.firstChild.data = _('Checking archive…'); btn.firstChild.data = _('Checking archive…');
return fs.exec('/bin/tar', [ '-tzf', '/tmp/backup.tar.gz' ]); return fs.exec('/bin/tar', [ '-tzf', '/tmp/backup.tar.gz' ]);
}, this, ev.target)) }, this, ev.target))
.then(L.bind(function(btn, res) { .then(L.bind(function(btn, res) {
if (res.code != 0) { if (res.code != 0) {
L.ui.addNotification(null, E('p', _('The uploaded backup archive is not readable'))); ui.addNotification(null, E('p', _('The uploaded backup archive is not readable')));
return fs.remove('/tmp/backup.tar.gz'); return fs.remove('/tmp/backup.tar.gz');
} }
L.ui.showModal(_('Apply backup?'), [ ui.showModal(_('Apply backup?'), [
E('p', _('The uploaded backup archive appears to be valid and contains the files listed below. Press "Continue" to restore the backup and reboot, or "Cancel" to abort the operation.')), E('p', _('The uploaded backup archive appears to be valid and contains the files listed below. Press "Continue" to restore the backup and reboot, or "Cancel" to abort the operation.')),
E('pre', {}, [ res.stdout ]), E('pre', {}, [ res.stdout ]),
E('div', { 'class': 'right' }, [ E('div', { 'class': 'right' }, [
E('button', { E('button', {
'class': 'btn', 'class': 'btn',
'click': L.ui.createHandlerFn(this, function(ev) { 'click': ui.createHandlerFn(this, function(ev) {
return fs.remove('/tmp/backup.tar.gz').finally(L.ui.hideModal); return fs.remove('/tmp/backup.tar.gz').finally(ui.hideModal);
}) })
}, [ _('Cancel') ]), ' ', }, [ _('Cancel') ]), ' ',
E('button', { E('button', {
'class': 'btn cbi-button-action important', 'class': 'btn cbi-button-action important',
'click': L.ui.createHandlerFn(this, 'handleRestoreConfirm', btn) 'click': ui.createHandlerFn(this, 'handleRestoreConfirm', btn)
}, [ _('Continue') ]) }, [ _('Continue') ])
]) ])
]); ]);
}, this, ev.target)) }, this, ev.target))
.catch(function(e) { L.ui.addNotification(null, E('p', e.message)) }) .catch(function(e) { ui.addNotification(null, E('p', e.message)) })
.finally(L.bind(function(btn, input) { .finally(L.bind(function(btn, input) {
btn.firstChild.data = _('Upload archive...'); btn.firstChild.data = _('Upload archive...');
}, this, ev.target)); }, this, ev.target));
@ -138,7 +139,7 @@ return L.view.extend({
return fs.exec('/sbin/sysupgrade', [ '--restore-backup', '/tmp/backup.tar.gz' ]) return fs.exec('/sbin/sysupgrade', [ '--restore-backup', '/tmp/backup.tar.gz' ])
.then(L.bind(function(btn, res) { .then(L.bind(function(btn, res) {
if (res.code != 0) { if (res.code != 0) {
L.ui.addNotification(null, [ ui.addNotification(null, [
E('p', _('The restore command failed with code %d').format(res.code)), E('p', _('The restore command failed with code %d').format(res.code)),
res.stderr ? E('pre', {}, [ res.stderr ]) : '' res.stderr ? E('pre', {}, [ res.stderr ]) : ''
]); ]);
@ -150,17 +151,17 @@ return L.view.extend({
}, this, ev.target)) }, this, ev.target))
.then(L.bind(function(res) { .then(L.bind(function(res) {
if (res.code != 0) { if (res.code != 0) {
L.ui.addNotification(null, E('p', _('The reboot command failed with code %d').format(res.code))); ui.addNotification(null, E('p', _('The reboot command failed with code %d').format(res.code)));
L.raise('Error', 'Reboot failed'); L.raise('Error', 'Reboot failed');
} }
L.ui.showModal(_('Rebooting…'), [ ui.showModal(_('Rebooting…'), [
E('p', { 'class': 'spinning' }, _('The system is rebooting now. If the restored configuration changed the current LAN IP address, you might need to reconnect manually.')) E('p', { 'class': 'spinning' }, _('The system is rebooting now. If the restored configuration changed the current LAN IP address, you might need to reconnect manually.'))
]); ]);
L.ui.awaitReconnect(window.location.host, '192.168.1.1', 'openwrt.lan'); ui.awaitReconnect(window.location.host, '192.168.1.1', 'openwrt.lan');
}, this)) }, this))
.catch(function(e) { L.ui.addNotification(null, E('p', e.message)) }) .catch(function(e) { ui.addNotification(null, E('p', e.message)) })
.finally(function() { btn.firstChild.data = _('Upload archive...') }); .finally(function() { btn.firstChild.data = _('Upload archive...') });
}, },
@ -183,11 +184,11 @@ return L.view.extend({
}, },
handleSysupgrade: function(storage_size, ev) { handleSysupgrade: function(storage_size, ev) {
return L.ui.uploadFile('/tmp/firmware.bin', ev.target.firstChild) return ui.uploadFile('/tmp/firmware.bin', ev.target.firstChild)
.then(L.bind(function(btn, reply) { .then(L.bind(function(btn, reply) {
btn.firstChild.data = _('Checking image…'); btn.firstChild.data = _('Checking image…');
L.ui.showModal(_('Checking image…'), [ ui.showModal(_('Checking image…'), [
E('span', { 'class': 'spinning' }, _('Verifying the uploaded image file.')) E('span', { 'class': 'spinning' }, _('Verifying the uploaded image file.'))
]); ]);
@ -254,15 +255,15 @@ return L.view.extend({
var cntbtn = E('button', { var cntbtn = E('button', {
'class': 'btn cbi-button-action important', 'class': 'btn cbi-button-action important',
'click': L.ui.createHandlerFn(this, 'handleSysupgradeConfirm', btn, keep, force), 'click': ui.createHandlerFn(this, 'handleSysupgradeConfirm', btn, keep, force),
'disabled': (!is_valid || is_too_big) ? true : null 'disabled': (!is_valid || is_too_big) ? true : null
}, [ _('Continue') ]); }, [ _('Continue') ]);
body.push(E('div', { 'class': 'right' }, [ body.push(E('div', { 'class': 'right' }, [
E('button', { E('button', {
'class': 'btn', 'class': 'btn',
'click': L.ui.createHandlerFn(this, function(ev) { 'click': ui.createHandlerFn(this, function(ev) {
return fs.remove('/tmp/firmware.bin').finally(L.ui.hideModal); return fs.remove('/tmp/firmware.bin').finally(ui.hideModal);
}) })
}, [ _('Cancel') ]), ' ', cntbtn }, [ _('Cancel') ]), ' ', cntbtn
])); ]));
@ -271,9 +272,9 @@ return L.view.extend({
cntbtn.disabled = !ev.target.checked; cntbtn.disabled = !ev.target.checked;
}); });
L.ui.showModal(_('Flash image?'), body); ui.showModal(_('Flash image?'), body);
}, this, ev.target)) }, this, ev.target))
.catch(function(e) { L.ui.addNotification(null, E('p', e.message)) }) .catch(function(e) { ui.addNotification(null, E('p', e.message)) })
.finally(L.bind(function(btn) { .finally(L.bind(function(btn) {
btn.firstChild.data = _('Flash image...'); btn.firstChild.data = _('Flash image...');
}, this, ev.target)); }, this, ev.target));
@ -282,7 +283,7 @@ return L.view.extend({
handleSysupgradeConfirm: function(btn, keep, force, ev) { handleSysupgradeConfirm: function(btn, keep, force, ev) {
btn.firstChild.data = _('Flashing…'); btn.firstChild.data = _('Flashing…');
L.ui.showModal(_('Flashing…'), [ ui.showModal(_('Flashing…'), [
E('p', { 'class': 'spinning' }, _('The system is flashing now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes before you try to reconnect. It might be necessary to renew the address of your computer to reach the device again, depending on your settings.')) E('p', { 'class': 'spinning' }, _('The system is flashing now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes before you try to reconnect. It might be necessary to renew the address of your computer to reach the device again, depending on your settings.'))
]); ]);
@ -300,28 +301,28 @@ return L.view.extend({
fs.exec('/sbin/sysupgrade', opts); fs.exec('/sbin/sysupgrade', opts);
if (keep.checked) if (keep.checked)
L.ui.awaitReconnect(window.location.host); ui.awaitReconnect(window.location.host);
else else
L.ui.awaitReconnect('192.168.1.1', 'openwrt.lan'); ui.awaitReconnect('192.168.1.1', 'openwrt.lan');
}, },
handleBackupList: function(ev) { handleBackupList: function(ev) {
return fs.exec('/sbin/sysupgrade', [ '--list-backup' ]).then(function(res) { return fs.exec('/sbin/sysupgrade', [ '--list-backup' ]).then(function(res) {
if (res.code != 0) { if (res.code != 0) {
L.ui.addNotification(null, [ ui.addNotification(null, [
E('p', _('The sysupgrade command failed with code %d').format(res.code)), E('p', _('The sysupgrade command failed with code %d').format(res.code)),
res.stderr ? E('pre', {}, [ res.stderr ]) : '' res.stderr ? E('pre', {}, [ res.stderr ]) : ''
]); ]);
L.raise('Error', 'Sysupgrade failed'); L.raise('Error', 'Sysupgrade failed');
} }
L.ui.showModal(_('Backup file list'), [ ui.showModal(_('Backup file list'), [
E('p', _('Below is the determined list of files to backup. It consists of changed configuration files marked by opkg, essential base files and the user defined backup patterns.')), E('p', _('Below is the determined list of files to backup. It consists of changed configuration files marked by opkg, essential base files and the user defined backup patterns.')),
E('ul', {}, (res.stdout || '').trim().split(/\n/).map(function(ln) { return E('li', {}, ln) })), E('ul', {}, (res.stdout || '').trim().split(/\n/).map(function(ln) { return E('li', {}, ln) })),
E('div', { 'class': 'right' }, [ E('div', { 'class': 'right' }, [
E('button', { E('button', {
'class': 'btn', 'class': 'btn',
'click': L.ui.hideModal 'click': ui.hideModal
}, [ _('Dismiss') ]) }, [ _('Dismiss') ])
]) ])
], 'cbi-modal'); ], 'cbi-modal');
@ -332,9 +333,9 @@ return L.view.extend({
return m.save(function() { return m.save(function() {
return fs.write('/etc/sysupgrade.conf', mapdata.config.editlist.trim().replace(/\r\n/g, '\n') + '\n'); return fs.write('/etc/sysupgrade.conf', mapdata.config.editlist.trim().replace(/\r\n/g, '\n') + '\n');
}).then(function() { }).then(function() {
L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info'); ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
}).catch(function(e) { }).catch(function(e) {
L.ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e))); ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e)));
}); });
}, },
@ -419,7 +420,7 @@ return L.view.extend({
node.appendChild(E('div', { 'class': 'cbi-page-actions' }, [ node.appendChild(E('div', { 'class': 'cbi-page-actions' }, [
E('button', { E('button', {
'class': 'cbi-button cbi-button-save', 'class': 'cbi-button cbi-button-save',
'click': L.ui.createHandlerFn(view, 'handleBackupSave', this.map) 'click': ui.createHandlerFn(view, 'handleBackupSave', this.map)
}, [ _('Save') ]) }, [ _('Save') ])
])); ]));

View file

@ -1,5 +1,6 @@
'use strict'; 'use strict';
'require fs'; 'require fs';
'require ui';
'require uci'; 'require uci';
'require rpc'; 'require rpc';
'require form'; 'require form';
@ -79,7 +80,7 @@ return L.view.extend({
return fs.exec('/sbin/block', ['mount']) return fs.exec('/sbin/block', ['mount'])
.then(function(res) { .then(function(res) {
if (res.code != 0) if (res.code != 0)
L.ui.addNotification(null, E('p', _('The <em>block mount</em> command failed with code %d').format(res.code))); ui.addNotification(null, E('p', _('The <em>block mount</em> command failed with code %d').format(res.code)));
}) })
.then(L.bind(uci.unload, uci, 'fstab')) .then(L.bind(uci.unload, uci, 'fstab'))
.then(L.bind(m.render, m)); .then(L.bind(m.render, m));
@ -89,7 +90,7 @@ return L.view.extend({
return fs.exec('/bin/umount', [path]) return fs.exec('/bin/umount', [path])
.then(L.bind(uci.unload, uci, 'fstab')) .then(L.bind(uci.unload, uci, 'fstab'))
.then(L.bind(m.render, m)) .then(L.bind(m.render, m))
.catch(function(e) { L.ui.addNotification(null, E('p', e.message)) }); .catch(function(e) { ui.addNotification(null, E('p', e.message)) });
}, },
load: function() { load: function() {
@ -210,7 +211,7 @@ return L.view.extend({
'%.2f%% (%1024.2mB)'.format(100 / this.mounts[i].size * used, used), '%.2f%% (%1024.2mB)'.format(100 / this.mounts[i].size * used, used),
umount ? E('button', { umount ? E('button', {
'class': 'btn cbi-button-remove', 'class': 'btn cbi-button-remove',
'click': L.ui.createHandlerFn(view, 'handleUmount', m, this.mounts[i].mount) 'click': ui.createHandlerFn(view, 'handleUmount', m, this.mounts[i].mount)
}, [ _('Unmount') ]) : '-' }, [ _('Unmount') ]) : '-'
]); ]);
} }

View file

@ -1,4 +1,5 @@
'use strict'; 'use strict';
'require ui';
'require form'; 'require form';
'require rpc'; 'require rpc';
@ -71,15 +72,15 @@ return L.view.extend({
return; return;
if (formData.password.pw1 != formData.password.pw2) { if (formData.password.pw1 != formData.password.pw2) {
L.ui.addNotification(null, E('p', _('Given password confirmation did not match, password not changed!')), 'danger'); ui.addNotification(null, E('p', _('Given password confirmation did not match, password not changed!')), 'danger');
return; return;
} }
return callSetPassword('root', formData.password.pw1).then(function(success) { return callSetPassword('root', formData.password.pw1).then(function(success) {
if (success) if (success)
L.ui.addNotification(null, E('p', _('The system password has been successfully changed.')), 'info'); ui.addNotification(null, E('p', _('The system password has been successfully changed.')), 'info');
else else
L.ui.addNotification(null, E('p', _('Failed to change the system password.')), 'danger'); ui.addNotification(null, E('p', _('Failed to change the system password.')), 'danger');
formData.password.pw1 = null; formData.password.pw1 = null;
formData.password.pw2 = null; formData.password.pw2 = null;

View file

@ -1,6 +1,7 @@
'use strict'; 'use strict';
'require rpc'; 'require rpc';
'require fs'; 'require fs';
'require ui';
return L.view.extend({ return L.view.extend({
callInitList: rpc.declare({ callInitList: rpc.declare({
@ -30,7 +31,7 @@ return L.view.extend({
return true; return true;
}).catch(function(e) { }).catch(function(e) {
L.ui.addNotification(null, E('p', _('Failed to execute "/etc/init.d/%s %s" action: %s').format(name, action, e))); ui.addNotification(null, E('p', _('Failed to execute "/etc/init.d/%s %s" action: %s').format(name, action, e)));
}); });
}, },
@ -48,16 +49,16 @@ return L.view.extend({
return fs.write('/etc/rc.local', value).then(function() { return fs.write('/etc/rc.local', value).then(function() {
document.querySelector('textarea').value = value; document.querySelector('textarea').value = value;
L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info'); ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
}).catch(function(e) { }).catch(function(e) {
L.ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message))); ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
}); });
}, },
renderEnableDisable: function(init) { renderEnableDisable: function(init) {
return E('button', { return E('button', {
class: 'btn cbi-button-%s'.format(init.enabled ? 'positive' : 'negative'), class: 'btn cbi-button-%s'.format(init.enabled ? 'positive' : 'negative'),
click: L.ui.createHandlerFn(this, 'handleEnableDisable', init.name, init.enabled) click: ui.createHandlerFn(this, 'handleEnableDisable', init.name, init.enabled)
}, init.enabled ? _('Enabled') : _('Disabled')); }, init.enabled ? _('Enabled') : _('Disabled'));
}, },
@ -93,9 +94,9 @@ return L.view.extend({
'%02d'.format(list[i].index), '%02d'.format(list[i].index),
list[i].name, list[i].name,
this.renderEnableDisable(list[i]), this.renderEnableDisable(list[i]),
E('button', { 'class': 'btn cbi-button-action', 'click': L.ui.createHandlerFn(this, 'handleAction', list[i].name, 'start') }, _('Start')), E('button', { 'class': 'btn cbi-button-action', 'click': ui.createHandlerFn(this, 'handleAction', list[i].name, 'start') }, _('Start')),
E('button', { 'class': 'btn cbi-button-action', 'click': L.ui.createHandlerFn(this, 'handleAction', list[i].name, 'restart') }, _('Restart')), E('button', { 'class': 'btn cbi-button-action', 'click': ui.createHandlerFn(this, 'handleAction', list[i].name, 'restart') }, _('Restart')),
E('button', { 'class': 'btn cbi-button-action', 'click': L.ui.createHandlerFn(this, 'handleAction', list[i].name, 'stop') }, _('Stop')) E('button', { 'class': 'btn cbi-button-action', 'click': ui.createHandlerFn(this, 'handleAction', list[i].name, 'stop') }, _('Stop'))
]); ]);
} }
@ -114,14 +115,14 @@ return L.view.extend({
E('div', { 'class': 'cbi-page-actions' }, [ E('div', { 'class': 'cbi-page-actions' }, [
E('button', { E('button', {
'class': 'btn cbi-button-save', 'class': 'btn cbi-button-save',
'click': L.ui.createHandlerFn(this, 'handleRcLocalSave') 'click': ui.createHandlerFn(this, 'handleRcLocalSave')
}, _('Save')) }, _('Save'))
]) ])
]) ])
]) ])
]); ]);
L.ui.tabs.initTabGroup(view.lastElementChild.childNodes); ui.tabs.initTabGroup(view.lastElementChild.childNodes);
return view; return view;
}, },

View file

@ -1,4 +1,5 @@
'use strict'; 'use strict';
'require ui';
'require uci'; 'require uci';
'require rpc'; 'require rpc';
'require form'; 'require form';
@ -58,14 +59,14 @@ CBILocalTime = form.DummyValue.extend({
' ', ' ',
E('button', { E('button', {
'class': 'cbi-button cbi-button-apply', 'class': 'cbi-button cbi-button-apply',
'click': L.ui.createHandlerFn(this, function() { 'click': ui.createHandlerFn(this, function() {
return callSetLocaltime(Math.floor(Date.now() / 1000)); return callSetLocaltime(Math.floor(Date.now() / 1000));
}) })
}, _('Sync with browser')), }, _('Sync with browser')),
' ', ' ',
this.ntpd_support ? E('button', { this.ntpd_support ? E('button', {
'class': 'cbi-button cbi-button-apply', 'class': 'cbi-button cbi-button-apply',
'click': L.ui.createHandlerFn(this, function() { 'click': ui.createHandlerFn(this, function() {
return callInitAction('sysntpd', 'restart'); return callInitAction('sysntpd', 'restart');
}) })
}, _('Sync with NTP-Server')) : '' }, _('Sync with NTP-Server')) : ''