From 4a48764f4940e0cc0fa4d024642ebb6d19171c92 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sat, 29 Jun 2024 00:13:28 +0200 Subject: [PATCH 1/6] first mock up --- application/controllers/Qso.php | 10 ++++++++++ application/views/qso/edit_ajax.php | 5 ++++- assets/js/sections/common.js | 30 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 0e28680e8..4f41723f7 100644 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -284,6 +284,16 @@ class QSO extends CI_Controller { $this->load->view('qso/edit_ajax', $data); } + // is used in edit_ajax view. We don't want directly update the database and can't use the LBA update function. + public function get_callbook_data() { + $callsign = xss_clean($this->input->post('callsign')); + + $this->load->model('logbook_model'); + $callbook = $this->logbook_model->loadCallBook($callsign, $this->config->item('use_fullname')); + + echo json_encode($callbook); + } + function qso_save_ajax() { $this->load->model('logbook_model'); $this->load->model('user_model'); diff --git a/application/views/qso/edit_ajax.php b/application/views/qso/edit_ajax.php index 9dc775525..be11c9dd1 100644 --- a/application/views/qso/edit_ajax.php +++ b/application/views/qso/edit_ajax.php @@ -588,7 +588,10 @@
- +
+ + +
diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index bf648173f..af1be8ad7 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -152,6 +152,36 @@ function displayQso(id) { }); } +// used in edit_ajax.php +function callbook_update(callsign) { + + var border_color = '2px solid green'; + + $.ajax({ + url: site_url + '/qso/get_callbook_data', + type: 'post', + data: { + callsign: callsign + }, + dataType: 'json', + success: function (data) { + console.log(data); + $('#qth').val(data.city).css('border', border_color); + $('#dxcc_id').val(data.dxcc).css('border', border_color); + $('#locator').val(data.gridsquare).css('border', border_color); + // $('#image').val(data.image).css('border', border_color); Not in use yet, but may in future + $('#iota_ref').val(data.iota).css('border', border_color); + $('#name').val(data.name).css('border', border_color); + $('#qsl-via').val(data.qslmgr).css('border', border_color); + $('#state').val(data.state).css('border', border_color); + $('#stationCntyInputEdit').val(data.us_county).css('border', border_color); + }, + error: function () { + console.log("Sorry, something is wrong here"); + }, + }); +} + function qso_delete(id, call) { BootstrapDialog.confirm({ title: lang_general_word_danger, From 1f9a2378040cfa50e85105fc237f3a48e2efbfff Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Fri, 5 Jul 2024 10:10:47 +0200 Subject: [PATCH 2/6] fill fields only if empty and data is not empty --- application/views/qso/edit_ajax.php | 2 +- assets/js/sections/common.js | 36 ++++++++++++++++++----------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/application/views/qso/edit_ajax.php b/application/views/qso/edit_ajax.php index be11c9dd1..f9dd804dd 100644 --- a/application/views/qso/edit_ajax.php +++ b/application/views/qso/edit_ajax.php @@ -589,7 +589,7 @@
- +
diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index af1be8ad7..bfb86ef4a 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -152,10 +152,10 @@ function displayQso(id) { }); } -// used in edit_ajax.php -function callbook_update(callsign) { +// used in edit_ajax.php to update the currently editing QSO +function single_callbook_update(callsign) { - var border_color = '2px solid green'; + $.ajax({ url: site_url + '/qso/get_callbook_data', @@ -165,22 +165,30 @@ function callbook_update(callsign) { }, dataType: 'json', success: function (data) { - console.log(data); - $('#qth').val(data.city).css('border', border_color); - $('#dxcc_id').val(data.dxcc).css('border', border_color); - $('#locator').val(data.gridsquare).css('border', border_color); - // $('#image').val(data.image).css('border', border_color); Not in use yet, but may in future - $('#iota_ref').val(data.iota).css('border', border_color); - $('#name').val(data.name).css('border', border_color); - $('#qsl-via').val(data.qslmgr).css('border', border_color); - $('#state').val(data.state).css('border', border_color); - $('#stationCntyInputEdit').val(data.us_county).css('border', border_color); + // console.log(data); + fill_if_empty('#qth', data.city); + fill_if_empty('#dxcc_id', data.dxcc); + fill_if_empty('#locator', data.gridsquare); + // fill_if_empty('#image', data.image); Not in use yet, but may in future + fill_if_empty('#iota_ref', data.iota); + fill_if_empty('#name', data.name); + fill_if_empty('#qsl-via', data.qslmgr); + fill_if_empty('#state', data.state); + fill_if_empty('#stationCntyInputEdit', data.us_county); }, error: function () { - console.log("Sorry, something is wrong here"); + console.error("Sorry, something went wrong to get the callbook data."); }, }); } +// used with single_callbook_update() to only fill fields which are empty +function fill_if_empty(field, data) { + var border_color = '2px solid green'; + + if ($(field).val() == '' && data != '') { + $(field).val(data).css('border', border_color); + } +} function qso_delete(id, call) { BootstrapDialog.confirm({ From 89f9d49b3e1026cd777723fe97b492db9b7fab6c Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Fri, 5 Jul 2024 16:46:22 +0200 Subject: [PATCH 3/6] direct approach --- application/controllers/Qso.php | 10 ------- application/views/qso/edit_ajax.php | 2 +- assets/js/sections/common.js | 46 +++++++++++++++++++---------- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index f20176f15..9181001fe 100644 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -281,16 +281,6 @@ class QSO extends CI_Controller { $this->load->view('qso/edit_ajax', $data); } - // is used in edit_ajax view. We don't want directly update the database and can't use the LBA update function. - public function get_callbook_data() { - $callsign = xss_clean($this->input->post('callsign')); - - $this->load->model('logbook_model'); - $callbook = $this->logbook_model->loadCallBook($callsign, $this->config->item('use_fullname')); - - echo json_encode($callbook); - } - function qso_save_ajax() { $this->load->model('logbook_model'); $this->load->model('user_model'); diff --git a/application/views/qso/edit_ajax.php b/application/views/qso/edit_ajax.php index f9dd804dd..ab5052841 100644 --- a/application/views/qso/edit_ajax.php +++ b/application/views/qso/edit_ajax.php @@ -589,7 +589,7 @@
- +
diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index bfb86ef4a..79ef272b0 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -153,28 +153,27 @@ function displayQso(id) { } // used in edit_ajax.php to update the currently editing QSO -function single_callbook_update(callsign) { +function single_callbook_update(callsign, band, mode) { $.ajax({ - url: site_url + '/qso/get_callbook_data', - type: 'post', - data: { - callsign: callsign - }, + url: site_url + '/logbook/json/' + callsign + '/' + band + '/' + mode, dataType: 'json', success: function (data) { // console.log(data); - fill_if_empty('#qth', data.city); - fill_if_empty('#dxcc_id', data.dxcc); - fill_if_empty('#locator', data.gridsquare); + fill_if_empty('#qth', data.callsign_qth); + fill_if_empty('#dxcc_id', data.dxcc.adif); + fill_if_empty('#continent', data.dxcc.cont); + fill_if_empty('#cqz', data.dxcc.cqz); + fill_if_empty('#distance', data.callsign_distance); + fill_if_empty('#locator', data.callsign_qra); // fill_if_empty('#image', data.image); Not in use yet, but may in future - fill_if_empty('#iota_ref', data.iota); - fill_if_empty('#name', data.name); - fill_if_empty('#qsl-via', data.qslmgr); - fill_if_empty('#state', data.state); - fill_if_empty('#stationCntyInputEdit', data.us_county); + fill_if_empty('#iota_ref', data.callsign_iota); + fill_if_empty('#name', data.callsign_name); + fill_if_empty('#qsl-via', data.qsl_manager); + fill_if_empty('#stateDropdown', data.callsign_state); + fill_if_empty('#stationCntyInputEdit', data.callsign_us_county); }, error: function () { console.error("Sorry, something went wrong to get the callbook data."); @@ -182,9 +181,26 @@ function single_callbook_update(callsign) { }); } // used with single_callbook_update() to only fill fields which are empty -function fill_if_empty(field, data) { +async function fill_if_empty(field, data) { var border_color = '2px solid green'; + // catch special case for dxcc + if (field == "#dxcc_id" && $(field).val() == 0) { + $(field).val(data).css('border', border_color); + } + + // catch special case for state + if (field == '#stateDropdown') { + await updateStateDropdown('#dxcc_id', '#stateInputLabel', '#location_us_county', '#stationCntyInputEdit'); + $(field).val(data).css('border', border_color); + } + + // catch special case for distance + if (field == "#distance" && $(field).val() == 0) { + $(field).val(data).css('border', border_color); + // $('#locator_info').html(data); + } + if ($(field).val() == '' && data != '') { $(field).val(data).css('border', border_color); } From 1705af464bfae711a8af10b9dc61b11a037b4931 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sat, 6 Jul 2024 14:10:05 +0200 Subject: [PATCH 4/6] add a spinner and lock the button during ajax --- application/views/qso/edit_ajax.php | 2 +- assets/js/sections/common.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/application/views/qso/edit_ajax.php b/application/views/qso/edit_ajax.php index ab5052841..a1ddb2e57 100644 --- a/application/views/qso/edit_ajax.php +++ b/application/views/qso/edit_ajax.php @@ -589,7 +589,7 @@
- +
diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index 79ef272b0..cfa25e6a7 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -155,7 +155,7 @@ function displayQso(id) { // used in edit_ajax.php to update the currently editing QSO function single_callbook_update(callsign, band, mode) { - + $('#update_from_callbook').prop("disabled", true).addClass("running"); $.ajax({ url: site_url + '/logbook/json/' + callsign + '/' + band + '/' + mode, @@ -174,9 +174,13 @@ function single_callbook_update(callsign, band, mode) { fill_if_empty('#qsl-via', data.qsl_manager); fill_if_empty('#stateDropdown', data.callsign_state); fill_if_empty('#stationCntyInputEdit', data.callsign_us_county); + + $('#update_from_callbook').prop("disabled", false).removeClass("running"); }, error: function () { console.error("Sorry, something went wrong to get the callbook data."); + + $('#update_from_callbook').prop("disabled", false).removeClass("running"); }, }); } From 51b6bd69e35ed5d7446613a3db00ea9b8408ef66 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sat, 6 Jul 2024 14:25:19 +0200 Subject: [PATCH 5/6] take the values from the form instead from database --- application/views/qso/edit_ajax.php | 4 ++-- assets/js/sections/common.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/application/views/qso/edit_ajax.php b/application/views/qso/edit_ajax.php index a1ddb2e57..a44ddec6c 100644 --- a/application/views/qso/edit_ajax.php +++ b/application/views/qso/edit_ajax.php @@ -60,7 +60,7 @@
- +
@@ -589,7 +589,7 @@
- +
diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index cfa25e6a7..2981fd614 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -153,7 +153,11 @@ function displayQso(id) { } // used in edit_ajax.php to update the currently editing QSO -function single_callbook_update(callsign, band, mode) { +function single_callbook_update() { + + var callsign = $('#call').val(); + var band = $('#band').val(); + var mode = $('#mode').val(); $('#update_from_callbook').prop("disabled", true).addClass("running"); From bbaaa190d341bdf07349009a7a44c4e3327fe445 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sat, 6 Jul 2024 15:01:59 +0200 Subject: [PATCH 6/6] id adjustment --- application/views/qso/edit_ajax.php | 6 +++--- assets/js/sections/common.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/application/views/qso/edit_ajax.php b/application/views/qso/edit_ajax.php index a44ddec6c..863e26cd8 100644 --- a/application/views/qso/edit_ajax.php +++ b/application/views/qso/edit_ajax.php @@ -60,7 +60,7 @@
- +
@@ -81,7 +81,7 @@
- $bandgroup) { echo ''; foreach($bandgroup as $band) { @@ -117,7 +117,7 @@
- result() as $mode){ var_dump($mode); diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index 2981fd614..d209f5ab9 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -155,9 +155,9 @@ function displayQso(id) { // used in edit_ajax.php to update the currently editing QSO function single_callbook_update() { - var callsign = $('#call').val(); - var band = $('#band').val(); - var mode = $('#mode').val(); + var callsign = $('#edit_callsign').val(); + var band = $('#edit_band').val(); + var mode = $('#edit_mode').val(); $('#update_from_callbook').prop("disabled", true).addClass("running");