szurubooru/public_html/js/Presenters/LogoutPresenter.js

37 lines
968 B
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-02 23:07:50 +02:00
function init() {
topNavigationPresenter.select('logout');
2014-09-04 18:06:25 +02:00
promise.wait(auth.logout()).then(function() {
$messages.empty();
2014-09-02 23:07:50 +02:00
var $messageDiv = messagePresenter.showInfo($messages, 'Logged out. <a href="">Back to main page</a>');
$messageDiv.find('a').click(mainPageLinkClicked);
2014-09-04 18:06:25 +02:00
}).fail(function(response) {
2014-09-07 08:47:06 +02:00
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);