summaryrefslogtreecommitdiffstats
path: root/settings/js
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-03-05 16:16:43 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-03-08 17:13:51 +0100
commit6e0044b668b8eb99c7dfc5c47e6b8f9c9f23298c (patch)
tree4d432e069b19eb5ef53a23f23a6a17cab1e4bcad /settings/js
parent51ec928623fe5d2aa0b010546f59807513c32052 (diff)
downloadnextcloud-server-6e0044b668b8eb99c7dfc5c47e6b8f9c9f23298c.tar.gz
nextcloud-server-6e0044b668b8eb99c7dfc5c47e6b8f9c9f23298c.zip
Fixed sharing groups select and fixed search
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'settings/js')
-rw-r--r--settings/js/settings.js121
1 files changed, 58 insertions, 63 deletions
diff --git a/settings/js/settings.js b/settings/js/settings.js
index ad0ab758e9e..dd4a3a4cc7d 100644
--- a/settings/js/settings.js
+++ b/settings/js/settings.js
@@ -24,75 +24,70 @@ OC.Settings = _.extend(OC.Settings, {
var self = this;
options = options || {};
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,
- toggleSelect: 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/users/groups'),
- data: queryData,
- dataType: 'json',
- success: function(data) {
- var results = [];
+ // Let's load the data and THEN init our select
+ $.ajax({
+ url: OC.generateUrl('/settings/users/groups'),
+ dataType: 'json',
+ success: function(data) {
+ var results = [];
- // add groups
- if (!options.excludeAdmins) {
- $.each(data.data.adminGroups, function(i, group) {
- results.push({id:group.id, displayname:group.name});
+ // add groups
+ if (!options.excludeAdmins) {
+ $.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});
+ });
+ },
+ always: function() {
+ // note: settings are saved through a "change" event registered
+ // on all input fields
+ $elements.select2(_.extend({
+ placeholder: t('core', 'Groups'),
+ allowClear: true,
+ multiple: true,
+ toggleSelect: true,
+ separator: '|',
+ data: { results: results, text: 'displayname' },
+ initSelection: function(element, callback) {
+ var groups = $(element).val();
+ var selection;
+ if (groups && results.length > 0) {
+ selection = _.map((groups || []).split('|').sort(), function(groupId) {
+ return {
+ id: groupId,
+ displayname: results.find(group =>group.id === groupId).displayname
+ };
+ });
+ } else if (groups) {
+ selection = _.map((groups || []).split('|').sort(), function(groupId) {
+ return {
+ id: groupId,
+ displayname: groupId
+ };
});
}
- $.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});
+ 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;
}
- });
- }, 100, true),
- id: function(element) {
- return element.id;
- },
- initSelection: function(element, callback) {
- var selection = _.map(($(element).val() || []).split('|').sort(), function(groupId) {
- return {
- id: groupId,
- displayname: groupId + 'FIXME' // FIXME
- };
- });
- callback(selection);
+ }, extraOptions || {}));
},
- formatResult: function (element) {
- return escapeHTML(element.displayname);
- },
- formatSelection: function (element) {
- return escapeHTML(element.displayname);
- },
- escapeMarkup: function(m) {
- // prevent double markup escape
- return m;
+ error : function(data) {
+ OC.Notification.show(t('settings', 'Unable to retrieve the group list'), {type: 'error'});
+ console.log(data);
}
- }, extraOptions || {}));
+ });
}
}
});
-