2017-01-10 00:16:39 +08:00
|
|
|
var SmartAnnotation = (function() {
|
2017-01-05 17:52:00 +08:00
|
|
|
'use strict';
|
|
|
|
|
2017-01-09 18:33:28 +08:00
|
|
|
// utilities
|
|
|
|
var Util = (function() {
|
|
|
|
// helper method that binds show/hidden action
|
|
|
|
function showHideBinding() {
|
|
|
|
$.each(['show', 'hide'], function (i, ev) {
|
|
|
|
var el = $.fn[ev];
|
|
|
|
$.fn[ev] = function () {
|
|
|
|
this.trigger(ev);
|
|
|
|
return el.apply(this, arguments);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var publicApi = {
|
|
|
|
showHideBinding: showHideBinding
|
|
|
|
};
|
|
|
|
|
|
|
|
return publicApi;
|
|
|
|
})();
|
|
|
|
|
2017-01-23 16:47:04 +08:00
|
|
|
// stop the user annotation popover on click propagation
|
|
|
|
function atwhoStopPropagation(element) {
|
|
|
|
$(element).on('click', function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-10 00:16:39 +08:00
|
|
|
function setAtWho(field) {
|
2017-01-19 00:25:33 +08:00
|
|
|
var FilterTypeEnum = Object.freeze({
|
|
|
|
USER: {tag: "users",
|
|
|
|
dataUrl: $(document.body).attr('data-atwho-users-url')},
|
|
|
|
TASK: {tag: "tsk",
|
|
|
|
dataUrl: $(document.body).attr('data-atwho-task-url')},
|
|
|
|
PROJECT: {tag: "prj",
|
|
|
|
dataUrl: $(document.body).attr('data-atwho-project-url')},
|
|
|
|
EXPERIMENT: {tag: "exp",
|
|
|
|
dataUrl: $(document.body).attr('data-atwho-experiment-url')},
|
2018-04-03 02:38:56 +08:00
|
|
|
REPOSITORY: {tag: "rep",
|
|
|
|
dataUrl: $(document.body).attr('data-atwho-rep-items-url')},
|
2017-01-19 00:25:33 +08:00
|
|
|
MENU: {tag: "menu",
|
|
|
|
dataUrl: $(document.body).attr('data-atwho-menu-items')}
|
|
|
|
});
|
|
|
|
var prevAt,
|
|
|
|
// Default selected filter when using '#'
|
2018-04-03 02:38:56 +08:00
|
|
|
DEFAULT_SEARCH_FILTER = FilterTypeEnum.REPOSITORY,
|
2017-01-19 00:25:33 +08:00
|
|
|
atWhoUpdating = false;
|
2017-01-05 17:52:00 +08:00
|
|
|
|
2018-04-03 02:38:56 +08:00
|
|
|
var defaultRepId;
|
|
|
|
|
2017-01-09 18:33:28 +08:00
|
|
|
// helper methods for AtWho callback
|
|
|
|
function _templateEval(_tpl, map) {
|
|
|
|
var res;
|
|
|
|
try {
|
2017-01-19 00:49:36 +08:00
|
|
|
if (map.no_results) {
|
|
|
|
res = noResultsTemplate();
|
|
|
|
} else {
|
|
|
|
res = generateTemplate(map);
|
|
|
|
}
|
2017-01-09 18:33:28 +08:00
|
|
|
} catch (_error) {
|
|
|
|
res = '';
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2017-01-05 20:29:21 +08:00
|
|
|
|
2017-01-19 00:25:33 +08:00
|
|
|
function _matchHighlighter(li, query, filterType) {
|
2017-01-11 21:56:47 +08:00
|
|
|
var $li, re;
|
2017-01-12 16:52:29 +08:00
|
|
|
|
2017-01-11 21:56:47 +08:00
|
|
|
function highlight(el, sel, re) {
|
|
|
|
var prevVal, newVal;
|
|
|
|
prevVal = el.find(sel).html();
|
|
|
|
newVal = prevVal.replace(re, '<strong>$&</strong>');
|
|
|
|
el.find(sel).html(newVal);
|
|
|
|
}
|
|
|
|
|
2017-01-19 00:49:36 +08:00
|
|
|
if (!query || $(li).data('no-results')) {
|
2017-01-09 18:33:28 +08:00
|
|
|
return li;
|
|
|
|
}
|
2017-01-11 21:56:47 +08:00
|
|
|
|
|
|
|
$li = $(li);
|
2017-01-09 18:33:28 +08:00
|
|
|
re = new RegExp(query, 'gi');
|
2017-01-12 16:52:29 +08:00
|
|
|
// search_filter is not passed for the user
|
2017-01-19 00:25:33 +08:00
|
|
|
if(filterType) {
|
2017-01-11 21:56:47 +08:00
|
|
|
highlight($li, '[data-val=name]', re);
|
|
|
|
} else {
|
|
|
|
highlight($li, '[data-val=full-name]', re);
|
|
|
|
highlight($li, '[data-val=email]', re);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $li[0].outerHTML
|
2017-01-09 18:33:28 +08:00
|
|
|
}
|
|
|
|
|
2017-01-11 21:56:47 +08:00
|
|
|
function _generateInputTag(value, li) {
|
2017-01-09 18:33:28 +08:00
|
|
|
var res = '';
|
|
|
|
res += '[#' + li.attr('data-name');
|
|
|
|
res += '~' + li.attr('data-type');
|
|
|
|
res += '~' + li.attr('data-id') + ']';
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-01-11 17:34:14 +08:00
|
|
|
// initialise dropdown dismiss button
|
2017-01-19 22:26:28 +08:00
|
|
|
function initDismissButton($currentAtWho) {
|
|
|
|
$currentAtWho.find('.dismiss').off('click')
|
|
|
|
.on('click', function() {
|
2017-01-11 00:05:32 +08:00
|
|
|
$(field).atwho('destroy');
|
|
|
|
init();
|
|
|
|
});
|
2017-01-11 17:34:14 +08:00
|
|
|
}
|
|
|
|
|
2017-01-19 22:26:28 +08:00
|
|
|
// Initialize or update dropdown header buttons
|
2018-04-03 02:38:56 +08:00
|
|
|
function updateHeaderButtons(query, filterType) {
|
2017-01-19 22:26:28 +08:00
|
|
|
var $currentAtWho = $('.atwho-view[style]');
|
|
|
|
initDismissButton($currentAtWho);
|
|
|
|
|
|
|
|
// Update the selected filter button when changing smart annotation type
|
|
|
|
$currentAtWho.find('[data-filter]')
|
|
|
|
.removeClass('btn-primary')
|
|
|
|
.addClass('btn-default');
|
2018-04-03 02:38:56 +08:00
|
|
|
if(filterType.tag === 'rep') {
|
|
|
|
$currentAtWho.find('[data-rep-id="' + filterType.repository_id + '"]')
|
|
|
|
.removeClass('btn-default')
|
|
|
|
.addClass('btn-primary');
|
|
|
|
} else {
|
|
|
|
$currentAtWho.find('[data-filter="' + filterType.tag + '"]')
|
|
|
|
.removeClass('btn-default')
|
|
|
|
.addClass('btn-primary');
|
|
|
|
}
|
2017-01-14 01:51:05 +08:00
|
|
|
|
2017-01-19 22:26:28 +08:00
|
|
|
// Update the selected filter button when clicking on one of them
|
|
|
|
$currentAtWho.find('[data-filter]').off()
|
|
|
|
.on('click', function(e) {
|
2018-04-03 02:38:56 +08:00
|
|
|
if($(this).hasClass('btn-primary')) {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-14 01:51:05 +08:00
|
|
|
var $selectedBtn = $(this);
|
2018-04-03 02:38:56 +08:00
|
|
|
var $prevBtn = $selectedBtn.closest('.atwho-header-res')
|
|
|
|
.children('.btn-primary');
|
2017-01-14 01:51:05 +08:00
|
|
|
$selectedBtn.removeClass('btn-default').addClass('btn-primary');
|
|
|
|
$prevBtn.removeClass('btn-primary').addClass('btn-default');
|
2017-01-05 20:29:21 +08:00
|
|
|
|
2017-01-14 01:51:05 +08:00
|
|
|
// Updates query and dropdown elements; focuses input
|
|
|
|
$(field).click().focus();
|
2017-01-05 20:29:21 +08:00
|
|
|
});
|
2017-01-09 18:33:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generates suggestion dropdown filter
|
|
|
|
function generateFilterMenu(active, res_data) {
|
2018-04-03 02:38:56 +08:00
|
|
|
var rep_buttons = '';
|
|
|
|
$.ajax({
|
|
|
|
async: false,
|
|
|
|
dataType: 'json',
|
|
|
|
url: $(document.body).attr('data-atwho-repositories-url'),
|
|
|
|
success: function(data) {
|
|
|
|
$.each(data['repositories'], function(id, name) {
|
|
|
|
if(defaultRepId === undefined){
|
|
|
|
defaultRepId = id;
|
|
|
|
}
|
|
|
|
rep_buttons += '<button data-filter="rep" data-rep-id="' + id +
|
|
|
|
'" class="btn btn-xs btn-primary">' + name + '</button>';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-01-11 00:05:32 +08:00
|
|
|
var header = '<div class="atwho-header-res">' +
|
2018-04-03 02:38:56 +08:00
|
|
|
'<button data-filter="prj" class="btn btn-xs btn-primary' +
|
|
|
|
'">Projects</button>' +
|
|
|
|
'<button data-filter="exp" class="btn btn-xs btn-primary' +
|
|
|
|
'">Experiments</button>' +
|
|
|
|
'<button data-filter="tsk" class="btn btn-xs btn-primary' +
|
|
|
|
'">Tasks</button>' +
|
|
|
|
rep_buttons +
|
|
|
|
'<div class="dismiss">' +
|
2018-07-09 19:13:44 +08:00
|
|
|
'<span class="fas fa-times"></span>' +
|
2017-01-11 00:05:32 +08:00
|
|
|
'</div>' +
|
2017-01-09 18:33:28 +08:00
|
|
|
'<div class="help">' +
|
|
|
|
'<div>' +
|
|
|
|
'<strong><%= I18n.t("atwho.users.navigate_1") %></strong> ' +
|
|
|
|
'<%= I18n.t("atwho.users.navigate_2") %>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div><strong><%= I18n.t("atwho.users.confirm_1") %></strong> ' +
|
|
|
|
'<%= I18n.t("atwho.users.confirm_2") %>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div>' +
|
|
|
|
'<strong><%= I18n.t("atwho.users.dismiss_1") %></strong> ' +
|
|
|
|
'<%= I18n.t("atwho.users.dismiss_2") %>' +
|
|
|
|
'</div>' +
|
|
|
|
'</div>' +
|
|
|
|
'</div>';
|
2017-01-05 20:29:21 +08:00
|
|
|
|
2017-01-09 18:33:28 +08:00
|
|
|
return header;
|
2017-01-05 20:29:21 +08:00
|
|
|
}
|
|
|
|
|
2017-01-19 00:49:36 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-05 17:52:00 +08:00
|
|
|
// Generates resources list items
|
|
|
|
function generateTemplate(map) {
|
|
|
|
var res = '';
|
2017-01-09 18:33:28 +08:00
|
|
|
res += '<li class="atwho-li atwho-li-res" data-name="' +
|
2017-01-18 23:57:51 +08:00
|
|
|
truncateLongString(map.name,
|
|
|
|
<%= Constants::NAME_TRUNCATION_LENGTH %>) +
|
|
|
|
'" data-id="' + map.id + '" data-type="' +
|
2017-01-09 18:33:28 +08:00
|
|
|
map.type + '">';
|
2017-01-05 17:52:00 +08:00
|
|
|
switch(map.type) {
|
|
|
|
case 'tsk':
|
|
|
|
res += '<span data-type class="res-type">' + map.type + '</span>';
|
|
|
|
break;
|
|
|
|
case 'prj':
|
|
|
|
res += '<span data-type class="res-type">' + map.type + '</span>';
|
|
|
|
break;
|
|
|
|
case 'exp':
|
|
|
|
res += '<span data-type class="res-type">' + map.type + '</span>';
|
|
|
|
break;
|
2018-04-03 02:38:56 +08:00
|
|
|
case 'rep_item':
|
|
|
|
res += '<span data-type class="res-type">' +
|
|
|
|
map.repository_tag + '</span>';
|
2017-01-05 17:52:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
res += ' ';
|
2017-01-11 00:05:32 +08:00
|
|
|
res += '<span data-val="name" class="res-name">';
|
2017-01-18 23:57:51 +08:00
|
|
|
res += truncateLongString(map.name,
|
|
|
|
<%= Constants::NAME_TRUNCATION_LENGTH %>);
|
2017-01-05 17:52:00 +08:00
|
|
|
res += '</span>';
|
2017-01-10 21:13:37 +08:00
|
|
|
if(map.archived) {
|
2017-01-11 17:34:14 +08:00
|
|
|
res += '<%= I18n.t("atwho.res.archived") %></span>';
|
2017-01-11 00:05:32 +08:00
|
|
|
} else {
|
|
|
|
res += '</span>';
|
2017-01-10 21:13:37 +08:00
|
|
|
}
|
2017-01-05 17:52:00 +08:00
|
|
|
res += ' ';
|
|
|
|
|
|
|
|
switch (map.type) {
|
|
|
|
case 'tsk':
|
2017-01-10 21:13:37 +08:00
|
|
|
|
2017-01-11 00:05:32 +08:00
|
|
|
res += '<span class="res-description">< ' + map.experimentName +
|
2017-01-05 17:52:00 +08:00
|
|
|
' < ' + map.projectName + '</span>';
|
|
|
|
break;
|
|
|
|
case 'exp':
|
2017-01-11 00:05:32 +08:00
|
|
|
res += '<span class="res-description">< ' + map.projectName + '</span>';
|
2017-01-05 17:52:00 +08:00
|
|
|
break;
|
|
|
|
case 'sam':
|
2017-01-11 00:05:32 +08:00
|
|
|
res += '<span class="res-description">' + map.description + '</span>';
|
2017-01-05 17:52:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
res += '</li>';
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-01-18 23:04:39 +08:00
|
|
|
/**
|
|
|
|
* Hackish wrapper function to make AtWho work when switching between
|
|
|
|
* multiple AtWho instances (e.g. from # to task#).
|
|
|
|
*
|
|
|
|
* Prevents second execution of AtWho update callback, triggered when user
|
|
|
|
* switches to different AtWho instance (e.g. from # to task#), which causes
|
|
|
|
* both of them to be called. In such case, AtWhO modal needs to be
|
|
|
|
* rerendered.
|
|
|
|
*/
|
2017-01-19 01:24:15 +08:00
|
|
|
function atWhoSwitchHack(filterTypeTag, remoteFilterCb) {
|
|
|
|
if(atWhoUpdating || (!$(field).length && _.isUndefined(filterTypeTag))) {
|
2017-01-18 23:04:39 +08:00
|
|
|
setTimeout(function() {
|
2017-01-19 17:12:01 +08:00
|
|
|
$(field).click();
|
2017-01-18 23:04:39 +08:00
|
|
|
}, 100);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
atWhoUpdating = true;
|
|
|
|
setTimeout(function() {
|
|
|
|
remoteFilterCb();
|
|
|
|
atWhoUpdating = false;
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
|
2017-01-19 00:25:33 +08:00
|
|
|
function atWhoSettings(at, defaultFilterType) {
|
2017-01-17 16:31:01 +08:00
|
|
|
return {
|
|
|
|
at: at,
|
|
|
|
callbacks: {
|
|
|
|
remoteFilter: function(query, callback) {
|
2017-01-19 22:26:28 +08:00
|
|
|
var $currentAtWho = $('.atwho-view[style]');
|
|
|
|
var filterTypeTag = $currentAtWho
|
|
|
|
.find('.btn-primary')
|
|
|
|
.data('filter');
|
2017-01-17 16:31:01 +08:00
|
|
|
|
2017-01-19 00:25:33 +08:00
|
|
|
atWhoSwitchHack(filterTypeTag, function() {
|
|
|
|
var filterType;
|
|
|
|
if (_.isUndefined(filterTypeTag)) {
|
2017-01-19 01:24:15 +08:00
|
|
|
// Switched smart annotation type (i.e. changed input)
|
2017-01-19 00:25:33 +08:00
|
|
|
filterType = defaultFilterType;
|
|
|
|
} else {
|
2017-01-19 01:24:15 +08:00
|
|
|
// Switched filtering type (i.e. different filter button
|
|
|
|
// pressed; works also for specific annotation types, e.g.
|
|
|
|
// task#, and coverts to the correct annotation type on confirm)
|
2017-01-19 00:25:33 +08:00
|
|
|
$.each(FilterTypeEnum, function(k, v) {
|
|
|
|
if (v.tag == filterTypeTag) {
|
|
|
|
filterType = FilterTypeEnum[k];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2017-01-18 22:29:48 +08:00
|
|
|
}
|
2017-01-19 00:25:33 +08:00
|
|
|
if (prevAt != at) {
|
2017-01-19 01:24:15 +08:00
|
|
|
// Switching smart annotation type (i.e. chaned input)
|
2017-01-19 22:26:28 +08:00
|
|
|
|
2017-01-18 22:29:48 +08:00
|
|
|
prevAt = at;
|
2017-01-19 00:25:33 +08:00
|
|
|
filterType = defaultFilterType;
|
2017-01-19 22:26:28 +08:00
|
|
|
// Hide current AtWho
|
|
|
|
$currentAtWho.removeAttr("style");
|
2017-01-17 16:31:01 +08:00
|
|
|
}
|
2017-01-18 22:29:48 +08:00
|
|
|
|
2018-04-03 02:38:56 +08:00
|
|
|
var params = { query: query };
|
|
|
|
|
|
|
|
if(filterType.tag === 'rep') {
|
|
|
|
params.repository_id = $currentAtWho
|
|
|
|
.find('.btn-primary')
|
|
|
|
.data('rep-id');
|
|
|
|
if(params.repository_id === undefined) {
|
|
|
|
params.repository_id = defaultRepId;
|
|
|
|
}
|
|
|
|
filterType.repository_id = params.repository_id;
|
|
|
|
}
|
|
|
|
|
2017-01-18 22:29:48 +08:00
|
|
|
$.getJSON(
|
2017-01-19 00:25:33 +08:00
|
|
|
filterType.dataUrl,
|
2018-04-03 02:38:56 +08:00
|
|
|
params,
|
2017-01-18 22:29:48 +08:00
|
|
|
function(data) {
|
2017-01-19 22:26:28 +08:00
|
|
|
// Updates dropdown
|
2017-01-19 00:49:36 +08:00
|
|
|
if (data.res.length < 1) {
|
|
|
|
callback([{no_results: 1}]);
|
|
|
|
} else {
|
|
|
|
callback(data.res);
|
|
|
|
}
|
2017-01-19 22:26:28 +08:00
|
|
|
|
2018-04-03 02:38:56 +08:00
|
|
|
updateHeaderButtons(query, filterType);
|
2017-01-18 22:29:48 +08:00
|
|
|
}
|
|
|
|
);
|
2017-01-18 23:04:39 +08:00
|
|
|
});
|
2017-01-17 16:31:01 +08:00
|
|
|
},
|
2017-01-19 00:49:36 +08:00
|
|
|
sorter: function(query, items, _searchKey) {
|
|
|
|
// Sorting is already done on server-side
|
|
|
|
return items;
|
|
|
|
},
|
2017-01-17 16:31:01 +08:00
|
|
|
tplEval: function(_tpl, map) {
|
|
|
|
return _templateEval(_tpl, map);
|
|
|
|
},
|
|
|
|
highlighter: function(li, query) {
|
|
|
|
return _matchHighlighter(li, query, true);
|
|
|
|
},
|
|
|
|
beforeInsert: function(value, li) {
|
|
|
|
return _generateInputTag(value, li);
|
2018-07-06 20:26:20 +08:00
|
|
|
},
|
|
|
|
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");
|
|
|
|
regexp = new RegExp(flag + "([A-Za-z" + _a + "-" + _y + "0-9_\\s\+\-\]*)$|" + flag + "([^\\x00-\\xff]*)$", 'gi');
|
|
|
|
match = regexp.exec(subtext);
|
|
|
|
if (match) {
|
|
|
|
return match[2] || match[1];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
2017-01-17 16:31:01 +08:00
|
|
|
},
|
2017-01-19 00:25:33 +08:00
|
|
|
headerTpl: generateFilterMenu(defaultFilterType),
|
2017-01-17 16:31:01 +08:00
|
|
|
limit: <%= Constants::ATWHO_SEARCH_LIMIT %>,
|
|
|
|
startWithSpace: true,
|
|
|
|
acceptSpaceBar: true,
|
|
|
|
displayTimeout: 120000
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
2017-01-09 18:33:28 +08:00
|
|
|
$(field)
|
2017-01-11 00:05:32 +08:00
|
|
|
.atwho({
|
|
|
|
at: '@',
|
|
|
|
callbacks: {
|
|
|
|
remoteFilter: function(query, callback) {
|
|
|
|
$.getJSON(
|
2017-01-19 00:25:33 +08:00
|
|
|
FilterTypeEnum.USER.dataUrl,
|
2017-01-11 00:05:32 +08:00
|
|
|
{query: query},
|
|
|
|
function(data) {
|
2017-01-19 00:49:36 +08:00
|
|
|
if (data.users.length < 1) {
|
2017-01-24 22:20:50 +08:00
|
|
|
callback([{no_results: 1}]);
|
|
|
|
} else {
|
|
|
|
callback(data.users);
|
|
|
|
}
|
|
|
|
initDismissButton($('.atwho-view[style]'));
|
2017-01-11 00:05:32 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
sorter: function(query, items, _searchKey) {
|
|
|
|
// Sorting is already done on server-side
|
|
|
|
return items;
|
|
|
|
},
|
|
|
|
tplEval: function(_tpl, map) {
|
|
|
|
var res;
|
|
|
|
try {
|
2017-01-19 00:49:36 +08:00
|
|
|
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 + '">';
|
2019-05-21 21:19:44 +08:00
|
|
|
res += '<span class="global-avatar-container"><img src="' + map.img_url + '" class="avatar" /></span>';
|
2017-01-19 00:49:36 +08:00
|
|
|
res += '<span data-val="full-name">';
|
|
|
|
res += map.full_name;
|
|
|
|
res += '</span>';
|
|
|
|
res += '<small>';
|
|
|
|
res += ' ';
|
|
|
|
res += '·';
|
|
|
|
res += ' ';
|
|
|
|
res += '<span data-val="email">';
|
|
|
|
res += map.email;
|
|
|
|
res += '</span>';
|
|
|
|
res += '</small>';
|
|
|
|
res += '</li>';
|
|
|
|
}
|
2017-01-11 00:05:32 +08:00
|
|
|
} catch (_error) {
|
|
|
|
res = '';
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
},
|
|
|
|
highlighter: function(li, query) {
|
2017-01-11 21:56:47 +08:00
|
|
|
return _matchHighlighter(li, query);
|
2017-01-11 00:05:32 +08:00
|
|
|
},
|
|
|
|
beforeInsert: function(value, li) {
|
|
|
|
var res = '';
|
|
|
|
res += '[@' + li.attr('data-full-name');
|
|
|
|
res += '~' + li.attr('data-id') + ']';
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
headerTpl:
|
|
|
|
'<div class="atwho-header-res">' +
|
2018-04-03 02:38:56 +08:00
|
|
|
'<div class="title-user"><%= I18n.t("atwho.users.title") %></div>' +
|
2017-01-11 00:05:32 +08:00
|
|
|
'<div class="help">' +
|
|
|
|
'<div>' +
|
|
|
|
'<strong><%= I18n.t("atwho.users.navigate_1") %></strong> ' +
|
|
|
|
'<%= I18n.t("atwho.users.navigate_2") %>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div>' +
|
|
|
|
'<strong><%= I18n.t("atwho.users.confirm_1") %></strong> ' +
|
|
|
|
'<%= I18n.t("atwho.users.confirm_2") %>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div>' +
|
|
|
|
'<strong><%= I18n.t("atwho.users.dismiss_1") %></strong> ' +
|
|
|
|
'<%= I18n.t("atwho.users.dismiss_2") %>' +
|
|
|
|
'</div>' +
|
2018-04-03 02:38:56 +08:00
|
|
|
'</div>' +
|
2017-01-11 00:05:32 +08:00
|
|
|
'<div class="dismiss">' +
|
2018-07-09 19:13:44 +08:00
|
|
|
'<span class="fas fa-times"></span>' +
|
2017-01-11 00:05:32 +08:00
|
|
|
'</div>' +
|
|
|
|
'</div>',
|
|
|
|
limit: <%= Constants::ATWHO_SEARCH_LIMIT %>,
|
|
|
|
startsWithSpace: true,
|
|
|
|
acceptSpaceBar: true,
|
|
|
|
displayTimeout: 120000
|
|
|
|
})
|
2018-04-03 02:38:56 +08:00
|
|
|
.atwho(atWhoSettings('#', DEFAULT_SEARCH_FILTER))
|
2017-01-20 18:33:10 +08:00
|
|
|
// .atwho(atWhoSettings('task#', FilterTypeEnum.TASK)) Waiting for better times
|
|
|
|
// .atwho(atWhoSettings('project#', FilterTypeEnum.PROJECT))
|
|
|
|
// .atwho(atWhoSettings('experiment#', FilterTypeEnum.EXPERIMENT))
|
2018-04-03 02:38:56 +08:00
|
|
|
// .atwho(atWhoSettings('sample#', FilterTypeEnum.REPOSITORY));
|
2017-01-05 17:52:00 +08:00
|
|
|
}
|
2017-01-09 18:33:28 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
init: init
|
|
|
|
};
|
2017-01-05 17:52:00 +08:00
|
|
|
}
|
2017-07-10 22:22:32 +08:00
|
|
|
// Closes the atwho popup * needed in repositories to close the popup
|
|
|
|
// if nothing is selected and the user leaves the form *
|
|
|
|
function closePopup() {
|
2018-07-09 19:13:44 +08:00
|
|
|
$('.atwho-header-res').find('.fa-times').click();
|
2017-07-10 22:22:32 +08:00
|
|
|
}
|
2017-01-05 17:52:00 +08:00
|
|
|
|
2017-01-10 00:16:39 +08:00
|
|
|
function initialize(field) {
|
|
|
|
var atWho = new setAtWho(field);
|
|
|
|
atWho.init();
|
|
|
|
}
|
2017-01-05 17:52:00 +08:00
|
|
|
|
2017-01-23 16:47:04 +08:00
|
|
|
var publicApi = Object.freeze({
|
|
|
|
init: initialize,
|
2017-07-10 22:22:32 +08:00
|
|
|
preventPropagation: atwhoStopPropagation,
|
|
|
|
closePopup: closePopup
|
2017-01-23 16:47:04 +08:00
|
|
|
});
|
2017-01-05 17:52:00 +08:00
|
|
|
|
2017-01-10 00:16:39 +08:00
|
|
|
return publicApi;
|
2017-01-05 17:52:00 +08:00
|
|
|
|
|
|
|
})();
|
2017-01-11 21:56:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
// initialize the smart annotations
|
|
|
|
(function initSmartAnnotation() {
|
|
|
|
$(document).on('focus', '[data-atwho-edit]', function() {
|
2017-01-12 16:52:29 +08:00
|
|
|
if(_.isUndefined($(this).data('atwho'))) {
|
|
|
|
SmartAnnotation.init(this);
|
|
|
|
}
|
2017-01-11 21:56:47 +08:00
|
|
|
});
|
|
|
|
})();
|