aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/locate.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js/locate.js')
-rw-r--r--www/js/locate.js165
1 files changed, 87 insertions, 78 deletions
diff --git a/www/js/locate.js b/www/js/locate.js
index a149a6a..25853be 100644
--- a/www/js/locate.js
+++ b/www/js/locate.js
@@ -1,90 +1,99 @@
-var Locate = ( function() { return {
- locating: 0,
+(function(FMS, Backbone, _) {
+ _.extend( FMS, {
+ Locate: function() { return {
+ locating: 0,
- lookup: function(q) {
- var that = this;
- if (!q) {
- this.trigger('failed', { msg: FMS.strings.missing_location } );
- return false;
- }
+ lookup: function(q) {
+ var that = this;
+ if (!q) {
+ this.trigger('search_failed', { msg: FMS.strings.missing_location } );
+ return false;
+ }
- var url = CONFIG.FMS_URL + '/ajax/lookup_location?term=' + q;
+ var url = CONFIG.FMS_URL + '/ajax/lookup_location?term=' + q;
- var x = $.ajax( {
- url: url,
- dataType: 'json',
- timeout: 30000,
- success: function(data, status) {
- if ( status == 'success' ) {
- if ( data.latitude ) {
- that.trigger('located', { coordinates: { latitude: data.latitude, longitude: data.longitude } } );
- } else if ( data.suggestions ) {
- that.trigger( 'failed', { locs: data.suggestions } );
- } else {
- that.trigger( 'failed', { msg: data.error } );
+ var x = $.ajax( {
+ url: url,
+ dataType: 'json',
+ timeout: 30000,
+ success: function(data, status) {
+ if ( status == 'success' ) {
+ if ( data.latitude ) {
+ that.trigger('search_located', { coordinates: { latitude: data.latitude, longitude: data.longitude } } );
+ } else if ( data.suggestions ) {
+ that.trigger( 'search_failed', { locs: data.suggestions } );
+ } else {
+ that.trigger( 'search_failed', { msg: data.error } );
+ }
+ } else {
+ that.trigger( 'search_failed', { msg: FMS.strings.location_problem } );
+ }
+ },
+ error: function(data, status, errorThrown) {
+ that.trigger( 'search_failed', { msg: FMS.strings.location_problem } );
}
- } else {
- that.trigger( 'failed', { msg: FMS.strings.location_problem } );
- }
+ } );
},
- error: function(data, status, errorThrown) {
- that.trigger( 'failed', { msg: FMS.strings.location_problem } );
- }
- } );
- },
- geolocate: function( minAccuracy ) {
- this.locating = 1;
+ geolocate: function( minAccuracy ) {
+ console.log('geolocation');
+ this.locating = 1;
- $('#ajaxOverlay').show();
- var that = this;
- this.watch_id = navigator.geolocation.watchPosition(
- function(location) {
- if ( that.watch_id === undefined ) { console.log( 'no watch id' ); return; }
+ $('#ajaxOverlay').show();
+ console.log(this);
+ var that = this;
+ this.watch_id = navigator.geolocation.watchPosition(
+ function(location) {
+ console.log('success');
+ console.log(location);
+ if ( that.watch_id === undefined ) { console.log( 'no watch id' ); return; }
- if ( minAccuracy && location.coords.accuracy > minAccuracy ) {
- that.trigger('locating', location.coords.accuracy);
- } else {
- console.log( 'located with accuracy of ' + location.coords.accuracy );
- that.locating = 0;
- navigator.geolocation.clearWatch( that.watch_id );
- delete that.watch_id;
+ if ( minAccuracy && location.coords.accuracy > minAccuracy ) {
+ that.trigger('gps_locating', location.coords.accuracy);
+ } else {
+ console.log( 'located with accuracy of ' + location.coords.accuracy );
+ that.locating = 0;
+ navigator.geolocation.clearWatch( that.watch_id );
+ delete that.watch_id;
- that.check_location(location.coords);
- }
- },
- function() {
- if ( that.watch_id === undefined ) { return; }
- that.locating = 0;
- navigator.geolocation.clearWatch( that.watch_id );
- delete that.watch_id;
- that.trigger('failed', { msg: FMS.strings.geolocation_failed } );
+ that.check_location(location.coords);
+ }
+ },
+ function() {
+ if ( that.watch_id === undefined ) { return; }
+ that.locating = 0;
+ navigator.geolocation.clearWatch( that.watch_id );
+ delete that.watch_id;
+ that.trigger('gps_failed', { msg: FMS.strings.geolocation_failed } );
+ },
+ { timeout: 20000, enableHighAccuracy: true }
+ );
},
- { timeout: 20000, enableHighAccuracy: true }
- );
- },
- check_location: function(coords) {
- var that = this;
- $.ajax( {
- url: CONFIG.FMS_URL + 'report/new/ajax',
- dataType: 'json',
- data: {
- latitude: coords.latitude,
- longitude: coords.longitude
- },
- timeout: 10000,
- success: function(data) {
- if (data.error) {
- that.trigger('failed', { msg: data.error } );
- return;
- }
- that.trigger('located', { coordinates: coords, details: data } );
- },
- error: function (data, status, errorThrown) {
- that.trigger('failed', { msg: FMS.strings.location_check_failed } );
- }
- } );
- }
-};});
+ check_location: function(coords) {
+ console.log('check_location');
+ var that = this;
+ $.ajax( {
+ url: CONFIG.FMS_URL + 'report/new/ajax',
+ dataType: 'json',
+ data: {
+ latitude: coords.latitude,
+ longitude: coords.longitude
+ },
+ timeout: 10000,
+ success: function(data) {
+ if (data.error) {
+ that.trigger('gps_failed', { msg: data.error } );
+ return;
+ }
+ that.trigger('gps_located', { coordinates: coords, details: data } );
+ },
+ error: function (data, status, errorThrown) {
+ that.trigger('gps_failed', { msg: FMS.strings.location_check_failed } );
+ }
+ } );
+ }
+ }; }
+ });
+})(FMS, Backbone, _);