diff --git a/application/controllers/Band.php b/application/controllers/Band.php index 7dea9fb4f..d5caa1a4b 100644 --- a/application/controllers/Band.php +++ b/application/controllers/Band.php @@ -34,11 +34,16 @@ class Band extends CI_Controller { $data['bands'] = $this->bands->get_all_bandedges_for_user(); + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/sections/bandedges.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/bandedges.js")), + ]; + // Render Page $data['page_title'] = __("Bands"); $this->load->view('interface_assets/header', $data); $this->load->view('bands/bandedges'); - $this->load->view('interface_assets/footer'); + $this->load->view('interface_assets/footer', $footerData); } public function create() @@ -184,4 +189,13 @@ class Band extends CI_Controller { $this->user_options_model->set_option('frequency', 'unit', array($band => $unit)); $this->session->set_userdata('qrgunit_'.$band, $unit); } + + public function deletebandedge() { + $id = $this->input->post('id'); + $this->load->model('bands'); + $this->bands->deletebandedge($id); + header('Content-Type: application/json'); + echo json_encode(array('message' => 'OK')); + return; + } } diff --git a/application/models/Bands.php b/application/models/Bands.php index f862493e1..cac64f5f7 100644 --- a/application/models/Bands.php +++ b/application/models/Bands.php @@ -109,12 +109,34 @@ class Bands extends CI_Model { return $result; } + $this->insert_band_edges_for_user(); + $this->db->from('bandedges'); $this->db->where('bandedges.userid', -1); return $this->db->get()->result(); } + function insert_band_edges_for_user() { + // Get band edges from default user + $this->db->from('bandedges'); + $this->db->where('bandedges.userid', -1); + $result = $this->db->get()->result(); + + if ($result) { + foreach($result as $edge) { + $data = array( + 'frequencyfrom' => $edge->frequencyfrom, + 'frequencyto' => $edge->frequencyto, + 'mode' => $edge->mode, + 'userid' => $this->session->userdata('user_id') + ); + $this->db->insert('bandedges', $data); + } + } + return true; + } + function all() { return $this->bandslots; } @@ -426,6 +448,14 @@ class Bands extends CI_Model { return $worked_slots; } + + function deletebandedge($id) { + // Clean ID + $clean_id = $this->security->xss_clean($id); + + // Delete Bandedge + $this->db->delete('bandedges', array('id' => $clean_id, 'userid' => $this->session->userdata('user_id'))); + } } ?> diff --git a/application/views/bands/bandedges.php b/application/views/bands/bandedges.php index 096420644..be095ed5c 100644 --- a/application/views/bands/bandedges.php +++ b/application/views/bands/bandedges.php @@ -30,11 +30,11 @@ - frequencyfrom;?> + frequencyfrom;?> frequencyto;?> mode;?> - - + + diff --git a/assets/js/sections/bandedges.js b/assets/js/sections/bandedges.js new file mode 100644 index 000000000..2704f8228 --- /dev/null +++ b/assets/js/sections/bandedges.js @@ -0,0 +1,86 @@ +function editBandEdgeDialog(id) { + $.ajax({ + url: base_url + 'index.php/band/bandedgedit', + type: 'post', + data: { + 'id': id + }, + success: function (html) { + BootstrapDialog.show({ + title: lang_options_bands_edit, + size: BootstrapDialog.SIZE_NORMAL, + cssClass: 'edit-band-dialog', + nl2br: false, + message: html, + buttons: [{ + label: lang_admin_close, + action: function (dialogItself) { + dialogItself.close(); + } + }] + }); + } + }); +} + +function saveUpdatedBandEdge(form) { + $(".alert").remove(); + if (form.band.value == "") { + $('#edit_band_dialog').prepend(''); + } + else { + $.ajax({ + url: base_url + 'index.php/band/saveupdatedbandedge', + type: 'post', + data: {'id': form.id.value, + 'band': form.band.value, + 'bandgroup': form.bandgroup.value, + 'ssbqrg': form.ssbqrg.value, + 'dataqrg': form.dataqrg.value, + 'cwqrg': form.cwqrg.value + }, + success: function (html) { + location.reload(); + } + }); + } +} + +function deleteBandEdge(id) { + BootstrapDialog.confirm({ + title: lang_general_word_danger, + message: 'Are you sure you want to delete this band edge?', + type: BootstrapDialog.TYPE_DANGER, + closable: true, + draggable: true, + btnOKClass: 'btn-danger', + callback: function (result) { + if (result) { + $.ajax({ + url: base_url + 'index.php/band/deletebandedge', + type: 'post', + data: { + 'id': id + }, + success: function (data) { + $(".bandedge_" + id).parent("tr:first").remove(); // removes band from table + } + }); + } + } + }); +} + +function saveBandEdge(id) { + $.ajax({ + url: base_url + 'index.php/band/saveBandEdge', + type: 'post', + data: {'id': id, + 'frequencyfrom': $('#frequencyfrom').val(), + 'frequencyto': $('#frequencyto').val(), + 'mode': $('#mode').val() + }, + success: function (html) { + } + }); +}