diff --git a/src/js/yunohost/controllers/tools.js b/src/js/yunohost/controllers/tools.js index 03f6f1a7..3f2e08c5 100644 --- a/src/js/yunohost/controllers/tools.js +++ b/src/js/yunohost/controllers/tools.js @@ -208,52 +208,45 @@ // Reboot or shutdown button 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 - app.get('#/tools/reboot/:action', function (c) { - var action = c.params['action'].toLowerCase(); - if (action == 'reboot' || action == 'shutdown') { - c.confirm( - y18n.t('tools_' + action), - // confirm_reboot_action_reboot or confirm_reboot_action_shutdown - y18n.t('confirm_reboot_action_' + action), - function(){ - c.api('PUT', '/'+action+'?force', {}, function(data) { - // This code is not executed due to 502 response (reboot or shutdown) - c.redirect_to('#/logout'); - }, function (xhr) { - c.flash('success', y18n.t('tools_' + action + '_done')) - // Disconnect from the webadmin - store.clear('url'); - store.clear('connected'); - store.set('path', '#/'); + c.confirm( + y18n.t('tools_' + action), + y18n.t('confirm_reboot_action_' + action), + function(){ + c.api('PUT', '/'+action+'?force', {}, function(data) { + // This code is not executed due to 502 response (reboot or shutdown) + c.redirect_to('#/logout'); + }, function (xhr) { + 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 - window.location.href = window.location.href.split('#')[0] + '#/'; - // Display reboot or shutdown info - // We can't use template because now the webserver is off - if (action == 'reboot') { - $('#main').replaceWith('
' + y18n.t('tools_rebooting') + '
'); - } - else { - $('#main').replaceWith('
' + y18n.t('tools_shuttingdown') + '
'); - } + // Rename the page to allow refresh without ask for rebooting + window.location.href = window.location.href.split('#')[0] + '#/'; + // Display reboot or shutdown info + // We can't use template because now the webserver is off + if (action == 'reboot') { + $('#main').replaceWith('
' + y18n.t('tools_rebooting') + '
'); + } + else { + $('#main').replaceWith('
' + y18n.t('tools_shuttingdown') + '
'); + } - // Remove loader if any - $('div.loader').remove(); + // Remove loader if any + $('div.loader').remove(); - // Force scrollTop on page load - $('html, body').scrollTop(0); + // Force scrollTop on page load + $('html, body').scrollTop(0); }, false); - } - ); - } - else { - c.flash('fail', y18n.t('unknown_action', [action])); - c.redirect_to('#/tools/reboot', {slide: false}); - } + }); + }); + }); }); // Diagnosis diff --git a/src/views/tools/tools_reboot.ms b/src/views/tools/tools_reboot.ms index c66bc0a0..ef184eaf 100644 --- a/src/views/tools/tools_reboot.ms +++ b/src/views/tools/tools_reboot.ms @@ -15,14 +15,14 @@

- +

- +