$(function() { function SortByQrg(a, b){ var a = a.frequency; var b = b.frequency; return ((a< b) ? -1 : ((a> b) ? 1 : 0)); } function get_dtable () { var table = $('.spottable').DataTable({ "retrieve":true, 'columnDefs': [ { 'targets': 1, "type":"num", 'createdCell': function (td, cellData, rowData, row, col) { $(td).addClass("kHz"); } }, { 'targets': 2, 'createdCell': function (td, cellData, rowData, row, col) { $(td).addClass("spotted_call"); $(td).attr( "title", "Click to prepare logging" ); } } ], "language": { url: getDataTablesLanguageUrl(), } }); return table; } function fill_list(band,de,maxAgeMinutes) { // var table = $('.spottable').DataTable(); var table = get_dtable(); if ((band != '') && (band !== undefined)) { let dxurl = dxcluster_provider + "/spots/" + band + "/" +maxAgeMinutes + "/" + de; $.ajax({ url: dxurl, cache: false, dataType: "json" }).done(function(dxspots) { table.page.len(50); let oldtable=table.data(); table.clear(); if (dxspots.length>0) { dxspots.sort(SortByQrg); dxspots.forEach((single) => { var data=[]; if (single.cnfmd_call) { addon_class="text-success"; } else if (single.worked_call) { addon_class="text-warning"; } else { addon_class=""; } data[0]=[]; data[0].push(single.when_pretty); data[0].push(single.frequency*1); data[0].push((addon_class != '' ?'' : '')+single.spotted+(addon_class != '' ? '' : '')); data[0].push(single.dxcc_spotted.entity); data[0].push(single.spotter); if (oldtable.length > 0) { let update=false; oldtable.each( function (srow) { if (JSON.stringify(srow) === JSON.stringify(data[0])) { update=true; } }); if (!update) { // Sth. Fresh? So highlight table.rows.add(data).draw().nodes().to$().addClass("fresh table-info"); } else { table.rows.add(data).draw(); } } else { table.rows.add(data).draw(); } }); setTimeout(function(){ // Remove Highlights within 15sec $(".fresh").removeClass("bg-info"); },1000); } }); } else { table.clear(); table.draw(); } } function highlight_current_qrg(qrg) { var table=get_dtable(); // var table=$('.spottable').DataTable(); table.rows().every(function() { var d=this.data(); var distance=Math.abs(parseInt(d[1])-qrg); if (distance<=20) { distance++; alpha=(.5/distance); this.nodes().to$().css('--bs-table-bg', 'rgba(0,0,255,' + alpha + ')'); this.nodes().to$().css('--bs-table-accent-bg', 'rgba(0,0,255,' + alpha + ')'); } else { this.nodes().to$().css('--bs-table-bg', ''); this.nodes().to$().css('--bs-table-accent-bg', ''); } }); } var table=get_dtable(); table.order([1, 'asc']); table.clear(); fill_list($('#band option:selected').val(), $('#decontSelect option:selected').val(),dxcluster_maxage); setInterval(function () { fill_list($('#band option:selected').val(), $('#decontSelect option:selected').val(),dxcluster_maxage); },60000); $("#decontSelect").on("change",function() { table.clear(); fill_list($('#band option:selected').val(), $('#decontSelect option:selected').val(),dxcluster_maxage); }); $("#band").on("change",function() { table.clear(); fill_list($('#band option:selected').val(), $('#decontSelect option:selected').val(),dxcluster_maxage); }); $("#spottertoggle").on("click", function() { if (table.column(4).visible()) { table.column(4).visible(false); } else { table.column(4).visible(true); } }); var qso_window_last_seen=Date.now()-3600; var bc_qsowin = new BroadcastChannel('qso_window'); bc_qsowin.onmessage = function (ev) { if (ev.data == 'pong') { qso_window_last_seen=Date.now(); } }; setInterval(function () { bc_qsowin.postMessage('ping') },500); var bc2qso = new BroadcastChannel('qso_wish'); $(document).on('click','.spotted_call', function() { if (Date.now()-qso_window_last_seen < 2000) { bc2qso.postMessage({ frequency: this.parentNode.cells[1].textContent*1000, call: this.innerText }); } else { let cl={}; cl.qrg=this.parentNode.cells[1].textContent*1000; cl.call=this.innerText; window.open(base_url + 'index.php/qso?manual=0','_blank'); setTimeout(function () { bc2qso.postMessage({ frequency: cl.qrg, call: cl.call }) },2500); // Wait at least 2500ms for new-Window to appear, before posting data to it } }); $("#menutoggle").on("click", function() { if ($('.navbar').is(":hidden")) { $('.navbar').show(); $('#dxtabs').show(); $('#dxtitle').show(); $('#menutoggle_i').removeClass('fa-arrow-down'); $('#menutoggle_i').addClass('fa-arrow-up'); } else { $('.navbar').hide(); $('#dxtabs').hide(); $('#dxtitle').hide(); $('#menutoggle_i').removeClass('fa-arrow-up'); $('#menutoggle_i').addClass('fa-arrow-down'); } }); var updateFromCAT = function() { if($('select.radios option:selected').val() != '0') { radioID = $('select.radios option:selected').val(); $.getJSON( base_url+"index.php/radio/json/" + radioID, function( data ) { if (data.error) { if (data.error == 'not_logged_in') { $(".radio_cat_state" ).remove(); if($('.radio_login_error').length == 0) { $('.messages').prepend('