mirror of https://github.com/nextcloud/server.git
Merge pull request #10968 from owncloud/admin-groupsselect2
Use select2 for the groups excluded from sharing in admin pageremotes/origin/fix-10825
commit
fed8100177
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 613 B After Width: | Height: | Size: 613 B |
Before Width: | Height: | Size: 845 B After Width: | Height: | Size: 845 B |
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
OC_JSON::checkAdminUser();
|
||||
OCP\JSON::callCheck();
|
||||
|
||||
$selectedGroups = isset($_POST["selectedGroups"]) ? json_decode($_POST["selectedGroups"]) : array();
|
||||
$changedGroup = isset($_POST["changedGroup"]) ? $_POST["changedGroup"] : '';
|
||||
|
||||
if ($changedGroup !== '') {
|
||||
if(($key = array_search($changedGroup, $selectedGroups)) !== false) {
|
||||
unset($selectedGroups[$key]);
|
||||
} else {
|
||||
$selectedGroups[] = $changedGroup;
|
||||
}
|
||||
} else {
|
||||
\OCP\Util::writeLog('core', 'Can not update list of excluded groups from sharing, parameter missing', \OCP\Util::WARN);
|
||||
}
|
||||
|
||||
\OC_Appconfig::setValue('core', 'shareapi_exclude_groups_list', implode(',', $selectedGroups));
|
@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Vincent Petry <pvince81@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
OC.Settings = OC.Settings || {};
|
||||
OC.Settings = _.extend(OC.Settings, {
|
||||
|
||||
_cachedGroups: null,
|
||||
|
||||
/**
|
||||
* Setup selection box for group selection.
|
||||
*
|
||||
* Values need to be separated by a pipe "|" character.
|
||||
* (mostly because a comma is more likely to be used
|
||||
* for groups)
|
||||
*
|
||||
* @param $elements jQuery element (hidden input) to setup select2 on
|
||||
* @param [extraOptions] extra options hash to pass to select2
|
||||
*/
|
||||
setupGroupsSelect: function($elements, extraOptions) {
|
||||
var self = this;
|
||||
if ($elements.length > 0) {
|
||||
// note: settings are saved through a "change" event registered
|
||||
// on all input fields
|
||||
$elements.select2(_.extend({
|
||||
placeholder: t('core', 'Groups'),
|
||||
allowClear: true,
|
||||
multiple: true,
|
||||
separator: '|',
|
||||
query: _.debounce(function(query) {
|
||||
var queryData = {};
|
||||
if (self._cachedGroups && query.term === '') {
|
||||
query.callback({results: self._cachedGroups});
|
||||
return;
|
||||
}
|
||||
if (query.term !== '') {
|
||||
queryData = {
|
||||
pattern: query.term,
|
||||
filterGroups: 1
|
||||
};
|
||||
}
|
||||
$.ajax({
|
||||
url: OC.generateUrl('/settings/ajax/grouplist'),
|
||||
data: queryData,
|
||||
dataType: 'json',
|
||||
success: 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});
|
||||
});
|
||||
|
||||
if (query.term === '') {
|
||||
// cache full list
|
||||
self._cachedGroups = results;
|
||||
}
|
||||
query.callback({results: results});
|
||||
} else {
|
||||
//FIXME add error handling
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 100, true),
|
||||
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 escapeHTML(element.displayname);
|
||||
},
|
||||
formatSelection: function (element) {
|
||||
return escapeHTML(element.displayname);
|
||||
},
|
||||
escapeMarkup: function(m) {
|
||||
// prevent double markup escape
|
||||
return m;
|
||||
}
|
||||
}, extraOptions || {}));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue