aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/views
diff options
context:
space:
mode:
Diffstat (limited to 'www/js/views')
-rw-r--r--www/js/views/around.js31
-rw-r--r--www/js/views/details.js35
-rw-r--r--www/js/views/details_extra.js8
-rw-r--r--www/js/views/fms.js30
-rw-r--r--www/js/views/home.js5
-rw-r--r--www/js/views/login.js28
-rw-r--r--www/js/views/offline.js93
-rw-r--r--www/js/views/photo.js67
-rw-r--r--www/js/views/submit.js110
9 files changed, 290 insertions, 117 deletions
diff --git a/www/js/views/around.js b/www/js/views/around.js
index f0b8692..4afc5bb 100644
--- a/www/js/views/around.js
+++ b/www/js/views/around.js
@@ -15,6 +15,7 @@
'vclick .ui-input-clear': 'clearSearchErrors',
'blur #pc': 'clearSearchErrors',
'vclick #relocate': 'centerMapOnPosition',
+ 'vclick #hidepins': 'toggleMarkersVisibility',
'vclick #cancel': 'onClickCancel',
'vclick #confirm-map': 'onClickReport',
'vclick #mark-here': 'onClickMark',
@@ -45,7 +46,7 @@
$('#view-my-reports').hide();
$('#login-options').hide();
$('#postcodeForm').hide();
- $('#relocate').hide();
+ $('#relocate, #hidepins').addClass("nodisplay");
$('#cancel').hide();
$('#map_box').removeClass('background-map');
this.fixPageHeight();
@@ -101,7 +102,7 @@
},
gotLocation: function( info ) {
- $('#relocate').show();
+ $('#relocate, #hidepins').removeClass("nodisplay");
this.finishedLocating();
this.listenTo(FMS.locator, 'gps_current_position', this.positionUpdate);
@@ -121,7 +122,7 @@
positionUpdate: function( info ) {
if ( $('#front-howto').is(':hidden') ) {
- $('#relocate').show();
+ $('#relocate, #hidepins').removeClass("nodisplay");
}
FMS.currentPosition = info.coordinates;
var centre = this.projectCoords( info.coordinates );
@@ -182,7 +183,7 @@
msg = FMS.strings.location_problem;
}
if ( !fixmystreet.map ) {
- $('#relocate').hide();
+ $('#relocate, #hidepins').addClass("nodisplay");
$('#mark-here').hide();
// if we are going to display the help then we don't want to focus on
// the search box as it will show through the help
@@ -197,7 +198,7 @@
},
displayHelpIfFirstTime: function() {
- if ( !FMS.usedBefore ) {
+ if ( !FMS.usedBefore && !CONFIG.HELP_DISABLED ) {
FMS.helpShow();
}
},
@@ -267,7 +268,6 @@
onClickCancel: function(e) {
e.preventDefault();
- fixmystreet.markers.removeAllFeatures();
fixmystreet_activate_drag();
// force pins to be refetched and displayed
fixmystreet.bbox_strategy.update({force: true});
@@ -352,7 +352,7 @@
},
goAddress: function(e) {
- $('#relocate').show();
+ $('#relocate, #hidepins').removeClass("nodisplay");
$('#front-howto').html('').hide();
var t = $(e.target);
var lat = t.attr('data-lat');
@@ -371,7 +371,7 @@
$('#pc').attr('placeholder', msg).addClass('error');;
} else {
$('#front-howto').html(msg);
- $('#relocate').hide();
+ $('#relocate, #hidepins').addClass("nodisplay");
$('#front-howto').show();
}
},
@@ -380,7 +380,7 @@
$('#pc').attr('placeholder', this.origPcPlaceholder).removeClass('error');;
if ( fixmystreet.map ) {
$('#front-howto').hide();
- $('#relocate').show();
+ $('#relocate, #hidepins').removeClass("nodisplay");
}
},
@@ -400,7 +400,7 @@
}
$('#front-howto').html('<p>' + FMS.strings.multiple_matches + '</p><ul data-role="listview" data-inset="true">' + multiple + '</ul>');
$('.ui-page').trigger('create');
- $('#relocate').hide();
+ $('#relocate, #hidepins').addClass("nodisplay");
$('#front-howto').show();
} else {
this.searchError( FMS.strings.location_problem );
@@ -410,9 +410,7 @@
pauseMap: function() {
this.stopListening(FMS.locator);
FMS.locator.stopTracking();
- if ( FMS.iPhoneModel > 3 ) {
- $('#map_box').addClass('background-map');
- }
+ $('#map_box').addClass('background-map');
$('#map_box').off('touchend');
if ( fixmystreet.map ) {
fixmystreet.nav.deactivate();
@@ -442,7 +440,7 @@
e.preventDefault();
if ( !fixmystreet.map ) {
this.$('#mark-here').hide();
- this.$('#relocate').hide();
+ this.$('#relocate, #hidepins').addClass("nodisplay");
$('#front-howto').html('<p>' + FMS.strings.locate_dismissed + '</p>');
$('#front-howto').show();
}
@@ -497,6 +495,11 @@
);
return centre;
+ },
+
+ toggleMarkersVisibility: function(e) {
+ e.preventDefault();
+ fixmystreet.markers.setVisibility(!fixmystreet.markers.getVisibility());
}
})
});
diff --git a/www/js/views/details.js b/www/js/views/details.js
index 9f03d58..84b6ac2 100644
--- a/www/js/views/details.js
+++ b/www/js/views/details.js
@@ -18,6 +18,16 @@
'blur input': 'updateCurrentReport'
},
+ initialize: function() {
+ var that = this;
+ window.addEventListener('native.keyboardshow', function(e) {
+ that.fixDetailTextAreaHeight(e.keyboardHeight);
+ });
+ window.addEventListener('native.keyboardhide', function(e) {
+ that.fixDetailTextAreaHeight();
+ });
+ },
+
afterRender: function() {
this.$('#form_category').attr('data-role', 'none');
@@ -28,13 +38,18 @@
},
- beforeDisplay: function() {
- this.fixPageHeight();
+ beforeDisplay: function(extra) {
+ this.fixDetailTextAreaHeight();
+ },
+
+ fixDetailTextAreaHeight: function(extra) {
+ extra = extra || 0;
+ this.fixPageHeight(extra);
var header = this.$("div[data-role='header']:visible"),
detail = this.$('#form_detail'),
top = detail.position().top,
viewHeight = $(window).height(),
- contentHeight = viewHeight - header.outerHeight() + 15;
+ contentHeight = viewHeight - header.outerHeight() + 15 - extra;
detail.height( contentHeight - top );
},
@@ -87,8 +102,18 @@
timeout: 30000,
success: function( data, status ) {
if ( data && data.category_extra && data.category_extra.length > 0 ) {
- that.model.set('category_extras', data.category_extra);
- that.navigate('details_extra');
+ // Some categories have only hidden fields - in that case we
+ // don't want to navigate to the details_extra view.
+ var all_hidden = data.category_extra_json.reduce(function(accumulator, field) {
+ return accumulator && (field.automated === "hidden_field");
+ }, true);
+
+ if (all_hidden) {
+ that.navigate( that.next );
+ } else {
+ that.model.set('category_extras', data.category_extra);
+ that.navigate('details_extra');
+ }
} else {
that.navigate( that.next );
}
diff --git a/www/js/views/details_extra.js b/www/js/views/details_extra.js
index 160ff11..e5f63ba 100644
--- a/www/js/views/details_extra.js
+++ b/www/js/views/details_extra.js
@@ -19,15 +19,19 @@
afterRender: function() {
this.populateFields();
+ this.enableScrolling();
},
- onClickButtonPrev: function() {
+ onClickButtonPrev: function(e) {
+ e.preventDefault();
+ this.disableScrolling();
this.model.set('hasExtras', 0);
this.updateCurrentReport();
this.navigate( this.prev, true );
},
onClickButtonNext: function() {
+ this.disableScrolling();
this.clearValidationErrors();
var valid = 1;
var that = this;
@@ -49,6 +53,8 @@
this.clearValidationErrors();
this.updateCurrentReport();
this.navigate( this.next );
+ } else {
+ this.enableScrolling();
}
},
diff --git a/www/js/views/fms.js b/www/js/views/fms.js
index 6ff569b..ae1174f 100644
--- a/www/js/views/fms.js
+++ b/www/js/views/fms.js
@@ -2,7 +2,7 @@
_.extend( FMS, {
FMSView: Backbone.View.extend({
tag: 'div',
- bottomMargin: 20,
+ bottomMargin: 0,
contentSelector: '[data-role="content"]',
events: {
@@ -45,12 +45,21 @@
return this;
},
- fixPageHeight: function() {
+ fixPageHeight: function(extra) {
+ extra = extra || 0;
var header = this.$("div[data-role='header']:visible"),
content = this.$(this.contentSelector),
top = content.position().top,
viewHeight = $(window).height(),
- contentHeight = FMS.windowHeight - header.outerHeight() - this.bottomMargin;
+ contentHeight = FMS.windowHeight - header.outerHeight() - this.bottomMargin - extra;
+
+ if ($("body").hasClass("iphone-x")) {
+ var body = $("body").get(0);
+ var inset = window.getComputedStyle(body).getPropertyValue("--safe-area-inset-bottom");
+ // We want the pixel value, not the CSS string
+ inset = parseInt(inset.replace(/[^\d]*/g, ''));
+ contentHeight -= inset;
+ }
this.setHeight( content, contentHeight - top );
},
@@ -107,7 +116,20 @@
$('.form-error').removeClass('form-error');
},
- destroy: function() { FMS.printDebug('destory for ' + this.id); this._destroy(); this.remove(); },
+ disableScrolling: function() {
+ if ( typeof cordova !== 'undefined' ) {
+ cordova.plugins.Keyboard.disableScroll(true);
+ $('body').scrollTop(0);
+ }
+ },
+
+ enableScrolling: function() {
+ if ( typeof cordova !== 'undefined' ) {
+ cordova.plugins.Keyboard.disableScroll(false);
+ }
+ },
+
+ destroy: function() { FMS.printDebug('destroy for ' + this.id); this._destroy(); this.remove(); },
_destroy: function() {}
})
diff --git a/www/js/views/home.js b/www/js/views/home.js
index 998af1c..d82b874 100644
--- a/www/js/views/home.js
+++ b/www/js/views/home.js
@@ -24,11 +24,14 @@
afterDisplay: function() {
$('#load-screen').hide();
+
if ( FMS.isOffline ) {
this.navigate( 'offline' );
+ } else if ( !FMS.isLoggedIn && CONFIG.LOGIN_REQUIRED ) {
+ this.navigate( 'login' );
} else if ( FMS.currentDraft && (
FMS.currentDraft.get('title') || FMS.currentDraft.get('lat') ||
- FMS.currentDraft.get('details') || FMS.currentDraft.get('file') )
+ FMS.currentDraft.get('details') || FMS.currentDraft.get('files').length > 0 )
) {
this.navigate( 'existing' );
} else {
diff --git a/www/js/views/login.js b/www/js/views/login.js
index c0f16ba..9225c18 100644
--- a/www/js/views/login.js
+++ b/www/js/views/login.js
@@ -40,8 +40,7 @@
that.model.set('name', data.name);
that.model.save();
FMS.isLoggedIn = 1;
- that.$('#password_row').hide();
- that.$('#success_row').show();
+ that.rerender();
} else {
that.validationError('signinForm', FMS.strings.login_details_error);
}
@@ -65,11 +64,7 @@
FMS.isLoggedIn = 0;
that.model.set('password', '');
that.model.save();
- that.$('#form_email').val('');
- that.$('#form_password').val('');
- that.$('#success_row').hide();
- that.$('#signed_in_row').hide();
- that.$('#password_row').show();
+ that.rerender();
},
error: function() {
that.validationError('err', FMS.strings.logout_error);
@@ -83,7 +78,7 @@
if ( !$('#form_password').val() ) {
isValid = 0;
- this.validationError('form_password', FMS.validationStrings.password );
+ this.validationError('form_password', FMS.validationStrings.password.required);
}
var email = $('#form_email').val();
@@ -102,6 +97,23 @@
}
return isValid;
+ },
+
+ beforeDisplay: function() {
+ this.fixPageHeight();
+ if ( !FMS.isLoggedIn && CONFIG.LOGIN_REQUIRED ) {
+ this.$("#reports-next-btn").hide();
+ }
+ },
+
+ rerender: function() {
+ // Simply calling this.render() breaks the DOM in a weird and
+ // interesting way - somehow the main view element is duplicated
+ // instead of replaced and none of the event handlers are
+ // hooked up so you end up with a blank screen.
+ // This is a convenience wrapper around the correct router call
+ // which works around the problem.
+ FMS.router.login();
}
})
});
diff --git a/www/js/views/offline.js b/www/js/views/offline.js
index ac007d1..3ce94a9 100644
--- a/www/js/views/offline.js
+++ b/www/js/views/offline.js
@@ -9,17 +9,18 @@
events: {
'pagehide': 'destroy',
- 'pagebeforeshow': 'beforeShow',
+ 'pagebeforeshow': 'beforeDisplay',
'pageshow': 'afterDisplay',
'vclick .ui-btn-left': 'onClickButtonPrev',
'vclick .ui-btn-right': 'onClickButtonNext',
'vclick #id_photo_button': 'takePhoto',
'vclick #id_existing': 'addPhoto',
- 'vclick #id_del_photo_button': 'deletePhoto',
+ 'vclick .del_photo_button': 'deletePhoto',
'vclick #locate': 'onClickLocate',
'vclick #locate_cancel': 'onClickCancel',
'blur input': 'toggleNextButton',
- 'blur textarea': 'toggleNextButton'
+ 'blur textarea': 'blurTextArea',
+ 'focus textarea': 'focusTextArea'
},
_back: function() {
@@ -30,7 +31,7 @@
var hasContent = false;
if ( $('#form_title').val() || $('#form_detail').val() ||
- this.model.get('lat') || this.model.get('file') ) {
+ this.model.get('lat') || this.model.get('files').length > 0 ) {
hasContent = true;
}
@@ -39,11 +40,22 @@
afterDisplay: function() {
$('body')[0].scrollTop = 0;
- $('div[data-role="content"]').show();
- },
- beforeShow: function() {
- $('div[data-role="content"]').hide();
+ // The height of the photos container needs to be adjusted
+ // depending on the number of photos - if the max number of
+ // photos have already been added then the 'add photo' UI isn't
+ // shown so we should use all the vertical space for the
+ // thumbnails.
+ var wrapperHeight = $(".ui-content").height();
+ wrapperHeight -= $(".ui-content .notopmargin").outerHeight(true);
+ wrapperHeight -= $(".ui-content #locate_result").outerHeight(true);
+ wrapperHeight -= $(".ui-content .inputcard").outerHeight(true);
+ wrapperHeight -= $(".ui-content #add_photo").outerHeight(true);
+ $(".photo-wrapper").height(wrapperHeight);
+ },
+
+ beforeDisplay: function() {
+ this.fixPageHeight();
this.toggleNextButton();
},
@@ -55,6 +67,15 @@
}
},
+ focusTextArea: function() {
+ $("textarea#form_detail").get(0).rows = 7;
+ },
+
+ blurTextArea: function(e) {
+ $("textarea#form_detail").get(0).rows = 2;
+ this.toggleNextButton();
+ },
+
failedLocation: function(details) {
this.finishedLocating();
this.locateCount = 21;
@@ -73,32 +94,47 @@
takePhoto: function() {
var that = this;
+ $.mobile.loading('show');
navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, { saveToPhotoAlbum: true, quality: 49, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.CAMERA, correctOrientation: true });
},
addPhoto: function() {
var that = this;
+ $.mobile.loading('show');
navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, { saveToPhotoAlbum: false, quality: 49, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, correctOrientation: true });
},
addPhotoSuccess: function(imgURI) {
- var move = FMS.files.moveURI( imgURI );
+ var move;
+ // on iOS the photos go into a temp folder in the apps own filespace so we
+ // can move them, and indeed have to as the tmp space is cleaned out by the OS
+ // so draft reports might have their images removed. on android you access the
+ // images where they are stored on the filesystem so if you move, and then delete
+ // them, you are moving and deleting the only copy of them which is likely to be
+ // surprising and unwelcome so we copy them instead.
+ var fileName = CONFIG.NAMESPACE + '_' + this.model.cid + '_' + moment().unix() + '.jpg';
+ if ( FMS.isAndroid ) {
+ move = FMS.files.copyURI( imgURI, fileName );
+ } else {
+ move = FMS.files.moveURI( imgURI, fileName );
+ }
var that = this;
move.done( function( file ) {
- $('#photo').attr('src', file.toURL());
- that.model.set('file', file.toURL());
- FMS.saveCurrentDraft();
+ var files = that.model.get('files');
+ files.push(file.toURL());
+ that.model.set('files', files);
+ that.updateCurrentReport();
- $('#photo-next-btn .ui-btn-text').text(FMS.strings.next);
- $('#display_photo').show();
- $('#add_photo').hide();
+ $.mobile.loading('hide');
+ that.rerender();
});
move.fail( function() { that.addPhotoFail(); } );
},
addPhotoFail: function(message) {
+ $.mobile.loading('hide');
if ( message != 'no image selected' &&
message != 'Selection cancelled.' &&
message != 'Camera cancelled.' ) {
@@ -106,18 +142,22 @@
}
},
- deletePhoto: function() {
- var that = this;
- var del = FMS.files.deleteURI( this.model.get('file') );
+ deletePhoto: function(e) {
+ e.preventDefault();
+ $.mobile.loading('show');
+ var files = this.model.get('files');
+ var index = parseInt($(e.target).data('fileIndex'));
+ var deleted_file = files.splice(index, 1)[0];
+ var del = FMS.files.deleteURI( deleted_file );
+
+ var that = this;
del.done( function() {
- that.model.set('file', '');
- FMS.saveCurrentDraft();
- $('#photo').attr('src', '');
+ that.model.set('files', files);
+ that.updateCurrentReport();
- $('#photo-next-btn .ui-btn-text').text(FMS.strings.skip);
- $('#display_photo').hide();
- $('#add_photo').show();
+ $.mobile.loading('hide');
+ that.rerender();
});
},
@@ -154,7 +194,12 @@
this.model.set('title', $('#form_title').val());
this.model.set('details', $('#form_detail').val());
FMS.saveCurrentDraft();
+ },
+
+ rerender: function() {
+ FMS.router.offline();
}
+
})
});
})(FMS, Backbone, _, $);
diff --git a/www/js/views/photo.js b/www/js/views/photo.js
index 485b74c..0b0c5e9 100644
--- a/www/js/views/photo.js
+++ b/www/js/views/photo.js
@@ -14,17 +14,23 @@
'vclick .ui-btn-right': 'onClickButtonNext',
'vclick #id_photo_button': 'takePhoto',
'vclick #id_existing': 'addPhoto',
- 'vclick #id_del_photo_button': 'deletePhoto'
+ 'vclick .del_photo_button': 'deletePhoto'
},
beforeDisplay: function() {
this.fixPageHeight();
- this.$('#id_del_photo_button').hide();
- if ( this.model.get('file') ) {
- $('#id_photo_button').parents('.ui-btn').hide();
- $('#id_existing').parents('.ui-btn').hide();
- window.setTimeout( function() { $('#id_del_photo_button').show(); }, 250 );
- }
+ },
+
+ afterDisplay: function() {
+ // The height of the photos container needs to be adjusted
+ // depending on the number of photos - if the max number of
+ // photos have already been added then the 'add photo' UI isn't
+ // shown so we should use all the vertical space for the
+ // thumbnails.
+ var wrapperHeight = $(".ui-content").height();
+ wrapperHeight -= $(".ui-content h2").outerHeight(true);
+ wrapperHeight -= $(".ui-content .bottom-btn").outerHeight(true)
+ $(".photo-wrapper").height(wrapperHeight);
},
getOptions: function(isFromAlbum) {
@@ -52,7 +58,7 @@
takePhoto: function(e) {
e.preventDefault();
$.mobile.loading('show');
- $('#photo').hide();
+ $('.photo-wrapper .photo img').hide();
var that = this;
var options = this.getOptions();
@@ -63,7 +69,7 @@
addPhoto: function(e) {
e.preventDefault();
$.mobile.loading('show');
- $('#photo').hide();
+ $('.photo-wrapper .photo img').hide();
var that = this;
var options = this.getOptions(true);
navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, options);
@@ -86,25 +92,19 @@
var that = this;
move.done( function( file ) {
- $('#nophoto_title').hide();
- $('#photo_title').html(FMS.strings.photo_added).show();
- $('#photo').attr('src', file.toURL()).addClass('small').removeClass('placeholder');
- that.model.set('file', file.toURL());
+ var files = that.model.get('files');
+ files.push(file.toURL());
+ that.model.set('files', files);
FMS.saveCurrentDraft();
-
- $('#photo-next-btn .ui-btn-text').text(FMS.strings.next);
- $('#id_photo_button').parents('.ui-btn').hide();
- $('#id_existing').parents('.ui-btn').hide();
- $('#photo').show();
- window.setTimeout(function() { $('#id_del_photo_button').show() }, 500);
- window.setTimeout(function() { $.mobile.loading('hide') }, 100);
+ $.mobile.loading('hide');
+ that.rerender();
});
move.fail( function() { that.addPhotoFail(); } );
},
addPhotoFail: function(message) {
- $('#photo').show();
+ $('.photo-wrapper .photo img').show();
$.mobile.loading('hide');
if ( message != 'no image selected' &&
message != 'Selection cancelled.' &&
@@ -115,22 +115,25 @@
deletePhoto: function(e) {
e.preventDefault();
- var that = this;
- var del = FMS.files.deleteURI( this.model.get('file') );
+ var files = this.model.get('files');
+ var index = parseInt($(e.target).data('fileIndex'));
+ var deleted_file = files.splice(index, 1)[0];
+ var del = FMS.files.deleteURI( deleted_file );
+
+ var that = this;
del.done( function() {
- $('#photo_title').hide();
- $('#nophoto_title').show();
- $('#id_del_photo_button').hide();
- that.model.set('file', '');
+ that.model.set('files', files);
FMS.saveCurrentDraft(true);
- $('#photo').attr('src', 'images/placeholder-photo.png').addClass('placeholder').removeClass('small');
-
- $('#photo-next-btn .ui-btn-text').text(FMS.strings.skip);
- $('#id_photo_button').parents('.ui-btn').show();
- $('#id_existing').parents('.ui-btn').show();
+ that.rerender();
});
+ },
+ rerender: function() {
+ // Simply calling this.render() breaks the DOM in a weird and
+ // interesting way, so this is a convenience wrapper around
+ // the correct router call.
+ FMS.router.photo();
}
})
});
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);
+ }
}
})
});