diff --git a/public/src/forum/admin/users.js b/public/src/forum/admin/users.js index 9269200ddf..93f3ea9e20 100644 --- a/public/src/forum/admin/users.js +++ b/public/src/forum/admin/users.js @@ -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; }); } diff --git a/public/templates/admin/users.tpl b/public/templates/admin/users.tpl index b2507828d3..3eea35a9d1 100644 --- a/public/templates/admin/users.tpl +++ b/public/templates/admin/users.tpl @@ -33,6 +33,9 @@ {users.postcount} +