From e3789ae1be0b99913c1f520731c50ff3ec561021 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 1 Aug 2023 10:30:05 +0200 Subject: [PATCH] [Advanced Logbook] Added dialog to set label offset when printing labels --- application/controllers/Labels.php | 3 +- application/controllers/Logbookadvanced.php | 4 + .../views/logbookadvanced/startatform.php | 4 + assets/js/sections/logbookadvanced.js | 107 ++++++++++++------ 4 files changed, 80 insertions(+), 38 deletions(-) create mode 100644 application/views/logbookadvanced/startatform.php diff --git a/application/controllers/Labels.php b/application/controllers/Labels.php index b995ff7b..ef12376b 100644 --- a/application/controllers/Labels.php +++ b/application/controllers/Labels.php @@ -90,10 +90,11 @@ class Labels extends CI_Controller { public function printids() { $ids = xss_clean(json_decode($this->input->post('id'))); + $offset = xss_clean($this->input->post('startat')); $this->load->model('labels_model'); $result = $this->labels_model->export_printrequestedids($ids); - $this->prepareLabel($result, true); + $this->prepareLabel($result, true, $offset); } public function print($station_id) { diff --git a/application/controllers/Logbookadvanced.php b/application/controllers/Logbookadvanced.php index 384889f3..8b7f0cf8 100644 --- a/application/controllers/Logbookadvanced.php +++ b/application/controllers/Logbookadvanced.php @@ -221,4 +221,8 @@ class Logbookadvanced extends CI_Controller { header("Content-Type: application/json"); print json_encode($q); } + + public function startAtLabel() { + $this->load->view('logbookadvanced/startatform'); + } } diff --git a/application/views/logbookadvanced/startatform.php b/application/views/logbookadvanced/startatform.php new file mode 100644 index 00000000..74fe356b --- /dev/null +++ b/application/views/logbookadvanced/startatform.php @@ -0,0 +1,4 @@ +
diff --git a/assets/js/sections/logbookadvanced.js b/assets/js/sections/logbookadvanced.js index 5a639c5b..e939c4e3 100644 --- a/assets/js/sections/logbookadvanced.js +++ b/assets/js/sections/logbookadvanced.js @@ -464,48 +464,28 @@ $(document).ready(function () { } $('#printLabel').prop("disabled", true); - var id_list=[]; - elements.each(function() { - let id = $(this).first().closest('tr').data('qsoID') - id_list.push(id); - }); $.ajax({ - url: base_url + 'index.php/labels/printids', + url: base_url + 'index.php/logbookadvanced/startAtLabel', type: 'post', - data: {'id': JSON.stringify(id_list, null, 2) }, - xhr:function(){ - var xhr = new XMLHttpRequest(); - xhr.responseType= 'blob' - return xhr; - }, - success: function(data) { - if(data){ - var file = new Blob([data], {type: 'application/pdf'}); - var fileURL = URL.createObjectURL(file); - window.open(fileURL); - } - $.each(id_list, function(k, v) { - unselectQsoID(this); + success: function (html) { + BootstrapDialog.show({ + title: 'Start printing at which label?', + size: BootstrapDialog.SIZE_NORMAL, + cssClass: 'qso-dialog', + nl2br: false, + message: html, + onshown: function(dialog) { + }, + buttons: [{ + label: 'Close', + action: function (dialogItself) { + dialogItself.close(); + } + }] }); - $('#printLabel').prop("disabled", false); - }, - error: function (data) { - BootstrapDialog.alert({ - title: 'ERROR', - message: 'Something went wrong with label print. Go to labels and check if you have defined a label, and that it is set for print!', - type: BootstrapDialog.TYPE_DANGER, - closable: false, - draggable: false, - callback: function (result) { - } - }); - $.each(id_list, function(k, v) { - unselectQsoID(this); - }); - $('#printLabel').prop("disabled", false); - }, + } }); }); @@ -591,3 +571,56 @@ $(document).ready(function () { $('#searchForm').submit(); }); + +function printlabel() { + var id_list=[]; + var elements = $('#qsoList tbody input:checked'); + var nElements = elements.length; + + elements.each(function() { + let id = $(this).first().closest('tr').data('qsoID') + id_list.push(id); + }); + $.ajax({ + url: base_url + 'index.php/labels/printids', + type: 'post', + data: {'id': JSON.stringify(id_list, null, 2), + 'startat': $('#startat').val() + }, + xhr:function(){ + var xhr = new XMLHttpRequest(); + xhr.responseType= 'blob' + return xhr; + }, + success: function(data) { + $.each(BootstrapDialog.dialogs, function(id, dialog){ + dialog.close(); + }); + if(data){ + var file = new Blob([data], {type: 'application/pdf'}); + var fileURL = URL.createObjectURL(file); + window.open(fileURL); + } + $.each(id_list, function(k, v) { + unselectQsoID(this); + }); + $('#printLabel').prop("disabled", false); + }, + error: function (data) { + BootstrapDialog.alert({ + title: 'ERROR', + message: 'Something went wrong with label print. Go to labels and check if you have defined a label, and that it is set for print!', + type: BootstrapDialog.TYPE_DANGER, + closable: false, + draggable: false, + callback: function (result) { + } + }); + $.each(id_list, function(k, v) { + unselectQsoID(this); + }); + $('#printLabel').prop("disabled", false); + }, + }); +} +