diff options
-rw-r--r-- | www/js/app.js | 7 | ||||
-rw-r--r-- | www/js/router.js | 11 | ||||
-rw-r--r-- | www/js/views/details.js | 2 | ||||
-rw-r--r-- | www/js/views/submit.js | 51 | ||||
-rw-r--r-- | www/templates/en/submit_confirm.html | 21 |
5 files changed, 90 insertions, 2 deletions
diff --git a/www/js/app.js b/www/js/app.js index fa153ba..15647ba 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', 'offline', 'save_offline', 'reports', 'address_search', 'existing', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'sent' + 'home', 'around', 'offline', 'save_offline', 'reports', 'address_search', 'existing', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'submit_confirm', 'sent' ], isOffline: 0, @@ -105,6 +105,11 @@ var tpl = { localStorage.currentDraftID = null; }, + isLoggedIn: function() { + return FMS.currentUser && FMS.currentUser.get('email') && + FMS.currentUser.get('password') && FMS.currentUser.get('name'); + }, + initialize: function () { if ( this.initialized == 1 ) { return this; diff --git a/www/js/router.js b/www/js/router.js index b7b9539..9d7e751 100644 --- a/www/js/router.js +++ b/www/js/router.js @@ -12,6 +12,7 @@ 'existing': 'existing', 'photo': 'photo', 'details': 'details', + 'submit-start': 'submitStart', 'submit': 'submit', 'submit-email': 'submitEmail', 'submit-name': 'submitName', @@ -71,6 +72,16 @@ this.changeView(detailsView); }, + submitStart: function() { + var submitView; + if ( FMS.currentUser && FMS.isLoggedIn() ) { + submitView = new FMS.SubmitConfirmView({ model: FMS.currentDraft }); + } else { + submitView = new FMS.SubmitEmailView({ model: FMS.currentDraft }); + } + this.changeView(submitView); + }, + submit: function(){ var submitView = new FMS.SubmitView({ model: FMS.currentDraft }); this.changeView(submitView); diff --git a/www/js/views/details.js b/www/js/views/details.js index 772d4c9..d3914c6 100644 --- a/www/js/views/details.js +++ b/www/js/views/details.js @@ -4,7 +4,7 @@ template: 'details', id: 'details-page', prev: 'photo', - next: 'submit-email', + next: 'submit-start', events: { 'pagehide': 'destroy', diff --git a/www/js/views/submit.js b/www/js/views/submit.js index 937eaa7..8ab54d7 100644 --- a/www/js/views/submit.js +++ b/www/js/views/submit.js @@ -244,3 +244,54 @@ }); })(FMS, Backbone, _, $); +(function (FMS, Backbone, _, $) { + _.extend( FMS, { + SubmitConfirmView: FMS.SubmitView.extend({ + template: 'submit_confirm', + id: 'submit-confirm-page', + prev: 'details', + + events: { + 'pagehide': 'destroy', + 'pageshow': 'afterDisplay', + 'click .ui-btn-left': 'onClickButtonPrev', + 'click #report': 'onClickSubmit' + }, + + validate: function() { + this.clearValidationErrors(); + var isValid = 1; + + var name = $('#form_name').val(); + if ( !name ) { + isValid = 0; + 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 ) ) { + isValid = 0; + this.validationError('form_name', FMS.validationStrings.name.validName); + } + } + + return isValid; + }, + + beforeSubmit: function() { + this.model.set('submit_clicked', 'submit_sign_in'); + }, + + onReportError: function(model, err, options) { + // TODO: this is a temporary measure which should be replaced by a more + // sensible login mechanism + if ( err.check_name ) { + this.onClickSubmit(); + } else { + if ( err.errors && err.errors.password ) { + this.validationError('form_password', err.errors.password ); + } + } + } + }) + }); +})(FMS, Backbone, _, $); diff --git a/www/templates/en/submit_confirm.html b/www/templates/en/submit_confirm.html new file mode 100644 index 0000000..286a203 --- /dev/null +++ b/www/templates/en/submit_confirm.html @@ -0,0 +1,21 @@ +<div id="submit-header" data-role="header" data-position="fixed" data-id="locate"> + <h1>Your details</h1> +</div> + +<div class="container" data-role="content" data-enhance="false"> + <p> + You are logged in as <%= user.email %>. + </p> + + <p> + Please confirm your name, if you want it to be public and optionally your phone number. + </p> + + <input type="text" value="<%= user.name %>" name="name" id="form_name" placeholder="Please enter your name" required> + <input type="tel" value="<%= user.phone %>" name="name" id="form_phone" placeholder="Please enter your phone number"> + <div class="checkbox-group"> + <input type="checkbox" name="may_show_name" id="form_may_show_name" value="1" checked> + <label class="inline" for="form_may_show_name">Show my name publicly</label> + </div> + <input class="green-btn" type="button" id="report" name="report" value="Report"> +</div> |