From b8d6b76b306ac372eec5ad3c1779262716dc0a76 Mon Sep 17 00:00:00 2001 From: Eric Gullickson <16152721+ericgullickson@users.noreply.github.com> Date: Sun, 27 Jul 2025 21:26:41 -0500 Subject: [PATCH] Mobile enhancements --- wwwroot/js/gasrecord.js | 80 +++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/wwwroot/js/gasrecord.js b/wwwroot/js/gasrecord.js index f564da9..f811b0a 100644 --- a/wwwroot/js/gasrecord.js +++ b/wwwroot/js/gasrecord.js @@ -1,31 +1,67 @@ // Initialize gas record modal for mobile (using shared mobile framework) function initializeGasRecordMobile() { - initMobileModal({ - modalId: '#gasRecordModal', - dateInputId: '#gasRecordDate', - tagSelectorId: '#gasRecordTag', - modeToggleId: '#fuelEntryModeToggle', - simpleModeDefault: true - }); - - // Handle desktop initialization - if (!isMobileDevice()) { - initDatePicker($('#gasRecordDate')); - initTagSelector($("#gasRecordTag")); + try { + console.log('Initializing gas record mobile - isMobile:', typeof isMobileDevice === 'function' ? isMobileDevice() : 'function not found'); + + if (typeof initMobileModal === 'function') { + initMobileModal({ + modalId: '#gasRecordModal', + dateInputId: '#gasRecordDate', + tagSelectorId: '#gasRecordTag', + modeToggleId: '#fuelEntryModeToggle', + simpleModeDefault: true + }); + } else { + console.error('initMobileModal function not found'); + } + + // Handle desktop initialization + if (typeof isMobileDevice === 'function' && !isMobileDevice()) { + console.log('Initializing desktop components'); + initDatePicker($('#gasRecordDate')); + initTagSelector($("#gasRecordTag")); + } + } catch (e) { + console.error('Error in initializeGasRecordMobile:', e); + // Fallback to basic initialization + if (typeof isMobileDevice !== 'function' || !isMobileDevice()) { + try { + initDatePicker($('#gasRecordDate')); + initTagSelector($("#gasRecordTag")); + } catch (fallbackError) { + console.error('Fallback initialization also failed:', fallbackError); + } + } } } function showAddGasRecordModal() { - $.get(`/Vehicle/GetAddGasRecordPartialView?vehicleId=${GetVehicleId().vehicleId}`, function (data) { - if (data) { - $("#gasRecordModalContent").html(data); - - // Initialize mobile experience using shared framework - initializeGasRecordMobile(); - - $('#gasRecordModal').modal('show'); - } - }); + try { + var vehicleInfo = GetVehicleId(); + console.log('Getting gas record modal for vehicle:', vehicleInfo.vehicleId); + + $.get(`/Vehicle/GetAddGasRecordPartialView?vehicleId=${vehicleInfo.vehicleId}`, function (data) { + if (data) { + $("#gasRecordModalContent").html(data); + + // Initialize mobile experience using shared framework + console.log('Initializing mobile gas record modal'); + initializeGasRecordMobile(); + + console.log('Showing gas record modal'); + $('#gasRecordModal').modal('show'); + } else { + console.error('No data received from GetAddGasRecordPartialView'); + errorToast('Failed to load gas record form'); + } + }).fail(function(xhr, status, error) { + console.error('AJAX request failed:', status, error); + errorToast('Failed to load gas record form: ' + error); + }); + } catch (e) { + console.error('Error in showAddGasRecordModal:', e); + errorToast('Error opening gas record form: ' + e.message); + } } function showEditGasRecordModal(gasRecordId, nocache) { if (!nocache) {