v1.18.x
Baris Usakli
parent 08ba911738
commit aeb831eeff

@ -1,6 +1,8 @@
(function() { (function() {
var yourid = templates.get('yourid');
function initUsers() { function initUsers() {
function isUserAdmin(element) { function isUserAdmin(element) {
@ -10,29 +12,32 @@
function isUserBanned(element) { function isUserBanned(element) {
var parent = $(element).parents('.users-box'); var parent = $(element).parents('.users-box');
return (parent.attr('data-banned') !== "" && parent.attr('data-banned') !== "0"); return (parent.attr('data-banned') !== "" && parent.attr('data-banned') !== "0");
} }
function getUID(element) { function getUID(element) {
var parent = $(element).parents('.users-box'); var parent = $(element).parents('.users-box');
return parent.attr('data-uid'); return parent.attr('data-uid');
} }
jQuery('.admin-btn').each(function(index, element) { jQuery('.admin-btn').each(function(index, element) {
var adminBtn = $(element); var adminBtn = $(element);
var isAdmin = isUserAdmin(adminBtn); var isAdmin = isUserAdmin(adminBtn);
var uid = getUID(adminBtn);
if(isAdmin) if(isAdmin)
adminBtn.addClass('btn-success'); adminBtn.addClass('btn-success');
else else
adminBtn.removeClass('btn-success'); adminBtn.removeClass('btn-success');
if(uid === yourid)
adminBtn.addClass('disabled');
}); });
jQuery('.delete-btn').each(function(index, element) { jQuery('.delete-btn').each(function(index, element) {
var deleteBtn = $(element); var deleteBtn = $(element);
var isAdmin = isUserAdmin(deleteBtn); var isAdmin = isUserAdmin(deleteBtn);
if(isAdmin) if(isAdmin)
deleteBtn.addClass('disabled'); deleteBtn.addClass('disabled');
else else
@ -43,12 +48,12 @@
var banBtn = $(element); var banBtn = $(element);
var isAdmin = isUserAdmin(banBtn); var isAdmin = isUserAdmin(banBtn);
var isBanned = isUserBanned(banBtn); var isBanned = isUserBanned(banBtn);
if(isAdmin) if(isAdmin)
banBtn.addClass('disabled'); banBtn.addClass('disabled');
else if(isBanned) else if(isBanned)
banBtn.addClass('btn-warning'); banBtn.addClass('btn-warning');
else else
banBtn.removeClass('btn-warning'); banBtn.removeClass('btn-warning');
}); });
@ -59,13 +64,12 @@
var parent = adminBtn.parents('.users-box'); var parent = adminBtn.parents('.users-box');
var uid = getUID(adminBtn); var uid = getUID(adminBtn);
if(isAdmin) { if(isAdmin && uid != yourid) {
socket.emit('api:admin.user.removeAdmin', uid); socket.emit('api:admin.user.removeAdmin', uid);
adminBtn.removeClass('btn-success'); adminBtn.removeClass('btn-success');
parent.find('.delete-btn').removeClass('disabled'); parent.find('.delete-btn').removeClass('disabled');
parent.attr('data-admin', 0); parent.attr('data-admin', 0);
} } else if(uid != yourid) {
else {
bootbox.confirm('Do you really want to make "' + parent.attr('data-username') +'" an admin?', function(confirm) { bootbox.confirm('Do you really want to make "' + parent.attr('data-username') +'" an admin?', function(confirm) {
if(confirm) { if(confirm) {
socket.emit('api:admin.user.makeAdmin', uid); socket.emit('api:admin.user.makeAdmin', uid);
@ -75,7 +79,7 @@
} }
}); });
} }
return false; return false;
}); });
@ -87,10 +91,10 @@
if(!isAdmin) { if(!isAdmin) {
bootbox.confirm('Do you really want to delete "' + parent.attr('data-username') +'"?', function(confirm) { bootbox.confirm('Do you really want to delete "' + parent.attr('data-username') +'"?', function(confirm) {
socket.emit('api:admin.user.deleteUser', uid); socket.emit('api:admin.user.deleteUser', uid);
}); });
} }
return false; return false;
}); });
@ -108,13 +112,13 @@
parent.attr('data-banned', 0); parent.attr('data-banned', 0);
} else { } else {
bootbox.confirm('Do you really want to ban "' + parent.attr('data-username') +'"?', function(confirm) { bootbox.confirm('Do you really want to ban "' + parent.attr('data-username') +'"?', function(confirm) {
socket.emit('api:admin.user.banUser', uid); socket.emit('api:admin.user.banUser', uid);
banBtn.addClass('btn-warning'); banBtn.addClass('btn-warning');
parent.attr('data-banned', 1); parent.attr('data-banned', 1);
}); });
} }
} }
return false; return false;
}); });
} }
@ -122,8 +126,7 @@
jQuery('document').ready(function() { jQuery('document').ready(function() {
var yourid = templates.get('yourid'), var timeoutId = 0,
timeoutId = 0,
loadingMoreUsers = false; loadingMoreUsers = false;
var url = window.location.href, var url = window.location.href,
@ -146,17 +149,17 @@
timeoutId = setTimeout(function() { timeoutId = setTimeout(function() {
var username = $('#search-user').val(); var username = $('#search-user').val();
jQuery('.icon-spinner').removeClass('none'); jQuery('.icon-spinner').removeClass('none');
socket.emit('api:admin.user.search', username); socket.emit('api:admin.user.search', username);
}, 250); }, 250);
}); });
initUsers(); initUsers();
socket.removeAllListeners('api:admin.user.search'); socket.removeAllListeners('api:admin.user.search');
socket.on('api:admin.user.search', function(data) { socket.on('api:admin.user.search', function(data) {
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
users: data users: data
@ -164,7 +167,7 @@
userListEl = document.querySelector('.users'); userListEl = document.querySelector('.users');
userListEl.innerHTML = html; userListEl.innerHTML = html;
jQuery('.icon-spinner').addClass('none'); jQuery('.icon-spinner').addClass('none');
if(data && data.length === 0) { if(data && data.length === 0) {
$('#user-notfound-notify').html('User not found!') $('#user-notfound-notify').html('User not found!')
@ -178,10 +181,10 @@
.addClass('label-success') .addClass('label-success')
.removeClass('label-important'); .removeClass('label-important');
} }
initUsers(); initUsers();
}); });
function onUsersLoaded(users) { function onUsersLoaded(users) {
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ users: users }); var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ users: users });
$('#users-container').append(html); $('#users-container').append(html);
@ -200,8 +203,8 @@
if(set) { if(set) {
loadingMoreUsers = true; loadingMoreUsers = true;
socket.emit('api:users.loadMore', { socket.emit('api:users.loadMore', {
set: set, set: set,
after: $('#users-container').children().length after: $('#users-container').children().length
}, function(data) { }, function(data) {
if(data.users.length) { if(data.users.length) {
onUsersLoaded(data.users); onUsersLoaded(data.users);

Loading…
Cancel
Save