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