Commit 79c63d76 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '34625-Remove-IIFEs-from-users_select.js' into 'master'

Resolve "Remove IIFEs from users_select.js"

Closes #34625

See merge request gitlab-org/gitlab!19290
parents 58b63a7c 9950dfb0
......@@ -27,10 +27,10 @@ function UsersSelect(currentUser, els, options = {}) {
}
const { handleClick } = options;
const userSelect = this;
$els.each(
(function(_this) {
return function(i, dropdown) {
$els.each((i, dropdown) => {
const userSelect = this;
const options = {};
const $dropdown = $(dropdown);
options.projectId = $dropdown.data('projectId');
......@@ -75,7 +75,7 @@ function UsersSelect(currentUser, els, options = {}) {
// Save current selected user to the DOM
const currentUserInfo = $dropdown.data('currentUserInfo') || {};
const currentUser = _this.currentUser || {};
const currentUser = userSelect.currentUser || {};
const fieldName = $dropdown.data('fieldName');
const userName = currentUserInfo.name;
const userId = currentUserInfo.id || currentUser.id;
......@@ -181,7 +181,7 @@ function UsersSelect(currentUser, els, options = {}) {
$block.on('click', '.js-assign-yourself', e => {
e.preventDefault();
return assignTo(_this.currentUser.id);
return assignTo(userSelect.currentUser.id);
});
assignTo = function(selected) {
......@@ -229,7 +229,7 @@ function UsersSelect(currentUser, els, options = {}) {
return $dropdown.glDropdown({
showMenuAbove,
data(term, callback) {
return _this.users(term, options, users => {
return userSelect.users(term, options, users => {
// GitLabDropdownFilter returns this.instance
// GitLabDropdownRemote returns this.options.instance
const glDropdown = this.instance || this.options.instance;
......@@ -488,10 +488,7 @@ function UsersSelect(currentUser, els, options = {}) {
// Automatically close dropdown after assignee is selected
// since CE has no multiple assignees
// EE does not have a max-select
if (
$dropdown.data('maxSelect') &&
getSelected().length === $dropdown.data('maxSelect')
) {
if ($dropdown.data('maxSelect') && getSelected().length === $dropdown.data('maxSelect')) {
// Close the dropdown
$dropdown.dropdown('toggle');
}
......@@ -551,17 +548,13 @@ function UsersSelect(currentUser, els, options = {}) {
img = `<img src='${avatar}' class='avatar avatar-inline m-0' width='32' />`;
}
return _this.renderRow(options.issuableType, user, selected, username, img);
return userSelect.renderRow(options.issuableType, user, selected, username, img);
},
});
};
})(this),
);
});
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('.ajax-users-select').each(
(function(_this) {
return function(i, select) {
$('.ajax-users-select').each((i, select) => {
const options = {};
options.skipLdap = $(select).hasClass('skip_ldap');
options.projectId = $(select).data('projectId');
......@@ -578,7 +571,7 @@ function UsersSelect(currentUser, els, options = {}) {
multiple: $(select).hasClass('multiselect'),
minimumInputLength: 0,
query(query) {
return _this.users(query.term, options, users => {
return userSelect.users(query.term, options, users => {
let name;
const data = {
results: users,
......@@ -616,11 +609,7 @@ function UsersSelect(currentUser, els, options = {}) {
data.results.unshift(anyUser);
}
}
if (
showEmailUser &&
data.results.length === 0 &&
query.term.match(/^[^@]+@[^@]+$/)
) {
if (showEmailUser && data.results.length === 0 && query.term.match(/^[^@]+@[^@]+$/)) {
const trimmed = query.term.trim();
const emailUser = {
name: sprintf(__('Invite "%{trimmed}" by email'), { trimmed }),
......@@ -635,15 +624,15 @@ function UsersSelect(currentUser, els, options = {}) {
},
initSelection() {
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return _this.initSelection.apply(_this, args);
return userSelect.initSelection.apply(userSelect, args);
},
formatResult() {
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return _this.formatResult.apply(_this, args);
return userSelect.formatResult.apply(userSelect, args);
},
formatSelection() {
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return _this.formatSelection.apply(_this, args);
return userSelect.formatSelection.apply(userSelect, args);
},
dropdownCssClass: 'ajax-users-dropdown',
// we do not want to escape markup since we are displaying html in results
......@@ -651,9 +640,7 @@ function UsersSelect(currentUser, els, options = {}) {
return m;
},
});
};
})(this),
);
});
})
.catch(() => {});
}
......
---
title: Remove IIFEs from users_select.js
merge_request: 19290
author: minghuan lei
type: other
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment