|
|
|
@@ -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 = '<div class="alert alert-danger">Search failed</div>'; }); }, 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();
|
|
|
|
|