diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/js/views/around.js | 30 | ||||
-rw-r--r-- | src/js/views/details_extra.js | 2 | ||||
-rw-r--r-- | src/js/views/submit.js | 34 |
3 files changed, 54 insertions, 12 deletions
diff --git a/src/js/views/around.js b/src/js/views/around.js index 1315710..501c371 100644 --- a/src/js/views/around.js +++ b/src/js/views/around.js @@ -140,6 +140,23 @@ // is up so we probably should not recenter if ( FMS.currentPosition ) { fixmystreet.map.panTo(this.projectCoords( FMS.currentPosition )); + + // If we've confirmed the report position then we should be able + // to reposition it if we've moved the map. + if ( $('#confirm').css('display') == 'block' ) { + var currentPos = this.projectCoords(FMS.currentPosition); + var markerPos = this.getMarkerPosition(true); + + // Displaying the button if the report is in the same place as the + // GPS location could be confusing so check they are different. + // The slight margin of error is there to account for both rounding + // wiggle in the projectCoords and also so that small changes due to + // GPS noise are ignored + if ( Math.abs(markerPos.lat - currentPos.lat) > 1 || + Math.abs(markerPos.lon - currentPos.lon) > 1 ) { + $('#reposition').show(); + } + } } }, @@ -155,7 +172,7 @@ if ( !fixmystreet.map ) { $('#relocate').hide(); $('#mark-here').hide(); - $('#pc').attr('Search for a place or postcode.').focus(); + $('#pc').attr('placeholder', 'Search for a place or postcode.').focus(); } $('#front-howto').html('<p>' + msg + '</msg>'); $('#front-howto').show(); @@ -291,7 +308,8 @@ }, searchSuccess: function( info ) { - this.stopListening(FMS.locator); + this.stopListening(FMS.locator, 'search_located'); + this.stopListening(FMS.locator, 'search_failed'); var coords = info.coordinates; if ( fixmystreet.map ) { fixmystreet.map.panTo(this.projectCoords( coords )); @@ -335,7 +353,8 @@ searchFail: function( details ) { // this makes sure any onscreen keyboard is dismissed $('#submit').focus(); - this.stopListening(FMS.locator); + this.stopListening(FMS.locator, 'search_located'); + this.stopListening(FMS.locator, 'search_failed'); if ( details.msg ) { this.searchError( details.msg ); } else if ( details.locations ) { @@ -420,10 +439,13 @@ return position; }, - getMarkerPosition: function() { + getMarkerPosition: function(skipTransform) { var marker = fixmystreet.report_location.features[0].geometry; var position = new OpenLayers.LonLat( marker.x, marker.y ); + if ( skipTransform ) { + return position; + } position.transform( fixmystreet.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326") diff --git a/src/js/views/details_extra.js b/src/js/views/details_extra.js index 7a96e8c..90237f7 100644 --- a/src/js/views/details_extra.js +++ b/src/js/views/details_extra.js @@ -23,6 +23,7 @@ }, onClickButtonPrev: function() { + this.model.set('hasExtras', 0); this.updateCurrentReport(); this.navigate( this.prev, true ); }, @@ -43,6 +44,7 @@ $('input').each(isRequired); $('textarea').each(isRequired); $('select').each(isRequired); + this.model.set('hasExtras', 1); if ( valid ) { this.clearValidationErrors(); diff --git a/src/js/views/submit.js b/src/js/views/submit.js index 3e11dd6..5a45de2 100644 --- a/src/js/views/submit.js +++ b/src/js/views/submit.js @@ -98,6 +98,7 @@ } } errorList += '</ul>'; + $('p.top').hide(); $('#errors').html(errorList).show(); } }, @@ -139,10 +140,23 @@ }); })(FMS, Backbone, _, $); +(function (FMS, Backbone, _, $) { + _.extend( FMS, { + SubmitInitialPageView: FMS.SubmitView.extend({ + onClickButtonPrev: function() { + if ( this.model.get('hasExtras') == 1 ) { + this.navigate( 'details_extra', true ); + } else { + this.navigate( 'details', true ); + } + } + }) + }); +})(FMS, Backbone, _, $); (function (FMS, Backbone, _, $) { _.extend( FMS, { - SubmitEmailView: FMS.SubmitView.extend({ + SubmitEmailView: FMS.SubmitInitialPageView.extend({ template: 'submit_email', id: 'submit-email-page', prev: 'details', @@ -236,7 +250,7 @@ this.validationError('form_name', FMS.validationStrings.name.required ); } else { var validNamePat = /\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i; - if ( name.length < 6 || !name.match( /\S/ ) || name.match( validNamePat ) ) { + if ( name.length < 6 || !name.match( /\s/ ) || !name.match( /\S/ ) || name.match( validNamePat ) ) { isValid = 0; this.validationError('form_name', FMS.validationStrings.name.validName); } @@ -253,6 +267,8 @@ }, beforeSubmit: function() { + $('#errors').hide(); + $('p.top').show(); this.model.set('name', $('#form_name').val()); this.model.set('phone', $('#form_phone').val()); this.model.set('may_show_name', $('#form_may_show_name').val()); @@ -362,12 +378,14 @@ onClickContinue: function(e) { e.preventDefault(); - $('#continue').focus(); - if ( ! this.model.get('submit_clicked') ) { - this.model.set('submit_clicked', 'submit_sign_in'); + if ( this.validate() ) { + $('#continue').focus(); + if ( ! this.model.get('submit_clicked') ) { + this.model.set('submit_clicked', 'submit_sign_in'); + } + FMS.currentUser.set('password', $('#form_password').val()); + this.navigate( this.next ); } - FMS.currentUser.set('password', $('#form_password').val()); - this.navigate( this.next ); } }) }); @@ -375,7 +393,7 @@ (function (FMS, Backbone, _, $) { _.extend( FMS, { - SubmitConfirmView: FMS.SubmitView.extend({ + SubmitConfirmView: FMS.SubmitInitialPageView.extend({ template: 'submit_confirm', id: 'submit-confirm-page', prev: 'details', |