aboutsummaryrefslogtreecommitdiffstats
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/app.js2
-rw-r--r--www/js/router.js8
-rw-r--r--www/js/strings.js1
-rw-r--r--www/js/views/around.js8
-rw-r--r--www/js/views/login.js77
5 files changed, 94 insertions, 2 deletions
diff --git a/www/js/app.js b/www/js/app.js
index 15647ba..7c85d84 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', 'submit_confirm', 'sent'
+ 'home', 'around', 'offline', 'save_offline', 'reports', 'login', 'address_search', 'existing', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'submit_confirm', 'sent'
],
isOffline: 0,
diff --git a/www/js/router.js b/www/js/router.js
index 9d7e751..748ef1a 100644
--- a/www/js/router.js
+++ b/www/js/router.js
@@ -19,7 +19,8 @@
'submit-password': 'submitPassword',
'save_offline': 'saveOffline',
'sent': 'sent',
- 'reports': 'reports'
+ 'reports': 'reports',
+ 'login': 'login'
},
initialize: function() {
@@ -117,6 +118,11 @@
this.changeView(reportsView);
},
+ login: function() {
+ var loginView = new FMS.LoginView({ model: FMS.currentUser });
+ this.changeView(loginView);
+ },
+
changeView: function(view) {
console.log( 'change View to ' + view.id );
$(view.el).attr('data-role', 'page');
diff --git a/www/js/strings.js b/www/js/strings.js
index f1a1aa2..13b149f 100644
--- a/www/js/strings.js
+++ b/www/js/strings.js
@@ -20,6 +20,7 @@
password: 'Please enter a password'
},
strings: {
+ login_error: 'There was a problem logging you in. Please check your email and password',
location_error: 'Location error',
location_problem: 'There was a problem looking up your location',
multiple_locations: 'More than one location matched that name',
diff --git a/www/js/views/around.js b/www/js/views/around.js
index a323d7e..67983db 100644
--- a/www/js/views/around.js
+++ b/www/js/views/around.js
@@ -9,6 +9,7 @@
'pagebeforeshow': 'beforeDisplay',
'pageshow': 'afterDisplay',
'click #locate_search': 'goSearch',
+ 'click #login': 'goLogin',
'click #reports': 'goReports',
'click #search': 'goSearch',
'click #relocate': 'centerMapOnPosition',
@@ -162,6 +163,13 @@
this.navigate( 'search' );
},
+ goLogin: function(e) {
+ e.preventDefault();
+ this.stopListening(FMS.locator);
+ FMS.locator.stopTracking();
+ this.navigate( 'login' );
+ },
+
goReports: function(e) {
e.preventDefault();
this.stopListening(FMS.locator);
diff --git a/www/js/views/login.js b/www/js/views/login.js
new file mode 100644
index 0000000..62aa325
--- /dev/null
+++ b/www/js/views/login.js
@@ -0,0 +1,77 @@
+(function (FMS, Backbone, _, $) {
+ _.extend( FMS, {
+ LoginView: FMS.FMSView.extend({
+ template: 'login',
+ id: 'login',
+ next: 'home',
+
+ events: {
+ 'pagehide': 'destroy',
+ 'pageshow': 'afterDisplay',
+ 'click #login': 'onClickLogin',
+ 'click #logout': 'onClickLogout',
+ 'click .ui-btn-left': 'onClickButtonPrev',
+ 'click .ui-btn-right': 'onClickButtonNext'
+ },
+
+ onClickLogin: function() {
+ if ( this.validate() ) {
+ var that = this;
+ $.ajax( {
+ url: CONFIG.FMS_URL + '/auth/ajax/sign_in',
+ type: 'POST',
+ data: {
+ email: $('#form_email').val(),
+ password_sign_in: $('#form_password').val()
+ },
+ dataType: 'json',
+ timeout: 30000,
+ success: function( data, status ) {
+ if ( data.name ) {
+ that.model.set('password', $('#form_password').val());
+ that.model.set('email', $('#form_email').val());
+ that.model.set('name', data.name);
+ that.model.save();
+ $('#password_row').hide();
+ $('#success_row').show();
+ } else {
+ that.validationError('form_email', FMS.strings.login_error);
+ }
+ },
+ error: function() {
+ alert('boo :(');
+ }
+ } );
+ }
+ },
+
+ onClickLogout: function() {
+ this.model.set('password', '');
+ this.model.save();
+ $('#signed_in_row').hide();
+ $('#password_row').show();
+ },
+
+ validate: function() {
+ var isValid = 1;
+
+ if ( !$('#form_password').val() ) {
+ isValid = 0;
+ this.validationError('form_password', FMS.validationStrings.password );
+ }
+
+ var email = $('#form_email').val();
+ if ( !email ) {
+ isValid = 0;
+ this.validationError('form_email', FMS.validationStrings.email.required);
+ // regexp stolen from jquery validate module
+ } else if ( ! /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(email) ) {
+ isValid = 0;
+ this.validationError('form_email', FMS.validationStrings.email.email);
+ }
+
+ return isValid;
+ }
+ })
+ });
+})(FMS, Backbone, _, $);