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 = {}) { ...@@ -27,10 +27,10 @@ function UsersSelect(currentUser, els, options = {}) {
} }
const { handleClick } = options; const { handleClick } = options;
const userSelect = this;
$els.each( $els.each((i, dropdown) => {
(function(_this) { const userSelect = this;
return function(i, dropdown) {
const options = {}; const options = {};
const $dropdown = $(dropdown); const $dropdown = $(dropdown);
options.projectId = $dropdown.data('projectId'); options.projectId = $dropdown.data('projectId');
...@@ -75,7 +75,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -75,7 +75,7 @@ function UsersSelect(currentUser, els, options = {}) {
// Save current selected user to the DOM // Save current selected user to the DOM
const currentUserInfo = $dropdown.data('currentUserInfo') || {}; const currentUserInfo = $dropdown.data('currentUserInfo') || {};
const currentUser = _this.currentUser || {}; const currentUser = userSelect.currentUser || {};
const fieldName = $dropdown.data('fieldName'); const fieldName = $dropdown.data('fieldName');
const userName = currentUserInfo.name; const userName = currentUserInfo.name;
const userId = currentUserInfo.id || currentUser.id; const userId = currentUserInfo.id || currentUser.id;
...@@ -181,7 +181,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -181,7 +181,7 @@ function UsersSelect(currentUser, els, options = {}) {
$block.on('click', '.js-assign-yourself', e => { $block.on('click', '.js-assign-yourself', e => {
e.preventDefault(); e.preventDefault();
return assignTo(_this.currentUser.id); return assignTo(userSelect.currentUser.id);
}); });
assignTo = function(selected) { assignTo = function(selected) {
...@@ -229,7 +229,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -229,7 +229,7 @@ function UsersSelect(currentUser, els, options = {}) {
return $dropdown.glDropdown({ return $dropdown.glDropdown({
showMenuAbove, showMenuAbove,
data(term, callback) { data(term, callback) {
return _this.users(term, options, users => { return userSelect.users(term, options, users => {
// GitLabDropdownFilter returns this.instance // GitLabDropdownFilter returns this.instance
// GitLabDropdownRemote returns this.options.instance // GitLabDropdownRemote returns this.options.instance
const glDropdown = this.instance || this.options.instance; const glDropdown = this.instance || this.options.instance;
...@@ -488,10 +488,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -488,10 +488,7 @@ function UsersSelect(currentUser, els, options = {}) {
// Automatically close dropdown after assignee is selected // Automatically close dropdown after assignee is selected
// since CE has no multiple assignees // since CE has no multiple assignees
// EE does not have a max-select // EE does not have a max-select
if ( if ($dropdown.data('maxSelect') && getSelected().length === $dropdown.data('maxSelect')) {
$dropdown.data('maxSelect') &&
getSelected().length === $dropdown.data('maxSelect')
) {
// Close the dropdown // Close the dropdown
$dropdown.dropdown('toggle'); $dropdown.dropdown('toggle');
} }
...@@ -551,17 +548,13 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -551,17 +548,13 @@ function UsersSelect(currentUser, els, options = {}) {
img = `<img src='${avatar}' class='avatar avatar-inline m-0' width='32' />`; 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') import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => { .then(() => {
$('.ajax-users-select').each( $('.ajax-users-select').each((i, select) => {
(function(_this) {
return function(i, select) {
const options = {}; const options = {};
options.skipLdap = $(select).hasClass('skip_ldap'); options.skipLdap = $(select).hasClass('skip_ldap');
options.projectId = $(select).data('projectId'); options.projectId = $(select).data('projectId');
...@@ -578,7 +571,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -578,7 +571,7 @@ function UsersSelect(currentUser, els, options = {}) {
multiple: $(select).hasClass('multiselect'), multiple: $(select).hasClass('multiselect'),
minimumInputLength: 0, minimumInputLength: 0,
query(query) { query(query) {
return _this.users(query.term, options, users => { return userSelect.users(query.term, options, users => {
let name; let name;
const data = { const data = {
results: users, results: users,
...@@ -616,11 +609,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -616,11 +609,7 @@ function UsersSelect(currentUser, els, options = {}) {
data.results.unshift(anyUser); data.results.unshift(anyUser);
} }
} }
if ( if (showEmailUser && data.results.length === 0 && query.term.match(/^[^@]+@[^@]+$/)) {
showEmailUser &&
data.results.length === 0 &&
query.term.match(/^[^@]+@[^@]+$/)
) {
const trimmed = query.term.trim(); const trimmed = query.term.trim();
const emailUser = { const emailUser = {
name: sprintf(__('Invite "%{trimmed}" by email'), { trimmed }), name: sprintf(__('Invite "%{trimmed}" by email'), { trimmed }),
...@@ -635,15 +624,15 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -635,15 +624,15 @@ function UsersSelect(currentUser, els, options = {}) {
}, },
initSelection() { initSelection() {
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : []; const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return _this.initSelection.apply(_this, args); return userSelect.initSelection.apply(userSelect, args);
}, },
formatResult() { formatResult() {
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : []; const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return _this.formatResult.apply(_this, args); return userSelect.formatResult.apply(userSelect, args);
}, },
formatSelection() { formatSelection() {
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : []; 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', dropdownCssClass: 'ajax-users-dropdown',
// we do not want to escape markup since we are displaying html in results // we do not want to escape markup since we are displaying html in results
...@@ -651,9 +640,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -651,9 +640,7 @@ function UsersSelect(currentUser, els, options = {}) {
return m; return m;
}, },
}); });
}; });
})(this),
);
}) })
.catch(() => {}); .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