Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createSelect2(customFieldId) {
- AJS.$("#" + customFieldId).auiSelect2({
- ajax: {
- url: AJS.contextPath() + "/rest/limited_user_picker/2.0/search",
- data: function(params) {
- console.log(params);
- return {
- template: params
- };
- },
- dataType: 'json',
- type: "GET",
- delay: 250,
- results: function (data) {
- var users = $.map(data.users, function(user) {
- return {
- id: user.username,
- text: user.displayName
- };
- });
- var groups = $.map(data.groups, function(group) {
- return {
- id: group,
- text: group,
- type: "group"
- };
- });
- var result = [];
- if (groups.length) {
- result.push({
- text: "Группы",
- children: groups
- });
- }
- if (users.length) {
- result.push({
- text: "Пользователи",
- children: users
- });
- }
- return {
- results: result
- };
- },
- cache: true
- },
- minimumInputLength: 2,
- formatResult: resultFormat,
- formatSelection: selectFormat,
- escapeMarkup: function(m) { return m; },
- placeholder: "Users or groups",
- allowClear: true,
- multiple: true
- });
- }
- function resultFormat(result, container, query) {
- var pattern = new RegExp(query.term, 'g');
- if (!result.id) {
- return result.text;
- } else if (!result.type) {
- return (result.text + " - " + result.id).replace(pattern, "<strong>$&</strong>");
- } else {
- return result.text.replace(pattern, "<strong>$&</strong>");
- }
- }
- function selectFormat(result) {
- if (!result.type) {
- return "<span class=\"aui-icon aui-icon-small aui-iconfont-user limited-user-picker-icon\">User</span>" + result.id;
- } else {
- return "<span class=\"aui-icon aui-icon-small aui-iconfont-group limited-user-picker-icon\">Group</span>" + result.id;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment