Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / package / luci / modules / luci-mod-system / luasrc / view / admin_system / reboot.htm
1 <%#
2  Copyright 2008 Steven Barth <steven@midlink.org>
3  Copyright 2008-2015 Jo-Philipp Wich <jow@openwrt.org>
4  Licensed to the public under the Apache License 2.0.
5 -%>
6
7 <%+header%>
8
9 <h2 name="content"><%:Reboot%></h2>
10
11 <p><%:Reboots the operating system of your device%></p>
12
13 <%- local c = require("luci.model.uci").cursor():changes(); if c and next(c) then -%>
14         <p class="alert-message warning"><%:Warning: There are unsaved changes that will get lost on reboot!%></p>
15 <%- end -%>
16
17 <hr />
18
19 <input class="cbi-button cbi-button-action important" type="button" value="<%:Perform reboot%>" onclick="reboot(this)" />
20
21 <p class="alert-message notice reboot-message" style="display:none">
22         <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
23         <span><%:Device is rebooting...%></span>
24 </p>
25
26 <script type="text/javascript">//<![CDATA[
27         var tries = 0,
28             message = document.querySelector('p.reboot-message'),
29             label = message.querySelector('span');
30
31         function ok() {
32                 window.location = '<%=url("admin")%>';
33         }
34
35         function check() {
36                 window.setTimeout(ping, 5000);
37         }
38
39         function ping() {
40                 var img = document.createElement('img');
41
42                 img.onload = ok;
43                 img.onerror = check;
44                 img.src = '<%=resource%>/icons/loading.gif?' + Math.random();
45
46                 if (tries++ >= 30) {
47                         message.classList.remove('notice');
48                         message.classList.add('warning');
49                         label.innerHTML = '<%:Device unreachable! Still waiting for device...%>';
50                 }
51         }
52
53         function reboot(button) {
54                 button.style.display = 'none';
55                 message.style.display = '';
56                 label.innerHTML = '<%:Waiting for device...%>';
57
58                 (new XHR()).post('<%=url("admin/system/reboot/call")%>', { token: '<%=token%>' }, check);
59         }
60 //]]></script>
61
62 <%+footer%>