diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 87044478..2b4197e2 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -784,6 +784,26 @@ if ($this->session->userdata('user_id') != null) { }); // Form "submit" // $('.custom-map-QSOs .btn_submit_map_custom').off('click').on('click', function() { + // Show loading spinner and disable button + const $button = $(this); + const $spinner = $('#load-spinner'); + + $button.prop('disabled', true); + $spinner.removeClass('d-none'); + + // Hide any previous alerts + $('.warningOnSubmit').hide(); + $('#map-success-alert').addClass('d-none'); + + // Failsafe timeout to prevent stuck spinner (35 seconds) + const failsafeTimeout = setTimeout(function() { + console.warn('Map loading timed out - forcing spinner hide'); + $button.prop('disabled', false); + $spinner.addClass('d-none'); + $('.warningOnSubmit .warningOnSubmit_txt').text('Map loading timed out. Please try again.'); + $('.warningOnSubmit').show(); + }, 35000); + var customdata = { 'dataPost': { 'date_from': $('.custom-map-QSOs input[name="from"]').val(), @@ -795,6 +815,49 @@ if ($this->session->userdata('user_id') != null) { }, 'map_id': '#custommap' }; + + // Add success and error callbacks to the customdata + customdata.onSuccess = function(plotjson) { + // Clear the failsafe timeout + clearTimeout(failsafeTimeout); + + try { + // Update statistics + if (typeof updateMapStatistics === 'function') { + updateMapStatistics(plotjson); + } + + // Show success message + const qsoCount = plotjson['markers'] ? plotjson['markers'].length : 0; + $('#qso-count-display').text(`Loaded ${qsoCount} QSOs successfully`); + $('#map-success-alert').removeClass('d-none'); + + setTimeout(() => { + $('#map-success-alert').addClass('d-none'); + }, 3000); + } catch (error) { + console.error('Error in success callback:', error); + $('.warningOnSubmit .warningOnSubmit_txt').text('Map loaded but encountered an error displaying statistics.'); + $('.warningOnSubmit').show(); + } finally { + // Always re-enable button and hide spinner + $button.prop('disabled', false); + $spinner.addClass('d-none'); + } + }; + + customdata.onError = function() { + // Clear the failsafe timeout + clearTimeout(failsafeTimeout); + + $('.warningOnSubmit .warningOnSubmit_txt').text('Failed to load map data. Please try again.'); + $('.warningOnSubmit').show(); + + // Re-enable button and hide spinner + $button.prop('disabled', false); + $spinner.addClass('d-none'); + }; + initplot(qso_loc, customdata); }) }); @@ -806,6 +869,10 @@ if ($this->session->userdata('user_id') != null) { success: function(data) { document.getElementById('from').value = data; document.getElementById('to').value = new Date().toISOString().split('T')[0]; + // Update the date range display + if (typeof updateDateRangeDisplay === 'function') { + updateDateRangeDisplay(); + } }, error: function() {}, }); diff --git a/application/views/map/custom_date.php b/application/views/map/custom_date.php index 58c982c7..b0498b24 100644 --- a/application/views/map/custom_date.php +++ b/application/views/map/custom_date.php @@ -1,107 +1,474 @@ + +