szurubooru/public_html/js/Presenters/LogoutPresenter.js

41 lines
1 KiB
JavaScript
Raw Normal View History

2014-08-31 23:22:56 +02:00
var App = App || {};
App.Presenters = App.Presenters || {};
App.Presenters.LogoutPresenter = function(
jQuery,
2014-09-04 18:06:25 +02:00
promise,
2014-09-04 19:06:12 +02:00
router,
auth,
topNavigationPresenter,
messagePresenter) {
2014-08-31 23:22:56 +02:00
var $messages = jQuery('#content');
2014-09-17 22:37:49 +02:00
function init(args, loaded) {
topNavigationPresenter.select('logout');
topNavigationPresenter.changeTitle('Logout');
2014-09-17 22:37:49 +02:00
promise.wait(auth.logout())
.then(function() {
loaded();
$messages.empty();
var $messageDiv = messagePresenter.showInfo($messages, 'Logged out. <a href="">Back to main page</a>');
$messageDiv.find('a').click(mainPageLinkClicked);
}).fail(function(response) {
loaded();
messagePresenter.showError(($messages, response.json && response.json.error || response) + '<br/>Reload the page to continue.');
});
2014-09-02 23:07:50 +02:00
}
function mainPageLinkClicked(e) {
e.preventDefault();
router.navigateToMainPage();
}
return {
init: init
};
2014-08-31 23:22:56 +02:00
};
App.DI.register('logoutPresenter', ['jQuery', 'promise', 'router', 'auth', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.LogoutPresenter);