diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index 41fc9590f..f18e75ebe 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -527,4 +527,11 @@ class Logbookadvanced extends CI_Controller { header("Content-Type: application/json"); print json_encode($q); } + + public function batchDeleteQsos() { + $ids = xss_clean($this->input->post('ids')); + + $this->load->model('logbookadvanced_model'); + $this->logbookadvanced_model->deleteQsos($ids); + } } diff --git a/application/models/Logbookadvanced_model.php b/application/models/Logbookadvanced_model.php index 4eb9c1a57..02b4155f6 100644 --- a/application/models/Logbookadvanced_model.php +++ b/application/models/Logbookadvanced_model.php @@ -485,4 +485,13 @@ class Logbookadvanced_model extends CI_Model { return array('message' => 'OK'); } + + function deleteQsos($ids) { + $this->db->trans_start(); + + $sql = "delete from " . $this->config->item('table_name') . " WHERE col_primary_key in ? and station_id in (select station_id from station_profile where user_id = ?)"; + + $query = $this->db->query($sql, array(json_decode($ids, true), $this->session->userdata('user_id'))); + $this->db->trans_complete(); + } } diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index 56c5a6391..616184bd6 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -356,6 +356,12 @@ $(document).ready(function () { return; } + var id_list=[]; + elements.each(function() { + let id = $(this).first().closest('tr').data('qsoID') + id_list.push(id); + }); + $('#deleteQsos').prop("disabled", true); var table = $('#qsoList').DataTable(); @@ -369,19 +375,22 @@ $(document).ready(function () { btnOKClass: 'btn-danger', callback: function(result) { if(result) { - elements.each(function() { - let id = $(this).first().closest('tr').data('qsoID') - $.ajax({ - url: base_url + 'index.php/qso/delete_ajax', - type: 'post', - data: {'id': id - }, - success: function(data) { + $.ajax({ + url: base_url + 'index.php/logbookadvanced/batchDeleteQsos', + type: 'post', + data: { + 'ids': JSON.stringify(id_list, null, 2) + }, + success: function(data) { + elements.each(function() { + let id = $(this).first().closest('tr').data('qsoID') var row = $("#qsoID-" + id); - table.row(row).remove().draw(false); - } - }); - $('#deleteQsos').prop("disabled", false); + table.row(row).remove(); + }); + $('#deleteQsos').prop("disabled", false); + table.draw(false); + $('#checkBoxAll').prop("checked", false); + } }) } },