4
0

users.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {% extends "admin/base.html" %}
  2. {% block content %}
  3. <div class="bg-white rounded-lg shadow-lg p-4 sm:p-6">
  4. <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 gap-4">
  5. <h2 class="text-xl sm:text-2xl font-bold text-gray-800">{{ _("Gestión de Usuarios") }}</h2>
  6. <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">
  7. <i class="fas fa-plus mr-2"></i>{{ _("Crear Usuario") }}
  8. </a>
  9. </div>
  10. <div class="overflow-x-auto -mx-4 sm:mx-0">
  11. <table class="min-w-full table-auto">
  12. <thead class="bg-gray-50">
  13. <tr>
  14. <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("ID") }}</th>
  15. <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("Usuario") }}</th>
  16. <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>
  17. <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("Estado") }}</th>
  18. <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>
  19. <th class="px-2 sm:px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">{{ _("Acciones") }}</th>
  20. </tr>
  21. </thead>
  22. <tbody class="bg-white divide-y divide-gray-200">
  23. {% for user in users %}
  24. <tr class="hover:bg-gray-50">
  25. <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm text-gray-900">{{ user.id }}</td>
  26. <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ user.username }}</td>
  27. <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm text-gray-500 hidden sm:table-cell">{{ user.role }}</td>
  28. <td class="px-2 sm:px-4 py-4 whitespace-nowrap">
  29. <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 %}">
  30. {% if user.is_active %}{{ _("Activo") }}{% else %}{{ _("Inactivo") }}{% endif %}
  31. </span>
  32. </td>
  33. <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm text-gray-500 hidden md:table-cell">
  34. {% if user.last_login %}
  35. {{ user.last_login | datetime_format('%Y-%m-%d %H:%M') }}
  36. {% else %}
  37. {{ _("Nunca") }}
  38. {% endif %}
  39. </td>
  40. <td class="px-2 sm:px-4 py-4 whitespace-nowrap text-sm font-medium">
  41. <a href="{{ url_for('admin.edit_user', user_id=user.id) }}" class="text-blue-600 hover:text-blue-900 mr-2">
  42. <i class="fas fa-edit"></i><span class="hidden sm:inline"> {{ _("Editar") }}</span>
  43. </a>
  44. {% if user.username != 'admin' %}
  45. <button type="button" onclick="confirmDelete({{ user.id }}, '{{ user.username }}')" class="text-red-600 hover:text-red-900">
  46. <i class="fas fa-trash"></i><span class="hidden sm:inline"> {{ _("Eliminar") }}</span>
  47. </button>
  48. {% else %}
  49. <span class="text-gray-400 cursor-not-allowed">
  50. <i class="fas fa-trash"></i><span class="hidden sm:inline"> {{ _("Eliminar") }}</span>
  51. </span>
  52. {% endif %}
  53. </td>
  54. </tr>
  55. {% endfor %}
  56. </tbody>
  57. </table>
  58. </div>
  59. </div>
  60. <script>
  61. function confirmDelete(userId, username) {
  62. showCustomConfirm(`¿Está seguro de que desea eliminar el usuario "${username}"? Esta acción no se puede deshacer.`, () => {
  63. const form = document.createElement('form');
  64. form.method = 'POST';
  65. form.action = `{{ url_for('admin.delete_user', user_id=0) }}`.replace('0', userId);
  66. const csrfInput = document.createElement('input');
  67. csrfInput.type = 'hidden';
  68. csrfInput.name = 'csrf_token';
  69. csrfInput.value = '{{ csrf_token() }}';
  70. form.appendChild(csrfInput);
  71. document.body.appendChild(form);
  72. form.submit();
  73. });
  74. }
  75. </script>
  76. {% endblock %}