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