aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/views/submit.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js/views/submit.js')
-rw-r--r--www/js/views/submit.js110
1 files changed, 82 insertions, 28 deletions
diff --git a/www/js/views/submit.js b/www/js/views/submit.js
index 6a7c946..4a92fe3 100644
--- a/www/js/views/submit.js
+++ b/www/js/views/submit.js
@@ -86,7 +86,7 @@
if ( !this._handleInvalid( model, err, options ) ) {
var errors = err.errors;
var errorList = '<ul><li class="plain">' + FMS.strings.invalid_report + '</li>';
- var validErrors = [ 'password', 'category', 'name' ];
+ var validErrors = [ 'password', 'password_register', 'category', 'name' ];
for ( var k in errors ) {
if ( validErrors.indexOf(k) >= 0 || errors[k].match(/required/) ) {
if ( k === 'password' ) {
@@ -128,6 +128,22 @@
}
},
+ validateUserTitle: function() {
+ if ( this.model.get('titles_list') && this.model.get('titles_list').length > 0 ) {
+ if ( $('#form_title').val() === '' ) {
+ this.validationError('form_title', FMS.strings.required);
+ return false;
+ }
+ }
+ return true;
+ },
+
+ setUserTitle: function() {
+ if ( this.model.get('titles_list') && this.model.get('titles_list').length > 0 ) {
+ FMS.currentUser.set('title', $('#form_title').val());
+ }
+ },
+
beforeSubmit: function() {},
afterSubmit: function() {},
@@ -145,7 +161,8 @@
(function (FMS, Backbone, _, $) {
_.extend( FMS, {
SubmitInitialPageView: FMS.SubmitView.extend({
- onClickButtonPrev: function() {
+ onClickButtonPrev: function(e) {
+ e.preventDefault();
if ( this.model.get('hasExtras') == 1 ) {
this.navigate( 'details_extra', true );
} else {
@@ -264,11 +281,8 @@
}
}
- if ( this.model.get('titles_list') && this.model.get('titles_list').length > 0 ) {
- if ( $('#form_title').val() === '' ) {
- this.validationError('form_title', FMS.strings.required);
- isValid = 0;
- }
+ if (!this.validateUserTitle()) {
+ isValid = 0;
}
return isValid;
@@ -282,10 +296,7 @@
this.model.set('may_show_name', $('#form_may_show_name').is(':checked'));
FMS.currentUser.set('name', $('#form_name').val());
FMS.currentUser.set('may_show_name', $('#form_may_show_name').is(':checked'));
-
- if ( this.model.get('titles_list') && this.model.get('titles_list').length > 0 ) {
- FMS.currentUser.set('title', $('#form_title').val());
- }
+ this.setUserTitle();
if ( FMS.currentUser ) {
FMS.currentUser.save();
@@ -329,20 +340,21 @@
},
validate: function() {
+ this.clearValidationErrors();
var isValid = 1;
if ( !$('#form_password').val() ) {
isValid = 0;
- this.validationError('form_password', FMS.validationStrings.password );
+ this.validationError('form_password', FMS.validationStrings.password.required );
+ } else if ( CONFIG.PASSWORD_MIN_LENGTH && $('#form_password').val().length < CONFIG.PASSWORD_MIN_LENGTH ) {
+ isValid = 0;
+ var msg = FMS.validationStrings.password.short.replace('%d', CONFIG.PASSWORD_MIN_LENGTH);
+ this.validationError('form_password', msg);
}
- if ( $('#form_name').val() && this.model.get('titles_list') && this.model.get('titles_list').length > 0 ) {
- if ( $('#form_title').val() === '' ) {
- this.validationError('form_title', FMS.strings.required);
- isValid = 0;
- }
+ if ($('#form_name').val() && !this.validateUserTitle()) {
+ isValid = 0;
}
-
return isValid;
},
@@ -357,9 +369,7 @@
this.model.set('may_show_name', $('#form_may_show_name').is(':checked'));
FMS.currentUser.set('name', $('#form_name').val());
FMS.currentUser.set('may_show_name', $('#form_may_show_name').is(':checked'));
- if ( this.model.get('titles_list') && this.model.get('titles_list').length > 0 ) {
- FMS.currentUser.set('title', $('#form_title').val());
- }
+ this.setUserTitle();
FMS.currentUser.save();
} else {
// if this is set then we are registering a password
@@ -408,14 +418,43 @@
onClickContinue: function(e) {
e.preventDefault();
- if ( this.validate() ) {
- $('#continue').focus();
- if ( ! this.model.get('submit_clicked') ) {
- this.model.set('submit_clicked', 'submit_sign_in');
+ if (this.validate()) {
+ // The password may be long enough, but is it going to be
+ // accepted by the server? Check before proceeding.
+ if (CONFIG.PASSWORD_CHECK_COMMON) {
+ var that = this;
+ $.post(
+ CONFIG.FMS_URL + "/auth/common_password",
+ { password_register: $('#form_password').val() },
+ null,
+ 'json'
+ )
+ .done(function(result) {
+ if (result === true) {
+ that.savePasswordAndContinue();
+ } else {
+ that.validationError('form_password', result);
+ }
+ })
+ .fail(function() {
+ // If this failed for whatever reason (e.g. network
+ // error etc), don't worry about it as it'll be
+ // resubmitted with the report.
+ that.savePasswordAndContinue();
+ });
+ } else {
+ this.savePasswordAndContinue();
}
- FMS.currentUser.set('password', $('#form_password').val());
- this.navigate( this.next );
}
+ },
+
+ savePasswordAndContinue: function() {
+ $('#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 );
}
})
});
@@ -462,18 +501,33 @@
this.model.set('submit_clicked', 'submit_register');
FMS.currentUser.set('name', $('#form_name').val());
FMS.currentUser.set('may_show_name', $('#form_may_show_name').is(':checked'));
+ this.setUserTitle();
},
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();
+ this.doSubmit();
} else {
if ( err.errors && err.errors.password ) {
this.validationError('form_password', err.errors.password );
}
}
+ },
+
+ afterRender: function() {
+ console.log("SubmitConfirmView.afterRender");
+ if (CONFIG.SKIP_CONFIRM_REPORT) {
+ var that = this;
+ setTimeout(function() {
+ // This needs to be in a setTimeout call otherwise
+ // the app gets stuck on an empty "Your Details" page.
+ // This is something to do with the way Backbone routes
+ // between views, I believe.
+ that.doSubmit();
+ }, 10);
+ }
}
})
});