/** * Copyright (c) 2014, Raghu Nayyar * Copyright (c) 2014, Arthur Schiwon * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ var $userGroupList; var GroupList; GroupList = { activeGID: '', everyoneGID: '_everyone', addGroup: function (gid, usercount) { var $li = $userGroupList.find('.isgroup:last-child').clone(); $li .data('gid', gid) .find('.groupname').text(gid); GroupList.setUserCount($li, usercount); $li.appendTo($userGroupList); GroupList.sortGroups(); return $li; }, setUserCount: function (groupLiElement, usercount) { var $groupLiElement = $(groupLiElement); if (usercount === undefined || usercount === 0 || usercount < 0) { usercount = ''; } $groupLiElement.data('usercount', usercount); $groupLiElement.find('.usercount').text(usercount); }, getUserCount: function ($groupLiElement) { return parseInt($groupLiElement.data('usercount'), 10); }, modEveryoneCount: function(diff) { var $li = GroupList.getGroupLI(GroupList.everyoneGID); var count = GroupList.getUserCount($li) + diff; GroupList.setUserCount($li, count); }, incEveryoneCount: function() { GroupList.modEveryoneCount(1); }, decEveryoneCount: function() { GroupList.modEveryoneCount(-1); }, getCurrentGID: function () { return GroupList.activeGID; }, sortGroups: function () { var lis = $userGroupList.find('.isgroup').get(); lis.sort(function (a, b) { return UserList.alphanum( $(a).find('a span').text(), $(b).find('a span').text() ); }); var items = []; $.each(lis, function (index, li) { items.push(li); if (items.length === 100) { $userGroupList.append(items); items = []; } }); if (items.length > 0) { $userGroupList.append(items); } }, createGroup: function (groupname) { $.post( OC.filePath('settings', 'ajax', 'creategroup.php'), { groupname: groupname }, function (result) { if (result.status !== 'success') { OC.dialogs.alert(result.data.message, t('settings', 'Error creating group')); } else { if (result.data.groupname) { var addedGroup = result.data.groupname; UserList.availableGroups = $.unique($.merge(UserList.availableGroups, [addedGroup])); GroupList.addGroup(result.data.groupname); $('.groupsselect, .subadminsselect') .append($('