From c7718d675c6c494f95774b91dec9e4e16d63fdbb Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Wed, 10 Apr 2024 15:15:54 +0100 Subject: [PATCH] Impliments HTMX for the user delete so that you never leave the main table display --- application/controllers/User.php | 31 +++++++++++++++++++++++++++++++ application/views/user/main.php | 11 +++++------ assets/css/general.css | 7 ++++++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/application/controllers/User.php b/application/controllers/User.php index 94998733..ce1d59f5 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -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'); } diff --git a/application/views/user/main.php b/application/views/user/main.php index b06344a0..a8ff0851 100644 --- a/application/views/user/main.php +++ b/application/views/user/main.php @@ -53,7 +53,7 @@ - + - user_id) { - echo "user_id . " class=\"btn btn-danger btn-sm\">"; - } - ?> + user_id) { ?> + + + table .dropdown{position:static;} -.table-responsive>table .dropdown>.dropdown-menu{left:auto !important;top:auto !important;} \ No newline at end of file +.table-responsive>table .dropdown>.dropdown-menu{left:auto !important;top:auto !important;} + +tr.htmx-swapping td { + opacity: 0; + transition: opacity 1s ease-out; +} \ No newline at end of file