|
|
@@ -29,10 +29,17 @@
|
|
|
</td>
|
|
|
<td class="p-6 text-xs text-gray-500">{{ data.assigned_templates|join(', ') or 'None' }}</td>
|
|
|
<td class="p-6 text-right">
|
|
|
- <button onclick="editUser('{{u}}', '{{data.role}}', {{data.assigned_templates|tojson}})" class="text-blue-500 hover:text-blue-400 text-[10px] font-black uppercase mr-4">Edit</button>
|
|
|
+
|
|
|
+ <button type="button"
|
|
|
+ onclick="editUser('{{ u|e }}', '{{ data.role|e }}', '{{ data.assigned_templates|join(',') if data.assigned_templates else '' }}')"
|
|
|
+ class="text-blue-500 hover:text-blue-400 text-[10px] font-black uppercase mr-4">
|
|
|
+ Edit
|
|
|
+ </button>
|
|
|
+
|
|
|
{% if u != 'admin' %}
|
|
|
- <a href="/users/delete/{{ u }}" onclick="return confirm('Delete user?')" class="text-red-500 hover:text-red-400 text-[10px] font-black uppercase">Delete</a>
|
|
|
+ <a href="/users/delete/{{ u|urlencode }}" onclick="return confirm('Are you sure you want to delete this user?')" class="text-red-500 hover:text-red-400 text-[10px] font-black uppercase">Delete</a>
|
|
|
{% endif %}
|
|
|
+
|
|
|
</td>
|
|
|
</tr>
|
|
|
{% endfor %}
|
|
|
@@ -48,7 +55,7 @@
|
|
|
<input type="hidden" name="old_username" id="oldUsername">
|
|
|
|
|
|
<input type="text" name="username" id="userName" placeholder="Username" required class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-3 text-sm font-bold text-white outline-none">
|
|
|
- <input type="password" name="password" id="userPass" placeholder="Password" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-3 text-sm font-bold text-white outline-none">
|
|
|
+ <input type="password" name="password" id="userPass" placeholder="Password (Leave blank to keep current)" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-3 text-sm font-bold text-white outline-none">
|
|
|
|
|
|
<select name="role" id="userRole" class="w-full bg-[#0b0e14] border border-gray-800 rounded-xl p-3 text-sm font-bold text-white outline-none">
|
|
|
<option value="user">User (Restricted)</option>
|
|
|
@@ -57,7 +64,7 @@
|
|
|
|
|
|
<div class="bg-black/20 p-4 rounded-xl border border-gray-800">
|
|
|
<label class="text-[10px] font-black text-gray-500 uppercase block mb-3">Assigned Templates</label>
|
|
|
- <div class="grid grid-cols-2 gap-2">
|
|
|
+ <div class="grid grid-cols-2 gap-2 max-h-48 overflow-y-auto pr-2">
|
|
|
{% for t in all_templates %}
|
|
|
<label class="flex items-center gap-2 text-xs text-gray-400 cursor-pointer hover:text-white">
|
|
|
<input type="checkbox" name="assigned_templates[]" value="{{ t }}" class="template-check rounded border-gray-700 bg-gray-900 text-blue-600">
|
|
|
@@ -68,8 +75,8 @@
|
|
|
</div>
|
|
|
|
|
|
<div class="flex gap-4 pt-4">
|
|
|
- <button type="button" onclick="closeUserModal()" class="flex-1 bg-gray-800 text-gray-400 font-bold py-3 rounded-xl uppercase text-xs">Cancel</button>
|
|
|
- <button type="submit" class="flex-1 bg-blue-600 text-white font-black py-3 rounded-xl uppercase text-xs">Save</button>
|
|
|
+ <button type="button" onclick="closeUserModal()" class="flex-1 bg-gray-800 text-gray-400 font-bold py-3 rounded-xl uppercase text-xs hover:text-white transition">Cancel</button>
|
|
|
+ <button type="submit" class="flex-1 bg-blue-600 text-white font-black py-3 rounded-xl uppercase text-xs hover:bg-blue-500 transition">Save</button>
|
|
|
</div>
|
|
|
</form>
|
|
|
</div>
|
|
|
@@ -81,19 +88,45 @@ function openAddUser() {
|
|
|
document.getElementById('userAction').value = 'add';
|
|
|
document.getElementById('modalTitle').innerText = 'Add User';
|
|
|
document.getElementById('userName').value = '';
|
|
|
- document.querySelectorAll('.template-check').forEach(c => c.checked = false);
|
|
|
+ document.getElementById('userPass').value = '';
|
|
|
+ document.getElementById('userPass').placeholder = 'Password (Required)';
|
|
|
+ document.getElementById('userPass').required = true;
|
|
|
+
|
|
|
+ var checkboxes = document.querySelectorAll('.template-check');
|
|
|
+ for (var i = 0; i < checkboxes.length; i++) {
|
|
|
+ checkboxes[i].checked = false;
|
|
|
+ }
|
|
|
}
|
|
|
-function editUser(u, role, templates) {
|
|
|
+
|
|
|
+function editUser(u, role, rawTemplates) {
|
|
|
+ // Παίρνουμε το απλό κείμενο "AWMN,LOCAL" και το κόβουμε εκεί που έχει κόμμα,
|
|
|
+ // φτιάχνοντας μια σωστή λίστα. Αν είναι άδειο, φτιάχνουμε κενή λίστα.
|
|
|
+ var templates = rawTemplates ? rawTemplates.split(',') : [];
|
|
|
+
|
|
|
+ // Εμφάνιση Modal
|
|
|
document.getElementById('userModal').classList.remove('hidden');
|
|
|
+
|
|
|
+ // Συμπλήρωση πεδίων
|
|
|
document.getElementById('userAction').value = 'edit';
|
|
|
document.getElementById('oldUsername').value = u;
|
|
|
document.getElementById('userName').value = u;
|
|
|
document.getElementById('userRole').value = role;
|
|
|
document.getElementById('modalTitle').innerText = 'Edit User';
|
|
|
- document.querySelectorAll('.template-check').forEach(c => {
|
|
|
- c.checked = templates.includes(c.value);
|
|
|
- });
|
|
|
+
|
|
|
+ // Ο κωδικός στο Edit δεν είναι υποχρεωτικός
|
|
|
+ document.getElementById('userPass').value = '';
|
|
|
+ document.getElementById('userPass').placeholder = 'Password (Leave blank to keep current)';
|
|
|
+ document.getElementById('userPass').required = false;
|
|
|
+
|
|
|
+ // Τσεκάρισμα των σωστών Templates
|
|
|
+ var checkboxes = document.querySelectorAll('.template-check');
|
|
|
+ for (var i = 0; i < checkboxes.length; i++) {
|
|
|
+ checkboxes[i].checked = templates.includes(checkboxes[i].value);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function closeUserModal() {
|
|
|
+ document.getElementById('userModal').classList.add('hidden');
|
|
|
}
|
|
|
-function closeUserModal() { document.getElementById('userModal').classList.add('hidden'); }
|
|
|
</script>
|
|
|
{% endblock %}
|