Commit 9950dfb0 authored by leiminghuan's avatar leiminghuan

code prettier

parent 4472fd8d
...@@ -29,7 +29,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -29,7 +29,7 @@ function UsersSelect(currentUser, els, options = {}) {
const { handleClick } = options; const { handleClick } = options;
const userSelect = this; const userSelect = this;
$els.each( (i, dropdown) => { $els.each((i, dropdown) => {
const userSelect = this; const userSelect = this;
const options = {}; const options = {};
const $dropdown = $(dropdown); const $dropdown = $(dropdown);
...@@ -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');
} }
...@@ -557,97 +554,92 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -557,97 +554,92 @@ function UsersSelect(currentUser, els, options = {}) {
}); });
import(/* webpackChunkName: 'select2' */ 'select2/select2') import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => { .then(() => {
$('.ajax-users-select').each( $('.ajax-users-select').each((i, select) => {
(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'); options.groupId = $(select).data('groupId');
options.groupId = $(select).data('groupId'); options.showCurrentUser = $(select).data('currentUser');
options.showCurrentUser = $(select).data('currentUser'); options.authorId = $(select).data('authorId');
options.authorId = $(select).data('authorId'); options.skipUsers = $(select).data('skipUsers');
options.skipUsers = $(select).data('skipUsers'); const showNullUser = $(select).data('nullUser');
const showNullUser = $(select).data('nullUser'); const showAnyUser = $(select).data('anyUser');
const showAnyUser = $(select).data('anyUser'); const showEmailUser = $(select).data('emailUser');
const showEmailUser = $(select).data('emailUser'); const firstUser = $(select).data('firstUser');
const firstUser = $(select).data('firstUser'); return $(select).select2({
return $(select).select2({ placeholder: __('Search for a user'),
placeholder: __('Search for a user'), multiple: $(select).hasClass('multiselect'),
multiple: $(select).hasClass('multiselect'), minimumInputLength: 0,
minimumInputLength: 0, query(query) {
query(query) { return userSelect.users(query.term, options, users => {
return userSelect.users(query.term, options, users => { let name;
let name; const data = {
const data = { results: users,
results: users, };
}; if (query.term.length === 0) {
if (query.term.length === 0) { if (firstUser) {
if (firstUser) { // Move current user to the front of the list
// Move current user to the front of the list const ref = data.results;
const ref = data.results;
for (let index = 0, len = ref.length; index < len; index += 1) {
for (let index = 0, len = ref.length; index < len; index += 1) { const obj = ref[index];
const obj = ref[index]; if (obj.username === firstUser) {
if (obj.username === firstUser) { data.results.splice(index, 1);
data.results.splice(index, 1); data.results.unshift(obj);
data.results.unshift(obj); break;
break;
}
}
}
if (showNullUser) {
const nullUser = {
name: s__('UsersSelect|Unassigned'),
id: 0,
};
data.results.unshift(nullUser);
}
if (showAnyUser) {
name = showAnyUser;
if (name === true) {
name = s__('UsersSelect|Any User');
} }
const anyUser = {
name,
id: null,
};
data.results.unshift(anyUser);
} }
} }
if ( if (showNullUser) {
showEmailUser && const nullUser = {
data.results.length === 0 && name: s__('UsersSelect|Unassigned'),
query.term.match(/^[^@]+@[^@]+$/) id: 0,
) {
const trimmed = query.term.trim();
const emailUser = {
name: sprintf(__('Invite "%{trimmed}" by email'), { trimmed }),
username: trimmed,
id: trimmed,
invite: true,
}; };
data.results.unshift(emailUser); data.results.unshift(nullUser);
} }
return query.callback(data); if (showAnyUser) {
}); name = showAnyUser;
}, if (name === true) {
initSelection() { name = s__('UsersSelect|Any User');
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : []; }
return userSelect.initSelection.apply(userSelect, args); const anyUser = {
}, name,
formatResult() { id: null,
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : []; };
return userSelect.formatResult.apply(userSelect, args); data.results.unshift(anyUser);
}, }
formatSelection() { }
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : []; if (showEmailUser && data.results.length === 0 && query.term.match(/^[^@]+@[^@]+$/)) {
return userSelect.formatSelection.apply(userSelect, args); const trimmed = query.term.trim();
}, const emailUser = {
dropdownCssClass: 'ajax-users-dropdown', name: sprintf(__('Invite "%{trimmed}" by email'), { trimmed }),
// we do not want to escape markup since we are displaying html in results username: trimmed,
escapeMarkup(m) { id: trimmed,
return m; invite: true,
}, };
}); data.results.unshift(emailUser);
}
return query.callback(data);
});
},
initSelection() {
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return userSelect.initSelection.apply(userSelect, args);
},
formatResult() {
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return userSelect.formatResult.apply(userSelect, args);
},
formatSelection() {
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
return userSelect.formatSelection.apply(userSelect, args);
},
dropdownCssClass: 'ajax-users-dropdown',
// we do not want to escape markup since we are displaying html in results
escapeMarkup(m) {
return m;
},
});
}); });
}) })
.catch(() => {}); .catch(() => {});
......
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