LinkStack/resources/views/panel/users.blade.php

113 lines
5.1 KiB
PHP
Raw Normal View History

<?php use App\Models\User; ?>
2021-04-16 01:00:00 +02:00
@extends('layouts.sidebar')
@section('content')
2023-10-20 00:29:37 +02:00
<style>
[x-cloak] { display: none !important; }
</style>
<div class="conatiner-fluid content-inner mt-n5 py-0">
<div class="row">
2021-04-16 01:00:00 +02:00
<div class="col-lg-12">
<div class="card rounded">
<div class="card-body">
<div class="row">
<div class="col-sm-12">
<section class="text-gray-400">
<h2 class="mb-4 card-header"><i class="bi bi-person"> {{__('messages.Manage Users')}}</i></h2>
<div class="card-body p-0 p-md-3">
2023-10-20 00:29:37 +02:00
<livewire:user-table />
<a href="{{ url('') }}/admin/new-user">+ {{__('messages.Add new user')}}</a>
2023-10-24 01:04:17 +02:00
<script type="text/javascript">
2023-10-25 18:37:32 +02:00
// Function to confirm and delete users
2024-01-02 22:44:09 +01:00
var confirmIt = function(e) {
2023-10-24 01:04:17 +02:00
e.preventDefault();
if (confirm("{{ __('messages.confirm.delete.user') }}")) {
var userId = this.getAttribute('data-id');
2024-01-02 22:44:09 +01:00
this.innerHTML = '<div class="d-flex justify-content-center"><div class="spinner-border spinner-border-sm text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';
2023-10-24 01:04:17 +02:00
deleteUserData(userId);
}
};
2024-01-02 22:44:09 +01:00
2023-10-24 01:04:17 +02:00
var deleteUserData = function(userId) {
var xhr = new XMLHttpRequest();
2024-01-02 22:44:09 +01:00
xhr.open('POST', `{{ route('deleteTableUser', ['id' => ':id']) }}`.replace(':id', userId), true);
2023-10-24 01:04:17 +02:00
xhr.setRequestHeader('X-CSRF-TOKEN', '{{ csrf_token() }}');
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
2024-01-02 22:44:09 +01:00
xhr.onreadystatechange = function() {
2023-10-24 01:04:17 +02:00
if (xhr.readyState === 4 && xhr.status === 200) {
refreshLivewireTable();
}
};
2024-01-02 22:44:09 +01:00
xhr.send(JSON.stringify({ id: userId }));
2023-10-24 01:04:17 +02:00
};
2024-01-02 22:44:09 +01:00
// Function to handle user actions (verification and blocking)
var handleUserClick = function(e) {
e.preventDefault();
var userId = this.getAttribute('data-id');
this.innerHTML = '<div class="d-flex justify-content-center"><div class="spinner-border spinner-border-sm text-primary" role="status"><span class="visually-hidden">Loading...</span></div></div>';
sendUserAction(userId);
2023-10-24 01:04:17 +02:00
};
2024-01-02 22:44:09 +01:00
var sendUserAction = function(userId) {
var xhr = new XMLHttpRequest();
xhr.open('GET', userId, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
refreshLivewireTable();
}
};
xhr.send();
2023-10-25 18:37:32 +02:00
};
2024-01-02 22:44:09 +01:00
// Attach click event listeners to elements with class 'confirmation', 'user-email', and 'user-block'
var attachClickEventListeners = function(className, handler) {
var elems = document.getElementsByClassName(className);
for (var i = 0, l = elems.length; i < l; i++) {
elems[i].addEventListener('click', handler, false);
2023-10-25 18:37:32 +02:00
}
};
2024-01-02 22:44:09 +01:00
// Function to refresh the Livewire table
var refreshLivewireTable = function() {
Livewire.components.getComponentsByName('user-table')[0].$wire.$refresh()
2023-10-25 18:37:32 +02:00
};
2024-01-02 22:44:09 +01:00
attachClickEventListeners('confirmation', confirmIt);
attachClickEventListeners('user-email', handleUserClick);
attachClickEventListeners('user-block', handleUserClick);
</script>
2023-10-25 18:37:32 +02:00
</div>
</section>
</div>
</div>
</div>
2021-04-16 01:00:00 +02:00
</div>
</div>
2023-02-16 13:02:05 +01:00
</div>
</div>
2022-07-11 17:21:19 +02:00
2023-10-23 23:55:19 +02:00
@push('sidebar-stylesheets')
2023-10-24 00:10:42 +02:00
<script defer src="{{url('assets/js/cdn.min.js')}}"></script>
2023-10-23 23:55:19 +02:00
<script src="{{url('vendor/livewire/livewire/dist/livewire.js')}}"></script>
2023-10-20 00:29:37 +02:00
@endpush
2023-10-20 00:29:37 +02:00
@push('sidebar-scripts')
<livewire:scripts />
2023-10-24 00:10:42 +02:00
<script src="{{url('assets/js/livewire-sortable.js')}}"></script>
2023-07-22 16:15:58 +02:00
@endpush
@endsection