summaryrefslogtreecommitdiffstats
path: root/web_src/js/features/comp/SearchUserBox.js
diff options
context:
space:
mode:
Diffstat (limited to 'web_src/js/features/comp/SearchUserBox.js')
-rw-r--r--web_src/js/features/comp/SearchUserBox.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/web_src/js/features/comp/SearchUserBox.js b/web_src/js/features/comp/SearchUserBox.js
index 08f97595af..46ecb8ebf4 100644
--- a/web_src/js/features/comp/SearchUserBox.js
+++ b/web_src/js/features/comp/SearchUserBox.js
@@ -3,15 +3,20 @@ import {htmlEscape} from 'escape-goat';
const {appSubUrl} = window.config;
+const looksLikeEmailAddressCheck = /^\S+@\S+$/;
+
export function initCompSearchUserBox() {
const $searchUserBox = $('#search-user-box');
+ const allowEmailInput = $searchUserBox.attr('data-allow-email') === 'true';
+ const allowEmailDescription = $searchUserBox.attr('data-allow-email-description');
$searchUserBox.search({
minCharacters: 2,
apiSettings: {
url: `${appSubUrl}/user/search?q={query}`,
onResponse(response) {
const items = [];
- const searchQueryUppercase = $searchUserBox.find('input').val().toUpperCase();
+ const searchQuery = $searchUserBox.find('input').val();
+ const searchQueryUppercase = searchQuery.toUpperCase();
$.each(response.data, (_i, item) => {
let title = item.login;
if (item.full_name && item.full_name.length > 0) {
@@ -28,6 +33,14 @@ export function initCompSearchUserBox() {
}
});
+ if (allowEmailInput && items.length === 0 && looksLikeEmailAddressCheck.test(searchQuery)) {
+ const resultItem = {
+ title: searchQuery,
+ description: allowEmailDescription
+ };
+ items.push(resultItem);
+ }
+
return {results: items};
}
},