[Advanced Logbook] Added dialog to set label offset when printing labels

This commit is contained in:
Andreas 2023-08-01 10:30:05 +02:00
parent f4feaea23b
commit e3789ae1be
4 changed files with 80 additions and 38 deletions

View File

@ -90,10 +90,11 @@ class Labels extends CI_Controller {
public function printids() { public function printids() {
$ids = xss_clean(json_decode($this->input->post('id'))); $ids = xss_clean(json_decode($this->input->post('id')));
$offset = xss_clean($this->input->post('startat'));
$this->load->model('labels_model'); $this->load->model('labels_model');
$result = $this->labels_model->export_printrequestedids($ids); $result = $this->labels_model->export_printrequestedids($ids);
$this->prepareLabel($result, true); $this->prepareLabel($result, true, $offset);
} }
public function print($station_id) { public function print($station_id) {

View File

@ -221,4 +221,8 @@ class Logbookadvanced extends CI_Controller {
header("Content-Type: application/json"); header("Content-Type: application/json");
print json_encode($q); print json_encode($q);
} }
public function startAtLabel() {
$this->load->view('logbookadvanced/startatform');
}
} }

View File

@ -0,0 +1,4 @@
<form method="post" class="form-inline">
<input class="form-control input-group-sm" type="number" id="startat" name="startat" value="1">
<button type="button" id="button1id" name="button1id" class="btn btn-primary ld-ext-right" onclick="printlabel();">Print</button>
</form>

View File

@ -464,49 +464,29 @@ $(document).ready(function () {
} }
$('#printLabel').prop("disabled", true); $('#printLabel').prop("disabled", true);
var id_list=[];
elements.each(function() {
let id = $(this).first().closest('tr').data('qsoID')
id_list.push(id);
});
$.ajax({ $.ajax({
url: base_url + 'index.php/labels/printids', url: base_url + 'index.php/logbookadvanced/startAtLabel',
type: 'post', type: 'post',
data: {'id': JSON.stringify(id_list, null, 2) }, success: function (html) {
xhr:function(){ BootstrapDialog.show({
var xhr = new XMLHttpRequest(); title: 'Start printing at which label?',
xhr.responseType= 'blob' size: BootstrapDialog.SIZE_NORMAL,
return xhr; cssClass: 'qso-dialog',
nl2br: false,
message: html,
onshown: function(dialog) {
}, },
success: function(data) { buttons: [{
if(data){ label: 'Close',
var file = new Blob([data], {type: 'application/pdf'}); action: function (dialogItself) {
var fileURL = URL.createObjectURL(file); dialogItself.close();
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);
},
});
}); });
$('#searchForm').on('reset', function(e) { $('#searchForm').on('reset', function(e) {
@ -591,3 +571,56 @@ $(document).ready(function () {
$('#searchForm').submit(); $('#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);
},
});
}