Fixed sharing groups select and fixed search

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-03-05 16:16:43 +01:00
parent 51ec928623
commit 6e0044b668
No known key found for this signature in database
GPG Key ID: FB5ACEED51955BF8
3 changed files with 63 additions and 67 deletions

View File

@ -167,7 +167,7 @@
url: OC.generateUrl('settings/users/groups'), url: OC.generateUrl('settings/users/groups'),
dataType: 'json', dataType: 'json',
quietMillis: 100, quietMillis: 100,
}).done(function(response) { }).success(function(response) {
// add admin groups // add admin groups
$.each(response.data.adminGroups, function(id, group) { $.each(response.data.adminGroups, function(id, group) {
self.groups.push({ id: group.id, displayname: group.name }); self.groups.push({ id: group.id, displayname: group.name });
@ -177,8 +177,9 @@
self.groups.push({ id: group.id, displayname: group.name }); self.groups.push({ id: group.id, displayname: group.name });
}); });
self.render(); self.render();
}).fail(function(response) { }).error(function(data) {
console.error('Failure happened', response); OC.Notification.error(t('workflowengine', 'Unable to retrieve the group list'), {type: 'error'});
console.log(data);
}); });
}, },
delete: function() { delete: function() {

View File

@ -42,7 +42,7 @@
$(element).css('width', '400px'); $(element).css('width', '400px');
$(element).select2({ $(element).select2({
data: groups, data: { results: groups, text: 'displayname' },
initSelection: function (element, callback) { initSelection: function (element, callback) {
var groupId = element.val(); var groupId = element.val();
if (groupId && groups.length > 0) { if (groupId && groups.length > 0) {

View File

@ -24,75 +24,70 @@ OC.Settings = _.extend(OC.Settings, {
var self = this; var self = this;
options = options || {}; options = options || {};
if ($elements.length > 0) { if ($elements.length > 0) {
// note: settings are saved through a "change" event registered // Let's load the data and THEN init our select
// on all input fields $.ajax({
$elements.select2(_.extend({ url: OC.generateUrl('/settings/users/groups'),
placeholder: t('core', 'Groups'), dataType: 'json',
allowClear: true, success: function(data) {
multiple: true, var results = [];
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 = [];
// add groups // add groups
if (!options.excludeAdmins) { if (!options.excludeAdmins) {
$.each(data.data.adminGroups, function(i, group) { $.each(data.data.adminGroups, function(i, group) {
results.push({id:group.id, displayname:group.name}); 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) { callback(selection);
results.push({id:group.id, displayname:group.name}); },
}); formatResult: function (element) {
return escapeHTML(element.displayname);
if (query.term === '') { },
// cache full list formatSelection: function (element) {
self._cachedGroups = results; return escapeHTML(element.displayname);
} },
query.callback({results: results}); escapeMarkup: function(m) {
// prevent double markup escape
return m;
} }
}); }, extraOptions || {}));
}, 100, true),
id: function(element) {
return element.id;
}, },
initSelection: function(element, callback) { error : function(data) {
var selection = _.map(($(element).val() || []).split('|').sort(), function(groupId) { OC.Notification.show(t('settings', 'Unable to retrieve the group list'), {type: 'error'});
return { console.log(data);
id: groupId,
displayname: groupId + 'FIXME' // FIXME
};
});
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 || {})); });
} }
} }
}); });