From 9eee9d9751504f4de14dd5e383ceeab0ad904ca2 Mon Sep 17 00:00:00 2001
From: Andreas <6977712+AndreasK79@users.noreply.github.com>
Date: Fri, 4 Aug 2023 10:00:14 +0200
Subject: [PATCH] [QSLPrint] Fixed js. Added button to mark as sent
---
 application/controllers/Qslprint.php          |   7 +-
 application/views/interface_assets/footer.php | 112 ---------------
 application/views/qslprint/qslprint.php       |   3 +-
 application/views/qslprint/qsolist.php        |  12 ++
 assets/js/sections/qslprint.js                | 128 ++++++++++++++++++
 5 files changed, 148 insertions(+), 114 deletions(-)
 create mode 100644 assets/js/sections/qslprint.js
diff --git a/application/controllers/Qslprint.php b/application/controllers/Qslprint.php
index 4f7f0b23..9c391c1e 100644
--- a/application/controllers/Qslprint.php
+++ b/application/controllers/Qslprint.php
@@ -38,11 +38,16 @@ class QSLPrint extends CI_Controller {
 			$data['qsos'] = $this->qslprint_model->get_qsos_for_print();
 		}
 
+		$footerData = [];
+		$footerData['scripts'] = [
+			'assets/js/sections/qslprint.js',
+		];
+
 		$data['page_title'] = "Print Requested QSLs";
 
 		$this->load->view('interface_assets/header', $data);
 		$this->load->view('qslprint/index');
-		$this->load->view('interface_assets/footer');
+		$this->load->view('interface_assets/footer', $footerData);
 
 	}
 
diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php
index 0c2fcb1d..def9c498 100644
--- a/application/views/interface_assets/footer.php
+++ b/application/views/interface_assets/footer.php
@@ -2808,118 +2808,6 @@ function viewEqsl(picture, callsign) {
 	
 
 
-uri->segment(1) == "qslprint") { ?>
-	
-
-
 uri->segment(1) == "awards") {
 	// Get Date format
 	if($this->session->userdata('user_date_format')) {
diff --git a/application/views/qslprint/qslprint.php b/application/views/qslprint/qslprint.php
index f543733b..7b347030 100644
--- a/application/views/qslprint/qslprint.php
+++ b/application/views/qslprint/qslprint.php
@@ -24,6 +24,7 @@ if ($qsos->result() != NULL) {
 
' . lang('gen_hamradio_qsl') . ' ' . lang('general_word_qslcard_via') . ' | ' . lang('gen_hamradio_station') . ' | Sent method+ | Mark as sent | Delete | QSO List@@ -48,11 +49,11 @@ if ($qsos->result() != NULL) {
 		echo ' | ' . $qsl->COL_QSL_VIA . '';
 		echo ' | ' . $qsl->station_callsign . '';
 		echo ' | '; echo_qsl_sent_via($qsl->COL_QSL_SENT_VIA); echo '';
+		echo ' | ';
 		echo ' | ';
 		echo ' | ';
 		echo '';
 	}
-
 	echo '';
 	?>
 
diff --git a/application/views/qslprint/qsolist.php b/application/views/qslprint/qsolist.php
index 8d6e8109..3cbf6699 100644
--- a/application/views/qslprint/qsolist.php
+++ b/application/views/qslprint/qsolist.php
@@ -9,6 +9,8 @@ if ($qsos->result() != NULL) { | ' . lang('gen_hamradio_mode') . ' | ' . lang('gen_hamradio_band') . ' | ' . lang('gen_hamradio_station') . '+ | ' . lang('gen_hamradio_qsl') . ' ' . lang('general_word_qslcard_via') . '+ | Sent method | QSL';
 	if ($this->session->userdata('user_eqsl_name') != "") {
 		echo ' | eQSL';
@@ -37,6 +39,8 @@ if ($qsos->result() != NULL) {
 		echo ' | '; echo $qsl->COL_SUBMODE==null?$qsl->COL_MODE:$qsl->COL_SUBMODE; echo '';
 		echo ' | '; if($qsl->COL_SAT_NAME != null) { echo $qsl->COL_SAT_NAME; } else { echo strtolower($qsl->COL_BAND); }; echo '';
 		echo ' | ' . $qsl->station_callsign . '';
+		echo ' | ' . $qsl->COL_QSL_VIA . '';
+		echo ' | '; echo_qsl_sent_via($qsl->COL_QSL_SENT_VIA); echo '';
 		echo ' | ';
 		echo 'COL_QSL_SENT != "N") {
@@ -192,4 +196,12 @@ if ($qsos->result() != NULL) {
 } else {
 	echo ' ×';
 }
+
+function echo_qsl_sent_via($method) {
+	switch($method) {
+		case 'B': echo 'Bureau'; break;
+		case 'D': echo 'Direct'; break;
+		case 'E': echo 'Electronic'; break;
+	}
+}
 ?>
diff --git a/assets/js/sections/qslprint.js b/assets/js/sections/qslprint.js
new file mode 100644
index 00000000..a9be815b
--- /dev/null
+++ b/assets/js/sections/qslprint.js
@@ -0,0 +1,128 @@
+function deleteFromQslQueue(id) {
+	BootstrapDialog.confirm({
+		title: 'DANGER',
+		message: 'Warning! Are you sure you want to removes this QSL from the queue?',
+		type: BootstrapDialog.TYPE_DANGER,
+		closable: true,
+		draggable: true,
+		btnOKClass: 'btn-danger',
+		callback: function(result) {
+			$.ajax({
+				url: base_url + 'index.php/qslprint/delete_from_qsl_queue',
+				type: 'post',
+				data: {'id': id	},
+				success: function(html) {
+					$("#qslprint_"+id).remove();
+				}
+			});
+		}
+	});
+}
+
+function openQsoList(callsign) {
+	$.ajax({
+		url: base_url + 'index.php/qslprint/open_qso_list',
+		type: 'post',
+		data: {'callsign': callsign},
+		success: function(html) {
+			BootstrapDialog.show({
+				title: 'QSO List',
+				size: BootstrapDialog.SIZE_WIDE,
+				cssClass: 'qso-dialog',
+				nl2br: false,
+				message: html,
+				onshown: function(dialog) {
+					$('[data-toggle="tooltip"]').tooltip();
+				},
+				buttons: [{
+					label: 'Close',
+					action: function (dialogItself) {
+						dialogItself.close();
+					}
+				}]
+			});
+		}
+	});
+}
+
+function addQsoToPrintQueue(id) {
+	$.ajax({
+		url: base_url + 'index.php/qslprint/add_qso_to_print_queue',
+		type: 'post',
+		data: {'id': id},
+		success: function(html) {
+			var line = 'No additional QSO\'s were found. That means they are probably already in the queue. ';
+			line += '';
+			$('.table tr:last').after(line);
+			$("#qsolist_"+id).remove();''
+		}
+	});
+}
+
+$(".station_id").change(function(){
+	var station_id = $(".station_id").val();
+	$.ajax({
+		url: base_url + 'index.php/qslprint/get_qsos_for_print_ajax',
+		type: 'post',
+		data: {'station_id': station_id},
+		success: function(html) {
+			$('.resulttable').empty();
+			$('.resulttable').append(html);
+		}
+	});
+});
+
+function showOqrs(id) {
+	$.ajax({
+		url: base_url + 'index.php/qslprint/show_oqrs',
+		type: 'post',
+		data: {'id': id},
+		success: function(html) {
+			BootstrapDialog.show({
+				title: 'OQRS',
+				size: BootstrapDialog.SIZE_WIDE,
+				cssClass: 'qso-dialog',
+				nl2br: false,
+				message: html,
+				onshown: function(dialog) {
+					$('[data-toggle="tooltip"]').tooltip();
+				},
+				buttons: [{
+					label: 'Close',
+					action: function (dialogItself) {
+						dialogItself.close();
+					}
+				}]
+			});
+		}
+	});
+}
+
+function mark_qsl_sent(id, method) {
+    $.ajax({
+        url: base_url + 'index.php/qso/qsl_sent_ajax',
+        type: 'post',
+        data: {'id': id,
+            'method': method
+        },
+        success: function(data) {
+            if (data.message == 'OK') {
+                $("#qslprint_" + id).remove(); // removes choice from menu
+            }
+            else {
+                $(".container").append('| '+$("#qsolist_"+id).find("td:eq(0)").text()+'';
+			line += ' | '+$("#qsolist_"+id).find("td:eq(1)").text()+'';
+			line += ' | '+$("#qsolist_"+id).find("td:eq(2)").text()+'';
+			line += ' | '+$("#qsolist_"+id).find("td:eq(3)").text()+'';
+			line += ' | '+$("#qsolist_"+id).find("td:eq(4)").text()+'';
+			line += ' | '+$("#qsolist_"+id).find("td:eq(6)").text()+'';
+			line += ' | '+$("#qsolist_"+id).find("td:eq(5)").text()+'';
+			line += ' | '+$("#qsolist_"+id).find("td:eq(7)").text()+'';
+			line += ' | ';
+			line += ' | ';
+			line += ' | ';
+			line += ' |  ×');
+            }
+        }
+    });
+}You are not allowed to update QSL status! |