luci-mod-system: port reboot view to client side js
authorJo-Philipp Wich <jo@mein.io>
Mon, 7 Oct 2019 08:51:28 +0000 (10:51 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 7 Oct 2019 09:53:39 +0000 (11:53 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js [new file with mode: 0644]
modules/luci-mod-system/luasrc/controller/admin/system.lua
modules/luci-mod-system/luasrc/view/admin_system/reboot.htm [deleted file]

diff --git a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js
new file mode 100644 (file)
index 0000000..0a14465
--- /dev/null
@@ -0,0 +1,59 @@
+'use strict';
+'require fs';
+'require ui';
+'require uci';
+'require rpc';
+
+var callReboot = rpc.declare({
+       object: 'luci',
+       method: 'setReboot',
+       expect: { result: false }
+});
+
+return L.view.extend({
+       load: function() {
+               return uci.changes();
+       },
+
+       render: function(changes) {
+               var body = E([
+                       E('h2', _('Reboot')),
+                       E('p', {}, _('Reboots the operating system of your device'))
+               ]);
+
+               for (var config in (changes || {})) {
+                       body.appendChild(E('p', { 'class': 'alert-message warning' },
+                               _('Warning: There are unsaved changes that will get lost on reboot!')));
+                       break;
+               }
+
+               body.appendChild(E('hr'));
+               body.appendChild(E('button', {
+                       'class': 'cbi-button cbi-button-action important',
+                       'click': ui.createHandlerFn(this, 'handleReboot')
+               }, _('Perform reboot')));
+
+               return body;
+       },
+
+       handleReboot: function(ev) {
+               return callReboot().then(function() {
+                       L.ui.showModal(_('Rebooting…'), [
+                               E('p', { 'class': 'spinning' }, _('Waiting for device...'))
+                       ]);
+
+                       window.setTimeout(function() {
+                               L.ui.showModal(_('Rebooting…'), [
+                                       E('p', { 'class': 'spinning alert-message warning' },
+                                               _('Device unreachable! Still waiting for device...'))
+                               ]);
+                       }, 150000);
+
+                       L.ui.awaitReconnect();
+               });
+       },
+
+       handleSaveApply: null,
+       handleSave: null,
+       handleReset: null
+});
index c7d8ac53236505d6e5be0a592ba5c3c3b60e2aad..2913a23ef241aa8b816114a9ee9166569a4d3151 100644 (file)
@@ -31,10 +31,5 @@ function index()
 
        entry({"admin", "system", "flash"}, view("system/flash"), _("Backup / Flash Firmware"), 70)
 
-       entry({"admin", "system", "reboot"}, template("admin_system/reboot"), _("Reboot"), 90)
-       entry({"admin", "system", "reboot", "call"}, post("action_reboot"))
-end
-
-function action_reboot()
-       luci.sys.reboot()
+       entry({"admin", "system", "reboot"}, view("system/reboot"), _("Reboot"), 90)
 end
diff --git a/modules/luci-mod-system/luasrc/view/admin_system/reboot.htm b/modules/luci-mod-system/luasrc/view/admin_system/reboot.htm
deleted file mode 100644 (file)
index d23664a..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-<%#
- Copyright 2008 Steven Barth <steven@midlink.org>
- Copyright 2008-2015 Jo-Philipp Wich <jow@openwrt.org>
- Licensed to the public under the Apache License 2.0.
--%>
-
-<%+header%>
-
-<h2 name="content"><%:Reboot%></h2>
-
-<p><%:Reboots the operating system of your device%></p>
-
-<%- local c = require("luci.model.uci").cursor():changes(); if c and next(c) then -%>
-       <p class="alert-message warning"><%:Warning: There are unsaved changes that will get lost on reboot!%></p>
-<%- end -%>
-
-<hr />
-
-<input class="cbi-button cbi-button-action important" type="button" value="<%:Perform reboot%>" onclick="reboot(this)" />
-
-<p class="alert-message notice reboot-message" style="display:none">
-       <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
-       <span><%:Device is rebooting...%></span>
-</p>
-
-<script type="text/javascript">//<![CDATA[
-       var tries = 0,
-           message = document.querySelector('p.reboot-message'),
-           label = message.querySelector('span');
-
-       function ok() {
-               window.location = '<%=url("admin")%>';
-       }
-
-       function check() {
-               window.setTimeout(ping, 5000);
-       }
-
-       function ping() {
-               var img = document.createElement('img');
-
-               img.onload = ok;
-               img.onerror = check;
-               img.src = '<%=resource%>/icons/loading.gif?' + Math.random();
-
-               if (tries++ >= 30) {
-                       message.classList.remove('notice');
-                       message.classList.add('warning');
-                       label.innerHTML = '<%:Device unreachable! Still waiting for device...%>';
-               }
-       }
-
-       function reboot(button) {
-               button.style.display = 'none';
-               message.style.display = '';
-               label.innerHTML = '<%:Waiting for device...%>';
-
-               (new XHR()).post('<%=url("admin/system/reboot/call")%>', { token: '<%=token%>' }, check);
-       }
-//]]></script>
-
-<%+footer%>