diff options
author | Struan Donald <struan@exo.org.uk> | 2013-03-20 16:46:42 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-03-21 17:19:40 +0000 |
commit | 73c76ce0aa20f32769a36e08a82e62bd63d6e9f5 (patch) | |
tree | aa24bb18d9b141c961f38954b62f1bb7dca0186f /www/js | |
parent | 7c28392bc868e2f7c978aee50eea641a62a3b21b (diff) |
simple address search functionality
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/app.js | 2 | ||||
-rw-r--r-- | www/js/router.js | 6 | ||||
-rw-r--r-- | www/js/views/around.js | 20 | ||||
-rw-r--r-- | www/js/views/search.js | 42 |
4 files changed, 68 insertions, 2 deletions
diff --git a/www/js/app.js b/www/js/app.js index 63d38d2..00c178c 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -38,7 +38,7 @@ var tpl = { (function (FMS, Backbone, _, $) { _.extend(FMS, { templates: [ - 'home', 'around', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'sent' + 'home', 'around', 'address_search', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'sent' ], initialized: 0, diff --git a/www/js/router.js b/www/js/router.js index 29a5d64..e9bce54 100644 --- a/www/js/router.js +++ b/www/js/router.js @@ -7,6 +7,7 @@ '': 'home', 'home': 'home', 'around': 'around', + 'search': 'search', 'photo': 'photo', 'details': 'details', 'submit': 'submit', @@ -30,6 +31,11 @@ this.changeView(aroundView); }, + search: function(){ + var searchView = new FMS.SearchView({ model: FMS.currentReport }); + this.changeView(searchView); + }, + home: function(){ var homeView = new FMS.HomeView({ model: FMS.currentReport }); this.changeView(homeView); diff --git a/www/js/views/around.js b/www/js/views/around.js index 8720ccc..49b65da 100644 --- a/www/js/views/around.js +++ b/www/js/views/around.js @@ -7,12 +7,20 @@ events: { 'pagehide': 'destroy', 'pageshow': 'afterDisplay', + 'click #search': 'goSearch', 'click #relocate': 'centerMapOnPosition', 'click #mark-here': 'onClickReport' }, afterDisplay: function() { - this.locate(); + if ( FMS.currentLocation ) { + var info = { coordinates: FMS.currentLocation }; + FMS.currentLocation = null; + FMS.locator.on('gps_current_position', this.positionUpdate, this); + this.showMap(info); + } else { + this.locate(); + } }, locate: function() { @@ -150,6 +158,16 @@ this.navigate( 'photo' ); }, + goSearch: function(e) { + e.preventDefault(); + FMS.locator.off('gps_located'); + FMS.locator.off('gps_failed'); + FMS.locator.off('gps_locating'); + FMS.locator.off('gps_current_position'); + FMS.locator.stopUpdating(); + this.navigate( 'search' ); + }, + getCrossHairPosition: function() { var cross = fixmystreet.map.getControlsByClass( "OpenLayers.Control.Crosshairs"); diff --git a/www/js/views/search.js b/www/js/views/search.js new file mode 100644 index 0000000..8e2bfd2 --- /dev/null +++ b/www/js/views/search.js @@ -0,0 +1,42 @@ +(function (FMS, Backbone, _, $) { + _.extend( FMS, { + SearchView: FMS.FMSView.extend({ + template: 'address_search', + id: 'search-page', + + events: { + 'click #submit': 'search', + 'pagehide': 'destroy', + 'pageshow': 'afterDisplay' + }, + + search: function() { + var pc = this.$('#pc').val(); + FMS.locator.on('search_located', this.searchSuccess, this ); + FMS.locator.on('search_failed', this.searchFail, this ); + + $('#ajaxOverlay').show(); + FMS.locator.lookup(pc); + }, + + + searchSuccess: function( info ) { + var coords = info.coordinates; + FMS.currentLocation = coords; + this.navigate('around'); + }, + + + searchFail: function( details ) { + $('#ajaxOverlay').hide(); + if ( details.msg ) { + this.displayError( details.msg ); + } else if ( details.locs ) { + this.displayError( FMS.strings.multiple_locations ); + } else { + this.displayError( FMS.strings.location_problem ); + } + } + }) + }); +})(FMS, Backbone, _, $); |