diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-09-09 17:06:50 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-09-09 18:03:05 +0200 |
commit | d23621536c23f89785f6beea13cdc53ec2b9392f (patch) | |
tree | 29cde309ce00e235f635f90156dd0eb2a5a3341b /settings/js | |
parent | 412da87e6583375f98ef1bdd755c56caab14b8ac (diff) | |
download | nextcloud-server-d23621536c23f89785f6beea13cdc53ec2b9392f.tar.gz nextcloud-server-d23621536c23f89785f6beea13cdc53ec2b9392f.zip |
Now using select2 for the groups excluded from sharing
Diffstat (limited to 'settings/js')
-rw-r--r-- | settings/js/admin.js | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/settings/js/admin.js b/settings/js/admin.js index 56dc1b98716..d38c770a28a 100644 --- a/settings/js/admin.js +++ b/settings/js/admin.js @@ -1,38 +1,60 @@ 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>'); + setupGroupsSelect: function($elements) { + if ($elements.length > 0) { + // note: settings are saved through a "change" event registered + // on all input fields + $elements.select2({ + placeholder: t('core', 'Groups'), + allowClear: true, + multiple: true, + ajax: { + url: OC.generateUrl('/settings/ajax/grouplist'), + dataType: 'json', + quietMillis: 100, + data: function (term) { + return { + pattern: term, //search term + }; + }, + results: 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}); + }); + + return {results: results}; + } else { + //FIXME add error handling + } } - }); - }; - - var label = null; - element.multiSelect({ - createCallback: addGroup, - createText: label, - selectedFirst: true, - checked: checked, - oncheck: checkHandeler, - onuncheck: checkHandeler, - minWidth: 100 + }, + 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 element.displayname; + }, + formatSelection: function (element) { + return element.displayname; + } }); - } } }; @@ -57,8 +79,8 @@ $(document).ready(function(){ } - $('select#excludedGroups[multiple]').each(function (index, element) { - SharingGroupList.applyMultipleSelect($(element)); + $('#excludedGroups').each(function (index, element) { + SharingGroupList.setupGroupsSelect($(element)); }); |