diff options
author | Struan Donald <struan@exo.org.uk> | 2012-11-06 17:29:03 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-11-06 17:30:37 +0000 |
commit | f321969ffaa13d275024a499eaa79bce1e19fad7 (patch) | |
tree | 1b2306a557887ea89176b35622d9ab942075a413 /www/js | |
parent | 630e77e0c196a3f580f2c58cded2c6d034c4df86 (diff) |
Slightly more fleshed out workflow for dealing with internet
connection being unavailable and creating an offline report
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/map-OpenLayers.js | 32 | ||||
-rw-r--r-- | www/js/mobile.js | 45 |
2 files changed, 65 insertions, 12 deletions
diff --git a/www/js/map-OpenLayers.js b/www/js/map-OpenLayers.js index c5fbe59..57fb9e9 100644 --- a/www/js/map-OpenLayers.js +++ b/www/js/map-OpenLayers.js @@ -248,18 +248,26 @@ $(document).delegate('#submit-problem', 'pageshow', function(event) { $('#pc').val(localStorage.pc); $('#fixmystreet\\.latitude').val(localStorage.latitude); $('#fixmystreet\\.longitude').val(localStorage.longitude); - $.getJSON( CONFIG.FMS_URL + 'report/new/ajax', { - latitude: $('#fixmystreet\\.latitude').val(), - longitude: $('#fixmystreet\\.longitude').val() - }, function(data) { - if (data.error) { - // XXX If they then click back and click somewhere in the area, this error will still show. - $('#side-form').html('<h1>Reporting a problem</h1><p>' + data.error + '</p>'); - return; - } - $('#councils_text').html(data.councils_text); - $('#form_category_row').html(data.category); - }); + if ( !localStorage.offline ) { + $.getJSON( CONFIG.FMS_URL + 'report/new/ajax', { + latitude: $('#fixmystreet\\.latitude').val(), + longitude: $('#fixmystreet\\.longitude').val() + }, function(data) { + if (data.error) { + // XXX If they then click back and click somewhere in the area, this error will still show. + $('#side-form').html('<h1>Reporting a problem</h1><p>' + data.error + '</p>'); + return; + } + $('#councils_text').html(data.councils_text); + $('#form_category_row').html(data.category); + }); + } else { + $('#councils_text').html("You are currently operating in offline mode so you can save the details of the problem but you'll need to finish reporting when you have internet access."); + $('#form_category_row').hide(); + $('#email_label').hide(); + $('#form_email').hide(); + $('#form_sign_in').hide(); + } }); function show_map(event) { diff --git a/www/js/mobile.js b/www/js/mobile.js index b096c83..38c714d 100644 --- a/www/js/mobile.js +++ b/www/js/mobile.js @@ -175,6 +175,47 @@ function getPosition() { } } +function check_for_gps() { + if ( !can_geolocate ) { + window.setTimeout( check_for_gps, 200 ); + return; + } + if ( !watch_id ) { + watch_count = 0; + watch_id = navigator.geolocation.watchPosition(have_gps, do_not_have_gps, { timeout: 60000, enableHighAccuracy: true } ); + } else { + alert('currently locating'); + } +} + +function have_gps(myLocation) { + navigator.geolocation.clearWatch(watch_id); + if ( watch_id ) { + watch_id = null; + var lat = myLocation.coords.latitude; + var long = myLocation.coords.longitude; + $('#have-gps').text('Determined location using GPS'); + $('#make-report').show(); + + localStorage.latitude = lat; + localStorage.longitude = long; + } +} + +function create_offline() { + $.mobile.changePage('submit-problem.html'); +} + +function do_not_have_gps(err) { + console.log(err); + if ( watch_id ) { + navigator.geolocation.clearWatch(watch_id); + watch_id = null; + $('#have-gps').text('Cannot determine location'); + $('#make-report').hide(); + } +} + function takePhotoSuccess(imageURI) { $('#form_photo').val(imageURI); @@ -596,8 +637,10 @@ function decide_front_page() { window.setTimeout( decide_front_page, 100 ); return; } + localStorage.offline = 0; if ( navigator.network.connection.type == Connection.NONE || navigator.network.connection.type == Connection.UNKNOWN ) { + localStorage.offline = 1; $.mobile.changePage( 'no_connection.html' ); } else { getPosition(); @@ -609,5 +652,7 @@ $(document).delegate('#account-page', 'pageshow', display_account_page); $(document).delegate('#my-reports-page', 'pageshow', display_saved_reports); $(document).delegate('#report-page', 'pageshow', display_saved_report); $(document).delegate('#submit-problem', 'pageshow', submit_problem_show); +$(document).delegate('#no-connection-page', 'pageshow', check_for_gps); $(document).delegate('.saved-report', 'click', open_saved_report_page); $(document).delegate('#mark-here', 'click', set_location); +$(document).delegate('#create_report', 'click', create_offline); |