Skip to content

Commit

Permalink
Ajax load groups in users page
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry authored and LukasReschke committed Sep 15, 2014
1 parent 31898aa commit 310ef7b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
4 changes: 4 additions & 0 deletions settings/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,7 @@ doesnotexist:-o-prefocus, .strengthify-wrapper {
border: 0;
overflow: auto;
}

#usergrouplist {
padding-bottom: 40px;
}
22 changes: 17 additions & 5 deletions settings/js/users/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ GroupList = {
activeGID: '',
everyoneGID: '_everyone',

addGroup: function (gid, usercount) {
var $li = $userGroupList.find('.isgroup:last-child').clone();
addGroup: function (gid, usercount, isAdmin) {
var $li = $userGroupList.find('.isgroup.template').clone();
$li.removeClass('template hidden');
$li
.data('gid', gid)
.find('.groupname').text(gid);
GroupList.setUserCount($li, usercount);

$li.appendTo($userGroupList);
if (isAdmin) {
$li.find('.action.delete').remove();
}

GroupList.sortGroups();

Expand Down Expand Up @@ -96,7 +100,7 @@ GroupList = {
else {
if (result.data.groupname) {
var addedGroup = result.data.groupname;
UserList.availableGroups = $.unique($.merge(UserList.availableGroups, [addedGroup]));
UserList.availableGroups = $.unique($.merge(UserList.availableGroups || [], [addedGroup]));
GroupList.addGroup(result.data.groupname);

$('.groupsselect, .subadminsselect')
Expand All @@ -114,23 +118,30 @@ GroupList = {
return;
}
GroupList.updating = true;

$userGroupList.addClass('hidden');
$userGroupList.before('<div class="loading" style="height:50px; margin-top: 20px"></div>');

$.get(
OC.generateUrl('/settings/ajax/grouplist'),
{
pattern: filter.getPattern(),
filterGroups: filter.filterGroups ? 1 : 0
},
function (result) {
$userGroupList.removeClass('hidden');
$userGroupList.parent().find('.loading').remove();

var lis = [];
if (result.status === 'success') {
$.each(result.data, function (i, subset) {
$.each(result.data, function (subsetName, subset) {
var isAdmin = (subsetName === 'adminGroups');
$.each(subset, function (index, group) {
if (GroupList.getGroupLI(group.name).length > 0) {
GroupList.setUserCount(GroupList.getGroupLI(group.name).first(), group.usercount);
}
else {
var $li = GroupList.addGroup(group.name, group.usercount);
var $li = GroupList.addGroup(group.name, group.usercount, isAdmin);

$li.addClass('appear transparent');
lis.push($li);
Expand Down Expand Up @@ -300,4 +311,5 @@ $(document).ready( function () {
$userGroupList.on('click', '.isgroup', function () {
GroupList.showGroup(GroupList.getElementGID(this));
});
GroupList.update();
});
34 changes: 11 additions & 23 deletions settings/templates/users/part.grouplist.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,16 @@
</span>
</li>

<!-- The Admin Group -->
<?php foreach($_["adminGroup"] as $adminGroup): ?>
<li data-gid="admin" data-usercount="<?php if($adminGroup['usercount'] > 0) { p($adminGroup['usercount']); } ?>" class="isgroup">
<a href="#"><span class="groupname"><?php p($l->t('Admins')); ?></span></a>
<span class="utils">
<span class="usercount"><?php if($adminGroup['usercount'] > 0) { p($adminGroup['usercount']); } ?></span>
</span>
</li>
<?php endforeach; ?>

<!--List of Groups-->
<?php foreach($_["groups"] as $group): ?>
<li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p($group['usercount']) ?>" class="isgroup">
<a href="#" class="dorename">
<span class="groupname"><?php p($group['name']); ?></span>
<!-- Group template -->
<li class="template isgroup hidden">
<a href="#" class="dorename">
<span class="groupname">{{name}}</span>
</a>
<span class="utils">
<span class="usercount">{{userCount}}</span>
<a href="#" class="action delete" original-title="<?php p($l->t('Delete'))?>">
<img src="<?php print_unescaped(image_path('core', 'actions/delete.svg')) ?>" class="svg" />
</a>
<span class="utils">
<span class="usercount"><?php if($group['usercount'] > 0) { p($group['usercount']); } ?></span>
<a href="#" class="action delete" original-title="<?php p($l->t('Delete'))?>">
<img src="<?php print_unescaped(image_path('core', 'actions/delete.svg')) ?>" class="svg" />
</a>
</span>
</li>
<?php endforeach; ?>
</span>
</li>
</ul>

0 comments on commit 310ef7b

Please sign in to comment.