diff options
author | Struan Donald <struan@exo.org.uk> | 2014-10-03 15:07:08 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2015-08-28 14:27:15 +0100 |
commit | a69d425c0e5c004145ac1ab70e2f7f9fc329b54c (patch) | |
tree | 8eb7ff0ff7aaa0fce8bc7214ec6e15b694fddbdc /www/js/views/search.js | |
parent | 8fd15b58733c51d7f001f9eac66b7d03830ec0b4 (diff) |
update Android to Cordova 3.6
Required due to security issue
Remove Android directory as no longer required, move src -> www to match
standard layout, update .gitignore to avoid including the standard
platform files, update README based on Steve's zurich one
Diffstat (limited to 'www/js/views/search.js')
-rw-r--r-- | www/js/views/search.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/www/js/views/search.js b/www/js/views/search.js new file mode 100644 index 0000000..6930e2a --- /dev/null +++ b/www/js/views/search.js @@ -0,0 +1,81 @@ +(function (FMS, Backbone, _, $) { + _.extend( FMS, { + SearchView: FMS.FMSView.extend({ + template: 'address_search', + id: 'search-page', + + events: { + 'vclick a.address': 'goAddress', + 'vclick #submit': 'search', + 'vclick #locate': 'goLocate', + 'pagehide': 'destroy', + 'pagebeforeshow': 'beforeDisplay', + 'pageshow': 'afterDisplay', + 'submit #postcodeForm': 'search' + }, + + afterDisplay: function() { + if ( FMS.isOffline ) { + this.navigate('offline'); + } + }, + + search: function(e) { + // this is to stop form submission + e.preventDefault(); + this.clearValidationErrors(); + var pc = this.$('#pc').val(); + this.listenTo(FMS.locator, 'search_located', this.searchSuccess ); + this.listenTo(FMS.locator, 'search_failed', this.searchFail); + + FMS.locator.lookup(pc); + }, + + searchSuccess: function( info ) { + this.stopListening(FMS.locator); + var coords = info.coordinates; + FMS.currentPosition = coords; + this.navigate('around'); + }, + + goAddress: function(e) { + var t = $(e.target); + var lat = t.attr('data-lat'); + var long = t.attr('data-long'); + + FMS.currentPosition = { latitude: lat, longitude: long }; + this.navigate('around'); + }, + + searchFail: function( details ) { + // this makes sure any onscreen keyboard is dismissed + $('#submit').focus(); + this.stopListening(FMS.locator); + if ( details.msg ) { + this.validationError( 'pc', details.msg ); + } else if ( details.locations ) { + var multiple = ''; + for ( var i = 0; i < details.locations.length; i++ ) { + var loc = details.locations[i]; + var li = '<li><a class="address" id="location_' + i + '" data-lat="' + loc.lat + '" data-long="' + loc.long + '">' + loc.address + '</a></li>'; + multiple = multiple + li; + } + $('#front-howto').html('<p>Multiple matches found</p><ul data-role="listview" data-inset="true">' + multiple + '</ul>'); + $('.ui-page').trigger('create'); + } else { + this.validationError( 'pc', FMS.strings.location_problem ); + } + }, + + goLocate: function(e) { + e.preventDefault(); + this.navigate( 'around' ); + }, + + _destroy: function() { + delete FMS.searchMessage; + this.stopListening(FMS.locator); + } + }) + }); +})(FMS, Backbone, _, $); |