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/views/search.js | |
parent | 7c28392bc868e2f7c978aee50eea641a62a3b21b (diff) |
simple address search functionality
Diffstat (limited to 'www/js/views/search.js')
-rw-r--r-- | www/js/views/search.js | 42 |
1 files changed, 42 insertions, 0 deletions
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, _, $); |