From 890c5e3c3d07c990622cebeb72db4eab23270e0e Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Wed, 18 Jan 2017 17:49:36 +0100 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=9Cno=20results=20found=E2=80=9D=20?= =?UTF-8?q?message=20in=20smart=20annotation=20[SCI-886]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascripts/sitewide/atwho_res.js.erb | 69 +++++++++++++------ app/assets/stylesheets/themes/scinote.scss | 4 ++ config/locales/en.yml | 1 + 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/sitewide/atwho_res.js.erb b/app/assets/javascripts/sitewide/atwho_res.js.erb index d9bd6cd2c..9da17d2d1 100644 --- a/app/assets/javascripts/sitewide/atwho_res.js.erb +++ b/app/assets/javascripts/sitewide/atwho_res.js.erb @@ -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 = '
'; + res += '<%= I18n.t("atwho.no_results") %>'; + res += '
'; + 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 += '
  • '; - res += ''; - res += ''; - res += map.full_name; - res += ''; - res += ''; - res += ' '; - res += '·'; - res += ' '; - res += ''; - res += map.email; - res += ''; - res += ''; - res += '
  • '; + if (map.no_results) { + res = noResultsTemplate(); + } else { + res = ''; + res += '
  • '; + res += ''; + res += ''; + res += map.full_name; + res += ''; + res += ''; + res += ' '; + res += '·'; + res += ' '; + res += ''; + res += map.email; + res += ''; + res += ''; + res += '
  • '; + } } catch (_error) { res = ''; } diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 27611b6b2..5d66c9f4d 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -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; diff --git a/config/locales/en.yml b/config/locales/en.yml index 8d7a829aa..8f90d2d42 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1452,6 +1452,7 @@ en: unassign_user_from_organization: "%{unassigned_user} was removed from team %{organization} by %{unassigned_by_user}." atwho: + no_results: "No results found" users: title: "People" navigate_1: "up/down"