Improve function
This commit is contained in:
parent
132c5cfbed
commit
896e6dae0e
|
@ -67,9 +67,9 @@ class UserTable extends DataTableComponent
|
|||
'id' => $row->id
|
||||
]);
|
||||
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 {
|
||||
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 {
|
||||
|
@ -85,9 +85,9 @@ class UserTable extends DataTableComponent
|
|||
} else {
|
||||
$route = route('blockUser', ['block' => $row->block, 'id' => $row->id]);
|
||||
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') {
|
||||
$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>";
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
<a href="{{ url('') }}/admin/new-user">+ {{__('messages.Add new user')}}</a>
|
||||
|
||||
<script type="text/javascript">
|
||||
// Function to confirm and delete users
|
||||
var elems = document.getElementsByClassName('confirmation');
|
||||
var confirmIt = function (e) {
|
||||
e.preventDefault();
|
||||
|
@ -51,14 +52,68 @@
|
|||
xhr.send(data);
|
||||
};
|
||||
|
||||
// Function to refresh the Livewire table
|
||||
var refreshLivewireTable = function () {
|
||||
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++) {
|
||||
elems[i].addEventListener('click', confirmIt, false);
|
||||
}
|
||||
</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>
|
||||
</section>
|
||||
|
|
Loading…
Reference in New Issue