Moaaar buttons (reboot/poweroff)

This commit is contained in:
Alexandre Aubin 2019-10-17 17:36:29 +02:00
parent 52b4623222
commit 266e349d1f
2 changed files with 38 additions and 45 deletions

View file

@ -208,52 +208,45 @@
// Reboot or shutdown button // Reboot or shutdown button
app.get('#/tools/reboot', function (c) { app.get('#/tools/reboot', function (c) {
c.view('tools/tools_reboot'); c.view('tools/tools_reboot', {}, function() {
}); // Configure reboot/shutdown buttons behavior
$("button[data-action]").on("click", function() {
var action = $(this).data("action");
// Reboot or shutdown actions c.confirm(
app.get('#/tools/reboot/:action', function (c) { y18n.t('tools_' + action),
var action = c.params['action'].toLowerCase(); y18n.t('confirm_reboot_action_' + action),
if (action == 'reboot' || action == 'shutdown') { function(){
c.confirm( c.api('PUT', '/'+action+'?force', {}, function(data) {
y18n.t('tools_' + action), // This code is not executed due to 502 response (reboot or shutdown)
// confirm_reboot_action_reboot or confirm_reboot_action_shutdown c.redirect_to('#/logout');
y18n.t('confirm_reboot_action_' + action), }, function (xhr) {
function(){ c.flash('success', y18n.t('tools_' + action + '_done'))
c.api('PUT', '/'+action+'?force', {}, function(data) { // Disconnect from the webadmin
// This code is not executed due to 502 response (reboot or shutdown) store.clear('url');
c.redirect_to('#/logout'); store.clear('connected');
}, function (xhr) { store.set('path', '#/');
c.flash('success', y18n.t('tools_' + action + '_done'))
// Disconnect from the webadmin
store.clear('url');
store.clear('connected');
store.set('path', '#/');
// Rename the page to allow refresh without ask for rebooting // Rename the page to allow refresh without ask for rebooting
window.location.href = window.location.href.split('#')[0] + '#/'; window.location.href = window.location.href.split('#')[0] + '#/';
// Display reboot or shutdown info // Display reboot or shutdown info
// We can't use template because now the webserver is off // We can't use template because now the webserver is off
if (action == 'reboot') { if (action == 'reboot') {
$('#main').replaceWith('<div id="main"><div class="alert alert-warning"><i class="fa-refresh"></i> ' + y18n.t('tools_rebooting') + '</div></div>'); $('#main').replaceWith('<div id="main"><div class="alert alert-warning"><i class="fa-refresh"></i> ' + y18n.t('tools_rebooting') + '</div></div>');
} }
else { else {
$('#main').replaceWith('<div id="main"><div class="alert alert-warning"><i class="fa-power-off"></i> ' + y18n.t('tools_shuttingdown') + '</div></div>'); $('#main').replaceWith('<div id="main"><div class="alert alert-warning"><i class="fa-power-off"></i> ' + y18n.t('tools_shuttingdown') + '</div></div>');
} }
// Remove loader if any // Remove loader if any
$('div.loader').remove(); $('div.loader').remove();
// Force scrollTop on page load // Force scrollTop on page load
$('html, body').scrollTop(0); $('html, body').scrollTop(0);
}, false); }, false);
} });
); });
} });
else {
c.flash('fail', y18n.t('unknown_action', [action]));
c.redirect_to('#/tools/reboot', {slide: false});
}
}); });
// Diagnosis // Diagnosis

View file

@ -15,14 +15,14 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
<p> <p>
<a role="button" href="#/tools/reboot/reboot" class="btn btn-danger"> <button class="btn btn-danger" data-action="reboot">
<i class="fa-refresh"></i> {{t 'tools_reboot_btn'}} <i class="fa-refresh"></i> {{t 'tools_reboot_btn'}}
</a> </button>
</p> </p>
<p> <p>
<a role="button" href="#/tools/reboot/shutdown" class="btn btn-danger"> <button class="btn btn-danger" data-action="shutdown">
<i class="fa-power-off"></i> {{t 'tools_shutdown_btn'}} <i class="fa-power-off"></i> {{t 'tools_shutdown_btn'}}
</a> </button>
</p> </p>
</div> </div>
</div> </div>