aboutsummaryrefslogtreecommitdiffstats
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/app.js51
-rw-r--r--www/js/config.js-example15
-rw-r--r--www/js/files.js4
-rw-r--r--www/js/map-OpenLayers.js2
-rw-r--r--www/js/router.js2
-rw-r--r--www/js/views/around.js2
-rw-r--r--www/js/views/fms.js2
-rw-r--r--www/js/views/home.js3
-rw-r--r--www/js/views/login.js26
9 files changed, 76 insertions, 31 deletions
diff --git a/www/js/app.js b/www/js/app.js
index 282e921..71a4f97 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -100,6 +100,11 @@ var tpl = {
printDebug: function(msg) {
if ( CONFIG.DEBUG ) {
console.log(msg);
+
+ // Some messages get logged before we've had a chance to
+ // attach the debugger, so keep them all for later reference.
+ FMS.debug_messages = FMS.debug_messages || [];
+ FMS.debug_messages.push(msg);
}
},
@@ -113,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) {
@@ -334,16 +346,21 @@ var tpl = {
FMS.allDrafts.fetch();
FMS.checkOnlineStatus();
FMS.loadCurrentDraft();
- FMS.checkLoggedInStatus();
- FMS.setupHelp();
-
- Backbone.history.start();
- if ( navigator && navigator.splashscreen ) {
- navigator.splashscreen.hide();
- } else {
- $('#load-screen').hide();
- }
- $('#display-help').show();
+ 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();
+ }
+ });
});
}
});
diff --git a/www/js/config.js-example b/www/js/config.js-example
index 2fceda7..a221cb0 100644
--- a/www/js/config.js-example
+++ b/www/js/config.js-example
@@ -43,7 +43,20 @@ var CONFIG = {
image_svg: 'images/pin.svg',
background_svg: 'images/pin_shadow.svg'
}
- }
+ },
+
+ // 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,
+
+ // 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,
+
+ // The ratio of the data bounds to the viewport bounds (in each dimension).
+ // See http://dev.openlayers.org/releases/OpenLayers-2.13.1/doc/apidocs/files/OpenLayers/Strategy/BBOX-js.html
+ MAP_LOADING_RATIO: 2
};
diff --git a/www/js/files.js b/www/js/files.js
index eea38c3..6d7ea26 100644
--- a/www/js/files.js
+++ b/www/js/files.js
@@ -124,7 +124,7 @@
function moveFile (src, dest, newName) {
- FMS.printDebug( 'moveing file ' + src.fullPath + ' to ' + dest.fullPath );
+ FMS.printDebug( 'moving file ' + src.fullPath + ' to ' + dest.fullPath );
var move = $.Deferred();
@@ -166,7 +166,7 @@
var file = $.Deferred();
- window.resolveLocalFileSystemURI( uri, file.resolve, file.reject);
+ window.resolveLocalFileSystemURL( uri, file.resolve, file.reject);
return file.promise();
}
diff --git a/www/js/map-OpenLayers.js b/www/js/map-OpenLayers.js
index d458641..a3fdc9d 100644
--- a/www/js/map-OpenLayers.js
+++ b/www/js/map-OpenLayers.js
@@ -128,7 +128,7 @@ function fixmystreet_onload() {
fixmystreet.map.addLayer(fixmystreet.report_location);
if (fixmystreet.page == 'around') {
- fixmystreet.bbox_strategy = new OpenLayers.Strategy.BBOX({ ratio: 1 });
+ fixmystreet.bbox_strategy = new OpenLayers.Strategy.BBOX({ ratio: CONFIG.MAP_LOADING_RATIO });
pin_layer_options.strategies = [ fixmystreet.bbox_strategy ];
pin_layer_options.protocol = new OpenLayers.Protocol.HTTP({
url: CONFIG.FMS_URL + '/ajax',
diff --git a/www/js/router.js b/www/js/router.js
index c691abb..2a23708 100644
--- a/www/js/router.js
+++ b/www/js/router.js
@@ -159,7 +159,7 @@
// any transitions as they just add visual distraction to no end
// likewise displaying the offline page
var options = { changeHash: false };
- if ( !this.currentView || this.currentView.id == 'front-page' || view.id == 'offline' ) {
+ if ( !this.currentView || this.currentView.id == 'front-page' || view.id == 'offline' || view.id === this.currentView.id) {
options.transition = 'none';
}
if ( this.reverse ) {
diff --git a/www/js/views/around.js b/www/js/views/around.js
index cb304ee..bafc65d 100644
--- a/www/js/views/around.js
+++ b/www/js/views/around.js
@@ -197,7 +197,7 @@
},
displayHelpIfFirstTime: function() {
- if ( !FMS.usedBefore ) {
+ if ( !FMS.usedBefore && !CONFIG.HELP_DISABLED ) {
FMS.helpShow();
}
},
diff --git a/www/js/views/fms.js b/www/js/views/fms.js
index 6ff569b..aef854f 100644
--- a/www/js/views/fms.js
+++ b/www/js/views/fms.js
@@ -107,7 +107,7 @@
$('.form-error').removeClass('form-error');
},
- destroy: function() { FMS.printDebug('destory for ' + this.id); this._destroy(); this.remove(); },
+ 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..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();
}
})
});