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 = '