Skip to content
Snippets Groups Projects
Unverified Commit d53193fd authored by John Molakvoæ's avatar John Molakvoæ
Browse files

Settings groups to ocs

parent 7ca526f8
No related branches found
No related tags found
No related merge requests found
...@@ -6,86 +6,89 @@ ...@@ -6,86 +6,89 @@
OC.Settings = OC.Settings || {}; OC.Settings = OC.Settings || {};
OC.Settings = _.extend(OC.Settings, { OC.Settings = _.extend(OC.Settings, {
_cachedGroups: null, _cachedGroups: null,
/** /**
* Setup selection box for group selection. * Setup selection box for group selection.
* *
* Values need to be separated by a pipe "|" character. * Values need to be separated by a pipe "|" character.
* (mostly because a comma is more likely to be used * (mostly because a comma is more likely to be used
* for groups) * for groups)
* *
* @param $elements jQuery element (hidden input) to setup select2 on * @param $elements jQuery element (hidden input) to setup select2 on
* @param {Array} [extraOptions] extra options hash to pass to select2 * @param {Array} [extraOptions] extra options hash to pass to select2
* @param {Array} [options] extra options * @param {Array} [options] extra options
* @param {Array} [options.excludeAdmins=false] flag whether to exclude admin groups * @param {Array} [options.excludeAdmins=false] flag whether to exclude admin groups
*/ */
setupGroupsSelect: function($elements, extraOptions, options) { setupGroupsSelect: function($elements, extraOptions, options) {
var self = this; var self = this;
options = options || {}; options = options || {};
if ($elements.length > 0) { if ($elements.length > 0) {
// Let's load the data and THEN init our select // Let's load the data and THEN init our select
$.ajax({ $.ajax({
url: OC.generateUrl('/settings/users/groups'), url: OC.linkToOCS('cloud/groups', 2) + 'details',
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
var results = []; var results = [];
// add groups if (data.ocs.data.groups && data.ocs.data.groups.length > 0) {
if (!options.excludeAdmins) {
$.each(data.data.adminGroups, function(i, group) { data.ocs.data.groups.forEach(function(group) {
results.push({id:group.id, displayname:group.name}); if (!options.excludeAdmins || group.id !== 'admin') {
}); results.push({ id: group.id, displayname: group.displayname });
} }
$.each(data.data.groups, function(i, group) { })
results.push({id:group.id, displayname:group.name});
}); // note: settings are saved through a "change" event registered
// note: settings are saved through a "change" event registered // on all input fields
// on all input fields $elements.select2(_.extend({
$elements.select2(_.extend({ placeholder: t('core', 'Groups'),
placeholder: t('core', 'Groups'), allowClear: true,
allowClear: true, multiple: true,
multiple: true, toggleSelect: true,
toggleSelect: true, separator: '|',
separator: '|', data: { results: results, text: 'displayname' },
data: { results: results, text: 'displayname' }, initSelection: function(element, callback) {
initSelection: function(element, callback) { var groups = $(element).val();
var groups = $(element).val(); var selection;
var selection; if (groups && results.length > 0) {
if (groups && results.length > 0) { selection = _.map((groups || []).split('|').sort(), function(groupId) {
selection = _.map((groups || []).split('|').sort(), function(groupId) { return {
return { id: groupId,
id: groupId, displayname: results.find(group => group.id === groupId).displayname
displayname: results.find(group =>group.id === groupId).displayname };
}; });
}); } else if (groups) {
} else if (groups) { selection = _.map((groups || []).split('|').sort(), function(groupId) {
selection = _.map((groups || []).split('|').sort(), function(groupId) { return {
return { id: groupId,
id: groupId, displayname: groupId
displayname: groupId };
}; });
}); }
} callback(selection);
callback(selection); },
}, formatResult: function(element) {
formatResult: function (element) { return escapeHTML(element.displayname);
return escapeHTML(element.displayname); },
}, formatSelection: function(element) {
formatSelection: function (element) { return escapeHTML(element.displayname);
return escapeHTML(element.displayname); },
}, escapeMarkup: function(m) {
escapeMarkup: function(m) { // prevent double markup escape
// prevent double markup escape return m;
return m; }
} }, extraOptions || {}));
}, extraOptions || {})); } else {
}, OC.Notification.show(t('settings', 'Group list is empty'), { type: 'error' });
error : function(data) { console.log(data);
OC.Notification.show(t('settings', 'Unable to retrieve the group list'), {type: 'error'}); }
console.log(data); },
} error: function(data) {
}); OC.Notification.show(t('settings', 'Unable to retrieve the group list'), { type: 'error' });
} console.log(data);
} }
}); });
}
}
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment