@@ -111,6 +111,7 @@ $("#qso_input").off('submit').on('submit', function (e) {
111
111
url : base_url + 'index.php/qso' + manual_addon ,
112
112
method : 'POST' ,
113
113
type : 'post' ,
114
+ timeout : 10000 ,
114
115
data : $ ( this ) . serialize ( ) ,
115
116
success : function ( resdata ) {
116
117
result = JSON . parse ( resdata ) ;
@@ -122,14 +123,9 @@ $("#qso_input").off('submit').on('submit', function (e) {
122
123
$ ( "#noticer" ) . addClass ( "alert alert-info" ) ;
123
124
$ ( "#noticer" ) . html ( "QSO Added" ) ;
124
125
$ ( "#noticer" ) . show ( ) ;
125
- reset_fields ( ) ;
126
- htmx . trigger ( "#qso-last-table" , "qso_event" )
127
- $ ( "#saveQso" ) . html ( saveQsoButtonText ) . prop ( "disabled" , false ) ;
128
- $ ( "#callsign" ) . val ( "" ) ;
126
+ prepare_next_qso ( saveQsoButtonText ) ;
129
127
$ ( "#noticer" ) . fadeOut ( 2000 ) ;
130
- var triggerEl = document . querySelector ( '#myTab a[href="#qso"]' )
131
- bootstrap . Tab . getInstance ( triggerEl ) . show ( ) // Select tab by name
132
- $ ( "#callsign" ) . trigger ( "focus" ) ;
128
+ processBacklog ( ) ; // If we have success with the live-QSO, we could also process the backlog
133
129
} else {
134
130
$ ( "#noticer" ) . removeClass ( "" ) ;
135
131
$ ( "#noticer" ) . addClass ( "alert alert-warning" ) ;
@@ -139,17 +135,69 @@ $("#qso_input").off('submit').on('submit', function (e) {
139
135
}
140
136
} ,
141
137
error : function ( ) {
138
+ saveToBacklog ( JSON . stringify ( this . data ) , manual_addon ) ;
139
+ prepare_next_qso ( saveQsoButtonText ) ;
142
140
$ ( "#noticer" ) . removeClass ( "" ) ;
143
- $ ( "#noticer" ) . addClass ( "alert alert-warning " ) ;
144
- $ ( "#noticer" ) . html ( "Timeout while adding QSO. NOT added " ) ;
141
+ $ ( "#noticer" ) . addClass ( "alert alert-info " ) ;
142
+ $ ( "#noticer" ) . html ( "QSO Added to Backlog " ) ;
145
143
$ ( "#noticer" ) . show ( ) ;
146
- $ ( "#saveQso " ) . html ( saveQsoButtonText ) . prop ( "disabled" , false ) ;
144
+ $ ( "#noticer " ) . fadeOut ( 5000 ) ;
147
145
}
148
146
} ) ;
149
147
}
150
148
return false ;
151
149
} ) ;
152
150
151
+ function prepare_next_qso ( saveQsoButtonText ) {
152
+ reset_fields ( ) ;
153
+ htmx . trigger ( "#qso-last-table" , "qso_event" )
154
+ $ ( "#saveQso" ) . html ( saveQsoButtonText ) . prop ( "disabled" , false ) ;
155
+ $ ( "#callsign" ) . val ( "" ) ;
156
+ var triggerEl = document . querySelector ( '#myTab a[href="#qso"]' )
157
+ bootstrap . Tab . getInstance ( triggerEl ) . show ( ) // Select tab by name
158
+ $ ( "#callsign" ) . trigger ( "focus" ) ;
159
+ }
160
+
161
+ var processingBL = false ;
162
+
163
+ async function processBacklog ( ) {
164
+ if ( ! processingBL ) {
165
+ processingBL = true ;
166
+ const Qsobacklog = JSON . parse ( localStorage . getItem ( 'qso-backlog' ) ) || [ ] ;
167
+ for ( const entry of [ ...Qsobacklog ] ) {
168
+ try {
169
+ await $ . ajax ( { url : base_url + 'index.php/qso' + entry . manual_addon , method : 'POST' , type : 'post' , data : JSON . parse ( entry . data ) ,
170
+ success : function ( resdata ) {
171
+ Qsobacklog . splice ( Qsobacklog . findIndex ( e => e . id === entry . id ) , 1 ) ;
172
+ } ,
173
+ error : function ( ) {
174
+ entry . attempts ++ ;
175
+ } } ) ;
176
+ } catch ( error ) {
177
+ entry . attempts ++ ;
178
+ }
179
+ }
180
+ localStorage . setItem ( 'qso-backlog' , JSON . stringify ( Qsobacklog ) ) ;
181
+ processingBL = false ;
182
+ }
183
+ }
184
+
185
+ function saveToBacklog ( formData , manual_addon ) {
186
+ const backlog = JSON . parse ( localStorage . getItem ( 'qso-backlog' ) ) || [ ] ;
187
+ const entry = {
188
+ id : Date . now ( ) ,
189
+ timestamp : new Date ( ) . toISOString ( ) ,
190
+ data : formData ,
191
+ manual_addon : manual_addon ,
192
+ attempts : 0
193
+ } ;
194
+ backlog . push ( entry ) ;
195
+ localStorage . setItem ( 'qso-backlog' , JSON . stringify ( backlog ) ) ;
196
+ }
197
+
198
+ window . addEventListener ( 'beforeunload' , processBacklog ( ) ) ; // process possible QSO-Backlog on unload of page
199
+ window . addEventListener ( 'pagehide' , processBacklog ( ) ) ; // process possible QSO-Backlog on Hide of page (Mobile-Browsers)
200
+
153
201
$ ( '#reset_time' ) . on ( "click" , function ( ) {
154
202
var now = new Date ( ) ;
155
203
$ ( '#start_time' ) . attr ( 'value' , ( "0" + now . getUTCHours ( ) ) . slice ( - 2 ) + ':' + ( "0" + now . getUTCMinutes ( ) ) . slice ( - 2 ) + ':' + ( "0" + now . getUTCSeconds ( ) ) . slice ( - 2 ) ) ;
@@ -1855,14 +1903,20 @@ $(document).ready(function () {
1855
1903
set_timers ( ) ;
1856
1904
updateStateDropdown ( '#dxcc_id' , '#stateInputLabel' , '#location_us_county' , '#stationCntyInputQso' ) ;
1857
1905
1858
- // Clear the localStorage for the qrg units, except the quicklogCallsign
1906
+ // Clear the localStorage for the qrg units, except the quicklogCallsign and a possible backlog
1859
1907
let quicklogCallsign = localStorage . getItem ( 'quicklogCallsign' ) ;
1908
+ let QsoBacklog = localStorage . getItem ( 'qso-backlog' ) ;
1909
+
1860
1910
localStorage . clear ( ) ;
1861
1911
if ( quicklogCallsign ) {
1862
1912
localStorage . setItem ( 'quicklogCallsign' , quicklogCallsign ) ;
1863
1913
}
1864
1914
set_qrg ( ) ;
1865
1915
1916
+ if ( QsoBacklog ) {
1917
+ localStorage . setItem ( 'qso-backlog' , QsoBacklog ) ;
1918
+ }
1919
+
1866
1920
$ ( "#locator" ) . popover ( { placement : 'top' , title : 'Gridsquare Formatting' , content : "Enter multiple (4-digit) grids separated with commas. For example: IO77,IO78" } )
1867
1921
. focus ( function ( ) {
1868
1922
$ ( '#locator' ) . popover ( 'show' ) ;
0 commit comments