2023-08-04 16:00:14 +08:00
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 ) {
2023-11-26 17:00:47 +08:00
$ ( '[data-bs-toggle="tooltip"]' ) . tooltip ( ) ;
2023-08-04 16:00:14 +08:00
} ,
buttons : [ {
2023-11-06 02:38:34 +08:00
label : lang _admin _close ,
2023-08-04 16:00:14 +08:00
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 = '<tr id="qslprint_' + id + '">' ;
line += '<td style=\'text-align: center\'>' + $ ( "#qsolist_" + id ) . find ( "td:eq(0)" ) . text ( ) + '</td>' ;
line += '<td style=\'text-align: center\'>' + $ ( "#qsolist_" + id ) . find ( "td:eq(1)" ) . text ( ) + '</td>' ;
line += '<td style=\'text-align: center\'>' + $ ( "#qsolist_" + id ) . find ( "td:eq(2)" ) . text ( ) + '</td>' ;
line += '<td style=\'text-align: center\'>' + $ ( "#qsolist_" + id ) . find ( "td:eq(3)" ) . text ( ) + '</td>' ;
line += '<td style=\'text-align: center\'>' + $ ( "#qsolist_" + id ) . find ( "td:eq(4)" ) . text ( ) + '</td>' ;
line += '<td style=\'text-align: center\'>' + $ ( "#qsolist_" + id ) . find ( "td:eq(6)" ) . text ( ) + '</td>' ;
2023-11-15 01:00:22 +08:00
line += '<td style=\'text-align: center\'><span class="badge text-bg-light">' + $ ( "#qsolist_" + id ) . find ( "td:eq(5)" ) . text ( ) + '</span></td>' ;
2023-08-04 16:00:14 +08:00
line += '<td style=\'text-align: center\'>' + $ ( "#qsolist_" + id ) . find ( "td:eq(7)" ) . text ( ) + '</td>' ;
line += '<td style=\'text-align: center\'><button onclick="mark_qsl_sent(' + id + ', \'B\')" class="btn btn-sm btn-success"><i class="fa fa-check"></i></button></td>' ;
line += '<td style=\'text-align: center\'><button onclick="deleteFromQslQueue(' + id + ')" class="btn btn-sm btn-danger"><i class="fas fa-trash-alt"></i></button></td></td>' ;
line += '<td style=\'text-align: center\'><button onclick="openQsoList(\'' + $ ( "#qsolist_" + id ) . find ( "td:eq(0)" ) . text ( ) + '\')" class="btn btn-sm btn-success"><i class="fas fa-search"></i></button></td>' ;
line += '</tr>' ;
$ ( '.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 ) {
2025-07-30 23:09:35 +08:00
// Destroy existing DataTable if it exists
if ( $ . fn . DataTable . isDataTable ( '#qslprint_table' ) ) {
$ ( '#qslprint_table' ) . DataTable ( ) . destroy ( ) ;
}
2023-08-04 16:00:14 +08:00
$ ( '.resulttable' ) . empty ( ) ;
$ ( '.resulttable' ) . append ( html ) ;
2025-07-30 23:09:35 +08:00
// Reinitialize DataTable
$ ( '#qslprint_table' ) . DataTable ( {
"stateSave" : true ,
paging : false ,
"language" : {
url : getDataTablesLanguageUrl ( ) ,
2025-07-31 00:30:05 +08:00
} ,
"drawCallback" : function ( settings ) {
// Re-attach event handlers after DataTable draws/redraws
attachCheckboxEvents ( ) ;
2025-07-30 23:09:35 +08:00
}
} ) ;
2025-07-31 00:30:05 +08:00
// Attach checkbox events immediately after initialization
attachCheckboxEvents ( ) ;
2023-08-04 16:00:14 +08:00
}
} ) ;
} ) ;
2025-07-31 00:30:05 +08:00
// Initialize DataTable only if it exists and isn't already initialized
$ ( document ) . ready ( function ( ) {
if ( $ ( '#qslprint_table' ) . length && ! $ . fn . DataTable . isDataTable ( '#qslprint_table' ) ) {
$ ( '#qslprint_table' ) . DataTable ( {
"stateSave" : true ,
paging : false ,
"language" : {
url : getDataTablesLanguageUrl ( ) ,
} ,
"drawCallback" : function ( settings ) {
// Re-attach event handlers after DataTable draws/redraws
attachCheckboxEvents ( ) ;
}
} ) ;
2024-01-04 11:03:11 +08:00
}
2025-07-31 00:30:05 +08:00
// Initial attachment of events
attachCheckboxEvents ( ) ;
2023-12-17 17:45:14 +08:00
} ) ;
2025-07-31 00:30:05 +08:00
// Function to attach checkbox events
function attachCheckboxEvents ( ) {
// Remove any existing handlers to prevent duplicates
$ ( '#checkBoxAll' ) . off ( 'change.qslprint' ) ;
$ ( '.qso-checkbox' ) . off ( 'click.qslprint' ) ;
// Attach select all functionality
$ ( '#checkBoxAll' ) . on ( 'change.qslprint' , function ( event ) {
var isChecked = this . checked ;
$ ( '#qslprint_table tbody tr .qso-checkbox' ) . each ( function ( i ) {
$ ( this ) . prop ( "checked" , isChecked ) ;
if ( isChecked ) {
$ ( this ) . closest ( 'tr' ) . addClass ( 'activeRow' ) ;
} else {
$ ( this ) . closest ( 'tr' ) . removeClass ( 'activeRow' ) ;
}
} ) ;
} ) ;
// Attach individual checkbox functionality
$ ( document ) . on ( 'click.qslprint' , '.qso-checkbox' , function ( ) {
if ( $ ( this ) . is ( ":checked" ) ) {
$ ( this ) . closest ( 'tr' ) . addClass ( 'activeRow' ) ;
} else {
$ ( this ) . closest ( 'tr' ) . removeClass ( 'activeRow' ) ;
}
// Update the "select all" checkbox state
var totalCheckboxes = $ ( '#qslprint_table tbody tr .qso-checkbox' ) . length ;
var checkedCheckboxes = $ ( '#qslprint_table tbody tr .qso-checkbox:checked' ) . length ;
$ ( '#checkBoxAll' ) . prop ( 'checked' , totalCheckboxes === checkedCheckboxes ) ;
} ) ;
}
2023-08-04 16:00:14 +08:00
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 ) {
2023-11-26 17:00:47 +08:00
$ ( '[data-bs-toggle="tooltip"]' ) . tooltip ( ) ;
2023-08-04 16:00:14 +08:00
} ,
buttons : [ {
2023-11-06 02:38:34 +08:00
label : lang _admin _close ,
2023-08-04 16:00:14 +08:00
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 ,
2023-12-14 16:05:16 +08:00
'method' : method
2023-08-04 16:00:14 +08:00
} ,
success : function ( data ) {
if ( data . message == 'OK' ) {
$ ( "#qslprint_" + id ) . remove ( ) ; // removes choice from menu
}
else {
$ ( ".container" ) . append ( '<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>You are not allowed to update QSL status!</div>' ) ;
}
}
} ) ;
}
2023-08-11 03:33:33 +08:00
function markSelectedQsos ( ) {
2025-07-31 00:06:13 +08:00
var elements = $ ( '.qso-checkbox:checked' ) ;
2023-08-11 03:33:33 +08:00
var nElements = elements . length ;
if ( nElements == 0 ) {
return ;
}
$ ( '.markallprinted' ) . prop ( "disabled" , true ) ;
var id _list = [ ] ;
elements . each ( function ( ) {
let id = $ ( this ) . first ( ) . closest ( 'tr' ) . attr ( 'id' ) ;
id = id . match ( /\d/g ) ;
id = id . join ( "" ) ;
id _list . push ( id ) ;
} ) ;
$ . ajax ( {
url : base _url + 'index.php/logbookadvanced/update_qsl' ,
type : 'post' ,
data : { 'id' : JSON . stringify ( id _list , null , 2 ) ,
'sent' : 'Y' ,
2023-12-14 15:44:58 +08:00
'method' : ''
2023-08-11 03:33:33 +08:00
} ,
success : function ( data ) {
2025-07-31 00:30:05 +08:00
if ( data && data . length > 0 ) {
2023-08-11 03:33:33 +08:00
$ . each ( data , function ( k , v ) {
$ ( "#qslprint_" + this . qsoID ) . remove ( ) ;
} ) ;
}
$ ( '.markallprinted' ) . prop ( "disabled" , false ) ;
}
} ) ;
}
function removeSelectedQsos ( ) {
2025-07-31 00:06:13 +08:00
var elements = $ ( '.qso-checkbox:checked' ) ;
2023-08-11 03:33:33 +08:00
var nElements = elements . length ;
if ( nElements == 0 ) {
return ;
}
$ ( '.removeall' ) . prop ( "disabled" , true ) ;
var id _list = [ ] ;
elements . each ( function ( ) {
let id = $ ( this ) . first ( ) . closest ( 'tr' ) . attr ( 'id' ) ;
id = id . match ( /\d/g ) ;
id = id . join ( "" ) ;
id _list . push ( id ) ;
} ) ;
$ . ajax ( {
url : base _url + 'index.php/logbookadvanced/update_qsl' ,
type : 'post' ,
data : { 'id' : JSON . stringify ( id _list , null , 2 ) ,
'sent' : 'N' ,
'method' : ''
} ,
success : function ( data ) {
2025-07-31 00:30:05 +08:00
if ( data && data . length > 0 ) {
2023-08-11 03:33:33 +08:00
$ . each ( data , function ( k , v ) {
$ ( "#qslprint_" + this . qsoID ) . remove ( ) ;
} ) ;
}
$ ( '.removeall' ) . prop ( "disabled" , false ) ;
}
} ) ;
}