/ segment from the pathname
- if(!result.id){
- try{
- var m = window.location.pathname.match(/\/case\/(\d+)(?:\/|$)/i) || window.location.pathname.match(/\/atlas\/case\/(\d+)(?:\/|$)/i);
- if(m) result.id = m[1];
- }catch(e){}
- }
-
- // If there's an H2 like 'Display Sets: TITLE' try to use it as title
- if(!result.title){
- var h2 = document.querySelector('h2');
- if(h2 && /Display Sets:/i.test(h2.textContent || '')){
- result.title = (h2.textContent || '').replace(/Display Sets:\s*/i, '').trim();
- }
- }
- return result;
- }catch(e){ return { id: null, title: null }; }
- }
+ // Simplified detection: rely on explicit dataset attributes set by the widget
+ // When a textarea includes `data-current-case` and optionally `data-current-case-title`, that will be used as the default filter.
})(window);
diff --git a/atlas/templates/atlas/partials/displayset_search_widget.html b/atlas/templates/atlas/partials/displayset_search_widget.html
index bc92889d..5267ad86 100644
--- a/atlas/templates/atlas/partials/displayset_search_widget.html
+++ b/atlas/templates/atlas/partials/displayset_search_widget.html
@@ -13,6 +13,13 @@
hx-trigger="keyup changed delay:400ms"
autocomplete="off">
+
+
+ {% if case %}Filtering: {{ case.title|escape }}{% endif %}
+
+
+
+
{% include 'atlas/partials/_displayset_search_results.html' with displaysets=displaysets case=case %}
@@ -46,3 +53,62 @@
} catch(e) { console.error('displayset search widget init error', e); }
})();
+
+
diff --git a/atlas/templates/atlas/partials/finding_search_widget.html b/atlas/templates/atlas/partials/finding_search_widget.html
index 2e34d50d..2eabf165 100644
--- a/atlas/templates/atlas/partials/finding_search_widget.html
+++ b/atlas/templates/atlas/partials/finding_search_widget.html
@@ -10,6 +10,13 @@
hx-trigger="keyup changed delay:400ms"
autocomplete="off">
+
+
+ {% if case %}Filtering: {{ case.title|escape }}{% endif %}
+
+
+
+
{% include 'atlas/partials/_finding_search_results.html' with findings=findings case=case %}
@@ -22,12 +29,45 @@
var input = document.getElementById('{{ input_id|default:"finding-search-input" }}');
if (!input) return;
var timer = null;
+
+ // If server provided a case via inclusion, ensure widget sets dataset and nearby textarea dataset
+ var meta = document.getElementById('current-case-meta');
+ var casePk = meta ? meta.getAttribute('data-current-case') : null;
+ var caseTitle = meta ? meta.getAttribute('data-current-case-title') : '';
+ var badge = document.getElementById('{{ input_id }}-case-badge');
+ var clearBtn = document.getElementById('{{ input_id }}-clear-case');
+
+ function applyCaseToInputs(pk, title){
+ if(pk){
+ input.dataset.currentCase = pk;
+ if(title) input.dataset.currentCaseTitle = title;
+ var container = input.closest('form,div') || document.body;
+ var ta = container.querySelector('textarea');
+ if(ta){ ta.dataset.currentCase = pk; if(title) ta.dataset.currentCaseTitle = title; }
+ if(badge){ badge.style.display = 'inline-block'; badge.textContent = 'Filtering: ' + (title || ('#' + pk)); }
+ if(clearBtn) clearBtn.style.display = 'inline-block';
+ } else {
+ delete input.dataset.currentCase; delete input.dataset.currentCaseTitle;
+ var container = input.closest('form,div') || document.body;
+ var ta = container.querySelector('textarea');
+ if(ta){ delete ta.dataset.currentCase; delete ta.dataset.currentCaseTitle; }
+ if(badge) badge.style.display = 'none';
+ if(clearBtn) clearBtn.style.display = 'none';
+ }
+ }
+
+ if(casePk){ applyCaseToInputs(casePk, caseTitle); }
+
+ if(clearBtn){ clearBtn.addEventListener('click', function(){ applyCaseToInputs(null, null); try{ input.removeAttribute('hx-vals'); }catch(e){}; input.dispatchEvent(new Event('input')); }); }
+
input.addEventListener('input', function(){
if (timer) clearTimeout(timer);
timer = setTimeout(function(){
try {
var q = encodeURIComponent(input.value || '');
- var url = "{% url 'atlas:finding_search' %}?q=" + q + ({% if case %} "&case={{ case.pk }}" {% else %} '' {% endif %});
+ // Respect dataset-based case filter if present
+ var caseParam = input.dataset.currentCase ? '&case=' + encodeURIComponent(input.dataset.currentCase) : '';
+ var url = "{% url 'atlas:finding_search' %}?q=" + q + caseParam;
var target = '#{{ target_id|default:"finding-search-results" }}';
if (window.htmx && typeof window.htmx.ajax === 'function') {
window.htmx.ajax('GET', url, { target: target, swap: 'innerHTML' });