closes #5569
parent
d64b814acb
commit
8446a733e5
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"administrators": "Administrators",
|
||||||
|
"global-moderators": "Global Moderators",
|
||||||
|
"no-global-moderators": "No Global Moderators",
|
||||||
|
"moderators-of-category": "%1 Moderators",
|
||||||
|
"no-moderators": "No Moderators",
|
||||||
|
"add-administrator": "Add Administrator",
|
||||||
|
"add-global-moderator": "Add Global Moderator",
|
||||||
|
"add-moderator": "Add Moderator"
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
.admins-mods {
|
||||||
|
.user-card {
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove-user-icon {
|
||||||
|
margin-right: 5px;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.category-depth-1 {
|
||||||
|
margin-left: 30px;
|
||||||
|
}
|
||||||
|
.category-depth-2 {
|
||||||
|
margin-left: 60px;
|
||||||
|
}
|
||||||
|
.category-depth-3 {
|
||||||
|
margin-left: 90px;
|
||||||
|
}
|
||||||
|
.category-depth-4 {
|
||||||
|
margin-left: 120px;
|
||||||
|
}
|
||||||
|
.category-depth-5 {
|
||||||
|
margin-left: 150px;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,142 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
define('admin/manage/admins-mods', ['translator', 'benchpress', 'autocomplete'], function (translator, Benchpress, autocomplete) {
|
||||||
|
var AdminsMods = {};
|
||||||
|
|
||||||
|
AdminsMods.init = function () {
|
||||||
|
autocomplete.user($('#admin-search'), function (ev, ui) {
|
||||||
|
socket.emit('admin.user.makeAdmins', [ui.item.user.uid], function (err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
app.alertSuccess('[[admin/manage/users:alerts.make-admin-success]]');
|
||||||
|
$('#admin-search').val('');
|
||||||
|
|
||||||
|
if ($('.administrator-area [data-uid="' + ui.item.user.uid + '"]').length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.parseAndTranslate('admin/manage/admins-mods', 'admins.members', { admins: { members: [ui.item.user] } }, function (html) {
|
||||||
|
$('.administrator-area').prepend(html);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.administrator-area').on('click', '.remove-user-icon', function () {
|
||||||
|
var userCard = $(this).parents('[data-uid]');
|
||||||
|
var uid = userCard.attr('data-uid');
|
||||||
|
if (parseInt(uid, 10) === parseInt(app.user.uid, 10)) {
|
||||||
|
return app.alertError('[[admin/manage/users:alerts.no-remove-yourself-admin]]');
|
||||||
|
}
|
||||||
|
bootbox.confirm('[[admin/manage/users:alerts.confirm-remove-admin]]', function (confirm) {
|
||||||
|
if (confirm) {
|
||||||
|
socket.emit('admin.user.removeAdmins', [uid], function (err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
app.alertSuccess('[[admin/manage/users:alerts.remove-admin-success]]');
|
||||||
|
userCard.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
autocomplete.user($('#global-mod-search'), function (ev, ui) {
|
||||||
|
socket.emit('admin.groups.join', {
|
||||||
|
groupName: 'Global Moderators',
|
||||||
|
uid: ui.item.user.uid,
|
||||||
|
}, function (err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
app.alertSuccess('[[admin/manage/users:alerts.make-global-mod-success]]');
|
||||||
|
$('#global-mod-search').val('');
|
||||||
|
|
||||||
|
if ($('.global-moderator-area [data-uid="' + ui.item.user.uid + '"]').length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.parseAndTranslate('admin/manage/admins-mods', 'globalMods.members', { globalMods: { members: [ui.item.user] } }, function (html) {
|
||||||
|
$('.global-moderator-area').prepend(html);
|
||||||
|
$('#no-global-mods-warning').addClass('hidden');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.global-moderator-area').on('click', '.remove-user-icon', function () {
|
||||||
|
var userCard = $(this).parents('[data-uid]');
|
||||||
|
var uid = userCard.attr('data-uid');
|
||||||
|
|
||||||
|
bootbox.confirm('[[admin/manage/users:alerts.confirm-remove-global-mod]]', function (confirm) {
|
||||||
|
if (confirm) {
|
||||||
|
socket.emit('admin.groups.leave', { uid: uid, groupName: 'Global Moderators' }, function (err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
app.alertSuccess('[[admin/manage/users:alerts.remove-global-mod-success]]');
|
||||||
|
userCard.remove();
|
||||||
|
if (!$('.global-moderator-area').children().length) {
|
||||||
|
$('#no-global-mods-warning').removeClass('hidden');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
autocomplete.user($('.moderator-search'), function (ev, ui) {
|
||||||
|
var input = $(ev.target);
|
||||||
|
var cid = $(ev.target).attr('data-cid');
|
||||||
|
socket.emit('admin.categories.setPrivilege', {
|
||||||
|
cid: cid,
|
||||||
|
privilege: ['moderate'],
|
||||||
|
set: true,
|
||||||
|
member: ui.item.user.uid,
|
||||||
|
}, function (err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
app.alertSuccess('[[admin/manage/users:alerts.make-moderator-success]]');
|
||||||
|
input.val('');
|
||||||
|
|
||||||
|
if ($('.moderator-area[data-cid="' + cid + '"] [data-uid="' + ui.item.user.uid + '"]').length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.parseAndTranslate('admin/manage/admins-mods', 'globalMods', { globalMods: [ui.item.user] }, function (html) {
|
||||||
|
$('.moderator-area[data-cid="' + cid + '"]').prepend(html);
|
||||||
|
$('.no-moderator-warning[data-cid="' + cid + '"]').addClass('hidden');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.moderator-area').on('click', '.remove-user-icon', function () {
|
||||||
|
var moderatorArea = $(this).parents('[data-cid]');
|
||||||
|
var cid = moderatorArea.attr('data-cid');
|
||||||
|
var userCard = $(this).parents('[data-uid]');
|
||||||
|
var uid = userCard.attr('data-uid');
|
||||||
|
|
||||||
|
bootbox.confirm('[[admin/manage/users:alerts.confirm-remove-moderator]]', function (confirm) {
|
||||||
|
if (confirm) {
|
||||||
|
socket.emit('admin.categories.setPrivilege', {
|
||||||
|
cid: cid,
|
||||||
|
privilege: ['moderate'],
|
||||||
|
set: false,
|
||||||
|
member: uid,
|
||||||
|
}, function (err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
app.alertSuccess('[[admin/manage/users:alerts.remove-moderator-success]]');
|
||||||
|
userCard.remove();
|
||||||
|
if (!moderatorArea.children().length) {
|
||||||
|
$('.no-moderator-warning[data-cid="' + cid + '"]').removeClass('hidden');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return AdminsMods;
|
||||||
|
});
|
@ -0,0 +1,50 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
|
var groups = require('../../groups');
|
||||||
|
var categories = require('../../categories');
|
||||||
|
|
||||||
|
var AdminsMods = module.exports;
|
||||||
|
|
||||||
|
AdminsMods.get = function (req, res, next) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
async.parallel({
|
||||||
|
admins: function (next) {
|
||||||
|
groups.get('administrators', { uid: req.uid }, next);
|
||||||
|
},
|
||||||
|
globalMods: function (next) {
|
||||||
|
groups.get('Global Moderators', { uid: req.uid }, next);
|
||||||
|
},
|
||||||
|
categories: function (next) {
|
||||||
|
getModeratorsOfCategories(req.uid, next);
|
||||||
|
},
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (results) {
|
||||||
|
res.render('admin/manage/admins-mods', results);
|
||||||
|
},
|
||||||
|
], next);
|
||||||
|
};
|
||||||
|
|
||||||
|
function getModeratorsOfCategories(uid, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
categories.buildForSelect(uid, 'find', next);
|
||||||
|
},
|
||||||
|
function (categoryData, next) {
|
||||||
|
async.map(categoryData, function (category, next) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
categories.getModerators(category.cid, next);
|
||||||
|
},
|
||||||
|
function (moderators, next) {
|
||||||
|
category.moderators = moderators;
|
||||||
|
next(null, category);
|
||||||
|
},
|
||||||
|
], next);
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
<div class="admins-mods">
|
||||||
|
<h4><!-- IF admins.icon --><i class="fa {admins.icon}"></i> <!-- ENDIF admins.icon -->[[admin/manage/admins-mods:administrators]]</h4>
|
||||||
|
<div class="administrator-area">
|
||||||
|
<!-- BEGIN admins.members -->
|
||||||
|
<div class="user-card pull-left" data-uid="{admins.members.uid}">
|
||||||
|
<!-- IF admins.members.picture -->
|
||||||
|
<img class="avatar avatar-sm" src="{admins.members.picture}" />
|
||||||
|
<!-- ELSE -->
|
||||||
|
<div class="avatar avatar-sm" style="background-color: {admins.members.icon:bgColor};">{admins.members.icon:text}</div>
|
||||||
|
<!-- ENDIF admins.members.picture -->
|
||||||
|
<a href="{config.relative_path}/user/{admins.members.userslug}">{admins.members.username}</a>
|
||||||
|
<i class="remove-user-icon fa fa-times" role="button"></i>
|
||||||
|
</div>
|
||||||
|
<!-- END admins.members -->
|
||||||
|
</div>
|
||||||
|
<input id="admin-search" class="form-control" placeholder="[[admin/manage/admins-mods:add-administrator]]" />
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<h4><!-- IF globalMods.icon --><i class="fa {globalMods.icon}"></i> <!-- ENDIF globalMods.icon -->[[admin/manage/admins-mods:global-moderators]]</h4>
|
||||||
|
<div class="global-moderator-area">
|
||||||
|
<!-- BEGIN globalMods.members -->
|
||||||
|
<div class="user-card pull-left" data-uid="{globalMods.members.uid}">
|
||||||
|
<!-- IF globalMods.members.picture -->
|
||||||
|
<img class="avatar avatar-sm" src="{globalMods.members.picture}" />
|
||||||
|
<!-- ELSE -->
|
||||||
|
<div class="avatar avatar-sm" style="background-color: {globalMods.members.icon:bgColor};">{globalMods.members.icon:text}</div>
|
||||||
|
<!-- ENDIF globalMods.members.picture -->
|
||||||
|
<a href="{config.relative_path}/user/{globalMods.members.userslug}">{globalMods.members.username}</a>
|
||||||
|
<i class="remove-user-icon fa fa-times" role="button"></i>
|
||||||
|
</div>
|
||||||
|
<!-- END globalMods.members -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="no-global-mods-warning" class="<!-- IF globalMods.members.length -->hidden<!-- ENDIF globalMods.members.length -->">[[admin/manage/admins-mods:no-global-moderators]]</div>
|
||||||
|
|
||||||
|
<input id="global-mod-search" class="form-control" placeholder="[[admin/manage/admins-mods:add-global-moderator]]" />
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<!-- BEGIN categories -->
|
||||||
|
<div class="categories category-wrapper category-depth-{categories.depth}">
|
||||||
|
<h4><!-- IF categories.icon --><i class="fa {categories.icon}"></i> <!-- ENDIF categories.icon -->[[admin/manage/admins-mods:moderators-of-category, {categories.name}]]</h4>
|
||||||
|
<div class="moderator-area" data-cid="{categories.cid}">
|
||||||
|
<!-- BEGIN categories.moderators -->
|
||||||
|
<div class="user-card pull-left" data-uid="{categories.moderators.uid}">
|
||||||
|
<!-- IF categories.moderators.picture -->
|
||||||
|
<img class="avatar avatar-sm" src="{categories.moderators.picture}" />
|
||||||
|
<!-- ELSE -->
|
||||||
|
<div class="avatar avatar-sm" style="background-color: {categories.moderators.icon:bgColor};">{categories.moderators.icon:text}</div>
|
||||||
|
<!-- ENDIF categories.moderators.picture -->
|
||||||
|
<a href="{config.relative_path}/user/{categories.moderators.userslug}">{categories.moderators.username}</a>
|
||||||
|
<i class="remove-user-icon fa fa-times" role="button"></i>
|
||||||
|
</div>
|
||||||
|
<!-- END categories.moderators -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div data-cid="{categories.cid}" class="no-moderator-warning <!-- IF categories.moderators.length -->hidden<!-- ENDIF categories.moderators.length -->">[[admin/manage/admins-mods:no-moderators]]</div>
|
||||||
|
|
||||||
|
<input data-cid="{categories.cid}" class="form-control moderator-search" placeholder="[[admin/manage/admins-mods:add-moderator]]" />
|
||||||
|
</div>
|
||||||
|
<br/>
|
||||||
|
<!-- END categories -->
|
||||||
|
</div>
|
Loading…
Reference in New Issue