luci-mod-system: use ubus method for reboot
[project/luci.git] / modules / luci-mod-system / htdocs / luci-static / resources / view / system / reboot.js
1 'use strict';
2 'require view';
3 'require rpc';
4 'require ui';
5 'require uci';
6
7 var callReboot = rpc.declare({
8 object: 'system',
9 method: 'reboot',
10 expect: { result: 0 }
11 });
12
13 return view.extend({
14 load: function() {
15 return uci.changes();
16 },
17
18 render: function(changes) {
19 var body = E([
20 E('h2', _('Reboot')),
21 E('p', {}, _('Reboots the operating system of your device'))
22 ]);
23
24 for (var config in (changes || {})) {
25 body.appendChild(E('p', { 'class': 'alert-message warning' },
26 _('Warning: There are unsaved changes that will get lost on reboot!')));
27 break;
28 }
29
30 body.appendChild(E('hr'));
31 body.appendChild(E('button', {
32 'class': 'cbi-button cbi-button-action important',
33 'click': ui.createHandlerFn(this, 'handleReboot')
34 }, _('Perform reboot')));
35
36 return body;
37 },
38
39 handleReboot: function(ev) {
40 return callReboot().then(function(res) {
41 if (res != 0) {
42 L.ui.addNotification(null, E('p', _('The reboot command failed with code %d').format(res)));
43 L.raise('Error', 'Reboot failed');
44 }
45
46 L.ui.showModal(_('Rebooting…'), [
47 E('p', { 'class': 'spinning' }, _('Waiting for device...'))
48 ]);
49
50 window.setTimeout(function() {
51 L.ui.showModal(_('Rebooting…'), [
52 E('p', { 'class': 'spinning alert-message warning' },
53 _('Device unreachable! Still waiting for device...'))
54 ]);
55 }, 150000);
56
57 L.ui.awaitReconnect();
58 })
59 .catch(function(e) { L.ui.addNotification(null, E('p', e.message)) });
60 },
61
62 handleSaveApply: null,
63 handleSave: null,
64 handleReset: null
65 });