aboutsummaryrefslogtreecommitdiffstats
path: root/settings
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-04-25 07:37:20 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-04-25 07:37:20 +0200
commitd53193fd8e49a86285dab67a128dcb588887838b (patch)
tree15e22a136a4a701c670838067b66a3a29d4d92bd /settings
parent7ca526f8ac30d52ddcaff0e1759cb6d3c5090fd1 (diff)
downloadnextcloud-server-d53193fd8e49a86285dab67a128dcb588887838b.tar.gz
nextcloud-server-d53193fd8e49a86285dab67a128dcb588887838b.zip
Settings groups to ocs
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'settings')
-rw-r--r--settings/js/settings.js165
1 files changed, 84 insertions, 81 deletions
diff --git a/settings/js/settings.js b/settings/js/settings.js
index 16718bd5cbe..66b8347fdf2 100644
--- a/settings/js/settings.js
+++ b/settings/js/settings.js
@@ -6,86 +6,89 @@
OC.Settings = OC.Settings || {};
OC.Settings = _.extend(OC.Settings, {
- _cachedGroups: null,
+ _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 {Array} [extraOptions] extra options hash to pass to select2
- * @param {Array} [options] extra options
- * @param {Array} [options.excludeAdmins=false] flag whether to exclude admin groups
- */
- setupGroupsSelect: function($elements, extraOptions, options) {
- var self = this;
- options = options || {};
- if ($elements.length > 0) {
- // Let's load the data and THEN init our select
- $.ajax({
- url: OC.generateUrl('/settings/users/groups'),
- dataType: 'json',
- success: function(data) {
- var results = [];
+ /**
+ * 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 {Array} [extraOptions] extra options hash to pass to select2
+ * @param {Array} [options] extra options
+ * @param {Array} [options.excludeAdmins=false] flag whether to exclude admin groups
+ */
+ setupGroupsSelect: function($elements, extraOptions, options) {
+ var self = this;
+ options = options || {};
+ if ($elements.length > 0) {
+ // Let's load the data and THEN init our select
+ $.ajax({
+ url: OC.linkToOCS('cloud/groups', 2) + 'details',
+ 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});
- });
- }
- $.each(data.data.groups, function(i, group) {
- results.push({id:group.id, displayname:group.name});
- });
- // 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
- };
- });
- }
- 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 || {}));
- },
- error : function(data) {
- OC.Notification.show(t('settings', 'Unable to retrieve the group list'), {type: 'error'});
- console.log(data);
- }
- });
- }
- }
-});
+ if (data.ocs.data.groups && data.ocs.data.groups.length > 0) {
+
+ data.ocs.data.groups.forEach(function(group) {
+ if (!options.excludeAdmins || group.id !== 'admin') {
+ results.push({ id: group.id, displayname: group.displayname });
+ }
+ })
+
+ // 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
+ };
+ });
+ }
+ 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 || {}));
+ } else {
+ OC.Notification.show(t('settings', 'Group list is empty'), { 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