| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- {% extends "admin/base.html" %}
- {% block content %}
- <div class="bg-white rounded-lg shadow-lg p-4 sm:p-6">
- <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 gap-4">
- <h2 class="text-xl sm:text-2xl font-bold text-gray-800">{{ _("Gestión de Usuarios") }}</h2>
- <a href="{{ url_for('admin.create_user') }}" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg transition-colors flex items-center w-full sm:w-auto justify-center">
- <i class="fas fa-plus mr-2"></i>{{ _("Crear Usuario") }}
- </a>
- </div>
- <div class="overflow-x-auto -mx-4 sm:mx-0">
- <table class="min-w-full table-auto">
- <thead class="bg-gray-50">
- <tr>
- <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("ID") }}</th>
- <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("Usuario") }}</th>
- <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider hidden sm:table-cell">{{ _("Rol") }}</th>
- <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("Estado") }}</th>
- <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider hidden md:table-cell">{{ _("Último Login") }}</th>
- <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("Acciones") }}</th>
- </tr>
- </thead>
- <tbody class="bg-white divide-y divide-gray-200">
- {% for user in users %}
- <tr class="hover:bg-gray-50">
- <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm text-gray-900">{{ user.id }}</td>
- <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ user.username }}</td>
- <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm text-gray-500 hidden sm:table-cell">{{ user.role }}</td>
- <td class="px-2 sm:px-4 py-4 whitespace-nowrap">
- <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full {% if user.is_active %}bg-green-100 text-green-800{% else %}bg-red-100 text-red-800{% endif %}">
- {% if user.is_active %}{{ _("Activo") }}{% else %}{{ _("Inactivo") }}{% endif %}
- </span>
- </td>
- <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm text-gray-500 hidden md:table-cell">
- {% if user.last_login %}
- {{ user.last_login | datetime_format('%Y-%m-%d %H:%M') }}
- {% else %}
- {{ _("Nunca") }}
- {% endif %}
- </td>
- <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm font-medium">
- <a href="{{ url_for('admin.edit_user', user_id=user.id) }}" class="text-blue-600 hover:text-blue-900 mr-2">
- <i class="fas fa-edit"></i><span class="hidden sm:inline"> {{ _("Editar") }}</span>
- </a>
- {% if user.username != 'admin' %}
- <button type="button" onclick="confirmDelete({{ user.id }}, '{{ user.username }}')" class="text-red-600 hover:text-red-900">
- <i class="fas fa-trash"></i><span class="hidden sm:inline"> {{ _("Eliminar") }}</span>
- </button>
- {% else %}
- <span class="text-gray-400 cursor-not-allowed">
- <i class="fas fa-trash"></i><span class="hidden sm:inline"> {{ _("Eliminar") }}</span>
- </span>
- {% endif %}
- </td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
- </div>
- </div>
- <script>
- function confirmDelete(userId, username) {
- showCustomConfirm(`¿Está seguro de que desea eliminar el usuario "${username}"? Esta acción no se puede deshacer.`, () => {
- const form = document.createElement('form');
- form.method = 'POST';
- form.action = `{{ url_for('admin.delete_user', user_id=0) }}`.replace('0', userId);
-
- const csrfInput = document.createElement('input');
- csrfInput.type = 'hidden';
- csrfInput.name = 'csrf_token';
- csrfInput.value = '{{ csrf_token() }}';
- form.appendChild(csrfInput);
-
- document.body.appendChild(form);
- form.submit();
- });
- }
- </script>
- {% endblock %}
|