Temp commit

This commit is contained in:
Luka Murn 2017-01-05 11:00:00 +01:00
parent eb64162633
commit a78bb79618
3 changed files with 52 additions and 19 deletions

View file

@ -10,6 +10,23 @@
.atwho({ .atwho({
at: '@', at: '@',
callbacks: { callbacks: {
matcher: function(flag, subtext, should_startWithSpace, acceptSpaceBar) {
var _a, _y, match, regexp, space;
flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
if (should_startWithSpace) {
flag = '(?:^|\\s)' + flag;
}
_a = decodeURI("%C3%80");
_y = decodeURI("%C3%BF");
space = ' \xa0'; // Use space...
regexp = new RegExp(flag + "([A-Za-z" + _a + "-" + _y + "0-9_" + space + "\'\.\+\-]*)$|" + flag + "([^\\x00-\\xff]*)$", 'gi');
match = regexp.exec(subtext);
if (match) {
return match[2] || match[1]
} else {
return null;
}
},
remoteFilter: function(query, callback) { remoteFilter: function(query, callback) {
$.getJSON( $.getJSON(
'/organizations/1/atwho_users.json', '/organizations/1/atwho_users.json',
@ -19,21 +36,28 @@
} }
); );
}, },
sorter: function(query, items, _searchKey) {
// Sorting is already done on server-side
return items;
},
tplEval: function(_tpl, map) { tplEval: function(_tpl, map) {
var res; var res;
try { try {
res = ''; res = '';
res += '<li class="atwho-li atwho-li-user">'; res += '<li class="atwho-li atwho-li-user" ';
res += '<img src="' + map.img_url + '" height="20" width="20" />'; res += 'data-id="' + map.id + '" ';
res += '&nbsp;'; res += 'data-full-name="' + map.full_name + '">';
res += '<span data-full-name>'; res += '<img src="' + map.img_url + '" class="avatar" />';
res += '<span data-val="full-name">';
res += map.full_name; res += map.full_name;
res += '</span>'; res += '</span>';
res += '<small>';
res += '&nbsp;'; res += '&nbsp;';
res += '<i class="fa fa-circle" aria-hidden="true"></i>'; res += '&#183;';
res += '&nbsp;'; res += '&nbsp;';
res += '<small data-email>'; res += '<span data-val="email">';
res += map.email; res += map.email;
res += '</span>';
res += '</small>'; res += '</small>';
res += '</li>'; res += '</li>';
} catch (_error) { } catch (_error) {
@ -42,30 +66,39 @@
return res; return res;
}, },
highlighter: function(li, query) { highlighter: function(li, query) {
if (!query) {
return li;
}
var li2 = $(li); var li2 = $(li);
li2.addClass('highlighted'); var re = new RegExp(query, 'gi');
var prevVal = var prevVal =
li2 li2
.find('[data-full-name]') .find('[data-val=full-name]')
.html(); .html();
var newVal = var newVal =
prevVal prevVal
.replace(query, '<strong>' + query + '</strong>'); .replace(re, '<strong>$&</strong>');
li2.find('[data-full-name]').html(newVal); li2.find('[data-val=full-name]').html(newVal);
prevVal = prevVal =
li2 li2
.find('[data-email]') .find('[data-val=email]')
.html(); .html();
newVal = newVal =
prevVal prevVal
.replace(query, '<strong>' + query + '</strong>'); .replace(re, '<strong>$&</strong>');
li2.find('[data-email]').html(newVal); li2.find('[data-val=email]').html(newVal);
return li2.html(); return li2[0].outerHTML;
},
beforeInsert: function(value, li) {
var res = '';
res += '[@' + li.attr('data-full-name');
res += '~' + li.attr('data-id') + ']';
return res;
} }
}, },
insertTpl: '[${atwho-at}${full_name}~${id}]',
limit: 5, limit: 5,
startWithSpace: true startsWithSpace: true
}); });
} }
}); });

View file

@ -10,8 +10,10 @@ class AtWhoController < ApplicationController
.limit(Constants::ATWHO_SEARCH_LIMIT) .limit(Constants::ATWHO_SEARCH_LIMIT)
.as_json .as_json
# Add avatars, convert to JSON # Add avatars, Base62, convert to JSON
res.each do |user_obj| res.each do |user_obj|
user_obj['full_name'] = user_obj['full_name'].truncate(Constants::NAME_TRUNCATION_LENGTH_DROPDOWN)
user_obj['id'] = user_obj['id'].base62_encode
user_obj['img_url'] = avatar_path(user_obj['id'], :icon_small) user_obj['img_url'] = avatar_path(user_obj['id'], :icon_small)
end end

View file

@ -62,8 +62,6 @@ class Organization < ActiveRecord::Base
.strip .strip
.gsub('_', '\\_') .gsub('_', '\\_')
.gsub('%', '\\%') .gsub('%', '\\%')
.split(/\s+/)
.map { |t| '%' + t + '%' }
else else
a_query = query a_query = query
end end