aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--www/js/map-OpenLayers.js32
-rw-r--r--www/js/mobile.js45
-rw-r--r--www/no_connection.html16
-rw-r--r--www/submit-problem.html10
4 files changed, 82 insertions, 21 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);
diff --git a/www/no_connection.html b/www/no_connection.html
index 110e806..d46049a 100644
--- a/www/no_connection.html
+++ b/www/no_connection.html
@@ -1,15 +1,19 @@
- <div class="wrapper" data-role="page">
+ <div id="no-connection-page" class="wrapper" data-role="page">
<div class="table-cell">
<div class="container">
- <div class="content" role="main">
+ <div class="content" role="main" data-enhance="false">
<div class="tablewrapper">
<h2>No Internet connection</h2>
- <p>
- There is no connection to the internet available which means
- you can't report a problem at the moment. Please try again when
- you have a connection.
+ <p id="have-gps">
</p>
+
+ <div id="make-report" class="form-box nodisplay">
+ <h5>Create an offline report</h5>
+ <div class="form-txt-submit-box">
+ <input class="green-btn" type="button" id="create_report" name="create_report" value="Create">
+ </div>
+ </div>
</div>
</div><!-- .content role=main -->
</div><!-- .container -->
diff --git a/www/submit-problem.html b/www/submit-problem.html
index db900ce..8c4cfad 100644
--- a/www/submit-problem.html
+++ b/www/submit-problem.html
@@ -136,9 +136,13 @@
<input class="green-btn" type="submit" id="submit_register" name="submit_register" value="Report">
</div>
- <div class="form-txt-submit-box">
- <input class="green-btn" type="button" id="save_report" name="save_report" value="Save">
- </div>
+ </div>
+ </div>
+
+ <div id="report_save" class="form-box">
+ <h5>Save this report for completion later</h5>
+ <div class="form-txt-submit-box">
+ <input class="green-btn" type="button" id="save_report" name="save_report" value="Save">
</div>
</div>
</div>