';
return header;
}
function noResultsTemplate() {
var res = '
';
res += '<%= I18n.t("atwho.no_results") %>';
res += '
';
return res;
}
// Generates resources list items
function generateTemplate(map) {
var res = '';
res += '
';
switch(map.type) {
case 'tsk':
res += '' + map.type + '';
break;
case 'prj':
res += '' + map.type + '';
break;
case 'exp':
res += '' + map.type + '';
break;
case 'rep_item':
res += '' +
map.repository_tag + '';
break;
}
res += ' ';
res += '';
res += truncateLongString(map.name,
<%= Constants::NAME_TRUNCATION_LENGTH %>);
res += '';
if(map.archived) {
res += '<%= I18n.t("atwho.res.archived") %>';
} else {
res += '';
}
res += ' ';
switch (map.type) {
case 'tsk':
res += '< ' + map.experimentName +
' < ' + map.projectName + '';
break;
case 'exp':
res += '< ' + map.projectName + '';
break;
case 'sam':
res += '' + map.description + '';
break;
}
res += '
';
return res;
}
/**
* 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.
*/
function atWhoSwitchHack(filterTypeTag, remoteFilterCb) {
if(atWhoUpdating || (!$(field).length && _.isUndefined(filterTypeTag))) {
setTimeout(function() {
$(field).click();
}, 100);
return;
}
atWhoUpdating = true;
setTimeout(function() {
remoteFilterCb();
atWhoUpdating = false;
}, 100);
}
function atWhoSettings(at, defaultFilterType) {
return {
at: at,
callbacks: {
remoteFilter: function(query, callback) {
var $currentAtWho = $('.atwho-view[style]');
var filterTypeTag = $currentAtWho
.find('.btn-primary')
.data('filter');
atWhoSwitchHack(filterTypeTag, function() {
var filterType;
if (_.isUndefined(filterTypeTag)) {
// Switched smart annotation type (i.e. changed input)
filterType = defaultFilterType;
} else {
// 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)
$.each(FilterTypeEnum, function(k, v) {
if (v.tag == filterTypeTag) {
filterType = FilterTypeEnum[k];
return false;
}
});
}
if (prevAt != at) {
// Switching smart annotation type (i.e. chaned input)
prevAt = at;
filterType = defaultFilterType;
// Hide current AtWho
$currentAtWho.removeAttr("style");
}
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;
}
$.getJSON(
filterType.dataUrl,
params,
function(data) {
// Updates dropdown
if (data.res.length < 1) {
callback([{no_results: 1}]);
} else {
callback(data.res);
}
updateHeaderButtons(query, filterType);
}
);
});
},
sorter: function(query, items, _searchKey) {
// Sorting is already done on server-side
return items;
},
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);
}
},
headerTpl: generateFilterMenu(defaultFilterType),
limit: <%= Constants::ATWHO_SEARCH_LIMIT %>,
startWithSpace: true,
acceptSpaceBar: true,
displayTimeout: 120000
}
}
function init() {
$(field)
.atwho({
at: '@',
callbacks: {
remoteFilter: function(query, callback) {
$.getJSON(
FilterTypeEnum.USER.dataUrl,
{query: query},
function(data) {
if (data.users.length < 1) {
callback([{no_results: 1}]);
} else {
callback(data.users);
}
initDismissButton($('.atwho-view[style]'));
}
);
},
sorter: function(query, items, _searchKey) {
// Sorting is already done on server-side
return items;
},
tplEval: function(_tpl, map) {
var res;
try {
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 = '';
}
return res;
},
highlighter: function(li, query) {
return _matchHighlighter(li, query);
},
beforeInsert: function(value, li) {
var res = '';
res += '[@' + li.attr('data-full-name');
res += '~' + li.attr('data-id') + ']';
return res;
}
},
headerTpl:
'