2017-01-11 23:27:41 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, one-var, no-var, prefer-rest-params, wrap-iife, quotes, max-len, one-var-declaration-per-line, vars-on-top, prefer-arrow-callback, consistent-return, comma-dangle, object-shorthand, no-shadow, no-unused-vars, no-else-return, no-self-compare, prefer-template, no-unused-expressions, no-lonely-if, yoda, prefer-spread, no-void, camelcase, no-param-reassign */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Issuable */
|
|
|
|
/* global ListUser */
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
2017-01-11 23:27:41 -05:00
|
|
|
var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; },
|
2016-07-24 16:45:11 -04:00
|
|
|
slice = [].slice;
|
|
|
|
|
|
|
|
this.UsersSelect = (function() {
|
2017-02-01 12:02:17 -05:00
|
|
|
function UsersSelect(currentUser, els) {
|
|
|
|
var $els;
|
2016-07-24 16:45:11 -04:00
|
|
|
this.users = bind(this.users, this);
|
|
|
|
this.user = bind(this.user, this);
|
|
|
|
this.usersPath = "/autocomplete/users.json";
|
|
|
|
this.userPath = "/autocomplete/users/:id.json";
|
|
|
|
if (currentUser != null) {
|
2016-10-05 07:20:59 -04:00
|
|
|
if (typeof currentUser === 'object') {
|
|
|
|
this.currentUser = currentUser;
|
|
|
|
} else {
|
|
|
|
this.currentUser = JSON.parse(currentUser);
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-02-01 12:02:17 -05:00
|
|
|
|
|
|
|
$els = $(els);
|
|
|
|
|
|
|
|
if (!els) {
|
2017-02-02 06:16:16 -05:00
|
|
|
$els = $('.js-user-search');
|
2017-02-01 12:02:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$els.each((function(_this) {
|
2016-07-24 16:45:11 -04:00
|
|
|
return function(i, dropdown) {
|
2016-07-31 18:38:24 -04:00
|
|
|
var options = {};
|
2016-10-04 15:21:06 -04:00
|
|
|
var $block, $collapsedSidebar, $dropdown, $loading, $selectbox, $value, abilityName, assignTo, assigneeTemplate, collapsedAssigneeTemplate, defaultLabel, firstUser, issueURL, selectedId, showAnyUser, showNullUser, showMenuAbove;
|
2016-07-24 16:45:11 -04:00
|
|
|
$dropdown = $(dropdown);
|
2016-07-31 18:38:24 -04:00
|
|
|
options.projectId = $dropdown.data('project-id');
|
2017-04-24 11:15:24 -04:00
|
|
|
options.groupId = $dropdown.data('group-id');
|
2016-07-31 18:38:24 -04:00
|
|
|
options.showCurrentUser = $dropdown.data('current-user');
|
2016-11-03 06:22:56 -04:00
|
|
|
options.todoFilter = $dropdown.data('todo-filter');
|
|
|
|
options.todoStateFilter = $dropdown.data('todo-state-filter');
|
2016-07-24 16:45:11 -04:00
|
|
|
showNullUser = $dropdown.data('null-user');
|
2016-10-04 15:21:06 -04:00
|
|
|
showMenuAbove = $dropdown.data('showMenuAbove');
|
2016-07-24 16:45:11 -04:00
|
|
|
showAnyUser = $dropdown.data('any-user');
|
|
|
|
firstUser = $dropdown.data('first-user');
|
2016-07-31 18:38:24 -04:00
|
|
|
options.authorId = $dropdown.data('author-id');
|
2016-07-24 16:45:11 -04:00
|
|
|
selectedId = $dropdown.data('selected');
|
|
|
|
defaultLabel = $dropdown.data('default-label');
|
|
|
|
issueURL = $dropdown.data('issueUpdate');
|
|
|
|
$selectbox = $dropdown.closest('.selectbox');
|
|
|
|
$block = $selectbox.closest('.block');
|
|
|
|
abilityName = $dropdown.data('ability-name');
|
|
|
|
$value = $block.find('.value');
|
|
|
|
$collapsedSidebar = $block.find('.sidebar-collapsed-user');
|
|
|
|
$loading = $block.find('.block-loading').fadeOut();
|
2016-10-05 07:20:59 -04:00
|
|
|
|
|
|
|
var updateIssueBoardsIssue = function () {
|
2017-03-15 08:08:01 -04:00
|
|
|
$loading.removeClass('hidden').fadeIn();
|
2016-10-20 03:54:33 -04:00
|
|
|
gl.issueBoards.BoardsStore.detail.issue.update($dropdown.attr('data-issue-update'))
|
2016-10-05 07:20:59 -04:00
|
|
|
.then(function () {
|
|
|
|
$loading.fadeOut();
|
2017-04-20 07:11:51 -04:00
|
|
|
})
|
|
|
|
.catch(function () {
|
|
|
|
$loading.fadeOut();
|
2016-10-05 07:20:59 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-02-22 02:26:32 -05:00
|
|
|
$('.assign-to-me-link').on('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
$(e.currentTarget).hide();
|
|
|
|
const $input = $(`input[name="${$dropdown.data('field-name')}"]`);
|
|
|
|
$input.val(gon.current_user_id);
|
|
|
|
selectedId = $input.val();
|
|
|
|
$dropdown.find('.dropdown-toggle-text').text(gon.current_user_fullname).removeClass('is-default');
|
|
|
|
});
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
$block.on('click', '.js-assign-yourself', function(e) {
|
|
|
|
e.preventDefault();
|
2016-10-05 07:20:59 -04:00
|
|
|
|
2016-10-06 09:36:44 -04:00
|
|
|
if ($dropdown.hasClass('js-issue-board-sidebar')) {
|
2017-04-07 15:36:09 -04:00
|
|
|
gl.issueBoards.boardStoreIssueSet('assignee', new ListUser({
|
2016-10-05 07:20:59 -04:00
|
|
|
id: _this.currentUser.id,
|
|
|
|
username: _this.currentUser.username,
|
|
|
|
name: _this.currentUser.name,
|
|
|
|
avatar_url: _this.currentUser.avatar_url
|
|
|
|
}));
|
|
|
|
|
|
|
|
updateIssueBoardsIssue();
|
|
|
|
} else {
|
|
|
|
return assignTo(_this.currentUser.id);
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
assignTo = function(selected) {
|
|
|
|
var data;
|
|
|
|
data = {};
|
|
|
|
data[abilityName] = {};
|
|
|
|
data[abilityName].assignee_id = selected != null ? selected : null;
|
2017-03-15 08:08:01 -04:00
|
|
|
$loading.removeClass('hidden').fadeIn();
|
2016-07-24 16:45:11 -04:00
|
|
|
$dropdown.trigger('loading.gl.dropdown');
|
|
|
|
return $.ajax({
|
|
|
|
type: 'PUT',
|
|
|
|
dataType: 'json',
|
|
|
|
url: issueURL,
|
|
|
|
data: data
|
|
|
|
}).done(function(data) {
|
|
|
|
var user;
|
|
|
|
$dropdown.trigger('loaded.gl.dropdown');
|
|
|
|
$loading.fadeOut();
|
|
|
|
$selectbox.hide();
|
|
|
|
if (data.assignee) {
|
|
|
|
user = {
|
|
|
|
name: data.assignee.name,
|
|
|
|
username: data.assignee.username,
|
|
|
|
avatar: data.assignee.avatar_url
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
user = {
|
|
|
|
name: 'Unassigned',
|
|
|
|
username: '',
|
|
|
|
avatar: ''
|
|
|
|
};
|
|
|
|
}
|
|
|
|
$value.html(assigneeTemplate(user));
|
|
|
|
$collapsedSidebar.attr('title', user.name).tooltip('fixTitle');
|
|
|
|
return $collapsedSidebar.html(collapsedAssigneeTemplate(user));
|
|
|
|
});
|
|
|
|
};
|
2016-10-06 08:14:24 -04:00
|
|
|
collapsedAssigneeTemplate = _.template('<% if( avatar ) { %> <a class="author_link" href="/<%- username %>"> <img width="24" class="avatar avatar-inline s24" alt="" src="<%- avatar %>"> </a> <% } else { %> <i class="fa fa-user"></i> <% } %>');
|
|
|
|
assigneeTemplate = _.template('<% if (username) { %> <a class="author_link bold" href="/<%- username %>"> <% if( avatar ) { %> <img width="32" class="avatar avatar-inline s32" alt="" src="<%- avatar %>"> <% } %> <span class="author"><%- name %></span> <span class="username"> @<%- username %> </span> </a> <% } else { %> <span class="no-value assign-yourself"> No assignee - <a href="#" class="js-assign-yourself"> assign yourself </a> </span> <% } %>');
|
2016-07-24 16:45:11 -04:00
|
|
|
return $dropdown.glDropdown({
|
2016-10-04 15:21:06 -04:00
|
|
|
showMenuAbove: showMenuAbove,
|
2016-07-24 16:45:11 -04:00
|
|
|
data: function(term, callback) {
|
|
|
|
var isAuthorFilter;
|
|
|
|
isAuthorFilter = $('.js-author-search');
|
2016-07-31 18:38:24 -04:00
|
|
|
return _this.users(term, options, function(users) {
|
2016-07-24 16:45:11 -04:00
|
|
|
var anyUser, index, j, len, name, obj, showDivider;
|
|
|
|
if (term.length === 0) {
|
|
|
|
showDivider = 0;
|
|
|
|
if (firstUser) {
|
2016-07-26 23:32:10 -04:00
|
|
|
// Move current user to the front of the list
|
2017-01-10 17:35:09 -05:00
|
|
|
for (index = j = 0, len = users.length; j < len; index = (j += 1)) {
|
2016-07-24 16:45:11 -04:00
|
|
|
obj = users[index];
|
|
|
|
if (obj.username === firstUser) {
|
|
|
|
users.splice(index, 1);
|
|
|
|
users.unshift(obj);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showNullUser) {
|
|
|
|
showDivider += 1;
|
|
|
|
users.unshift({
|
|
|
|
beforeDivider: true,
|
|
|
|
name: 'Unassigned',
|
|
|
|
id: 0
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (showAnyUser) {
|
|
|
|
showDivider += 1;
|
|
|
|
name = showAnyUser;
|
|
|
|
if (name === true) {
|
|
|
|
name = 'Any User';
|
|
|
|
}
|
|
|
|
anyUser = {
|
|
|
|
beforeDivider: true,
|
|
|
|
name: name,
|
|
|
|
id: null
|
|
|
|
};
|
|
|
|
users.unshift(anyUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showDivider) {
|
|
|
|
users.splice(showDivider, 0, "divider");
|
|
|
|
}
|
2016-10-04 15:21:06 -04:00
|
|
|
|
|
|
|
callback(users);
|
|
|
|
if (showMenuAbove) {
|
|
|
|
$dropdown.data('glDropdown').positionMenuAbove();
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
filterable: true,
|
|
|
|
filterRemote: true,
|
|
|
|
search: {
|
|
|
|
fields: ['name', 'username']
|
|
|
|
},
|
|
|
|
selectable: true,
|
|
|
|
fieldName: $dropdown.data('field-name'),
|
2016-08-30 06:21:29 -04:00
|
|
|
toggleLabel: function(selected, el) {
|
|
|
|
if (selected && 'id' in selected && $(el).hasClass('is-active')) {
|
2016-07-24 16:45:11 -04:00
|
|
|
if (selected.text) {
|
|
|
|
return selected.text;
|
|
|
|
} else {
|
|
|
|
return selected.name;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return defaultLabel;
|
|
|
|
}
|
|
|
|
},
|
2016-08-30 06:21:29 -04:00
|
|
|
defaultLabel: defaultLabel,
|
2016-07-24 16:45:11 -04:00
|
|
|
inputId: 'issue_assignee_id',
|
|
|
|
hidden: function(e) {
|
|
|
|
$selectbox.hide();
|
2016-07-26 23:32:10 -04:00
|
|
|
// display:block overrides the hide-collapse rule
|
2016-07-24 16:45:11 -04:00
|
|
|
return $value.css('display', '');
|
|
|
|
},
|
2016-10-06 04:03:10 -04:00
|
|
|
vue: $dropdown.hasClass('js-issue-board-sidebar'),
|
2016-08-05 12:24:16 -04:00
|
|
|
clicked: function(user, $el, e) {
|
2016-07-24 16:45:11 -04:00
|
|
|
var isIssueIndex, isMRIndex, page, selected;
|
|
|
|
page = $('body').data('page');
|
|
|
|
isIssueIndex = page === 'projects:issues:index';
|
|
|
|
isMRIndex = (page === page && page === 'projects:merge_requests:index');
|
2016-08-30 06:21:29 -04:00
|
|
|
if ($dropdown.hasClass('js-filter-bulk-update') || $dropdown.hasClass('js-issuable-form-dropdown')) {
|
|
|
|
e.preventDefault();
|
|
|
|
selectedId = user.id;
|
2017-02-22 02:26:32 -05:00
|
|
|
if (selectedId === gon.current_user_id) {
|
|
|
|
$('.assign-to-me-link').hide();
|
|
|
|
} else {
|
|
|
|
$('.assign-to-me-link').show();
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
return;
|
|
|
|
}
|
2017-01-31 06:48:43 -05:00
|
|
|
if ($el.closest('.add-issues-modal').length) {
|
|
|
|
gl.issueBoards.ModalStore.store.filter[$dropdown.data('field-name')] = user.id;
|
2016-08-05 10:24:03 -04:00
|
|
|
} else if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) {
|
2016-07-24 16:45:11 -04:00
|
|
|
selectedId = user.id;
|
|
|
|
return Issuable.filterResults($dropdown.closest('form'));
|
|
|
|
} else if ($dropdown.hasClass('js-filter-submit')) {
|
|
|
|
return $dropdown.closest('form').submit();
|
2016-10-06 04:03:10 -04:00
|
|
|
} else if ($dropdown.hasClass('js-issue-board-sidebar')) {
|
2016-10-05 07:20:59 -04:00
|
|
|
if (user.id) {
|
2017-04-07 15:36:09 -04:00
|
|
|
gl.issueBoards.boardStoreIssueSet('assignee', new ListUser({
|
2016-10-05 07:20:59 -04:00
|
|
|
id: user.id,
|
|
|
|
username: user.username,
|
|
|
|
name: user.name,
|
|
|
|
avatar_url: user.avatar_url
|
|
|
|
}));
|
|
|
|
} else {
|
2017-04-07 15:36:09 -04:00
|
|
|
gl.issueBoards.boardStoreIssueDelete('assignee');
|
2016-10-05 07:20:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
updateIssueBoardsIssue();
|
2016-07-24 16:45:11 -04:00
|
|
|
} else {
|
|
|
|
selected = $dropdown.closest('.selectbox').find("input[name='" + ($dropdown.data('field-name')) + "']").val();
|
|
|
|
return assignTo(selected);
|
|
|
|
}
|
|
|
|
},
|
2016-08-30 06:21:29 -04:00
|
|
|
id: function (user) {
|
|
|
|
return user.id;
|
|
|
|
},
|
2017-02-22 02:26:32 -05:00
|
|
|
opened: function(e) {
|
|
|
|
const $el = $(e.currentTarget);
|
|
|
|
$el.find('.is-active').removeClass('is-active');
|
|
|
|
$el.find(`li[data-user-id="${selectedId}"] .dropdown-menu-user-link`).addClass('is-active');
|
|
|
|
},
|
2016-07-24 16:45:11 -04:00
|
|
|
renderRow: function(user) {
|
|
|
|
var avatar, img, listClosingTags, listWithName, listWithUserName, selected, username;
|
|
|
|
username = user.username ? "@" + user.username : "";
|
|
|
|
avatar = user.avatar_url ? user.avatar_url : false;
|
2017-02-22 02:26:32 -05:00
|
|
|
selected = user.id === parseInt(selectedId, 10) ? "is-active" : "";
|
2016-07-24 16:45:11 -04:00
|
|
|
img = "";
|
|
|
|
if (user.beforeDivider != null) {
|
|
|
|
"<li> <a href='#' class='" + selected + "'> " + user.name + " </a> </li>";
|
|
|
|
} else {
|
|
|
|
if (avatar) {
|
|
|
|
img = "<img src='" + avatar + "' class='avatar avatar-inline' width='30' />";
|
|
|
|
}
|
|
|
|
}
|
2016-07-26 23:32:10 -04:00
|
|
|
// split into three parts so we can remove the username section if nessesary
|
2017-02-22 02:26:32 -05:00
|
|
|
listWithName = "<li data-user-id=" + user.id + "> <a href='#' class='dropdown-menu-user-link " + selected + "'> " + img + " <strong class='dropdown-menu-user-full-name'> " + user.name + " </strong>";
|
2016-07-24 16:45:11 -04:00
|
|
|
listWithUserName = "<span class='dropdown-menu-user-username'> " + username + " </span>";
|
|
|
|
listClosingTags = "</a> </li>";
|
|
|
|
if (username === '') {
|
|
|
|
listWithUserName = '';
|
|
|
|
}
|
|
|
|
return listWithName + listWithUserName + listClosingTags;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
$('.ajax-users-select').each((function(_this) {
|
|
|
|
return function(i, select) {
|
|
|
|
var firstUser, showAnyUser, showEmailUser, showNullUser;
|
2016-07-31 18:38:24 -04:00
|
|
|
var options = {};
|
|
|
|
options.skipLdap = $(select).hasClass('skip_ldap');
|
|
|
|
options.projectId = $(select).data('project-id');
|
|
|
|
options.groupId = $(select).data('group-id');
|
|
|
|
options.showCurrentUser = $(select).data('current-user');
|
|
|
|
options.pushCodeToProtectedBranches = $(select).data('push-code-to-protected-branches');
|
|
|
|
options.authorId = $(select).data('author-id');
|
|
|
|
options.skipUsers = $(select).data('skip-users');
|
2016-07-24 16:45:11 -04:00
|
|
|
showNullUser = $(select).data('null-user');
|
|
|
|
showAnyUser = $(select).data('any-user');
|
|
|
|
showEmailUser = $(select).data('email-user');
|
|
|
|
firstUser = $(select).data('first-user');
|
|
|
|
return $(select).select2({
|
|
|
|
placeholder: "Search for a user",
|
|
|
|
multiple: $(select).hasClass('multiselect'),
|
|
|
|
minimumInputLength: 0,
|
|
|
|
query: function(query) {
|
2016-07-31 18:38:24 -04:00
|
|
|
return _this.users(query.term, options, function(users) {
|
2016-07-24 16:45:11 -04:00
|
|
|
var anyUser, data, emailUser, index, j, len, name, nullUser, obj, ref;
|
|
|
|
data = {
|
|
|
|
results: users
|
|
|
|
};
|
|
|
|
if (query.term.length === 0) {
|
|
|
|
if (firstUser) {
|
2016-07-26 23:32:10 -04:00
|
|
|
// Move current user to the front of the list
|
2016-07-24 16:45:11 -04:00
|
|
|
ref = data.results;
|
2017-01-10 17:35:09 -05:00
|
|
|
for (index = j = 0, len = ref.length; j < len; index = (j += 1)) {
|
2016-07-24 16:45:11 -04:00
|
|
|
obj = ref[index];
|
|
|
|
if (obj.username === firstUser) {
|
|
|
|
data.results.splice(index, 1);
|
|
|
|
data.results.unshift(obj);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showNullUser) {
|
|
|
|
nullUser = {
|
|
|
|
name: 'Unassigned',
|
|
|
|
id: 0
|
|
|
|
};
|
|
|
|
data.results.unshift(nullUser);
|
|
|
|
}
|
|
|
|
if (showAnyUser) {
|
|
|
|
name = showAnyUser;
|
|
|
|
if (name === true) {
|
|
|
|
name = 'Any User';
|
|
|
|
}
|
|
|
|
anyUser = {
|
|
|
|
name: name,
|
|
|
|
id: null
|
|
|
|
};
|
|
|
|
data.results.unshift(anyUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showEmailUser && data.results.length === 0 && query.term.match(/^[^@]+@[^@]+$/)) {
|
2016-09-22 14:15:00 -04:00
|
|
|
var trimmed = query.term.trim();
|
2016-07-24 16:45:11 -04:00
|
|
|
emailUser = {
|
|
|
|
name: "Invite \"" + query.term + "\"",
|
2016-09-22 14:15:00 -04:00
|
|
|
username: trimmed,
|
|
|
|
id: trimmed
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
data.results.unshift(emailUser);
|
|
|
|
}
|
|
|
|
return query.callback(data);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
initSelection: function() {
|
|
|
|
var args;
|
|
|
|
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
|
|
return _this.initSelection.apply(_this, args);
|
|
|
|
},
|
|
|
|
formatResult: function() {
|
|
|
|
var args;
|
|
|
|
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
|
|
return _this.formatResult.apply(_this, args);
|
|
|
|
},
|
|
|
|
formatSelection: function() {
|
|
|
|
var args;
|
|
|
|
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
|
|
return _this.formatSelection.apply(_this, args);
|
|
|
|
},
|
|
|
|
dropdownCssClass: "ajax-users-dropdown",
|
2016-07-26 23:32:10 -04:00
|
|
|
// we do not want to escape markup since we are displaying html in results
|
2016-07-24 16:45:11 -04:00
|
|
|
escapeMarkup: function(m) {
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
UsersSelect.prototype.initSelection = function(element, callback) {
|
|
|
|
var id, nullUser;
|
|
|
|
id = $(element).val();
|
|
|
|
if (id === "0") {
|
|
|
|
nullUser = {
|
|
|
|
name: 'Unassigned'
|
|
|
|
};
|
|
|
|
return callback(nullUser);
|
|
|
|
} else if (id !== "") {
|
|
|
|
return this.user(id, callback);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UsersSelect.prototype.formatResult = function(user) {
|
|
|
|
var avatar;
|
|
|
|
if (user.avatar_url) {
|
|
|
|
avatar = user.avatar_url;
|
|
|
|
} else {
|
|
|
|
avatar = gon.default_avatar_url;
|
|
|
|
}
|
|
|
|
return "<div class='user-result " + (!user.username ? 'no-username' : void 0) + "'> <div class='user-image'><img class='avatar s24' src='" + avatar + "'></div> <div class='user-name'>" + user.name + "</div> <div class='user-username'>" + (user.username || "") + "</div> </div>";
|
|
|
|
};
|
|
|
|
|
|
|
|
UsersSelect.prototype.formatSelection = function(user) {
|
|
|
|
return user.name;
|
|
|
|
};
|
|
|
|
|
|
|
|
UsersSelect.prototype.user = function(user_id, callback) {
|
2017-01-11 23:27:41 -05:00
|
|
|
if (!/^\d+$/.test(user_id)) {
|
2016-10-14 09:04:23 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
var url;
|
|
|
|
url = this.buildUrl(this.userPath);
|
|
|
|
url = url.replace(':id', user_id);
|
|
|
|
return $.ajax({
|
|
|
|
url: url,
|
|
|
|
dataType: "json"
|
|
|
|
}).done(function(user) {
|
|
|
|
return callback(user);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-07-26 23:32:10 -04:00
|
|
|
// Return users list. Filtered by query
|
|
|
|
// Only active users retrieved
|
2016-07-31 18:38:24 -04:00
|
|
|
UsersSelect.prototype.users = function(query, options, callback) {
|
2016-07-24 16:45:11 -04:00
|
|
|
var url;
|
|
|
|
url = this.buildUrl(this.usersPath);
|
|
|
|
return $.ajax({
|
|
|
|
url: url,
|
|
|
|
data: {
|
|
|
|
search: query,
|
|
|
|
per_page: 20,
|
|
|
|
active: true,
|
2016-07-31 18:38:24 -04:00
|
|
|
project_id: options.projectId || null,
|
|
|
|
group_id: options.groupId || null,
|
|
|
|
skip_ldap: options.skipLdap || null,
|
2016-11-03 06:22:56 -04:00
|
|
|
todo_filter: options.todoFilter || null,
|
|
|
|
todo_state_filter: options.todoStateFilter || null,
|
2016-07-31 18:38:24 -04:00
|
|
|
current_user: options.showCurrentUser || null,
|
|
|
|
push_code_to_protected_branches: options.pushCodeToProtectedBranches || null,
|
|
|
|
author_id: options.authorId || null,
|
|
|
|
skip_users: options.skipUsers || null
|
2016-07-24 16:45:11 -04:00
|
|
|
},
|
|
|
|
dataType: "json"
|
|
|
|
}).done(function(users) {
|
|
|
|
return callback(users);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
UsersSelect.prototype.buildUrl = function(url) {
|
|
|
|
if (gon.relative_url_root != null) {
|
|
|
|
url = gon.relative_url_root.replace(/\/$/, '') + url;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
|
|
|
return UsersSelect;
|
|
|
|
})();
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|