Merge branch 'AdminButton' of github.com:genderup/NodeBB into genderup-AdminButton

v1.18.x
Julian Lam 11 years ago
commit 35d6a99775

@ -1,6 +1,7 @@
# NodeBB
**NodeBB** is a robust Node.js driven forum built on a redis database. It is powered by web sockets, and is compatible down to IE8.
* [NodeBB Homepage](http://www.nodebb.org/ "NodeBB")
* [Demo & Meta Discussion](http://try.nodebb.org)
* [Wiki Guides](https://github.com/designcreateplay/NodeBB/wiki) - includes setup for other platforms

@ -19,7 +19,7 @@ define(function() {
return parent.attr('data-uid');
}
function updateUserButtons() {
function updateUserBanButtons() {
jQuery('.ban-btn').each(function(index, element) {
var banBtn = $(element);
var uid = getUID(banBtn);
@ -27,15 +27,37 @@ define(function() {
banBtn.addClass('disabled');
else if (isUserBanned(banBtn))
banBtn.addClass('btn-warning');
else if (!isUserAdmin(banBtn))
banBtn.removeClass('disabled');
else
banBtn.removeClass('btn-warning');
updateUserAdminButtons();
});
}
function updateUserAdminButtons() {
jQuery('.admin-btn').each(function(index, element) {
var banBtn = $(element);
var uid = getUID(banBtn);
if (isUserAdmin(banBtn) || uid === yourid)
banBtn.attr('value', 'UnMake Admin').html('Remove as Admin');
else if (isUserBanned(banBtn))
banBtn.addClass('disabled');
else if (!isUserBanned(banBtn))
banBtn.removeClass('disabled');
else
banBtn.removeClass('btn-warning');
});
}
function initUsers() {
updateUserButtons();
updateUserBanButtons();
updateUserAdminButtons();
$('#users-container').on('click', '.ban-btn', function() {
var banBtn = $(this);
@ -49,17 +71,51 @@ define(function() {
socket.emit('api:admin.user.unbanUser', uid);
banBtn.removeClass('btn-warning');
parent.attr('data-banned', 0);
updateUserAdminButtons();
} else {
bootbox.confirm('Do you really want to ban "' + parent.attr('data-username') + '"?', function(confirm) {
if (confirm) {
socket.emit('api:admin.user.banUser', uid);
banBtn.addClass('btn-warning');
parent.attr('data-banned', 1);
updateUserAdminButtons();
}
});
}
}
return false;
});
$('#users-container').on('click', '.admin-btn', function() {
var adminBtn = $(this);
var isAdmin = isUserAdmin(adminBtn);
var parent = adminBtn.parents('.users-box');
var isBanned = isUserBanned(adminBtn);
var uid = getUID(adminBtn);
if(uid === yourid){
alert("you can't remove yourself as admin");
}
else if (!isAdmin) {
socket.emit('api:admin.user.makeAdmin', uid);
adminBtn.attr('value', 'UnMake Admin').html('Remove as Admin');
parent.attr('data-admin', 1);
updateUserBanButtons();
} else if(uid !== yourid) {
bootbox.confirm('Do you really want to remove this user as admin "' + parent.attr('data-username') + '"?', function(confirm) {
if (confirm) {
socket.emit('api:admin.user.removeAdmin', uid);
adminBtn.attr('value', 'Make Admin').html('Make Admin');
parent.attr('data-admin', 0);
updateUserBanButtons();
}
});
}
return false;
});
}

@ -33,6 +33,9 @@
<i class='fa fa-pencil'></i>
<span id='postcount'>{users.postcount}</span>
</div>
<div>
<a href="#" class="btn btn-default admin-btn">Make Admin</a>
</div>
<div>
<a href="#" class="btn btn-default ban-btn">Ban</a>
</div>

Loading…
Cancel
Save