Improve function

This commit is contained in:
Julian Prieber 2023-10-25 18:37:32 +02:00
parent 132c5cfbed
commit 896e6dae0e
2 changed files with 64 additions and 9 deletions

View File

@ -67,9 +67,9 @@ class UserTable extends DataTableComponent
'id' => $row->id 'id' => $row->id
]); ]);
if ($row->email_verified_at == '') { if ($row->email_verified_at == '') {
return '<a href="' . $verifyLink . '" class="text-danger"><span class="badge bg-danger">' . __('messages.Pending') . '</span></a>'; return '<a style="cursor:pointer" data-id="'.$verifyLink.'" class="user-email text-danger"><span class="badge bg-danger">' . __('messages.Pending') . '</span></a>';
} else { } else {
return '<a href="' . $verifyLink . '" class="text-danger"><span class="badge bg-success">' . __('messages.Verified') . '</span></a>'; return '<a style="cursor:pointer" data-id="'.$verifyLink.'" class="user-email text-danger"><span class="badge bg-success">' . __('messages.Verified') . '</span></a>';
} }
} }
} else { } else {
@ -85,9 +85,9 @@ class UserTable extends DataTableComponent
} else { } else {
$route = route('blockUser', ['block' => $row->block, 'id' => $row->id]); $route = route('blockUser', ['block' => $row->block, 'id' => $row->id]);
if ($row->block === 'yes') { if ($row->block === 'yes') {
$badge = '<span class="badge bg-danger">'.__('messages.Pending').'</span>'; $badge = '<a style="cursor:pointer" data-id="'.$route.'" class="user-block text-danger"><span class="badge bg-danger">'.__('messages.Pending').'</span></a>';
} elseif ($row->block === 'no') { } elseif ($row->block === 'no') {
$badge = '<span class="badge bg-success">'.__('messages.Approved').'</span>'; $badge = '<a style="cursor:pointer" data-id="'.$route.'" class="user-block text-danger"><span class="badge bg-success">'.__('messages.Approved').'</span></a>';
} }
return "<a href=\"$route\">$badge</a>"; return "<a href=\"$route\">$badge</a>";
} }

View File

@ -27,6 +27,7 @@
<a href="{{ url('') }}/admin/new-user">+ {{__('messages.Add new user')}}</a> <a href="{{ url('') }}/admin/new-user">+ {{__('messages.Add new user')}}</a>
<script type="text/javascript"> <script type="text/javascript">
// Function to confirm and delete users
var elems = document.getElementsByClassName('confirmation'); var elems = document.getElementsByClassName('confirmation');
var confirmIt = function (e) { var confirmIt = function (e) {
e.preventDefault(); e.preventDefault();
@ -51,14 +52,68 @@
xhr.send(data); xhr.send(data);
}; };
// Function to refresh the Livewire table
var refreshLivewireTable = function () { var refreshLivewireTable = function () {
Livewire.components.getComponentsByName('user-table')[0].$wire.$refresh() Livewire.components.getComponentsByName('user-table')[0].$wire.$refresh()
}; };
// Attach click event listeners to elements with class 'confirmation'
for (var i = 0, l = elems.length; i < l; i++) { for (var i = 0, l = elems.length; i < l; i++) {
elems[i].addEventListener('click', confirmIt, false); elems[i].addEventListener('click', confirmIt, false);
} }
</script> </script>
<script type="text/javascript">
// Function to handle user verification requests
var elems = document.getElementsByClassName('user-email');
var handleUserClick = function (e) {
e.preventDefault();
var userId = this.getAttribute('data-id');
sendVerificationRequest(userId);
};
var sendVerificationRequest = function(userId) {
var xhr = new XMLHttpRequest();
xhr.open('GET', userId, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
refreshLivewireTable();
}
};
xhr.send();
};
// Attach click event listeners to elements with class 'user-email'
for (var i = 0, l = elems.length; i < l; i++) {
elems[i].addEventListener('click', handleUserClick, false);
}
</script>
<script type="text/javascript">
// Function to handle user blocking
var elems = document.getElementsByClassName('user-block');
var handleUserClick = function (e) {
e.preventDefault();
var userId = this.getAttribute('data-id');
sendVerificationRequest(userId);
};
var sendVerificationRequest = function(userId) {
var xhr = new XMLHttpRequest();
xhr.open('GET', userId, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
refreshLivewireTable();
}
};
xhr.send();
};
// Attach click event listeners to elements with class 'user-block'
for (var i = 0, l = elems.length; i < l; i++) {
elems[i].addEventListener('click', handleUserClick, false);
}
</script>
</div> </div>
</section> </section>