HH/templates/components/department_response_modal.html
ismail badb6a9ebf
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m41s
feat: QI Projects — team-member task management + My Tasks + notifications
Fixed 3 gaps in the QI Projects module:

Gap 1 (critical): team members couldn't manage their own tasks — the toggle
checkbox/edit/delete were gated behind admin-only can_edit. Now:
- _can_manage_task() helper: admins OR the task assignee OR project team members
- task_toggle_status + htmx_task_toggle_status use the new helper
- task_row.html shows the toggle for assignees (task.assigned_to.user_id check)

Gap 2: no "My QI Tasks" view — added /projects/my-tasks/ showing tasks assigned
to the current user across all projects, with toggle links + stats. Sidebar link.

Gap 3: no notification on task assignment — added apps/projects/signals.py
(post_save on QIProjectTask → create_in_app_notification). apps.py ready() wired.

Tested (headed, 11 PASS / 1 FAIL):
- Cross-department team members (Contact Center + different dept) can VIEW the
  project AND toggle their assigned tasks (both PASS)
- My Tasks view loads for team members
- Excel export returns 500 (real bug, reported)
- Project close via edit form needs correct hospital UUID (test harness issue)

Also bundles accumulated in-progress work across complaints, observations,
organizations, templates, and other modules.

Harness: seed_e2e_project + get_e2e_project_state CLI + qi-projects-workflow.spec.ts
2026-06-16 23:55:58 +03:00

131 lines
5.6 KiB
HTML

{% load i18n %}
<div id="deptResponseModal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm">
<div class="bg-white rounded-2xl shadow-2xl w-full max-w-lg mx-4 overflow-hidden">
<div class="bg-gradient-to-r from-navy to-blue p-4 flex justify-between items-center">
<h3 class="text-white font-bold text-lg flex items-center gap-2">
<i data-lucide="message-square" class="w-5 h-5"></i>
{% trans "Submit Department Response" %}
</h3>
<button onclick="closeDeptResponseModal()" class="text-white/80 hover:text-white transition">
<i data-lucide="x" class="w-5 h-5"></i>
</button>
</div>
<div class="p-6 space-y-4">
<div class="bg-slate-50 rounded-xl p-4 border border-slate-200">
<p class="text-[10px] text-slate-500 uppercase font-bold mb-1">{% trans "Reference" %}</p>
<p id="drmRef" class="font-mono text-sm font-bold text-navy"></p>
<p class="text-[10px] text-slate-500 uppercase font-bold mb-1 mt-2">{% trans "Subject" %}</p>
<p id="drmSubject" class="text-sm text-slate-700"></p>
</div>
<div>
<label class="block text-sm font-semibold text-slate-700 mb-2">
{% trans "Your Response" %} <span class="text-red-500">*</span>
</label>
<textarea id="drmResponseNotes" rows="6"
class="w-full px-4 py-3 border-2 border-slate-200 rounded-xl text-slate-700 focus:outline-none focus:border-navy focus:ring-2 focus:ring-navy/20 resize-none text-sm"
placeholder="{% trans "Enter your department's response..." %}"></textarea>
</div>
<div id="drmError" class="hidden text-sm text-red-600 bg-red-50 border border-red-200 p-3 rounded-lg"></div>
<div class="flex gap-3 pt-2">
<button type="button" id="drmSubmitBtn" onclick="submitDeptResponse()"
class="flex-1 px-4 py-2.5 bg-navy text-white font-medium rounded-xl hover:bg-blue transition flex items-center justify-center gap-2">
<i data-lucide="send" class="w-4 h-4"></i>
{% trans "Submit Response" %}
</button>
<button type="button" onclick="closeDeptResponseModal()"
class="flex-1 px-4 py-2.5 bg-slate-100 text-slate-700 font-medium rounded-xl hover:bg-slate-200 transition">
{% trans "Cancel" %}
</button>
</div>
</div>
</div>
</div>
<script>
let _drmConfig = {};
function openDeptResponseModal(type, pk, url, reference, subject, existingEn, existingAr) {
_drmConfig = { type: type, pk: pk, url: url };
document.getElementById('drmRef').textContent = reference || '';
document.getElementById('drmSubject').textContent = subject || '';
document.getElementById('drmResponseNotes').value = existingEn || existingAr || '';
document.getElementById('drmError').classList.add('hidden');
document.getElementById('deptResponseModal').classList.remove('hidden');
if (window.lucide) lucide.createIcons();
}
function closeDeptResponseModal() {
document.getElementById('deptResponseModal').classList.add('hidden');
document.getElementById('drmError').classList.add('hidden');
}
function submitDeptResponse() {
const errorEl = document.getElementById('drmError');
const submitBtn = document.getElementById('drmSubmitBtn');
errorEl.classList.add('hidden');
const value = document.getElementById('drmResponseNotes').value.trim();
if (!value) {
errorEl.textContent = '{% trans "Please enter a response." %}';
errorEl.classList.remove('hidden');
return;
}
let body = {};
if (_drmConfig.type === 'complaint') {
body.response_notes = value;
} else {
body.response_en = value;
}
submitBtn.disabled = true;
submitBtn.innerHTML = '<i data-lucide="loader" class="w-4 h-4 animate-spin"></i> {% trans "Submitting..." %}';
if (window.lucide) lucide.createIcons();
const csrftoken = document.querySelector('[name=csrfmiddlewaretoken]')?.value
|| document.cookie.split(';').map(c => c.trim()).find(c => c.startsWith('csrftoken='))?.split('=')[1];
fetch(_drmConfig.url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRFToken': csrftoken,
'X-Requested-With': 'XMLHttpRequest',
},
body: new URLSearchParams(body),
})
.then(response => response.json())
.then(data => {
if (data.success) {
closeDeptResponseModal();
if (data.redirect_url) {
window.location.href = data.redirect_url;
} else {
window.location.reload();
}
} else {
errorEl.textContent = data.error || '{% trans "An error occurred." %}';
errorEl.classList.remove('hidden');
}
})
.catch(() => {
errorEl.textContent = '{% trans "Network error. Please try again." %}';
errorEl.classList.remove('hidden');
})
.finally(() => {
submitBtn.disabled = false;
submitBtn.innerHTML = '<i data-lucide="send" class="w-4 h-4"></i> {% trans "Submit Response" %}';
if (window.lucide) lucide.createIcons();
});
}
document.getElementById('deptResponseModal').addEventListener('click', function(e) {
if (e.target === this) closeDeptResponseModal();
});
</script>