Add “no results found” message in smart annotation [SCI-886]

This commit is contained in:
Oleksii Kriuchykhin 2017-01-18 17:49:36 +01:00 committed by Matej Zrimšek
parent 039a8d7da6
commit 890c5e3c3d
3 changed files with 53 additions and 21 deletions

View file

@ -45,7 +45,11 @@ var SmartAnnotation = (function() {
function _templateEval(_tpl, map) {
var res;
try {
res = generateTemplate(map);
if (map.no_results) {
res = noResultsTemplate();
} else {
res = generateTemplate(map);
}
} catch (_error) {
res = '';
}
@ -62,7 +66,7 @@ var SmartAnnotation = (function() {
el.find(sel).html(newVal);
}
if (!query) {
if (!query || $(li).data('no-results')) {
return li;
}
@ -184,6 +188,13 @@ var SmartAnnotation = (function() {
return header;
}
function noResultsTemplate() {
var res = '<div class="atwho-no-results" data-no-results="1">';
res += '<span><%= I18n.t("atwho.no_results") %></span>';
res += '</div>';
return res;
}
// Generates resources list items
function generateTemplate(map) {
var res = '';
@ -296,12 +307,20 @@ var SmartAnnotation = (function() {
filterType.dataUrl,
{query: query},
function(data) {
callback(data.res);
if (data.res.length < 1) {
callback([{no_results: 1}]);
} else {
callback(data.res);
}
initButtons(query, filterType.tag);
}
);
});
},
sorter: function(query, items, _searchKey) {
// Sorting is already done on server-side
return items;
},
tplEval: function(_tpl, map) {
return _templateEval(_tpl, map);
},
@ -330,7 +349,11 @@ var SmartAnnotation = (function() {
FilterTypeEnum.USER.dataUrl,
{query: query},
function(data) {
callback(data.users);
if (data.users.length < 1) {
callback([{no_results: 1}]);
} else {
callback(data.users);
}
initDismissButton();
}
);
@ -342,23 +365,27 @@ var SmartAnnotation = (function() {
tplEval: function(_tpl, map) {
var res;
try {
res = '';
res += '<li class="atwho-li atwho-li-user" ';
res += 'data-id="' + map.id + '" ';
res += 'data-full-name="' + map.full_name + '">';
res += '<img src="' + map.img_url + '" class="avatar" />';
res += '<span data-val="full-name">';
res += map.full_name;
res += '</span>';
res += '<small>';
res += '&nbsp;';
res += '&#183;';
res += '&nbsp;';
res += '<span data-val="email">';
res += map.email;
res += '</span>';
res += '</small>';
res += '</li>';
if (map.no_results) {
res = noResultsTemplate();
} else {
res = '';
res += '<li class="atwho-li atwho-li-user" ';
res += 'data-id="' + map.id + '" ';
res += 'data-full-name="' + map.full_name + '">';
res += '<img src="' + map.img_url + '" class="avatar" />';
res += '<span data-val="full-name">';
res += map.full_name;
res += '</span>';
res += '<small>';
res += '&nbsp;';
res += '&#183;';
res += '&nbsp;';
res += '<span data-val="email">';
res += map.email;
res += '</span>';
res += '</small>';
res += '</li>';
}
} catch (_error) {
res = '';
}

View file

@ -1885,6 +1885,10 @@ th.custom-field .modal-tooltiptext {
cursor: not-allowed;
}
.atwho-no-results {
padding: 5px 10px;
}
.popover {
border-radius: 3px;
min-width: 450px;

View file

@ -1452,6 +1452,7 @@ en:
unassign_user_from_organization: "<i>%{unassigned_user}</i> was removed from team <strong>%{organization}</strong> by <i>%{unassigned_by_user}</i>."
atwho:
no_results: "No results found"
users:
title: "People"
navigate_1: "up/down"