diff options
author | Lukas Reschke <lukas@owncloud.com> | 2014-09-19 16:50:56 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2014-09-19 16:50:56 +0200 |
commit | fed81001770236d02c6990ffebc6d9fdd980b5b9 (patch) | |
tree | b58f92fc318bc87c69dfbbafbcdacf9944217d3a /settings/js | |
parent | fb033cce980ba58b64eed0cd0882c31021f43df0 (diff) | |
parent | 71776e307f16a43d806ee0fe3142ed1a1c0d7d6f (diff) | |
download | nextcloud-server-fed81001770236d02c6990ffebc6d9fdd980b5b9.tar.gz nextcloud-server-fed81001770236d02c6990ffebc6d9fdd980b5b9.zip |
Merge pull request #10968 from owncloud/admin-groupsselect2
Use select2 for the groups excluded from sharing in admin page
Diffstat (limited to 'settings/js')
-rw-r--r-- | settings/js/admin.js | 54 | ||||
-rw-r--r-- | settings/js/apps.js | 35 | ||||
-rw-r--r-- | settings/js/settings.js | 98 |
3 files changed, 127 insertions, 60 deletions
diff --git a/settings/js/admin.js b/settings/js/admin.js index 56dc1b98716..95be13d2288 100644 --- a/settings/js/admin.js +++ b/settings/js/admin.js @@ -1,42 +1,3 @@ -var SharingGroupList = { - applyMultipleSelect: function(element) { - var checked = []; - if ($(element).hasClass('groupsselect')) { - if (element.data('userGroups')) { - checked = element.data('userGroups'); - } - var checkHandeler = function(group) { - $.post(OC.filePath('settings', 'ajax', 'excludegroups.php'), - {changedGroup: group, selectedGroups: JSON.stringify(checked)}, - function() {}); - }; - - - var addGroup = function(select, group) { - $(this).each(function(index, element) { - if ($(element).find('option[value="' + group + '"]').length === 0 && - select.data('msid') !== $(element).data('msid')) { - $(element).append('<option value="' + escapeHTML(group) + '">' + - escapeHTML(group) + '</option>'); - } - }); - }; - - var label = null; - element.multiSelect({ - createCallback: addGroup, - createText: label, - selectedFirst: true, - checked: checked, - oncheck: checkHandeler, - onuncheck: checkHandeler, - minWidth: 100 - }); - - } - } -}; - $(document).ready(function(){ var params = OC.Util.History.parseUrlQuery(); @@ -57,8 +18,17 @@ $(document).ready(function(){ } - $('select#excludedGroups[multiple]').each(function (index, element) { - SharingGroupList.applyMultipleSelect($(element)); + $('#excludedGroups').each(function (index, element) { + OC.Settings.setupGroupsSelect($(element)); + $(element).change(function(ev) { + var groups = ev.val || []; + if (groups.length > 0) { + groups = ev.val.join(','); // FIXME: make this JSON + } else { + groups = ''; + } + OC.AppConfig.setValue('core', $(this).attr('name'), groups); + }); }); @@ -81,7 +51,7 @@ $(document).ready(function(){ $('#shareAPI p:not(#enable)').toggleClass('hidden', !this.checked); }); - $('#shareAPI input').change(function() { + $('#shareAPI input:not(#excludedGroups)').change(function() { if ($(this).attr('type') === 'checkbox') { if (this.checked) { var value = 'yes'; diff --git a/settings/js/apps.js b/settings/js/apps.js index e808e51e936..22bac1eaf3e 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -7,6 +7,11 @@ OC.Settings = OC.Settings || {}; OC.Settings.Apps = OC.Settings.Apps || { + setupGroupsSelect: function() { + OC.Settings.setupGroupsSelect($('#group_select'), { + placeholder: t('core', 'All') + }); + }, loadApp:function(app) { var page = $('#app-content'); page.find('p.license').show(); @@ -112,23 +117,16 @@ OC.Settings.Apps = OC.Settings.Apps || { page.find(".warning").hide(); } - page.find("div.multiselect").parent().remove(); if(OC.Settings.Apps.isType(app, 'filesystem') || OC.Settings.Apps.isType(app, 'prelogin') || OC.Settings.Apps.isType(app, 'authentication') || OC.Settings.Apps.isType(app, 'logging')) { page.find("#groups_enable").hide(); page.find("label[for='groups_enable']").hide(); page.find("#groups_enable").attr('checked', null); } else { - $('#group_select > option').each(function (i, el) { - if (app.groups.length === 0 || app.groups.indexOf(el.value) >= 0) { - $(el).attr('selected', 'selected'); - } else { - $(el).attr('selected', null); - } - }); if (app.active) { if (app.groups.length) { - $('#group_select').multiSelect(); + OC.Settings.Apps.setupGroupsSelect(); + $('#group_select').select2('val', app.groups || []); page.find("#groups_enable").attr('checked','checked'); } else { page.find("#groups_enable").attr('checked', null); @@ -380,9 +378,10 @@ $(document).ready(function(){ } }); - $('#group_select').change(function() { + $('#group_select').change(function(ev) { var element = $('#app-content input.enable'); - var groups = $(this).val(); + // getting an array of values from select2 + var groups = ev.val || []; var appid = element.data('appid'); if (appid) { OC.Settings.Apps.enableApp(appid, false, element, groups); @@ -404,14 +403,14 @@ $(document).ready(function(){ } $("#groups_enable").change(function() { + var $select = $('#group_select'); + $select.val(''); if (this.checked) { - $("div.multiselect").parent().remove(); - $('#group_select').multiSelect(); - } else { - $('#group_select').hide().val(null); - $("div.multiselect").parent().remove(); + OC.Settings.Apps.setupGroupsSelect(); } - - $('#group_select').change(); + else { + $select.select2('destroy'); + } + $select.change(); }); }); diff --git a/settings/js/settings.js b/settings/js/settings.js new file mode 100644 index 00000000000..13c56a8f53a --- /dev/null +++ b/settings/js/settings.js @@ -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 || {})); + } + } +}); + |