Enhance markup inserter and search result templates with custom label prompts for cases, display sets, and findings

This commit is contained in:
Ross
2026-03-23 14:35:59 +00:00
parent f70ecb4648
commit 97db951c79
4 changed files with 31 additions and 8 deletions
+28 -5
View File
@@ -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();
@@ -2,7 +2,7 @@
<div class="list-group">
{% if cases %}
{% for case in cases %}
<div class="list-group-item d-flex justify-content-between align-items-center" data-case-pk="{{ case.pk }}">
<div class="list-group-item d-flex justify-content-between align-items-center" data-case-pk="{{ case.pk }}" data-label="{{ case.title|escape }}">
<div class="flex-fill me-3">
<div class="d-flex w-100 justify-content-between">
<h6 class="mb-1">{{ case.title }}</h6>
@@ -1,7 +1,7 @@
<div class="list-group">
{% if displaysets %}
{% for ds in displaysets %}
<div class="list-group-item d-flex justify-content-between align-items-center" data-ds-pk="{{ ds.pk }}">
<div class="list-group-item d-flex justify-content-between align-items-center" data-ds-pk="{{ ds.pk }}" data-label="{{ ds.name|escape }}">
<div class="flex-fill">
<div class="d-flex w-100 justify-content-between">
<div>
@@ -1,7 +1,7 @@
<div class="list-group">
{% if findings %}
{% for f in findings %}
<div class="list-group-item d-flex justify-content-between align-items-center" data-finding-pk="{{ f.pk }}" data-seriesfinding-pk="{{ f.pk }}">
<div class="list-group-item d-flex justify-content-between align-items-center" data-finding-pk="{{ f.pk }}" data-seriesfinding-pk="{{ f.pk }}" data-label="{% if f.findings.all %}{% for sub in f.findings.all %}{{ sub.name }}{% if not forloop.last %}, {% endif %}{% endfor %}{% elif f.description %}{{ f.description|truncatechars:80|escape }}{% elif f.series %}Series {{ f.series.id }}{% else %}Finding {{ f.pk }}{% endif %}">
<div class="flex-fill">
<div class="d-flex w-100 justify-content-between">
<strong class="mb-1">{% if f.series %}{{ f.series.id }}{% else %}Series{% endif %}{% if f.description %}: {{ f.description|truncatechars:80 }}{% endif %}</strong>