|  | 
|  | 1 | +{% extends 'base.html' %} | 
|  | 2 | + | 
|  | 3 | +{% block title %}Schedule Appointment - Step 1{% endblock %} | 
|  | 4 | + | 
|  | 5 | + | 
|  | 6 | +{% block content %} | 
|  | 7 | +<style> | 
|  | 8 | +    .appointment-form { | 
|  | 9 | +        position: relative; | 
|  | 10 | +        z-index: 1; | 
|  | 11 | +    } | 
|  | 12 | + | 
|  | 13 | +    .form-control { | 
|  | 14 | +        width: 100%; | 
|  | 15 | +        height: 50px; | 
|  | 16 | +        background-color: rgba(0, 0, 0, 0.3); | 
|  | 17 | +        border-radius: 2px; | 
|  | 18 | +        border: none; | 
|  | 19 | +        color: #fff; | 
|  | 20 | +        font-size: 12px; | 
|  | 21 | +        padding: 0 30px; | 
|  | 22 | +        font-style: italic; | 
|  | 23 | +    } | 
|  | 24 | + | 
|  | 25 | +    .form-control:focus { | 
|  | 26 | +        box-shadow: none; | 
|  | 27 | +    } | 
|  | 28 | + | 
|  | 29 | +    select { | 
|  | 30 | +        appearance: none; | 
|  | 31 | +        -moz-appearance: none; | 
|  | 32 | +    } | 
|  | 33 | + | 
|  | 34 | +    select option { | 
|  | 35 | +        width: 100%; | 
|  | 36 | +        height: 40px; | 
|  | 37 | +        background-color: #fff; | 
|  | 38 | +        color: #000; /* Replace with your desired color */ | 
|  | 39 | +    } | 
|  | 40 | + | 
|  | 41 | +    textarea.form-control { | 
|  | 42 | +        padding: 30px; | 
|  | 43 | +        height: 120px; | 
|  | 44 | +    } | 
|  | 45 | + | 
|  | 46 | +    #location-prompt, | 
|  | 47 | +    #location-confirm { | 
|  | 48 | +        max-width: 400px; | 
|  | 49 | +        margin: 0 auto; | 
|  | 50 | +        text-align: center; | 
|  | 51 | +        padding: 20px; | 
|  | 52 | +        background-color: #fff; | 
|  | 53 | +        border-radius: 8px; | 
|  | 54 | +        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | 
|  | 55 | +        margin-top: 20px; | 
|  | 56 | +    } | 
|  | 57 | + | 
|  | 58 | +    #location-prompt p, | 
|  | 59 | +    #location-confirm p { | 
|  | 60 | +        font-size: 16px; | 
|  | 61 | +        margin-bottom: 15px; | 
|  | 62 | +    } | 
|  | 63 | + | 
|  | 64 | +    #location-prompt button, | 
|  | 65 | +    #location-confirm button { | 
|  | 66 | +        background-color: #007bff; | 
|  | 67 | +        color: #fff; | 
|  | 68 | +        border: none; | 
|  | 69 | +        padding: 10px 20px; | 
|  | 70 | +        font-size: 14px; | 
|  | 71 | +        cursor: pointer; | 
|  | 72 | +        border-radius: 4px; | 
|  | 73 | +        margin-top: 10px; | 
|  | 74 | +    } | 
|  | 75 | + | 
|  | 76 | +    #location-prompt button:hover, | 
|  | 77 | +    #location-confirm button:hover { | 
|  | 78 | +        background-color: #0056b3; | 
|  | 79 | +    } | 
|  | 80 | +</style> | 
|  | 81 | + | 
|  | 82 | +    <h2>Schedule Appointment - Step 1</h2> | 
|  | 83 | + | 
|  | 84 | +    <div id="location-prompt" style="display: none;"> | 
|  | 85 | +        <p>Healdi is requesting your location. Click the button below to share your location.</p> | 
|  | 86 | +        <button onclick="requestLocation()">Share Location</button> | 
|  | 87 | +    </div> | 
|  | 88 | + | 
|  | 89 | +    <div id="location-confirm" style="display: none;"> | 
|  | 90 | +        <p>Is this your correct location?</p> | 
|  | 91 | +        <p id="location-display"></p> | 
|  | 92 | +        <button onclick="submitForm()">Yes, Confirm</button> | 
|  | 93 | +        <button onclick="showLocationPrompt()">No, Retry</button> | 
|  | 94 | +    </div> | 
|  | 95 | + | 
|  | 96 | +    <form method="post" action="{% url 'schedule_step2' %}" class="appointment-form" id="appointment-form"> | 
|  | 97 | +        {% csrf_token %} | 
|  | 98 | +        <!-- Other form fields go here --> | 
|  | 99 | + | 
|  | 100 | +        <input type="hidden" name="latitude" id="latitude" value=""> | 
|  | 101 | +        <input type="hidden" name="longitude" id="longitude" value=""> | 
|  | 102 | +        <input type="hidden" name="city" id="city" value=""> | 
|  | 103 | +        <input type="hidden" name="state" id="state" value=""> | 
|  | 104 | +        <input type="hidden" name="country" id="country" value=""> | 
|  | 105 | +        <input type="hidden" name="zip_code" id="zip_code" value=""> | 
|  | 106 | + | 
|  | 107 | +        <input type="submit" value="Next" style="display: none;"> | 
|  | 108 | +    </form> | 
|  | 109 | + | 
|  | 110 | + | 
|  | 111 | + | 
|  | 112 | +    <script> | 
|  | 113 | +        function requestLocation() { | 
|  | 114 | +            if (navigator.geolocation) { | 
|  | 115 | +                navigator.geolocation.getCurrentPosition( | 
|  | 116 | +                    function(position) { | 
|  | 117 | +                        // Update hidden form fields with latitude and longitude | 
|  | 118 | +                        document.getElementById('latitude').value = position.coords.latitude; | 
|  | 119 | +                        document.getElementById('longitude').value = position.coords.longitude; | 
|  | 120 | + | 
|  | 121 | +                        // Reverse geocode the location | 
|  | 122 | +                        reverseGeocode(position.coords.latitude, position.coords.longitude); | 
|  | 123 | +                    }, | 
|  | 124 | +                    function(error) { | 
|  | 125 | +                        console.error("Error getting user's location: " + error.message); | 
|  | 126 | +                        // Handle error, show a message, or provide an alternative | 
|  | 127 | +                    } | 
|  | 128 | +                ); | 
|  | 129 | +            } else { | 
|  | 130 | +                console.log("Geolocation is not supported by this browser."); | 
|  | 131 | +                // Handle the case where geolocation is not supported | 
|  | 132 | +            } | 
|  | 133 | +        } | 
|  | 134 | + | 
|  | 135 | +        function reverseGeocode(latitude, longitude) { | 
|  | 136 | +            var apiKey = 'API'; | 
|  | 137 | +            var apiUrl = `https://api.opencagedata.com/geocode/v1/json?key=${apiKey}&q=${latitude}+${longitude}&pretty=1`; | 
|  | 138 | + | 
|  | 139 | +            fetch(apiUrl) | 
|  | 140 | +                .then(response => response.json()) | 
|  | 141 | +                .then(data => { | 
|  | 142 | +                    // Display location details for confirmation | 
|  | 143 | +                    var locationDetails = `City: ${data.results[0].components.city},  | 
|  | 144 | +                                           State: ${data.results[0].components.state}, | 
|  | 145 | +                                           Country: ${data.results[0].components.country}, | 
|  | 146 | +                                           Zip Code: ${data.results[0].components.postcode}`; | 
|  | 147 | + | 
|  | 148 | +                    document.getElementById('location-display').innerText = locationDetails; | 
|  | 149 | + | 
|  | 150 | +                    // Update hidden form fields with location details | 
|  | 151 | +                    document.getElementById('city').value = data.results[0].components.city; | 
|  | 152 | +                    document.getElementById('state').value = data.results[0].components.state; | 
|  | 153 | +                    document.getElementById('country').value = data.results[0].components.country; | 
|  | 154 | +                    document.getElementById('zip_code').value = data.results[0].components.postcode; | 
|  | 155 | + | 
|  | 156 | +                    // Show confirmation prompt | 
|  | 157 | +                    showLocationConfirm(); | 
|  | 158 | +                }) | 
|  | 159 | +                .catch(error => { | 
|  | 160 | +                    console.error("Error in reverse geocoding: " + error.message); | 
|  | 161 | +                    // Handle error, show a message, or provide an alternative | 
|  | 162 | +                }); | 
|  | 163 | +        } | 
|  | 164 | + | 
|  | 165 | +        function showLocationConfirm() { | 
|  | 166 | +            document.getElementById('location-prompt').style.display = 'none'; | 
|  | 167 | +            document.getElementById('location-confirm').style.display = 'block'; | 
|  | 168 | +        } | 
|  | 169 | + | 
|  | 170 | +        function showLocationPrompt() { | 
|  | 171 | +            document.getElementById('location-prompt').style.display = 'block'; | 
|  | 172 | +            document.getElementById('location-confirm').style.display = 'none'; | 
|  | 173 | +        } | 
|  | 174 | + | 
|  | 175 | +        function submitForm() { | 
|  | 176 | +            // Optionally, you can add more logic here before submitting the form | 
|  | 177 | +            document.getElementById('appointment-form').submit(); | 
|  | 178 | +        } | 
|  | 179 | + | 
|  | 180 | +        document.addEventListener('DOMContentLoaded', function() { | 
|  | 181 | +            // Display the location prompt when the page loads | 
|  | 182 | +            document.getElementById('location-prompt').style.display = 'block'; | 
|  | 183 | +        }); | 
|  | 184 | +    </script> | 
|  | 185 | +{% endblock %} | 
0 commit comments