diff --git a/assets/js/sections/contesting.js b/assets/js/sections/contesting.js index 9675cbcb..1b820aa9 100644 --- a/assets/js/sections/contesting.js +++ b/assets/js/sections/contesting.js @@ -1,8 +1,10 @@ // Callsign always has focus on load $("#callsign").focus(); -$(document).ready(function () { - getSession().done(restoreContestSession); +var sessiondata={}; +$(document).ready(async function () { + sessiondata=await getSession(); // save sessiondata global (we need it later, when adding qso) + await restoreContestSession(sessiondata); // wait for restoring until finished setRst($("#mode").val()); }); @@ -435,8 +437,6 @@ function logQso() { vuccr, ]]; - table.rows.add(data).draw(); - var formdata = new FormData(document.getElementById("qso_input")); $.ajax({ url: base_url + 'index.php/qso/saveqso', @@ -445,7 +445,7 @@ function logQso() { processData: false, contentType: false, enctype: 'multipart/form-data', - success: function (html) { + success: async function (html) { var exchangetype = $("#exchangetype").val(); if (exchangetype == "Serial" || exchangetype == 'Serialexchange' || exchangetype == 'Serialgridsquare') { $("#exch_serial_s").val(+$("#exch_serial_s").val() + 1); @@ -462,6 +462,7 @@ function logQso() { $("#callsign").focus(); setSession(formdata); + await refresh_qso_table(sessiondata); var qTable = $('.qsotable').DataTable(); qTable.search('').order([0, 'desc']).draw(); @@ -470,14 +471,14 @@ function logQso() { } } -function getSession() { - return $.ajax({ +async function getSession() { + return await $.ajax({ url: base_url + 'index.php/contesting/getSession', type: 'post', }); } -function restoreContestSession(data) { +async function restoreContestSession(data) { if (data) { if (data.copytodok == "1") { $('#copyexchangetodok').prop('checked', true); @@ -498,70 +499,74 @@ function restoreContestSession(data) { } if (data.qso != "") { - $.ajax({ - url: base_url + 'index.php/contesting/getSessionQsos', - type: 'post', - data: { 'qso': data.qso, }, - success: function (html) { - var mode = ''; - - $.each(html, function () { - if (this.col_submode == null || this.col_submode == '') { - mode = this.col_mode; - } else { - mode = this.col_submode; - } - - $(".qsotable tbody").prepend('' + - '' + this.col_time_on + '' + - '' + this.col_call + '' + - '' + this.col_band + '' + - '' + mode + '' + - '' + this.col_rst_sent + '' + - '' + this.col_rst_rcvd + '' + - '' + this.col_stx_string + '' + - '' + this.col_srx_string + '' + - '' + this.col_stx + '' + - '' + this.col_srx + '' + - '' + this.col_gridsquare + '' + - '' + this.col_vucc_grids + '' + - ''); - }); - if (!$.fn.DataTable.isDataTable('.qsotable')) { - $.fn.dataTable.moment('DD-MM-YYYY HH:mm:ss'); - $('.qsotable').DataTable({ - "stateSave": true, - "pageLength": 25, - responsive: false, - "scrollY": "400px", - "scrollCollapse": true, - "paging": false, - "scrollX": true, - order: [0, 'desc'], - "columnDefs": [ - { - "render": function ( data, type, row ) { - return pad(row[8],3); - }, - "targets" : 8 - }, - { - "render": function ( data, type, row ) { - return pad(row[9],3); - }, - "targets" : 9 - } - ] - }); - } - } - }); + await refresh_qso_table(data); } } else { $("#exch_serial_s").val("1"); } } +async function refresh_qso_table(data) { + $.ajax({ + url: base_url + 'index.php/contesting/getSessionQsos', + type: 'post', + data: { 'qso': data.qso, }, + success: function (html) { + var mode = ''; + $(".contest_qso_table_contents").empty(); + $.each(html, function () { + if (this.col_submode == null || this.col_submode == '') { + mode = this.col_mode; + } else { + mode = this.col_submode; + } + + $(".qsotable tbody").prepend('' + + '' + this.col_time_on + '' + + '' + this.col_call + '' + + '' + this.col_band + '' + + '' + mode + '' + + '' + this.col_rst_sent + '' + + '' + this.col_rst_rcvd + '' + + '' + this.col_stx_string + '' + + '' + this.col_srx_string + '' + + '' + this.col_stx + '' + + '' + this.col_srx + '' + + '' + this.col_gridsquare + '' + + '' + this.col_vucc_grids + '' + + ''); + }); + if (!$.fn.DataTable.isDataTable('.qsotable')) { + $.fn.dataTable.moment('DD-MM-YYYY HH:mm:ss'); + $('.qsotable').DataTable({ + "stateSave": true, + "pageLength": 25, + responsive: false, + "scrollY": "400px", + "scrollCollapse": true, + "paging": false, + "scrollX": true, + order: [0, 'desc'], + "columnDefs": [ + { + "render": function ( data, type, row ) { + return pad(row[8],3); + }, + "targets" : 8 + }, + { + "render": function ( data, type, row ) { + return pad(row[9],3); + }, + "targets" : 9 + } + ] + }); + } + } + }); +} + function pad (str, max) { str = str.toString(); return str.length < max ? pad("0" + str, max) : str;