refactor: deprecate app.logout
use logout module instead move header related code out of app.jsisekai-main
parent
415dfbb9f7
commit
8b4510cc70
@ -0,0 +1,71 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
define('forum/header', ['forum/header/notifications', 'forum/header/chat'], function (notifications, chat) {
|
||||||
|
const module = {};
|
||||||
|
|
||||||
|
module.prepareDOM = function () {
|
||||||
|
notifications.prepareDOM();
|
||||||
|
chat.prepareDOM();
|
||||||
|
handleStatusChange();
|
||||||
|
createHeaderTooltips();
|
||||||
|
handleLogout();
|
||||||
|
};
|
||||||
|
|
||||||
|
function handleStatusChange() {
|
||||||
|
$('[component="header/usercontrol"] [data-status]').off('click').on('click', function (e) {
|
||||||
|
const status = $(this).attr('data-status');
|
||||||
|
socket.emit('user.setStatus', status, function (err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
$('[data-uid="' + app.user.uid + '"] [component="user/status"], [component="header/profilelink"] [component="user/status"]')
|
||||||
|
.removeClass('away online dnd offline')
|
||||||
|
.addClass(status);
|
||||||
|
$('[component="header/usercontrol"] [data-status]').each(function () {
|
||||||
|
$(this).find('span').toggleClass('bold', $(this).attr('data-status') === status);
|
||||||
|
});
|
||||||
|
app.user.status = status;
|
||||||
|
});
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createHeaderTooltips() {
|
||||||
|
const env = utils.findBootstrapEnvironment();
|
||||||
|
if (env === 'xs' || env === 'sm' || utils.isTouchDevice()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$('#header-menu li a[title]').each(function () {
|
||||||
|
$(this).tooltip({
|
||||||
|
placement: 'bottom',
|
||||||
|
trigger: 'hover',
|
||||||
|
title: $(this).attr('title'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('#search-form').tooltip({
|
||||||
|
placement: 'bottom',
|
||||||
|
trigger: 'hover',
|
||||||
|
title: $('#search-button i').attr('title'),
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('#user_dropdown').tooltip({
|
||||||
|
placement: 'bottom',
|
||||||
|
trigger: 'hover',
|
||||||
|
title: $('#user_dropdown').attr('title'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleLogout() {
|
||||||
|
$('#header-menu .container').on('click', '[component="user/logout"]', function () {
|
||||||
|
require(['logout'], function (logout) {
|
||||||
|
logout();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return module;
|
||||||
|
});
|
@ -0,0 +1,28 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
define('logout', ['hooks'], function (hooks) {
|
||||||
|
return function logout(redirect) {
|
||||||
|
redirect = redirect === undefined ? true : redirect;
|
||||||
|
hooks.fire('action:app.logout');
|
||||||
|
|
||||||
|
$.ajax(config.relative_path + '/logout', {
|
||||||
|
type: 'POST',
|
||||||
|
headers: {
|
||||||
|
'x-csrf-token': config.csrf_token,
|
||||||
|
},
|
||||||
|
beforeSend: function () {
|
||||||
|
app.flags._logout = true;
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
hooks.fire('action:app.loggedOut', data);
|
||||||
|
if (redirect) {
|
||||||
|
if (data.next) {
|
||||||
|
window.location.href = data.next;
|
||||||
|
} else {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
Loading…
Reference in New Issue