(function() { 'use strict'; function smartAnnotation(field) { // 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 'sam': res += ''; break; } res += ' '; res += ''; res += map.name; 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; default: break; } res += '
  • '; return res; } function init() { if (_.isUndefined($(field).data('atwho'))) { $(field) .atwho({ at: '#', callbacks: { remoteFilter: function(query, callback) { $.getJSON( '/organizations/1/atwho_resources.json', {query: query}, function(data) { callback(data.res); } ); }, tplEval: function(_tpl, map) { var res; try { res = generateTemplate(map); } catch (_error) { res = ''; } return res; }, }, displayTpl: '${type}${name}', insertTpl: '[${atwho-at}${name}~${id}]', limit: 5, startWithSpace: true }) .atwho({ at: 'task#', callbacks: { remoteFilter: function(query, callback) { $.getJSON( '/organizations/1/atwho_resources.json', {query: query}, function(data) { callback(data.res); } ); }, tplEval: function(_tpl, map) { var res; try { res = generateTemplate(map); } catch (_error) { res = ''; } return res; }, }, displayTpl: '${type}${name}', insertTpl: '[${atwho-at}${name}~${id}]', limit: 5, startWithSpace: true }) .atwho({ at: 'project#', callbacks: { remoteFilter: function(query, callback) { $.getJSON( '/organizations/1/atwho_resources.json', {query: query}, function(data) { callback(data.res); } ); }, tplEval: function(_tpl, map) { var res; try { res = generateTemplate(map); } catch (_error) { res = ''; } return res; }, }, displayTpl: '${type}${name}', insertTpl: '[${atwho-at}${name}~${id}]', limit: 5, startWithSpace: true }) .atwho({ at: 'experiment#', callbacks: { remoteFilter: function(query, callback) { $.getJSON( '/organizations/1/atwho_resources.json', {query: query}, function(data) { callback(data.res); } ); }, tplEval: function(_tpl, map) { var res; try { res = generateTemplate(map); } catch (_error) { res = ''; } return res; }, }, displayTpl: '${type}${name}', insertTpl: '[${atwho-at}${name}~${id}]', limit: 5, startWithSpace: true }) .atwho({ at: 'sample#', callbacks: { remoteFilter: function(query, callback) { $.getJSON( '/organizations/1/atwho_resources.json', {query: query}, function(data) { callback(data.res); } ); }, tplEval: function(_tpl, map) { var res; try { res = generateTemplate(map); } catch (_error) { res = ''; } return res; }, }, displayTpl: '' + '${name}', insertTpl: '[${atwho-at}${name}~${id}]', limit: 5, startWithSpace: true }); } } return { init: init }; } var smartA = new smartAnnotation('#comment_message'); $(document).ready(function() { setTimeout(function(){ smartA.init(); }, 1000); }); })();