From 1114973f8d35cce54fb289116b4c32742ad6cc56 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 6 Sep 2022 20:18:17 +0200 Subject: [PATCH] [Bands] Added edit band --- application/controllers/Band.php | 37 +++++++++------------ application/models/Bands.php | 17 ++++++++++ application/views/bands/edit.php | 14 ++++++++ application/views/bands/index.php | 2 +- assets/js/sections/bands.js | 54 +++++++++++++++++++++++++++++-- 5 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 application/views/bands/edit.php diff --git a/application/controllers/Band.php b/application/controllers/Band.php index 5d3bf386..61403418 100644 --- a/application/controllers/Band.php +++ b/application/controllers/Band.php @@ -46,37 +46,30 @@ class Band extends CI_Controller { } } - public function edit($id) + public function edit() { - $this->load->library('form_validation'); - $this->load->model('bands'); - $item_id_clean = $this->security->xss_clean($id); + $item_id_clean = $this->security->xss_clean($this->input->post('id')); - $mode_query = $this->bands->mode($item_id_clean); + $band_query = $this->bands->getband($item_id_clean); - $data['my_mode'] = $mode_query->row(); + $data['my_band'] = $band_query->row(); - $data['page_title'] = "Edit Mode"; + $data['page_title'] = "Edit Band"; - $this->form_validation->set_rules('mode', 'Mode', 'required'); - $this->form_validation->set_rules('qrgmode', 'QRG-Mode', 'required'); - - if ($this->form_validation->run() == FALSE) - { - $this->load->view('interface_assets/header', $data); - $this->load->view('mode/edit'); - $this->load->view('interface_assets/footer'); - } - else - { - $this->bands->edit(); + $this->load->view('bands/edit', $data); + } - $data['notice'] = "Mode ".$this->security->xss_clean($this->input->post('mode', true))." Updated"; + public function saveupdatedband() { + $this->load->model('bands'); - redirect('mode'); - } + $id = $this->security->xss_clean($this->input->post('id', true)); + $band = $this->security->xss_clean($this->input->post('band', true)); + + $this->bands->saveupdatedband($id, $band); + echo json_encode(array('message' => 'OK')); + return; } public function delete() { diff --git a/application/models/Bands.php b/application/models/Bands.php index cf7e51f9..3c7c2b81 100644 --- a/application/models/Bands.php +++ b/application/models/Bands.php @@ -257,6 +257,23 @@ class Bands extends CI_Model { $this->db->query("insert into bandxuser (bandid, userid, active, cq, dok, dxcc, iota, sig, sota, uscounties, was, vucc) select bands.id, " . $this->session->userdata('user_id') . ", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 from bands where band ='".$data['band']."' and not exists (select 1 from bandxuser where userid = " . $this->session->userdata('user_id') . " and bandid = bands.id);"); } + + function getband($id) { + $this->db->where('id', $id); + return $this->db->get('bands'); + } + + function saveupdatedband($id, $band) { + $data = array( + 'band' => $band, + ); + + $this->db->where('bands.id', $id); + + $this->db->update('bands', $data); + + return true; + } } ?> \ No newline at end of file diff --git a/application/views/bands/edit.php b/application/views/bands/edit.php new file mode 100644 index 00000000..79d14742 --- /dev/null +++ b/application/views/bands/edit.php @@ -0,0 +1,14 @@ +
+
+ + +
+ + band; } ?>" required> + Name of band +
+ + + +
+
\ No newline at end of file diff --git a/application/views/bands/index.php b/application/views/bands/index.php index a705701f..6a64f768 100644 --- a/application/views/bands/index.php +++ b/application/views/bands/index.php @@ -58,7 +58,7 @@ was == 1) {echo 'checked';}?>> vucc == 1) {echo 'checked';}?>> - Edit + Edit Delete diff --git a/assets/js/sections/bands.js b/assets/js/sections/bands.js index 4c35ab6e..e7ceb41d 100644 --- a/assets/js/sections/bands.js +++ b/assets/js/sections/bands.js @@ -15,7 +15,7 @@ function createBandDialog() { success: function (html) { BootstrapDialog.show({ title: 'Create band', - size: BootstrapDialog.SIZE_WIDE, + size: BootstrapDialog.SIZE_NORMAL, cssClass: 'create-band-dialog', nl2br: false, message: html, @@ -31,7 +31,11 @@ function createBandDialog() { } function createBand(form) { - if (form.band.value != '') { + $(".alert").remove(); + if (form.band.value == "") { + $('#create_mode').prepend(''); + } + else { $.ajax({ url: base_url + 'index.php/band/create', type: 'post', @@ -45,6 +49,50 @@ function createBand(form) { } } +function editBandDialog(id) { + $.ajax({ + url: base_url + 'index.php/band/edit', + type: 'post', + data: { + 'id': id + }, + success: function (html) { + BootstrapDialog.show({ + title: 'Edit band', + size: BootstrapDialog.SIZE_NORMAL, + cssClass: 'edit-band-dialog', + nl2br: false, + message: html, + buttons: [{ + label: 'Close', + action: function (dialogItself) { + dialogItself.close(); + } + }] + }); + } + }); +} + +function saveUpdatedBand(form) { + $(".alert").remove(); + if (form.band.value == "") { + $('#edit_band_dialog').prepend(''); + } + else { + $.ajax({ + url: base_url + 'index.php/band/saveupdatedband', + type: 'post', + data: {'id': form.id.value, + 'band': form.band.value + }, + success: function (html) { + location.reload(); + } + }); + } +} + function deleteBand(id, band) { BootstrapDialog.confirm({ title: 'DANGER', @@ -62,7 +110,7 @@ function deleteBand(id, band) { 'id': id }, success: function (data) { - $(".band_" + id).parent("tr:first").remove(); // removes mode from table + $(".band_" + id).parent("tr:first").remove(); // removes band from table } }); }