aboutsummaryrefslogtreecommitdiffstats
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/app.js4
-rw-r--r--www/js/locate.js165
-rw-r--r--www/js/views/around.js18
3 files changed, 97 insertions, 90 deletions
diff --git a/www/js/app.js b/www/js/app.js
index 959a19e..0e0544e 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -57,8 +57,10 @@ var tpl = {
FMS.initialized = 1;
tpl.loadTemplates( FMS.templates, function() {
_.extend(FMS, {
- router: new FMS.appRouter()
+ router: new FMS.appRouter(),
+ locator: new FMS.Locate()
});
+ _.extend( FMS.locator, Backbone.Events );
// we only ever have the details of one user
FMS.users.fetch();
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, _);
diff --git a/www/js/views/around.js b/www/js/views/around.js
index 59a01e1..df2c1da 100644
--- a/www/js/views/around.js
+++ b/www/js/views/around.js
@@ -17,13 +17,11 @@
locate: function() {
$('#locating').show();
var that = this;
- var l = new Locate();
- _.extend(l, Backbone.Events);
- l.on('located', this.showMap, this );
- l.on('failed', this.noMap, this );
- l.on('locating', this.locationUpdate, this);
+ FMS.locator.on('gps_located', this.showMap, this );
+ FMS.locator.on('gps_failed', this.noMap, this );
+ FMS.locator.on('gps_locating', this.locationUpdate, this);
- l.geolocate(100);
+ FMS.locator.geolocate(100);
this.startLocateProgress();
},
@@ -92,11 +90,9 @@
onClickReport: function() {
var position = this.getCrossHairPosition();
- var l = new Locate();
- _.extend(l, Backbone.Events);
- l.on('failed', this.noMap, this );
- l.on('located', this.goPhoto, this );
- l.check_location( { latitude: position.lat, longitude: position.lon } );
+ FMS.locator.on('search_failed', this.noMap, this );
+ FMS.locator.on('search_located', this.goPhoto, this );
+ FMS.locator.check_location( { latitude: position.lat, longitude: position.lon } );
},
goPhoto: function(info) {