[Pkg-owncloud-commits] [owncloud] 62/70: increment group counters when a user is created

David Prévot taffit at moszumanska.debian.org
Mon Jul 14 17:38:09 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit a310415b098721809d7096e64016da3afcaf82dc
Author: Arthur Schiwon <blizzz at owncloud.com>
Date:   Sat Jul 5 01:21:18 2014 +0200

    increment group counters when a user is created
    
    decrease user count in affected groups after user delete
    
    increase/decrease everyone count on user creation/deletion
    
    avoid global selector
---
 settings/js/users/groups.js                 | 23 +++++++++++--
 settings/js/users/users.js                  | 51 +++++++++++++++++++++++++----
 settings/templates/users/part.grouplist.php |  4 +--
 3 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/settings/js/users/groups.js b/settings/js/users/groups.js
index dcaf593..e3acce5 100644
--- a/settings/js/users/groups.js
+++ b/settings/js/users/groups.js
@@ -10,6 +10,7 @@ var $userGroupList;
 var GroupList;
 GroupList = {
 	activeGID: '',
+	everyoneGID: '_everyone',
 
 	addGroup: function (gid, usercount) {
 		var $li = $userGroupList.find('.isgroup:last-child').clone();
@@ -27,19 +28,37 @@ GroupList = {
 
 	setUserCount: function (groupLiElement, usercount) {
 		var $groupLiElement = $(groupLiElement);
-		if (usercount === undefined || usercount === 0) {
+		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) {
+		$li = GroupList.getGroupLI(GroupList.everyoneGID);
+		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 = $('.isgroup').get();
+		var lis = $userGroupList.find('.isgroup').get();
 
 		lis.sort(function (a, b) {
 			return UserList.alphanum(
diff --git a/settings/js/users/users.js b/settings/js/users/users.js
index f84d67b..60e1e1d 100644
--- a/settings/js/users/users.js
+++ b/settings/js/users/users.js
@@ -91,8 +91,8 @@ var UserList = {
 		}
 		$tdLastLogin = $tr.find('td.lastLogin');
 		$tdLastLogin.text(lastLoginRel);
-		//tooltip makes it complicated … to not insert new HTML, we adjust the 
-		//original title. We use a temporary div to get back the html that we 
+		//tooltip makes it complicated … to not insert new HTML, we adjust the
+		//original title. We use a temporary div to get back the html that we
 		//can pass later. It is also required to initialise tipsy.
 		var tooltip = $('<div>').html($($tdLastLogin.attr('original-title')).text(lastLoginAbs)).html();
 		$tdLastLogin.tipsy({gravity:'s', fade:true, html:true});
@@ -237,9 +237,43 @@ var UserList = {
 	show: function(uid) {
 		UserList.getRow(uid).show();
 	},
+	markRemove: function(uid) {
+		$tr = UserList.getRow(uid);
+		groups = $tr.find('.groups .groupsselect').val();
+		for(i in groups) {
+			var gid = groups[i];
+			$li = GroupList.getGroupLI(gid);
+			userCount = GroupList.getUserCount($li);
+			if(userCount == 1) {
+				newUserCount = '';
+			} else {
+				newUserCount = userCount - 1;
+			}
+			GroupList.setUserCount($li, newUserCount);
+		}
+		GroupList.decEveryoneCount();
+		UserList.hide(uid);
+	},
 	remove: function(uid) {
 		UserList.getRow(uid).remove();
 	},
+	undoRemove: function(uid) {
+		$tr = UserList.getRow(uid);
+		groups = $tr.find('.groups .groupsselect').val();
+		for(i in groups) {
+			var gid = groups[i];
+			$li = GroupList.getGroupLI(gid);
+			userCount = GroupList.getUserCount($li);
+			if(userCount == 1) {
+				newUserCount = '';
+			} else {
+				newUserCount = userCount + 1;
+			}
+			GroupList.setUserCount($li, newUserCount);
+		}
+		GroupList.incEveryoneCount();
+		UserList.getRow(uid).show();
+	},
 	has: function(uid) {
 		return UserList.getRow(uid).length > 0;
 	},
@@ -257,14 +291,14 @@ var UserList = {
 	initDeleteHandling: function() {
 		//set up handler
 		UserDeleteHandler = new DeleteHandler('removeuser.php', 'username',
-											UserList.hide, UserList.remove);
+											UserList.markRemove, UserList.remove);
 
 		//configure undo
 		OC.Notification.hide();
 		var msg = escapeHTML(t('settings', 'deleted {userName}', {userName: '%oid'})) + '<span class="undo">' +
 			escapeHTML(t('settings', 'undo')) + '</span>';
 		UserDeleteHandler.setNotification(OC.Notification, 'deleteuser', msg,
-										UserList.show);
+										UserList.undoRemove);
 
 		//when to mark user for delete
 		$userListBody.on('click', '.delete', function () {
@@ -468,11 +502,9 @@ $(document).ready(function () {
 	UserList.doSort();
 	UserList.availableGroups = $userList.data('groups');
 
-
 	UserList.scrollArea = $('#app-content');
 	UserList.scrollArea.scroll(function(e) {UserList._onScroll(e);});
 
-
 	$userList.after($('<div class="loading" style="height: 200px; visibility: hidden;"></div>'));
 
 	$('.groupsselect').each(function (index, element) {
@@ -602,6 +634,12 @@ $(document).ready(function () {
 					if (result.data.groups) {
 						var addedGroups = result.data.groups;
 						UserList.availableGroups = $.unique($.merge(UserList.availableGroups, addedGroups));
+						for (i in result.data.groups) {
+							var gid = result.data.groups[i];
+							$li = GroupList.getGroupLI(gid);
+							userCount = GroupList.getUserCount($li);
+							GroupList.setUserCount($li, userCount + 1);
+						}
 					}
 					if (result.data.homeExists){
 						OC.Notification.hide();
@@ -619,6 +657,7 @@ $(document).ready(function () {
 						UserList.add(username, username, result.data.groups, null, 'default', result.data.storageLocation, 0, true);
 					}
 					$('#newusername').focus();
+					GroupList.incEveryoneCount();
 				}
 			}
 		);
diff --git a/settings/templates/users/part.grouplist.php b/settings/templates/users/part.grouplist.php
index 28f2236..c5e85fa 100644
--- a/settings/templates/users/part.grouplist.php
+++ b/settings/templates/users/part.grouplist.php
@@ -12,7 +12,7 @@
 		</form>
 	</li>
 	<!-- Everyone -->
-	<li data-gid="" class="isgroup">
+	<li data-gid="_everyone" data-usercount="<?php p($_["usercount"]); ?>" class="isgroup">
 		<a href="#">
 			<span class="groupname">
 				<?php p($l->t('Everyone')); ?>
@@ -27,7 +27,7 @@
 
 	<!-- The Admin Group -->
 	<?php foreach($_["adminGroup"] as $adminGroup): ?>
-		<li data-gid="admin" class="isgroup">
+		<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>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list