[Pkg-owncloud-commits] [owncloud] 104/258: Now using select2 for the groups excluded from sharing

David Prévot taffit at moszumanska.debian.org
Sat Oct 11 17:22:26 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 a385a367b0d555cc888c8b7f644d86c3c37625ae
Author: Vincent Petry <pvince81 at owncloud.com>
Date:   Tue Sep 9 17:06:50 2014 +0200

    Now using select2 for the groups excluded from sharing
---
 settings/admin.php           | 16 +-------
 settings/js/admin.js         | 90 +++++++++++++++++++++++++++-----------------
 settings/templates/admin.php |  9 +----
 3 files changed, 58 insertions(+), 57 deletions(-)

diff --git a/settings/admin.php b/settings/admin.php
index 3702cf9..f6c0b10 100755
--- a/settings/admin.php
+++ b/settings/admin.php
@@ -53,22 +53,8 @@ $tmpl->assign('shareExpireAfterNDays', OC_Appconfig::getValue('core', 'shareapi_
 $tmpl->assign('shareEnforceExpireDate', OC_Appconfig::getValue('core', 'shareapi_enforce_expire_date', 'no'));
 $excludeGroups = OC_Appconfig::getValue('core', 'shareapi_exclude_groups', 'no') === 'yes' ? true : false;
 $tmpl->assign('shareExcludeGroups', $excludeGroups);
-$allGroups =  OC_Group::getGroups();
 $excludedGroupsList = OC_Appconfig::getValue('core', 'shareapi_exclude_groups_list', '');
-$excludedGroups = $excludedGroupsList !== '' ? explode(',', $excludedGroupsList) : array();
-$groups = array();
-foreach ($allGroups as $group) {
-	if (in_array($group, $excludedGroups)) {
-		$groups[$group] = array('gid' => $group,
-			'excluded' => true);
-	} else {
-		$groups[$group] = array('gid' => $group,
-			'excluded' => false);
-	}
-}
-ksort($groups);
-$tmpl->assign('groups', $groups);
-
+$tmpl->assign('shareExcludedGroupsList', $excludedGroupsList);
 
 // Check if connected using HTTPS
 $tmpl->assign('isConnectedViaHTTPS', OC_Request::serverProtocol() === 'https');
diff --git a/settings/js/admin.js b/settings/js/admin.js
index 56dc1b9..d38c770 100644
--- a/settings/js/admin.js
+++ b/settings/js/admin.js
@@ -1,38 +1,60 @@
 var SharingGroupList = {
-	applyMultipleSelect: function(element) {
-		var checked = [];
-		if ($(element).hasClass('groupsselect')) {
-			if (element.data('userGroups')) {
-				checked = element.data('userGroups');
-			}
-			var checkHandeler = function(group) {
-					$.post(OC.filePath('settings', 'ajax', 'excludegroups.php'),
-						{changedGroup: group, selectedGroups: JSON.stringify(checked)},
-						function() {});
-				};
-
-
-			var addGroup = function(select, group) {
-				$(this).each(function(index, element) {
-					if ($(element).find('option[value="' + group + '"]').length === 0 &&
-							select.data('msid') !== $(element).data('msid')) {
-						$(element).append('<option value="' + escapeHTML(group) + '">' +
-								escapeHTML(group) + '</option>');
+	setupGroupsSelect: function($elements) {
+		if ($elements.length > 0) {
+			// note: settings are saved through a "change" event registered
+			// on all input fields
+			$elements.select2({
+				placeholder: t('core', 'Groups'),
+				allowClear: true,
+				multiple: true,
+				ajax: {
+					url: OC.generateUrl('/settings/ajax/grouplist'),
+					dataType: 'json',
+					quietMillis: 100,
+					data: function (term) {
+						return {
+							pattern: term, //search term
+						};
+					},
+					results: function (data) {
+						if (data.status === "success") {
+							var results = [];
+
+							// add groups
+							$.each(data.data.adminGroups, function(i, group) {
+								results.push({id:group.id, displayname:group.name});
+							});
+							$.each(data.data.groups, function(i, group) {
+								results.push({id:group.id, displayname:group.name});
+							});
+
+							return {results: results};
+						} else {
+							//FIXME add error handling
+						}
 					}
-				});
-			};
-
-			var label = null;
-			element.multiSelect({
-				createCallback: addGroup,
-				createText: label,
-				selectedFirst: true,
-				checked: checked,
-				oncheck: checkHandeler,
-				onuncheck: checkHandeler,
-				minWidth: 100
+				},
+				id: function(element) {
+					return element.id;
+				},
+				initSelection: function(element, callback) {
+					var selection =
+						_.map(($(element).val() || []).split(',').sort(),
+							function(groupName) {
+						return {
+							id: groupName,
+							displayname: groupName
+						};
+					});
+					callback(selection);
+				},
+				formatResult: function (element) {
+					return element.displayname;
+				},
+				formatSelection: function (element) {
+					return element.displayname;
+				}
 			});
-
 		}
 	}
 };
@@ -57,8 +79,8 @@ $(document).ready(function(){
 	}
 
 
-	$('select#excludedGroups[multiple]').each(function (index, element) {
-		SharingGroupList.applyMultipleSelect($(element));
+	$('#excludedGroups').each(function (index, element) {
+		SharingGroupList.setupGroupsSelect($(element));
 	});
 
 
diff --git a/settings/templates/admin.php b/settings/templates/admin.php
index 5ee1507..18c4508 100644
--- a/settings/templates/admin.php
+++ b/settings/templates/admin.php
@@ -303,14 +303,7 @@ if ($_['suggestedOverwriteWebroot']) {
 			<label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing'));?></label><br/>
 		</p>
 			<p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>">
-				<select
-					class="groupsselect"
-					id="excludedGroups" data-placeholder="groups"
-					title="<?php p($l->t('Groups'))?>" multiple="multiple">
-					<?php foreach($_["groups"] as $group): ?>
-						<option value="<?php p($group['gid'])?>" <?php if($group['excluded']) { p('selected="selected"'); }?>><?php p($group['gid']);?></option>
-					<?php endforeach;?>
-				</select>
+				<input name="shareapi_exclude_groups_list" type="hidden" id="excludedGroups" value="<?php p($_['shareExcludedGroupsList']) ?>" style="width: 400px"/>
 				<br />
 				<em><?php p($l->t('These groups will still be able to receive shares, but not to initiate them.')); ?></em>
 			</p>

-- 
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