-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved setupGroupsSelect() from admin.js to a common settings.js as OC.Settings.setupGoupsSelect(). Now using select2 as well on the apps page.
- Loading branch information
Vincent Petry
committed
Sep 9, 2014
1 parent
39f5580
commit 0d28ba0
Showing
6 changed files
with
99 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright (c) 2014, Vincent Petry <[email protected]> | ||
* 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, { | ||
/** | ||
* Setup selection box for group selection. | ||
* @param $elements jQuery element (hidden input) to setup select2 on | ||
* @param [extraOptions] extra options hash to pass to select2 | ||
*/ | ||
setupGroupsSelect: function($elements, extraOptions) { | ||
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, | ||
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 | ||
} | ||
} | ||
}, | ||
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; | ||
} | ||
}, extraOptions || {})); | ||
} | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters