mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[enh] Add some comments
This commit is contained in:
parent
fae6c974d1
commit
169e592cbc
1 changed files with 36 additions and 1 deletions
|
@ -10,7 +10,20 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Update group or permissions
|
||||
*
|
||||
* @model data organize in the same way than /users/groups?full&include_primary_groups
|
||||
* @params.operation "add"|"remove"
|
||||
* @params.type "members"|"permissions"
|
||||
* @param.item Name of the user or the permission to add or remove
|
||||
* @param.group Name of the group affected
|
||||
*
|
||||
* This function is built to be apply with params generated by the use of
|
||||
* HTML dataset attributes (e.g. link in the partial inline view "label" in group_list.ms)
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function updateGroup(model, params) {
|
||||
var type = params.type;
|
||||
var operation = params.operation;
|
||||
|
@ -44,7 +57,16 @@
|
|||
updateView(data);
|
||||
}, 'PUT', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the view with the new model
|
||||
*
|
||||
* @model data organize in the same way than /users/groups?full&include_primary_groups
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function updateView(model) {
|
||||
// Sort in aphanumerical order to improve user experience
|
||||
for (var group in model.groups) {
|
||||
model.groups[group].permissions.sort();
|
||||
model.groups[group].permissionsInv.sort();
|
||||
|
@ -52,8 +74,11 @@
|
|||
model.groups[group].membersInv.sort();
|
||||
}
|
||||
|
||||
// Manual render, we don't use c.view to avoid scrollTop and other
|
||||
// uneeded behaviour
|
||||
var rendered = c.render('views/user/group_list.ms', model);
|
||||
rendered.swap(function () {
|
||||
// Add click event to get a nice "reactive" interface
|
||||
jQuery(".group-update").on('click', function (e) {
|
||||
updateGroup(model, jQuery(this)[0].dataset);
|
||||
return false;
|
||||
|
@ -65,6 +90,8 @@
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
app.get('#/groups', function (c) {
|
||||
c.api('/users/groups?full&include_primary_groups', function(data_groups) {
|
||||
c.api('/users', function(data_users) {
|
||||
|
@ -73,6 +100,8 @@
|
|||
var specific_perms = {};
|
||||
var all_perms = data_permissions.permissions;
|
||||
var users = Object.keys(data_users.users);
|
||||
|
||||
// Enrich groups data with primary group indicator and inversed items list
|
||||
for (var group in data_groups.groups) {
|
||||
data_groups.groups[group].primary = users.indexOf(group) !== -1;
|
||||
data_groups.groups[group].permissionsInv = all_perms.filter(function(item) {
|
||||
|
@ -82,11 +111,17 @@
|
|||
return data_groups.groups[group].members.indexOf(item) === -1;
|
||||
});
|
||||
}
|
||||
|
||||
// Declare all_users and visitors has special
|
||||
data_groups.groups['all_users'].special = true;
|
||||
data_groups.groups['visitors'].special = true;
|
||||
|
||||
// Data given to the view with 2 functions to display permission in
|
||||
// a better way
|
||||
data = {
|
||||
'groups':data_groups.groups,
|
||||
'displayPermission': function (text) {
|
||||
// Display a permission correctly for a human
|
||||
text = text.replace('.main', '');
|
||||
if (text.indexOf('.') > -1)
|
||||
text = text.replace('.', ' (') + ')';
|
||||
|
|
Loading…
Reference in a new issue