mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-01 21:21:50 +08:00
Temp commit
This commit is contained in:
parent
eb64162633
commit
a78bb79618
3 changed files with 52 additions and 19 deletions
|
@ -10,6 +10,23 @@
|
|||
.atwho({
|
||||
at: '@',
|
||||
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) {
|
||||
$.getJSON(
|
||||
'/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) {
|
||||
var res;
|
||||
try {
|
||||
res = '';
|
||||
res += '<li class="atwho-li atwho-li-user">';
|
||||
res += '<img src="' + map.img_url + '" height="20" width="20" />';
|
||||
res += ' ';
|
||||
res += '<span data-full-name>';
|
||||
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 += ' ';
|
||||
res += '<i class="fa fa-circle" aria-hidden="true"></i>';
|
||||
res += '·';
|
||||
res += ' ';
|
||||
res += '<small data-email>';
|
||||
res += '<span data-val="email">';
|
||||
res += map.email;
|
||||
res += '</span>';
|
||||
res += '</small>';
|
||||
res += '</li>';
|
||||
} catch (_error) {
|
||||
|
@ -42,30 +66,39 @@
|
|||
return res;
|
||||
},
|
||||
highlighter: function(li, query) {
|
||||
if (!query) {
|
||||
return li;
|
||||
}
|
||||
|
||||
var li2 = $(li);
|
||||
li2.addClass('highlighted');
|
||||
var re = new RegExp(query, 'gi');
|
||||
var prevVal =
|
||||
li2
|
||||
.find('[data-full-name]')
|
||||
.find('[data-val=full-name]')
|
||||
.html();
|
||||
var newVal =
|
||||
prevVal
|
||||
.replace(query, '<strong>' + query + '</strong>');
|
||||
li2.find('[data-full-name]').html(newVal);
|
||||
.replace(re, '<strong>$&</strong>');
|
||||
li2.find('[data-val=full-name]').html(newVal);
|
||||
prevVal =
|
||||
li2
|
||||
.find('[data-email]')
|
||||
.find('[data-val=email]')
|
||||
.html();
|
||||
newVal =
|
||||
prevVal
|
||||
.replace(query, '<strong>' + query + '</strong>');
|
||||
li2.find('[data-email]').html(newVal);
|
||||
return li2.html();
|
||||
.replace(re, '<strong>$&</strong>');
|
||||
li2.find('[data-val=email]').html(newVal);
|
||||
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,
|
||||
startWithSpace: true
|
||||
startsWithSpace: true
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -10,8 +10,10 @@ class AtWhoController < ApplicationController
|
|||
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
||||
.as_json
|
||||
|
||||
# Add avatars, convert to JSON
|
||||
# Add avatars, Base62, convert to JSON
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -62,8 +62,6 @@ class Organization < ActiveRecord::Base
|
|||
.strip
|
||||
.gsub('_', '\\_')
|
||||
.gsub('%', '\\%')
|
||||
.split(/\s+/)
|
||||
.map { |t| '%' + t + '%' }
|
||||
else
|
||||
a_query = query
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue