Spaces:
Sleeping
Sleeping
File size: 8,851 Bytes
6ea020b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | <!-- templates/provinces.html -->
{% extends "base.html" %}
{% block title %}Provinces - NexLab{% endblock %}
{% block page_title %}Province Definition{% endblock %}
{% block content %}
<!-- Tom Select CSS -->
<link href="/static/vendor/tom-select/tom-select.css" rel="stylesheet">
<div class="bg-white rounded-xl shadow-sm border border-slate-200">
<div class="p-6 border-b border-slate-200 flex justify-between items-center">
<div>
<h3 class="text-lg font-semibold text-slate-800">Province Definition</h3>
<p class="text-sm text-slate-500">Define provinces for patient locations</p>
</div>
<button onclick="toggleForm('addProvinceForm')"
class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg text-sm font-medium transition duration-200">
<svg class="w-5 h-5 inline mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
Add Province
</button>
</div>
<!-- Add/Edit Province Form -->
<div id="addProvinceForm" style="display: none;" class="p-6 bg-slate-50 border-b border-slate-200">
<h4 class="text-md font-semibold text-slate-700 mb-4" id="formTitle">New Province Details</h4>
<form method="POST" id="provinceForm" action="/provinces/create">
<input type="hidden" id="province_id" name="province_id" value="">
<!-- Basic Info -->
<div class="mb-4">
<label class="block text-sm font-medium text-slate-700 mb-1">Province Name *</label>
<input type="text" id="province_name" name="province_name" required placeholder="e.g., Riyadh, Makkah, Madinah"
class="w-full border border-slate-300 rounded-lg px-3 py-2 focus:ring-2 focus:ring-indigo-500 focus:outline-none">
</div>
<div class="flex gap-2">
<button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg text-sm font-medium">
<svg class="w-4 h-4 inline mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"></path></svg>
Save Province
</button>
<button type="button" onclick="toggleForm('addProvinceForm')"
class="bg-white border border-slate-300 text-slate-700 px-4 py-2 rounded-lg text-sm font-medium hover:bg-slate-50">
Cancel
</button>
</div>
</form>
</div>
<!-- Search Box -->
<div class="p-6 border-b border-slate-200 bg-slate-50">
<h5 class="text-sm font-semibold text-slate-700 mb-3">Search Provinces</h5>
<div class="max-w-md">
<label class="block text-xs font-medium text-slate-600 mb-1">Province Name</label>
<select id="searchProvince" placeholder="Search provinces..." class="w-full border border-slate-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:outline-none">
<option value="">All Provinces</option>
{% for province in provinces %}
<option value="{{ province.province_name|lower }}">{{ province.province_name }}</option>
{% endfor %}
</select>
</div>
</div>
<!-- Provinces Table -->
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-slate-200">
<thead class="bg-slate-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Province Name</th>
<th class="px-6 py-3 text-left text-xs font-medium text-slate-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-slate-200" id="provincesTableBody">
{% for province in provinces %}
<tr class="hover:bg-slate-50" data-province-name="{{ province.province_name|lower }}">
<td class="px-6 py-4 whitespace-nowrap text-sm text-slate-500">#{{ province.id }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-slate-800">{{ province.province_name }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<div class="flex items-center space-x-3">
<button onclick='editProvince({{ provinces_json[loop.index0] | tojson }})'
class="text-blue-600 hover:text-blue-900" title="Edit">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg>
</button>
<a href="javascript:void(0)"
onclick="confirmDelete('/provinces/delete/{{ province.id }}')"
class="text-red-600 hover:text-red-900" title="Delete">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
</a>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if not provinces %}
<div class="text-center py-12">
<svg class="mx-auto h-12 w-12 text-slate-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<h3 class="mt-2 text-sm font-medium text-slate-900">No provinces defined</h3>
<p class="mt-1 text-sm text-slate-500">Get started by adding a new province definition.</p>
</div>
{% endif %}
</div>
<!-- Tom Select JS -->
<script src="/static/vendor/tom-select/tom-select.complete.min.js"></script>
<script>
let searchProvinceSelect;
function toggleForm(formId) {
const form = document.getElementById(formId);
form.style.display = form.style.display === 'none' ? 'block' : 'none';
if (form.style.display === 'none') {
document.getElementById('provinceForm').reset();
document.getElementById('province_id').value = '';
document.getElementById('formTitle').textContent = 'New Province Details';
}
}
// Initialize Tom Select on page load
document.addEventListener('DOMContentLoaded', function() {
// Initialize search dropdown
searchProvinceSelect = new TomSelect('#searchProvince', {
plugins: ['dropdown_input'],
placeholder: 'Search provinces...',
create: false,
maxItems: 1,
onChange: function(value) {
filterProvinces();
}
});
});
function editProvince(province) {
document.getElementById('province_id').value = province.id;
document.getElementById('province_name').value = province.province_name;
document.getElementById('formTitle').textContent = 'Edit Province Details';
document.getElementById('addProvinceForm').style.display = 'block';
document.getElementById('provinceForm').action = '/provinces/update/' + province.id;
}
// Filter provinces based on search selection
function filterProvinces() {
const provinceInput = (searchProvinceSelect?.getValue() || '').toLowerCase();
const rows = document.querySelectorAll('#provincesTableBody tr');
rows.forEach(row => {
const provinceName = row.dataset.provinceName || '';
if (!provinceInput || provinceName.includes(provinceInput)) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
}
</script>
{% endblock %} |