Skip to content

Commit

Permalink
feat: highlight privs row if group is added / navigating from group page
Browse files Browse the repository at this point in the history
  • Loading branch information
psychobunny committed Jul 23, 2020
1 parent 53f6139 commit 10e4ae6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
14 changes: 14 additions & 0 deletions public/less/admin/manage/privileges.less
Expand Up @@ -4,4 +4,18 @@
overflow-y: auto;
overflow-x: hidden;
}
}

.page-admin-privileges {
@keyframes fadeOut {
0% {background-color: @brand-primary;}
100% {background-color: white;}
}

[data-group-name].selected {
animation-name: fadeOut;
animation-duration: 5s;
animation-fill-mode: both;
animation-timing-function: ease-out;
}
}
2 changes: 1 addition & 1 deletion public/src/admin/manage/group.js
Expand Up @@ -93,7 +93,7 @@ define('admin/manage/group', [
var cid = $(this).attr('data-cid');

if (cid) {
var url = 'admin/manage/privileges/' + cid;
var url = 'admin/manage/privileges/' + cid + '?group=' + ajaxify.data.group.name;
if (app.flags && app.flags._unsaved === true) {
translator.translate('[[global:unsaved-changes]]', function (text) {
bootbox.confirm(text, function (navigate) {
Expand Down
66 changes: 46 additions & 20 deletions public/src/admin/manage/privileges.js
Expand Up @@ -6,7 +6,7 @@ define('admin/manage/privileges', [
'benchpress',
'categorySelector',
], function (autocomplete, translator, Benchpress, categorySelector) {
var Privileges = {};
var Privileges = {};

var cid;

Expand All @@ -21,6 +21,8 @@ define('admin/manage/privileges', [
});

Privileges.setupPrivilegeTable();

highlightRow();
};

Privileges.setupPrivilegeTable = function () {
Expand Down Expand Up @@ -79,7 +81,7 @@ define('admin/manage/privileges', [
Privileges.exposeAssumedPrivileges();
};

Privileges.refreshPrivilegeTable = function () {
Privileges.refreshPrivilegeTable = function (groupToHighlight) {
socket.emit('admin.categories.getPrivilegeSettings', cid, function (err, privileges) {
if (err) {
return app.alertError(err.message);
Expand All @@ -92,6 +94,10 @@ define('admin/manage/privileges', [
translator.translate(html, function (html) {
$('.privilege-table-container').html(html);
Privileges.exposeAssumedPrivileges();

if (groupToHighlight) {
$('[data-group-name="' + groupToHighlight + '"]').addClass('selected');
}
});
});
});
Expand Down Expand Up @@ -182,24 +188,7 @@ define('admin/manage/privileges', [
inputEl.focus();

autocomplete.group(inputEl, function (ev, ui) {
var defaultPrivileges;
if (ajaxify.data.url === '/admin/manage/privileges/admin') {
defaultPrivileges = ['groups:admin:dashboard'];
} else {
defaultPrivileges = cid ? ['groups:find', 'groups:read', 'groups:topics:read'] : ['groups:chat'];
}

socket.emit('admin.categories.setPrivilege', {
cid: isNaN(cid) ? 0 : cid,
privilege: defaultPrivileges,
set: true,
member: ui.item.group.name,
}, function (err) {
if (err) {
return app.alertError(err.message);
}

Privileges.refreshPrivilegeTable();
addGroupToCategory(ui.item.group.name, function () {
modal.modal('hide');
});
});
Expand Down Expand Up @@ -235,5 +224,42 @@ define('admin/manage/privileges', [
});
};

function highlightRow() {
var params = utils.params();
if (params.group) {
var el = $('[data-group-name="' + params.group + '"]');
if (el.length) {
return el.addClass('selected');
}

addGroupToCategory(params.group);
}
}

function addGroupToCategory(group, cb) {
var defaultPrivileges;
if (ajaxify.data.url === '/admin/manage/privileges/admin') {
defaultPrivileges = ['groups:admin:dashboard'];
} else {
defaultPrivileges = cid ? ['groups:find', 'groups:read', 'groups:topics:read'] : ['groups:chat'];
}

socket.emit('admin.categories.setPrivilege', {
cid: isNaN(cid) ? 0 : cid,
privilege: defaultPrivileges,
set: true,
member: group,
}, function (err) {
if (err) {
return app.alertError(err.message);
}

Privileges.refreshPrivilegeTable(group);
if (typeof cb === 'function') {
cb();
}
});
}

return Privileges;
});

0 comments on commit 10e4ae6

Please sign in to comment.