824 lines
38 KiB
HTML
824 lines
38 KiB
HTML
{% extends 'layouts/base.html' %}
|
|
{% load i18n static %}
|
|
{% load standards_filters %}
|
|
|
|
{% block title %}{% trans "Department Standards" %} - {{ department.name }}{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<style>
|
|
:root {
|
|
--hh-navy: #005696;
|
|
--hh-blue: #007bbd;
|
|
--hh-light: #eef6fb;
|
|
--hh-slate: #64748b;
|
|
}
|
|
|
|
.page-header-gradient {
|
|
background: linear-gradient(135deg, var(--hh-navy) 0%, #0069a8 50%, var(--hh-blue) 100%);
|
|
color: white;
|
|
padding: 1.5rem 2rem;
|
|
border-radius: 1rem;
|
|
margin-bottom: 1.5rem;
|
|
box-shadow: 0 10px 15px -3px rgba(0, 86, 150, 0.2);
|
|
}
|
|
|
|
.section-card {
|
|
background: white;
|
|
border-radius: 1rem;
|
|
border: 2px solid #e2e8f0;
|
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
|
overflow: hidden;
|
|
transition: all 0.3s ease;
|
|
}
|
|
.section-card:hover {
|
|
border-color: #005696;
|
|
box-shadow: 0 10px 25px -5px rgba(0, 86, 150, 0.15);
|
|
}
|
|
|
|
.section-header {
|
|
padding: 1rem 1.5rem;
|
|
border-bottom: 2px solid #e2e8f0;
|
|
background: linear-gradient(to right, #f8fafc, #f1f5f9);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
}
|
|
|
|
.section-icon {
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: 0.75rem;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.btn-transition {
|
|
transition: all 0.2s ease-in-out;
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<!-- CSRF token for AJAX requests -->
|
|
<meta name="csrf-token" content="{{ csrf_token }}">
|
|
<script>
|
|
window.CSRF_TOKEN = '{{ csrf_token }}';
|
|
</script>
|
|
|
|
<div class="px-6 py-4">
|
|
<div class="page-header-gradient">
|
|
<div class="flex justify-between items-center">
|
|
<div>
|
|
<h1 class="text-2xl font-bold mb-1">{{ department.name }}</h1>
|
|
<p class="text-blue-100 text-sm">{% trans "Standards Compliance" %}</p>
|
|
</div>
|
|
<div class="flex gap-2">
|
|
{% if is_px_admin %}
|
|
<a href="{% url 'standards:standard_create' department_id=department.id %}" class="btn-transition inline-flex items-center px-4 py-2.5 bg-green-500 text-white font-medium rounded-xl hover:bg-green-600 transition">
|
|
<i data-lucide="plus" class="w-4 h-4 me-2"></i>{% trans "Add Standard" %}
|
|
</a>
|
|
{% endif %}
|
|
<a href="{% url 'standards:dashboard' %}" class="btn-transition inline-flex items-center px-4 py-2.5 bg-white/10 border-2 border-white/30 text-white font-medium rounded-xl hover:bg-white hover:text-navy transition">
|
|
<i data-lucide="arrow-left" class="w-4 h-4 me-2"></i>{% trans "Back to Dashboard" %}
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section-card mb-6">
|
|
<div class="p-6">
|
|
<div class="relative">
|
|
<i data-lucide="search" class="absolute left-4 top-1/2 transform -translate-y-1/2 w-5 h-5 text-gray-400"></i>
|
|
<input type="text"
|
|
class="w-full pl-12 pr-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-navy focus:border-transparent transition"
|
|
id="searchInput"
|
|
placeholder="{% trans 'Search standards...' %}">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section-card">
|
|
<div class="section-header">
|
|
<div class="section-icon bg-navy/10">
|
|
<i data-lucide="clipboard-list" class="w-5 h-5 text-navy"></i>
|
|
</div>
|
|
<h5 class="text-lg font-semibold text-gray-800">{% trans "Standards List" %}</h5>
|
|
</div>
|
|
<div class="p-0">
|
|
<div class="overflow-x-auto">
|
|
<table class="min-w-full divide-y divide-gray-200" id="standardsTable">
|
|
<thead class="bg-gray-50">
|
|
<tr>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
{% trans "Code" %}
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
{% trans "Title" %}
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
{% trans "Status" %}
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
{% trans "Evidence" %}
|
|
</th>
|
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
{% trans "Actions" %}
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="bg-white divide-y divide-gray-200">
|
|
{% for item in standards_data %}
|
|
<tr class="hover:bg-gray-50 transition"
|
|
data-standard-id="{{ item.standard.id }}"
|
|
data-compliance-id="{% if item.compliance %}{{ item.compliance.id }}{% endif %}">
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<span class="inline-flex items-center px-3 py-1 rounded-lg text-xs font-semibold bg-navy/10 text-navy">
|
|
{{ item.standard.code }}
|
|
</span>
|
|
</td>
|
|
<td class="px-6 py-4">
|
|
<a href="{% url 'standards:standard_detail' pk=item.standard.id %}" class="text-sm font-medium text-gray-900 hover:text-navy transition">
|
|
{{ item.standard.title }}
|
|
</a>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
{% if item.compliance %}
|
|
{% if item.compliance.status == 'met' %}
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800">
|
|
<i data-lucide="check-circle" class="w-3 h-3 me-1"></i>{{ item.compliance.get_status_display }}
|
|
</span>
|
|
{% elif item.compliance.status == 'partially_met' %}
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800">
|
|
<i data-lucide="alert-circle" class="w-3 h-3 me-1"></i>{{ item.compliance.get_status_display }}
|
|
</span>
|
|
{% elif item.compliance.status == 'not_met' %}
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-red-100 text-red-800">
|
|
<i data-lucide="x-circle" class="w-3 h-3 me-1"></i>{{ item.compliance.get_status_display }}
|
|
</span>
|
|
{% else %}
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-800">
|
|
<i data-lucide="help-circle" class="w-3 h-3 me-1"></i>{{ item.compliance.get_status_display }}
|
|
</span>
|
|
{% endif %}
|
|
{% else %}
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-800">
|
|
<i data-lucide="help-circle" class="w-3 h-3 me-1"></i>{% trans "Not Assessed" %}
|
|
</span>
|
|
{% endif %}
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
|
|
<i data-lucide="file-text" class="w-3 h-3 me-1"></i>{{ item.attachment_count }}
|
|
</span>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-right">
|
|
<div class="flex gap-2 justify-end">
|
|
{% if item.compliance %}
|
|
<button class="btn-transition inline-flex items-center px-3 py-1.5 border-2 border-navy text-navy text-xs font-medium rounded-lg hover:bg-navy hover:text-white transition"
|
|
onclick="openEvidenceModal('{{ item.compliance.id }}', '{{ item.standard.code|escapejs }}', '{{ item.standard.title|escapejs }}')">
|
|
<i data-lucide="paperclip" class="w-3 h-3 me-1"></i>{% trans "Evidence" %}
|
|
{% if item.attachment_count > 0 %}
|
|
<span class="ml-1 bg-navy text-white text-[10px] font-bold px-1.5 py-0.5 rounded-full">{{ item.attachment_count }}</span>
|
|
{% endif %}
|
|
</button>
|
|
<button class="btn-transition inline-flex items-center px-3 py-1.5 bg-navy text-white text-xs font-medium rounded-lg hover:bg-blue transition"
|
|
onclick="openAssessModal('{{ item.compliance.id }}')">
|
|
<i data-lucide="edit-2" class="w-3 h-3 me-1"></i>{% trans "Assess" %}
|
|
</button>
|
|
{% else %}
|
|
<button class="btn-transition inline-flex items-center px-3 py-1.5 bg-green-500 text-white text-xs font-medium rounded-lg hover:bg-green-600 transition"
|
|
onclick="createAndAssess('{{ item.standard.id }}')">
|
|
<i data-lucide="plus" class="w-3 h-3 me-1"></i>{% trans "Assess" %}
|
|
</button>
|
|
{% endif %}
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
{% empty %}
|
|
<tr>
|
|
<td colspan="5" class="px-6 py-12 text-center text-gray-500">
|
|
<i data-lucide="inbox" class="w-12 h-12 mx-auto mb-3 text-gray-300"></i>
|
|
<p>{% trans "No standards found" %}</p>
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Compliance Assessment Modal (Tailwind) -->
|
|
<div class="hidden fixed inset-0 bg-black/50 flex items-center justify-center z-50" id="assessmentModal">
|
|
<div class="bg-white rounded-2xl shadow-2xl max-w-lg w-full mx-4 max-h-[90vh] overflow-y-auto">
|
|
<!-- Modal Header -->
|
|
<div class="flex justify-between items-center p-6 border-b border-gray-200">
|
|
<h5 class="text-xl font-bold text-gray-900">{% trans "Compliance Assessment" %}</h5>
|
|
<button type="button" class="text-gray-400 hover:text-gray-600 transition" onclick="closeModal('assessmentModal')">
|
|
<i data-lucide="x" class="w-6 h-6"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Modal Body -->
|
|
<form id="assessmentForm">
|
|
<div class="p-6 space-y-4">
|
|
<input type="hidden" id="complianceId" name="compliance_id">
|
|
|
|
<div>
|
|
<label for="status" class="block text-sm font-medium text-gray-700 mb-2">
|
|
{% trans "Compliance Status" %} <span class="text-red-500">*</span>
|
|
</label>
|
|
<select class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-navy focus:border-transparent transition" id="status" name="status" required>
|
|
<option value="not_assessed">{% trans "Not Assessed" %}</option>
|
|
<option value="met">{% trans "Met" %}</option>
|
|
<option value="partially_met">{% trans "Partially Met" %}</option>
|
|
<option value="not_met">{% trans "Not Met" %}</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="last_assessed_date" class="block text-sm font-medium text-gray-700 mb-2">
|
|
{% trans "Assessment Date" %}
|
|
</label>
|
|
<input type="date" class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-navy focus:border-transparent transition" id="last_assessed_date" name="last_assessed_date">
|
|
<p class="mt-1 text-xs text-gray-500">{% trans "Auto-filled with today's date" %}</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="assessor" class="block text-sm font-medium text-gray-700 mb-2">{% trans "Assessor" %}</label>
|
|
<input type="text" class="w-full px-4 py-2.5 border border-gray-300 rounded-lg bg-gray-50 text-gray-600 transition" id="assessor" name="assessor" readonly>
|
|
<input type="hidden" id="assessor_id" name="assessor_id" value="{{ user.id }}">
|
|
<p class="mt-1 text-xs text-gray-500">{% trans "Current logged-in user" %}</p>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="notes" class="block text-sm font-medium text-gray-700 mb-2">{% trans "Notes" %}</label>
|
|
<textarea class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-navy focus:border-transparent transition" id="notes" name="notes" rows="3"
|
|
placeholder="{% trans 'Add any notes about the assessment...' %}"></textarea>
|
|
</div>
|
|
|
|
<div>
|
|
<label for="evidence_summary" class="block text-sm font-medium text-gray-700 mb-2">{% trans "Evidence Summary" %}</label>
|
|
<textarea class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-navy focus:border-transparent transition" id="evidence_summary" name="evidence_summary" rows="3"
|
|
placeholder="{% trans 'Summarize the evidence supporting this assessment...' %}"></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal Footer -->
|
|
<div class="flex justify-end gap-3 p-6 border-t border-gray-200 bg-gray-50 rounded-b-2xl">
|
|
<button type="button" class="px-6 py-2.5 bg-gray-100 text-gray-700 font-medium rounded-xl hover:bg-gray-200 transition" onclick="closeModal('assessmentModal')">
|
|
{% trans "Cancel" %}
|
|
</button>
|
|
<button type="submit" class="px-6 py-2.5 bg-green-500 text-white font-medium rounded-xl hover:bg-green-600 transition inline-flex items-center">
|
|
<i data-lucide="save" class="w-4 h-4 me-2"></i>{% trans "Save Assessment" %}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Evidence Modal (Tailwind) -->
|
|
<div class="hidden fixed inset-0 bg-black/50 flex items-center justify-center z-50" id="evidenceModal">
|
|
<div class="bg-white rounded-2xl shadow-2xl max-w-4xl w-full mx-4 max-h-[90vh] overflow-y-auto border-2 border-gray-200">
|
|
<!-- Modal Header -->
|
|
<div class="flex justify-between items-center p-6 border-b-2 border-gray-200 bg-gradient-to-r from-[#005696] to-[#007bbd]">
|
|
<div>
|
|
<h5 class="text-xl font-bold text-white">{% trans "Evidence Management" %}</h5>
|
|
<p class="text-sm text-blue-100 mt-1" id="evidenceModalTitle"></p>
|
|
</div>
|
|
<button type="button" class="text-white/70 hover:text-white transition" onclick="closeModal('evidenceModal')">
|
|
<i data-lucide="x" class="w-6 h-6"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Modal Body -->
|
|
<div class="p-6 space-y-6 bg-gradient-to-b from-gray-50 to-white">
|
|
<!-- Upload Section -->
|
|
<div class="bg-white rounded-xl p-5 border-2 border-gray-200 shadow-sm">
|
|
<h6 class="text-sm font-semibold text-navy mb-4 flex items-center">
|
|
<span class="w-8 h-8 rounded-lg bg-navy/10 flex items-center justify-center mr-3">
|
|
<i data-lucide="upload-cloud" class="w-4 h-4 text-navy"></i>
|
|
</span>
|
|
{% trans "Upload New Attachment" %}
|
|
</h6>
|
|
<form id="evidenceUploadForm" class="space-y-4">
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">{% trans "File" %}</label>
|
|
<input type="file" id="evidenceFile" name="file"
|
|
accept=".pdf,.doc,.docx,.xls,.xlsx,.jpg,.jpeg,.png,.zip"
|
|
class="block w-full text-sm text-gray-900 border-2 border-gray-200 rounded-lg cursor-pointer bg-white focus:outline-none focus:ring-2 focus:ring-navy focus:border-navy">
|
|
<p class="mt-2 text-xs text-gray-500">
|
|
<i data-lucide="info" class="w-3 h-3 inline mr-1"></i>
|
|
{% trans "Accepted: PDF, DOC, DOCX, XLS, XLSX, JPG, PNG, ZIP (max 50MB)" %}
|
|
</p>
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">{% trans "Description" %}</label>
|
|
<textarea id="evidenceDescription" name="description" rows="2"
|
|
class="w-full px-4 py-3 border-2 border-gray-200 rounded-lg focus:ring-2 focus:ring-navy focus:border-navy transition"
|
|
placeholder="{% trans 'Add a description for this attachment...' %}"></textarea>
|
|
</div>
|
|
<div id="uploadProgress" class="hidden">
|
|
<div class="w-full bg-gray-200 rounded-full h-2.5">
|
|
<div id="uploadProgressBar" class="bg-navy h-2.5 rounded-full transition-all duration-300" style="width: 0%"></div>
|
|
</div>
|
|
<p class="text-xs text-gray-500 mt-2 flex items-center">
|
|
<i data-lucide="loader-2" class="w-3 h-3 inline mr-1 animate-spin"></i>
|
|
{% trans "Uploading..." %}
|
|
</p>
|
|
</div>
|
|
<div id="uploadError" class="hidden text-sm text-red-600 bg-red-50 border border-red-200 p-3 rounded-lg"></div>
|
|
<button type="button" onclick="uploadEvidence()"
|
|
class="inline-flex items-center px-5 py-2.5 bg-navy text-white text-sm font-medium rounded-xl hover:bg-blue transition shadow-md hover:shadow-lg">
|
|
<i data-lucide="upload" class="w-4 h-4 mr-2"></i>{% trans "Upload" %}
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Attachments List -->
|
|
<div>
|
|
<h6 class="text-sm font-semibold text-navy mb-4 flex items-center">
|
|
<span class="w-8 h-8 rounded-lg bg-navy/10 flex items-center justify-center mr-3">
|
|
<i data-lucide="paperclip" class="w-4 h-4 text-navy"></i>
|
|
</span>
|
|
{% trans "Existing Attachments" %}
|
|
</h6>
|
|
<div class="overflow-x-auto border-2 border-gray-200 rounded-xl bg-white shadow-sm">
|
|
<table class="min-w-full divide-y divide-gray-200">
|
|
<thead class="bg-gradient-to-r from-gray-50 to-gray-100">
|
|
<tr>
|
|
<th class="px-4 py-3 text-left text-xs font-semibold text-navy uppercase tracking-wider">
|
|
{% trans "File" %}
|
|
</th>
|
|
<th class="px-4 py-3 text-left text-xs font-semibold text-navy uppercase tracking-wider">
|
|
{% trans "Description" %}
|
|
</th>
|
|
<th class="px-4 py-3 text-left text-xs font-semibold text-navy uppercase tracking-wider">
|
|
{% trans "Uploaded" %}
|
|
</th>
|
|
<th class="px-4 py-3 text-right text-xs font-semibold text-navy uppercase tracking-wider">
|
|
{% trans "Actions" %}
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="attachmentsList" class="bg-white divide-y divide-gray-200">
|
|
<tr>
|
|
<td colspan="4" class="px-6 py-8 text-center text-gray-500">
|
|
<div class="w-16 h-16 mx-auto mb-3 rounded-full bg-navy/10 flex items-center justify-center">
|
|
<i data-lucide="inbox" class="w-8 h-8 text-navy/50"></i>
|
|
</div>
|
|
<p class="text-sm">{% trans "Loading..." %}</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal Footer -->
|
|
<div class="flex justify-end gap-3 p-6 border-t-2 border-gray-200 bg-gradient-to-r from-gray-50 to-gray-100 rounded-b-2xl">
|
|
<button type="button" class="px-6 py-2.5 bg-white border-2 border-gray-300 text-gray-700 font-medium rounded-xl hover:bg-gray-50 hover:border-gray-400 transition shadow-sm" onclick="closeModal('evidenceModal')">
|
|
<i data-lucide="x" class="w-4 h-4 mr-2 inline"></i>{% trans "Close" %}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const userData = {
|
|
id: '{{ user.id }}',
|
|
username: "{{ user.username|escapejs }}",
|
|
fullName: "{% if user.get_full_name %}{{ user.get_full_name|escapejs }}{% else %}{{ user.username|escapejs }}{% endif %}"
|
|
};
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const today = new Date().toISOString().split('T')[0];
|
|
const dateInput = document.getElementById('last_assessed_date');
|
|
if (dateInput) {
|
|
dateInput.value = today;
|
|
}
|
|
|
|
const assessorInput = document.getElementById('assessor');
|
|
if (assessorInput) {
|
|
assessorInput.value = userData.fullName;
|
|
}
|
|
|
|
const searchInput = document.getElementById('searchInput');
|
|
const table = document.getElementById('standardsTable');
|
|
|
|
function filterTable() {
|
|
const searchText = searchInput.value.toLowerCase();
|
|
const rows = table.querySelectorAll('tbody tr');
|
|
|
|
rows.forEach(row => {
|
|
const text = row.textContent.toLowerCase();
|
|
const matchesSearch = text.includes(searchText);
|
|
|
|
if (matchesSearch) {
|
|
row.style.display = '';
|
|
} else {
|
|
row.style.display = 'none';
|
|
}
|
|
});
|
|
}
|
|
|
|
searchInput.addEventListener('input', filterTable);
|
|
|
|
const form = document.getElementById('assessmentForm');
|
|
if (form) {
|
|
form.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
submitAssessment();
|
|
});
|
|
}
|
|
});
|
|
|
|
function getCookie(name) {
|
|
let cookieValue = null;
|
|
if (document.cookie && document.cookie !== '') {
|
|
const cookies = document.cookie.split(';');
|
|
for (let i = 0; i < cookies.length; i++) {
|
|
const cookie = cookies[i].trim();
|
|
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return cookieValue;
|
|
}
|
|
|
|
function showModal(modalId) {
|
|
const modal = document.getElementById(modalId);
|
|
if (modal) {
|
|
modal.classList.remove('hidden');
|
|
// Reinitialize Lucide icons
|
|
setTimeout(() => {
|
|
if (typeof lucide !== 'undefined') {
|
|
lucide.createIcons();
|
|
}
|
|
}, 100);
|
|
}
|
|
}
|
|
|
|
function closeModal(modalId) {
|
|
const modal = document.getElementById(modalId);
|
|
if (modal) {
|
|
modal.classList.add('hidden');
|
|
}
|
|
}
|
|
|
|
function createAndAssess(standardId) {
|
|
const data = {
|
|
standard_id: standardId,
|
|
department_id: '{{ department.id }}'
|
|
};
|
|
|
|
console.log('Creating compliance:', data);
|
|
|
|
fetch('{% url "standards:compliance_create_ajax" %}', {
|
|
method: 'POST',
|
|
headers: {
|
|
'X-CSRFToken': window.CSRF_TOKEN || getCookie('csrftoken'),
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(response => {
|
|
console.log('Response status:', response.status);
|
|
if (!response.ok) {
|
|
return response.text().then(text => {
|
|
console.error('Error response:', text);
|
|
throw new Error('Server error: ' + response.status);
|
|
});
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
console.log('Response data:', data);
|
|
if (data.success) {
|
|
openAssessModal(data.compliance_id);
|
|
} else {
|
|
alert('{% trans "Error creating compliance record:" %} ' + (data.error || '{% trans "Unknown error" %}'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('{% trans "Error creating compliance record:" %} ' + error.message);
|
|
});
|
|
}
|
|
|
|
function openAssessModal(complianceId) {
|
|
document.getElementById('complianceId').value = complianceId;
|
|
showModal('assessmentModal');
|
|
}
|
|
|
|
function submitAssessment() {
|
|
const form = document.getElementById('assessmentForm');
|
|
const formData = new FormData(form);
|
|
|
|
const compliance_id = document.getElementById('complianceId').value;
|
|
const status = document.getElementById('status').value;
|
|
const notes = document.getElementById('notes').value;
|
|
const evidence_summary = document.getElementById('evidence_summary').value;
|
|
const last_assessed_date = document.getElementById('last_assessed_date').value;
|
|
const assessor_id = document.getElementById('assessor_id').value;
|
|
|
|
if (!compliance_id || !status) {
|
|
alert('{% trans "Missing required fields" %}');
|
|
return;
|
|
}
|
|
|
|
const data = {
|
|
compliance_id: compliance_id,
|
|
status: status,
|
|
notes: notes || '',
|
|
evidence_summary: evidence_summary || '',
|
|
last_assessed_date: last_assessed_date || '',
|
|
assessor_id: assessor_id || ''
|
|
};
|
|
|
|
console.log('Submitting assessment:', data);
|
|
|
|
fetch('{% url "standards:compliance_update_ajax" %}', {
|
|
method: 'POST',
|
|
headers: {
|
|
'X-CSRFToken': window.CSRF_TOKEN || getCookie('csrftoken'),
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(response => {
|
|
console.log('Response status:', response.status);
|
|
if (!response.ok) {
|
|
return response.text().then(text => {
|
|
console.error('Error response:', text);
|
|
throw new Error('Server error: ' + response.status);
|
|
});
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
console.log('Response data:', data);
|
|
if (data.success) {
|
|
closeModal('assessmentModal');
|
|
location.reload();
|
|
} else {
|
|
alert('{% trans "Error updating compliance:" %} ' + (data.error || '{% trans "Unknown error" %}'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('{% trans "Error updating compliance:" %} ' + error.message);
|
|
});
|
|
}
|
|
|
|
// Close modal when clicking outside
|
|
document.addEventListener('click', function(e) {
|
|
if (e.target && e.target.id === 'assessmentModal') {
|
|
closeModal('assessmentModal');
|
|
}
|
|
if (e.target && e.target.id === 'evidenceModal') {
|
|
closeModal('evidenceModal');
|
|
}
|
|
});
|
|
|
|
// Evidence Modal Functions
|
|
let currentEvidenceComplianceId = null;
|
|
let currentEvidenceStandardCode = '';
|
|
let currentEvidenceStandardTitle = '';
|
|
|
|
function openEvidenceModal(complianceId, standardCode, standardTitle) {
|
|
currentEvidenceComplianceId = complianceId;
|
|
currentEvidenceStandardCode = standardCode;
|
|
currentEvidenceStandardTitle = standardTitle;
|
|
|
|
// Update modal title
|
|
document.getElementById('evidenceModalTitle').textContent = standardCode + ' - ' + standardTitle;
|
|
|
|
// Reset upload form
|
|
document.getElementById('evidenceUploadForm').reset();
|
|
document.getElementById('uploadProgress').classList.add('hidden');
|
|
document.getElementById('uploadError').classList.add('hidden');
|
|
|
|
// Load attachments
|
|
loadAttachments(complianceId);
|
|
|
|
showModal('evidenceModal');
|
|
}
|
|
|
|
function loadAttachments(complianceId) {
|
|
const attachmentsList = document.getElementById('attachmentsList');
|
|
attachmentsList.innerHTML = '<tr><td colspan="4" class="px-6 py-4 text-center text-gray-500">{% trans "Loading..." %}</td></tr>';
|
|
|
|
fetch(`{% url "standards:attachments_list_ajax" "00000000-0000-0000-0000-000000000000" %}`.replace('00000000-0000-0000-0000-000000000000', complianceId), {
|
|
method: 'GET',
|
|
headers: {
|
|
'X-CSRFToken': window.CSRF_TOKEN || getCookie('csrftoken'),
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
renderAttachments(data.attachments);
|
|
} else {
|
|
attachmentsList.innerHTML = '<tr><td colspan="4" class="px-6 py-4 text-center text-red-500">{% trans "Error loading attachments" %}</td></tr>';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error loading attachments:', error);
|
|
attachmentsList.innerHTML = '<tr><td colspan="4" class="px-6 py-4 text-center text-red-500">{% trans "Error loading attachments" %}</td></tr>';
|
|
});
|
|
}
|
|
|
|
function renderAttachments(attachments) {
|
|
const attachmentsList = document.getElementById('attachmentsList');
|
|
|
|
if (attachments.length === 0) {
|
|
attachmentsList.innerHTML = '<tr><td colspan="4" class="px-6 py-10 text-center text-gray-500"><div class="w-16 h-16 mx-auto mb-3 rounded-full bg-navy/10 flex items-center justify-center"><i data-lucide="inbox" class="w-8 h-8 text-navy/50"></i></div><p class="text-sm">{% trans "No attachments yet" %}</p><p class="text-xs text-gray-400 mt-1">{% trans "Upload files above" %}</p></td></tr>';
|
|
if (typeof lucide !== 'undefined') {
|
|
lucide.createIcons();
|
|
}
|
|
return;
|
|
}
|
|
|
|
attachmentsList.innerHTML = attachments.map(att => `
|
|
<tr class="hover:bg-navy/5 transition border-b border-gray-100 last:border-b-0">
|
|
<td class="px-4 py-4 whitespace-nowrap">
|
|
<div class="flex items-center">
|
|
<span class="w-8 h-8 rounded-lg bg-navy/10 flex items-center justify-center mr-3">
|
|
<i data-lucide="file-text" class="w-4 h-4 text-navy"></i>
|
|
</span>
|
|
<span class="text-sm font-medium text-gray-900">${escapeHtml(att.filename)}</span>
|
|
</div>
|
|
</td>
|
|
<td class="px-4 py-4">
|
|
<span class="text-sm text-gray-600">${escapeHtml(att.description) || '<span class="text-gray-400 italic">{% trans "No description" %}</span>'}</span>
|
|
</td>
|
|
<td class="px-4 py-4 whitespace-nowrap text-sm">
|
|
<span class="text-gray-900 font-medium">${escapeHtml(att.uploaded_by)}</span>
|
|
<div class="text-xs text-gray-400">${att.uploaded_at}</div>
|
|
</td>
|
|
<td class="px-4 py-4 whitespace-nowrap text-right">
|
|
<div class="flex gap-2 justify-end">
|
|
<a href="${att.file_url}" target="_blank"
|
|
class="btn-transition inline-flex items-center px-3 py-1.5 bg-navy text-white text-xs font-medium rounded-lg hover:bg-blue transition shadow-sm"
|
|
title="{% trans 'Download' %}">
|
|
<i data-lucide="download" class="w-3 h-3"></i>
|
|
</a>
|
|
<button type="button"
|
|
onclick="deleteAttachment('${att.id}')"
|
|
class="btn-transition inline-flex items-center px-3 py-1.5 bg-white border-2 border-red-200 text-red-600 text-xs font-medium rounded-lg hover:bg-red-50 hover:border-red-300 transition"
|
|
title="{% trans 'Delete' %}">
|
|
<i data-lucide="trash-2" class="w-3 h-3"></i>
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
`).join('');
|
|
|
|
// Reinitialize Lucide icons
|
|
if (typeof lucide !== 'undefined') {
|
|
lucide.createIcons();
|
|
}
|
|
}
|
|
|
|
function escapeHtml(text) {
|
|
if (!text) return '';
|
|
const div = document.createElement('div');
|
|
div.textContent = text;
|
|
return div.innerHTML;
|
|
}
|
|
|
|
function uploadEvidence() {
|
|
const form = document.getElementById('evidenceUploadForm');
|
|
const fileInput = document.getElementById('evidenceFile');
|
|
const descriptionInput = document.getElementById('evidenceDescription');
|
|
const progressBar = document.getElementById('uploadProgressBar');
|
|
const progressContainer = document.getElementById('uploadProgress');
|
|
const errorDiv = document.getElementById('uploadError');
|
|
|
|
if (!fileInput.files || fileInput.files.length === 0) {
|
|
errorDiv.textContent = '{% trans "Please select a file" %}';
|
|
errorDiv.classList.remove('hidden');
|
|
return;
|
|
}
|
|
|
|
const file = fileInput.files[0];
|
|
const maxSize = 50 * 1024 * 1024; // 50MB
|
|
if (file.size > maxSize) {
|
|
errorDiv.textContent = '{% trans "File size must be less than 50MB" %}';
|
|
errorDiv.classList.remove('hidden');
|
|
return;
|
|
}
|
|
|
|
errorDiv.classList.add('hidden');
|
|
progressContainer.classList.remove('hidden');
|
|
progressBar.style.width = '0%';
|
|
|
|
const formData = new FormData();
|
|
formData.append('compliance_id', currentEvidenceComplianceId);
|
|
formData.append('file', file);
|
|
formData.append('description', descriptionInput.value);
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
xhr.upload.addEventListener('progress', function(e) {
|
|
if (e.lengthComputable) {
|
|
const percentComplete = (e.loaded / e.total) * 100;
|
|
progressBar.style.width = percentComplete + '%';
|
|
}
|
|
});
|
|
|
|
xhr.addEventListener('load', function() {
|
|
progressContainer.classList.add('hidden');
|
|
|
|
if (xhr.status === 200) {
|
|
const response = JSON.parse(xhr.responseText);
|
|
if (response.success) {
|
|
form.reset();
|
|
loadAttachments(currentEvidenceComplianceId);
|
|
updateAttachmentCount(currentEvidenceComplianceId, response.attachment_count);
|
|
} else {
|
|
errorDiv.textContent = response.error || '{% trans "Upload failed" %}';
|
|
errorDiv.classList.remove('hidden');
|
|
}
|
|
} else {
|
|
errorDiv.textContent = '{% trans "Upload failed" %}';
|
|
errorDiv.classList.remove('hidden');
|
|
}
|
|
});
|
|
|
|
xhr.addEventListener('error', function() {
|
|
progressContainer.classList.add('hidden');
|
|
errorDiv.textContent = '{% trans "Upload failed" %}';
|
|
errorDiv.classList.remove('hidden');
|
|
});
|
|
|
|
xhr.open('POST', '{% url "standards:attachment_upload_ajax" %}', true);
|
|
xhr.setRequestHeader('X-CSRFToken', window.CSRF_TOKEN || getCookie('csrftoken'));
|
|
xhr.send(formData);
|
|
}
|
|
|
|
function deleteAttachment(attachmentId) {
|
|
if (!confirm('{% trans "Are you sure you want to delete this attachment?" %}')) {
|
|
return;
|
|
}
|
|
|
|
const url = `{% url "standards:attachment_delete_ajax" "00000000-0000-0000-0000-000000000000" %}`.replace('00000000-0000-0000-0000-000000000000', attachmentId);
|
|
|
|
fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'X-CSRFToken': window.CSRF_TOKEN || getCookie('csrftoken'),
|
|
'Content-Type': 'application/json',
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
loadAttachments(currentEvidenceComplianceId);
|
|
updateAttachmentCount(currentEvidenceComplianceId, data.attachment_count);
|
|
} else {
|
|
alert('{% trans "Error deleting attachment:" %} ' + (data.error || '{% trans "Unknown error" %}'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error deleting attachment:', error);
|
|
alert('{% trans "Error deleting attachment" %}');
|
|
});
|
|
}
|
|
|
|
function updateAttachmentCount(complianceId, count) {
|
|
// Find the row with this compliance ID and update the badge
|
|
const rows = document.querySelectorAll('tr[data-compliance-id="' + complianceId + '"]');
|
|
rows.forEach(row => {
|
|
const evidenceCell = row.querySelector('td:nth-child(4) span');
|
|
if (evidenceCell) {
|
|
evidenceCell.innerHTML = `<i data-lucide="file-text" class="w-3 h-3 me-1"></i>${count}`;
|
|
if (typeof lucide !== 'undefined') {
|
|
lucide.createIcons();
|
|
}
|
|
}
|
|
// Update the Evidence button badge
|
|
const evidenceBtn = row.querySelector('button[onclick^="openEvidenceModal"]');
|
|
if (evidenceBtn) {
|
|
const badge = evidenceBtn.querySelector('span');
|
|
if (count > 0) {
|
|
if (badge) {
|
|
badge.textContent = count;
|
|
} else {
|
|
evidenceBtn.innerHTML += `<span class="ml-1 bg-white text-blue-600 text-[10px] font-bold px-1.5 py-0.5 rounded-full">${count}</span>`;
|
|
}
|
|
} else if (badge) {
|
|
badge.remove();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
{% endblock %}
|