diff options
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/app.js | 48 | ||||
-rw-r--r-- | www/js/config.js-example | 6 | ||||
-rw-r--r-- | www/js/views/home.js | 3 | ||||
-rw-r--r-- | www/js/views/login.js | 26 |
4 files changed, 55 insertions, 28 deletions
diff --git a/www/js/app.js b/www/js/app.js index 61ee590..71a4f97 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -118,21 +118,28 @@ var tpl = { }, checkLoggedInStatus: function() { + var p = $.Deferred(); + if ( FMS.isOffline ) { + p.resolve(); } else { $.ajax( { url: CONFIG.FMS_URL + '/auth/ajax/check_auth', type: 'GET', dataType: 'json', timeout: 30000, - success: function( data, status ) { - FMS.isLoggedIn = 1; - }, - error: function() { - FMS.isLoggedIn = 0; - } - } ); + }) + .done(function() { + FMS.isLoggedIn = 1; + p.resolve(); + }) + .fail(function() { + FMS.isLoggedIn = 0; + p.resolve(); + }) } + + return p; }, saveCurrentDraft: function(force) { @@ -339,20 +346,21 @@ var tpl = { FMS.allDrafts.fetch(); FMS.checkOnlineStatus(); FMS.loadCurrentDraft(); - FMS.checkLoggedInStatus(); - if (!CONFIG.HELP_DISABLED) { - FMS.setupHelp(); - } + FMS.checkLoggedInStatus().done(function() { + if (!CONFIG.HELP_DISABLED) { + FMS.setupHelp(); + } - Backbone.history.start(); - if ( navigator && navigator.splashscreen ) { - navigator.splashscreen.hide(); - } else { - $('#load-screen').hide(); - } - if (!CONFIG.HELP_DISABLED) { - $('#display-help').show(); - } + Backbone.history.start(); + if ( navigator && navigator.splashscreen ) { + navigator.splashscreen.hide(); + } else { + $('#load-screen').hide(); + } + if (!CONFIG.HELP_DISABLED) { + $('#display-help').show(); + } + }); }); } }); diff --git a/www/js/config.js-example b/www/js/config.js-example index 2e8017b..6260aef 100644 --- a/www/js/config.js-example +++ b/www/js/config.js-example @@ -48,7 +48,11 @@ var CONFIG = { // Set this to true if you want to disable the help button on the right hand // side of the screen. NB you'll also need to hide #display-help and #help // elements in your CSS. - HELP_DISABLED: false + HELP_DISABLED: false, + + // If this is true then the user must login as the first step after + // installing the app, and before making any reports. + LOGIN_REQUIRED: false }; diff --git a/www/js/views/home.js b/www/js/views/home.js index 998af1c..05ee2f7 100644 --- a/www/js/views/home.js +++ b/www/js/views/home.js @@ -24,8 +24,11 @@ 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') ) diff --git a/www/js/views/login.js b/www/js/views/login.js index c0f16ba..93a9a5b 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); @@ -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(); } }) }); |