diff --git a/atlas/static/atlas/js/markup_inserter.js b/atlas/static/atlas/js/markup_inserter.js index 6b4f9e77..a6787c3e 100644 --- a/atlas/static/atlas/js/markup_inserter.js +++ b/atlas/static/atlas/js/markup_inserter.js @@ -172,10 +172,15 @@ var pk = item.getAttribute('data-case-pk'); if(!pk){ var a = item.querySelector('a'); - if(a){ var m = a.getAttribute('href').match(/case\/(\d+)\/?.*$/); if(m) pk = m[1]; } + if(a){ var m = a.getAttribute('href').match(/case\/(\d+)\/?/); if(m) pk = m[1]; } } if(!pk) return; - insertAtCursor(textarea, '[['+'case:'+pk+']]' ); + var defaultLabel = item.getAttribute('data-label') || (item.querySelector('h6') ? item.querySelector('h6').textContent.trim() : ''); + var custom = window.prompt('Custom text (leave empty to use default)', defaultLabel || ''); + if(custom === null){ if(overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); return; } + var labelToUse = custom && custom.length ? custom : (defaultLabel || null); + var token = '[[' + 'case:' + pk + (labelToUse ? '|' + labelToUse : '') + ']]'; + insertAtCursor(textarea, token); // remove modal if(overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); }); @@ -214,10 +219,16 @@ if(!item) return; var sfpk = item.getAttribute('data-seriesfinding-pk'); var fpk = item.getAttribute('data-finding-pk'); + var defaultLabel = item.getAttribute('data-label') || (item.querySelector('strong') ? item.querySelector('strong').textContent.trim() : ''); + var custom = window.prompt('Custom text (leave empty to use default)', defaultLabel || ''); + if(custom === null){ if(overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); return; } + var labelToUse = custom && custom.length ? custom : (defaultLabel || null); if(sfpk){ - insertAtCursor(textarea, '[['+'seriesfinding:'+sfpk+']]' ); + var token = '[['+'seriesfinding:'+sfpk + (labelToUse ? '|' + labelToUse : '') + ']]'; + insertAtCursor(textarea, token); } else if(fpk){ - insertAtCursor(textarea, '[['+'finding:'+fpk+']]' ); + var token = '[['+'finding:'+fpk + (labelToUse ? '|' + labelToUse : '') + ']]'; + insertAtCursor(textarea, token); } else { return; } @@ -250,7 +261,19 @@ var timer = null; input.addEventListener('input', function(){ if(timer) clearTimeout(timer); timer = setTimeout(function(){ var q = encodeURIComponent(input.value || ''); var url = window.location.origin + '/atlas/search/displaysets/?q=' + q + (currentCaseD ? '&case=' + currentCaseD : ''); fetch(url, {credentials:'same-origin'}).then(function(r){ return r.text(); }).then(function(html){ results.innerHTML = html; }).catch(function(e){ console.error('displayset picker fetch error', e); results.innerHTML = '
Search failed
'; }); }, 300); }); - results.addEventListener('click', function(e){ var item = e.target.closest('.list-group-item'); if(!item) return; var pk = item.getAttribute('data-ds-pk'); if(!pk) return; insertAtCursor(textarea, '[['+'displayset:'+pk+']]' ); if(overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); }); + results.addEventListener('click', function(e){ + var item = e.target.closest('.list-group-item'); + if(!item) return; + var pk = item.getAttribute('data-ds-pk'); + if(!pk) return; + var defaultLabel = item.getAttribute('data-label') || (item.querySelector('strong') ? item.querySelector('strong').textContent.trim() : ''); + var custom = window.prompt('Custom text (leave empty to use default)', defaultLabel || ''); + if(custom === null){ if(overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); return; } + var labelToUse = custom && custom.length ? custom : (defaultLabel || null); + var token = '[['+'displayset:'+pk + (labelToUse ? '|' + labelToUse : '') + ']]'; + insertAtCursor(textarea, token); + if(overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); + }); overlay.tabIndex = -1; overlay.focus(); function fetchInitialDisplaysets(){ var initDisplaysetsUrl = window.location.origin + '/atlas/search/displaysets/' + (currentCaseD ? '?case=' + currentCaseD : ''); fetch(initDisplaysetsUrl).then(function(r){ return r.text(); }).then(function(html){ results.innerHTML = html; }).catch(function(){}); } fetchInitialDisplaysets(); diff --git a/atlas/templates/atlas/partials/_case_search_results.html b/atlas/templates/atlas/partials/_case_search_results.html index b1b5bf3d..ce3180d6 100644 --- a/atlas/templates/atlas/partials/_case_search_results.html +++ b/atlas/templates/atlas/partials/_case_search_results.html @@ -2,7 +2,7 @@
{% if cases %} {% for case in cases %} -
+
{{ case.title }}
diff --git a/atlas/templates/atlas/partials/_displayset_search_results.html b/atlas/templates/atlas/partials/_displayset_search_results.html index 32e58ba3..d49ff6a4 100644 --- a/atlas/templates/atlas/partials/_displayset_search_results.html +++ b/atlas/templates/atlas/partials/_displayset_search_results.html @@ -1,7 +1,7 @@
{% if displaysets %} {% for ds in displaysets %} -
+
diff --git a/atlas/templates/atlas/partials/_finding_search_results.html b/atlas/templates/atlas/partials/_finding_search_results.html index 45abe419..6720d9dd 100644 --- a/atlas/templates/atlas/partials/_finding_search_results.html +++ b/atlas/templates/atlas/partials/_finding_search_results.html @@ -1,7 +1,7 @@
{% if findings %} {% for f in findings %} -
+
{% if f.series %}{{ f.series.id }}{% else %}Series{% endif %}{% if f.description %}: {{ f.description|truncatechars:80 }}{% endif %}