10 NO_BOARD_NAME : function(args
) { return _('Unable to find Device Board Name.')},
11 NO_DUAL_FLAG : function(args
) {return _('Unable to find Dual Boot Flag Partition.')},
12 ERR_SET_DUAL_FLAG : function(args
) { return _('Unable to set Dual Boot Flag Partition entry for partition: %s.').format(args
[0])},
13 NO_FIRM_ENV : function(args
) { return _('Unable to obtain firmware environment variable: %s.').format(args
[0])},
14 ERR_SET_ENV : function(args
) { return _('Unable to set firmware environment variable: %s to %s.').format(args
[0],args
[1])}
17 callReboot
: rpc
.declare({
23 callObtainDeviceInfo
: rpc
.declare({
24 object
: 'luci.advanced_reboot',
25 method
: 'obtain_device_info',
29 callTogglePartition
: rpc
.declare({
30 object
: 'luci.advanced_reboot',
31 method
: 'toggle_boot_partition',
35 callPowerOff: function() {
36 return fs
.exec('/sbin/poweroff').then(function() {
37 ui
.showModal(_('Shutting down...'), [
38 E('p', { 'class': 'spinning' }, _('The system is shutting down now.<br /> DO NOT POWER OFF THE DEVICE!<br /> It might be necessary to renew the address of your computer to reach the device again, depending on your settings.'))
43 handlePowerOff: function() {
45 ui
.showModal(_('Power Off Device'), [
46 E('p', _("WARNING: Power off might result in a reboot on a device which doesn't support power off.<br /><br />\
47 Click \"Proceed\" below to power off your device.")),
48 E('div', { 'class': 'right' }, [
54 'class': 'btn cbi-button cbi-button-positive important',
55 'click': L
.bind(this.callPowerOff
, this)
62 handleReboot: function(ev
) {
63 return this.callReboot().then(function(res
) {
65 ui
.addNotification(null, E('p', _('The reboot command failed with code %d').format(res
)));
66 L
.raise('Error', 'Reboot failed');
69 ui
.showModal(_('Rebooting…'), [
70 E('p', { 'class': 'spinning' }, _('Waiting for device...'))
73 window
.setTimeout(function() {
74 ui
.showModal(_('Rebooting…'), [
75 E('p', { 'class': 'spinning alert-message warning' },
76 _('Device unreachable! Still waiting for device...'))
82 .catch(function(e
) { ui
.addNotification(null, E('p', e
.message
)) });
85 handleTogglePartition: function(ev
) {
86 return this.callTogglePartition().then(L
.bind(function(res
) {
89 return ui
.addNotification(null, E('p', this.translateTable
[res
.error
](res
.args
)));
92 return this.callReboot().then(function(res
) {
94 ui
.addNotification(null, E('p', _('The reboot command failed with code %d').format(res
)));
95 L
.raise('Error', 'Reboot failed');
98 ui
.showModal(_('Rebooting…'), [
99 E('p', { 'class': 'spinning' }, _('The system is rebooting to an alternative partition 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.'))
102 window
.setTimeout(function() {
103 ui
.showModal(_('Rebooting…'), [
104 E('p', { 'class': 'spinning alert-message warning' },
105 _('Device unreachable! Still waiting for device...'))
111 .catch(function(e
) { ui
.addNotification(null, E('p', e
.message
)) });
115 handleAlternativeReboot: function(ev
) {
117 L
.resolveDefault(fs
.stat('/usr/sbin/fw_printenv'), null),
118 L
.resolveDefault(fs
.stat('/usr/sbin/fw_setenv'), null),
119 ]).then(L
.bind(function (data
) {
120 if (!data
[0] || !data
[1]) {
121 return ui
.addNotification(null, E('p', _('No access to fw_printenv or fw_printenv!')));
124 ui
.showModal(_('Reboot Device to an Alternative Partition') + " - " + _("Confirm"), [
125 E('p', _("WARNING: An alternative partition might have its own settings and completely different firmware.<br /><br />\
126 As your network configuration and WiFi SSID/password on alternative partition might be different,\
127 you might have to adjust your computer settings to be able to access your device once it reboots.<br /><br />\
128 Please also be aware that alternative partition firmware might not provide an easy way to switch active partition\
129 and boot back to the currently active partition.<br /><br />\
130 Click \"Proceed\" below to reboot device to an alternative partition.")),
131 E('div', { 'class': 'right' }, [
134 'click': ui
.hideModal
135 }, _('Cancel')), ' ',
137 'class': 'btn cbi-button cbi-button-positive important',
138 'click': L
.bind(this.handleTogglePartition
, this)
145 parsePartitions: function(partitions
) {
148 partitions
.forEach(L
.bind(function(partition
) {
151 if (partition
.state
== 'Current') {
152 func
= 'handleReboot';
153 text
= _('Reboot to current partition');
155 func
= 'handleAlternativeReboot';
156 text
= _('Reboot to alternative partition...');
160 (partition
.number
+0x100).toString(16).substr(-2).toUpperCase(),
162 partition
.os
.replace("Unknown", _("Unknown")).replace("Compressed", _("Compressed")),
164 'class': 'btn cbi-button cbi-button-apply important',
165 'click': ui
.createHandlerFn(this, func
)
176 L
.resolveDefault(fs
.stat('/sbin/poweroff'), null),
177 this.callObtainDeviceInfo()
181 render: function(data
) {
182 var changes
= data
[0],
183 poweroff_supported
= data
[1] != null ? true : false,
184 device_info
= data
[2];
187 E('h2', _('Advanced Reboot'))
190 for (var config
in (changes
|| {})) {
191 body
.appendChild(E('p', { 'class': 'alert-message warning' },
192 _('Warning: There are unsaved changes that will get lost on reboot!')));
196 if (device_info
.error
)
197 body
.appendChild(E('p', { 'class' : 'alert-message warning'}, _("ERROR: ") + this.translateTable
[device_info
.error
]()));
199 body
.appendChild(E('h3', device_info
.device_name
+ _(' Partitions')));
200 if (device_info
.device_name
) {
201 var partitions_table
= E('table', { 'class': 'table' }, [
202 E('tr', { 'class': 'tr table-titles' }, [
203 E('th', { 'class': 'th' }, [ _('Partition') ]),
204 E('th', { 'class': 'th' }, [ _('Status') ]),
205 E('th', { 'class': 'th' }, [ _('Firmware') ]),
206 E('th', { 'class': 'th' }, [ _('Reboot') ])
210 cbi_update_table(partitions_table
, this.parsePartitions(device_info
.partitions
));
212 body
.appendChild(partitions_table
);
214 body
.appendChild(E('p', { 'class' : 'alert-message warning'},
215 device_info
.rom_board_name
? _("Warning: Device (%s) is unknown or isn't a dual-partition device!").format(device_info
.rom_board_name
)
216 : _('Warning: Unable to obtain device information!')
220 body
.appendChild(E('hr'));
222 poweroff_supported
? E('button', {
223 'class': 'btn cbi-button cbi-button-apply important',
224 'click': ui
.createHandlerFn(this, 'handlePowerOff')
225 }, _('Perform power off...'))
227 : E('p', { 'class' : 'alert-message warning'},
228 _('Warning: This system does not support powering off!'))
234 handleSaveApply
: null,