szurubooru/public_html/js/Presenters/LogoutPresenter.js

41 lines
1.2 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(
2015-06-28 10:07:11 +02:00
jQuery,
promise,
router,
auth,
topNavigationPresenter,
messagePresenter) {
2014-08-31 23:22:56 +02:00
2015-06-28 10:07:11 +02:00
var $messages = jQuery('#content');
2014-08-31 23:22:56 +02:00
2015-06-28 10:07:11 +02:00
function init(params, loaded) {
topNavigationPresenter.select('logout');
topNavigationPresenter.changeTitle('Logout');
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) {
messagePresenter.showError(($messages, response.json && response.json.error || response) + '<br/>Reload the page to continue.');
loaded();
});
}
2014-09-02 23:07:50 +02:00
2015-06-28 10:07:11 +02:00
function mainPageLinkClicked(e) {
e.preventDefault();
router.navigateToMainPage();
}
2014-09-02 23:07:50 +02:00
2015-06-28 10:07:11 +02:00
return {
init: init
};
2014-08-31 23:22:56 +02:00
};
App.DI.register('logoutPresenter', ['jQuery', 'promise', 'router', 'auth', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.LogoutPresenter);