kopia lustrzana https://github.com/magicbug/Cloudlog
Impliments HTMX for the user delete so that you never leave the main table display
rodzic
0bc7f44e26
commit
c7718d675c
|
@ -812,6 +812,37 @@ class User extends CI_Controller {
|
|||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a user by their ID.
|
||||
*
|
||||
* This function first loads the 'user_model'. It then checks if the current user has the authorization level of 99.
|
||||
* If not, it sets a flash message and redirects the user to the dashboard.
|
||||
*
|
||||
* If the user is authorized, it gets the user to be deleted by their ID from the URI segment 3.
|
||||
* It then calls the 'delete' function from the 'user_model' with the user ID as a parameter.
|
||||
*
|
||||
* If the 'delete' function executes successfully, it sets the HTTP status code to 200.
|
||||
* If the 'delete' function fails, it sets the HTTP status code to 500.
|
||||
*
|
||||
* @param int $id The ID of the user to delete.
|
||||
*/
|
||||
function delete_new($id) {
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
$query = $this->user_model->get_by_id($this->uri->segment(3));
|
||||
|
||||
// call $this->user_model->delete and if no errors return true
|
||||
if ($this->user_model->delete($id)) {
|
||||
// request responds with a 200 status code and empty content
|
||||
$this->output->set_status_header(200);
|
||||
} else {
|
||||
// request responds with a 500 status code and empty content
|
||||
$this->output->set_status_header(500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function delete() {
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
<th style="text-align: center; vertical-align: middle;" scope="col"><?php echo lang('admin_delete'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody hx-confirm="Are you sure you want to delete the user?" hx-target="closest tr" hx-swap="outerHTML swap:1s">
|
||||
|
||||
<?php
|
||||
|
||||
|
@ -80,11 +80,10 @@
|
|||
}
|
||||
?></td>
|
||||
<td style="text-align: center; vertical-align: middle;">
|
||||
<?php
|
||||
if ($_SESSION['user_id'] != $row->user_id) {
|
||||
echo "<a href=" . site_url('user/delete') . "/" . $row->user_id . " class=\"btn btn-danger btn-sm\"><i class=\"fas fa-user-minus\"></i></a>";
|
||||
}
|
||||
?></td>
|
||||
<?php if ($_SESSION['user_id'] != $row->user_id) { ?>
|
||||
<button class="btn btn-danger btn-sm" hx-delete="<?php echo site_url('user/delete_new/'.$row->user_id);?>"><i class="fas fa-user-minus"></i></button>
|
||||
<?php } ?>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
<?php $i++;
|
||||
|
|
|
@ -797,3 +797,8 @@ label {
|
|||
|
||||
.table-responsive>table .dropdown{position:static;}
|
||||
.table-responsive>table .dropdown>.dropdown-menu{left:auto !important;top:auto !important;}
|
||||
|
||||
tr.htmx-swapping td {
|
||||
opacity: 0;
|
||||
transition: opacity 1s ease-out;
|
||||
}
|
Ładowanie…
Reference in New Issue