aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--templates/login.html16
-rw-r--r--www/js/app.js48
-rw-r--r--www/js/config.js-example6
-rw-r--r--www/js/views/home.js3
-rw-r--r--www/js/views/login.js26
-rw-r--r--www/templates/en/login.html16
6 files changed, 59 insertions, 56 deletions
diff --git a/templates/login.html b/templates/login.html
index 43e93d9..0cc7c51 100644
--- a/templates/login.html
+++ b/templates/login.html
@@ -12,13 +12,9 @@
<input type="button" id="logout" name="logout" value="[% loc('Sign Out') %]" data-theme="a">
</div>
</div>
- <div id="password_row" class="nodisplay">
- <p class="notopmargin">
- [% loc('Signed out!') %]
- </p>
<% } else { %>
<div id="password_row">
- <% } %>
+ <p class="notopmargin">[% loc('You are not signed in.') %]</p>
<form name="signinForm" class="inputcard" id="signinForm">
<div>
<input data-role="none" type="email" value="" name="email" id="form_email" placeholder="[% loc('Your Email') %]" required>
@@ -31,13 +27,5 @@
</div>
</form>
</div>
- <div id="success_row" class="nodisplay">
- <p class="notopmargin">
- [% loc('Signed in!') %]
- </p>
- <div id="err" class="nodisplay"></div>
- <div class="bottom-btn">
- <input type="button" id="logout" name="logout" value="[% loc('Sign Out') %]" data-theme="a">
- </div>
- </div>
+ <% } %>
</div>
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();
}
})
});
diff --git a/www/templates/en/login.html b/www/templates/en/login.html
index 13944e8..bbe6267 100644
--- a/www/templates/en/login.html
+++ b/www/templates/en/login.html
@@ -12,13 +12,9 @@
<input type="button" id="logout" name="logout" value="Sign Out" data-theme="a">
</div>
</div>
- <div id="password_row" class="nodisplay">
- <p class="notopmargin">
- Signed out!
- </p>
<% } else { %>
<div id="password_row">
- <% } %>
+ <p class="notopmargin">You are not signed in.</p>
<form name="signinForm" class="inputcard" id="signinForm">
<div>
<input data-role="none" type="email" value="" name="email" id="form_email" placeholder="Your Email" required>
@@ -31,13 +27,5 @@
</div>
</form>
</div>
- <div id="success_row" class="nodisplay">
- <p class="notopmargin">
- Signed in!
- </p>
- <div id="err" class="nodisplay"></div>
- <div class="bottom-btn">
- <input type="button" id="logout" name="logout" value="Sign Out" data-theme="a">
- </div>
- </div>
+ <% } %>
</div>