diff options
-rw-r--r-- | www/js/models/report.js | 19 | ||||
-rw-r--r-- | www/js/views/submit.js | 44 | ||||
-rw-r--r-- | www/templates/en/submit.html | 24 |
3 files changed, 77 insertions, 10 deletions
diff --git a/www/js/models/report.js b/www/js/models/report.js index 26d91ad..539832b 100644 --- a/www/js/models/report.js +++ b/www/js/models/report.js @@ -71,18 +71,31 @@ params.name = FMS.currentUser.get('name'); params.email = FMS.currentUser.get('email'); params.phone = FMS.currentUser.get('phone'); + params.password_sign_in = FMS.currentUser.get('password'); + params.submit_sign_in = 1; } else { params.name = $('#form_name').val(); params.email = $('#form_email').val(); params.phone = $('#form_phone').val(); + params.password_sign_in = $('#password_sign_in').val(); + if ( this.submit_clicked == 'submit_sign_in' ) { + params.submit_sign_in = 1; + } else { + params.submit_register = 1; + } + + /* FMS.currentUser = new FMS.User( { name: params.name, email: params.email, - phone: params.phone + phone: params.phone, + password: params.password }); + */ } + var that = this; if ( model.get('file') && model.get('file') !== '' ) { var handlers = options; var fileUploadSuccess = function(r) { @@ -127,9 +140,9 @@ timeout: 30000, success: function(data) { if ( data.success ) { - options.success( data ); + that.trigger('sync', that, data, options); } else { - options.error( data ); + that.trigger('error', that, data, options); } }, error: function (data, status, errorThrown ) { diff --git a/www/js/views/submit.js b/www/js/views/submit.js index 3a04621..7d8644d 100644 --- a/www/js/views/submit.js +++ b/www/js/views/submit.js @@ -3,7 +3,49 @@ SubmitView: FMS.FMSView.extend({ template: 'submit', id: 'submit-page', - prev: 'details' + prev: 'details', + + events: { + 'pagehide': 'destroy', + 'pageshow': 'afterDisplay', + 'click .ui-btn-left': 'onClickButtonPrev', + 'click .ui-btn-right': 'onClickButtonNext', + 'click #submit_signed_in': 'onClickSubmit', + 'click #submit_sign_in': 'onClickSubmit', + 'click #submit_register': 'onClickSubmit' + }, + + render: function(){ + if ( !this.template ) { + console.log('no template to render'); + return; + } + template = _.template( tpl.get( this.template ) ); + if ( this.model ) { + this.$el.html(template({ model: this.model.toJSON(), user: FMS.currentUser })); + } else { + this.$el.html(template()); + } + this.afterRender(); + return this; + }, + + onClickSubmit: function(e) { + this.model.set( 'submit_clicked', $(e.target).attr('id') ); + + this.model.on('sync', this.onReportSync, this ); + this.model.on('error', this.onReportError, this ); + + this.model.save(); + }, + + onReportSync: function(model, resp, options) { + this.navigate( 'sent', 'left' ); + }, + + onReportError: function(model, err, options) { + alert( FMS.strings.sync_error + ': ' + err.errors); + } }) }); })(FMS, Backbone, _, $); diff --git a/www/templates/en/submit.html b/www/templates/en/submit.html index af05003..986617a 100644 --- a/www/templates/en/submit.html +++ b/www/templates/en/submit.html @@ -5,10 +5,10 @@ <div class="container" data-role="content" data-enhance="false"> <div class="content" role="main"> - <form action="" method="post" name="mapForm" id="mapForm" enctype="multipart/form-data" class="validate" data-ajax="false"> <fieldset> <div id="problem_form"> + <% if ( user ) { %> <div id="signed_in"> <p> You are signed in as <span id="username"></span> @@ -29,10 +29,10 @@ </div> <div class="form-txt-submit-box"> - <input class="green-btn" type="submit" id="submit_signed_in" name="submit_signed_in" value="Report"> + <input class="green-btn" type="button" id="submit_signed_in" name="submit_signed_in" value="Report"> </div> </div> - + <% } else { %> <div id="signed_out"> <label for="form_email" id="email_label">Your email</label> <input type="email" value="" name="email" id="form_email" placeholder="Please enter your email address" required> @@ -47,13 +47,25 @@ <label class="hidden-js n" for="password_sign_in">Yes I have a password</label> <div class="form-txt-submit-box"> <input type="password" name="password_sign_in" id="password_sign_in" placeholder="Your password" value=""> - <input class="green-btn" type="submit" id="submit_sign_in" name="submit_sign_in" value="Report"> + <input class="green-btn" type="button" id="submit_sign_in" name="submit_sign_in" value="Report"> </div> </div> <div id="form_sign_in_no" class="form-box"> <h5 id="let_me_confirm"><strong>No</strong> Let me confirm my report by email</h5> + <div id="name_details"> + <label for="form_may_show_name">Name</label> + <input type="text" class="validName" value="" name="name" id="form_name" placeholder="Your name"> + + <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> + + <label for="form_phone">Phone number</label> + <input type="text" value="" name="phone" id="form_phone" placeholder="Your phone number (optional)"> + </div> <div id="password_surround"> <label class="form-focus-hidden" for="password_register" id="password_label">Password</label> @@ -61,12 +73,13 @@ <div class="form-txt-submit-box form-focus-hidden"> <input type="password" name="password_register" id="password_register" value="" placeholder="Enter a password (optional)"> - <input class="green-btn" type="submit" id="submit_register" name="submit_register" value="Report"> + <input class="green-btn" type="button" id="submit_register" name="submit_register" value="Report"> </div> </div> </div> </div> + <% } %> <div id="report_save" class="form-box"> <h5>Save this report for completion later</h5> @@ -81,6 +94,5 @@ </div> </div> - </form> </div> </div> |