diff options
-rw-r--r-- | www/js/app.js | 15 | ||||
-rw-r--r-- | www/js/views/home.js | 4 |
2 files changed, 16 insertions, 3 deletions
diff --git a/www/js/app.js b/www/js/app.js index 20eceed..07be917 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -41,6 +41,7 @@ var tpl = { 'home', 'around', 'offline', 'reports', 'address_search', 'existing', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'sent' ], + isOffline: 0, initialized: 0, users: new FMS.Users(), currentUser: null, @@ -52,6 +53,14 @@ var tpl = { reportToView: null, + online: function() { + FMS.isOffline = 0; + }, + + offline: function() { + FMS.isOffline = 1; + }, + saveCurrentDraft: function() { FMS.router.pause(); FMS.allDrafts.add( FMS.currentDraft ); @@ -67,6 +76,10 @@ var tpl = { } } localStorage.currentDraftID = null; + if ( navigator && navigator.connection && ( navigator.connection.type == Connection.NONE || + navigator.connection.type == Connection.UNKNOWN ) ) { + FMS.offline(); + } }, removeDraft: function(draftID, removePhoto) { @@ -109,6 +122,8 @@ var tpl = { document.addEventListener('pause', function() { FMS.saveCurrentDraft(); }, false); document.addEventListener('resume', function() { FMS.loadCurrentDraft(); }, false); document.addEventListener('backbutton', function() { FMS.router.back(); }, true); + document.addEventListener('offline', function() { FMS.offline(); }, true); + document.addEventListener('online', function() { FMS.online(); }, true); FMS.allDrafts.fetch(); FMS.loadCurrentDraft(); diff --git a/www/js/views/home.js b/www/js/views/home.js index 383275e..dd908f0 100644 --- a/www/js/views/home.js +++ b/www/js/views/home.js @@ -23,9 +23,7 @@ }, afterDisplay: function() { - if ( navigator && navigator.connection && ( navigator.connection.type == Connection.NONE || - navigator.connection.type == Connection.UNKNOWN ) ) { - localStorage.offline = 1; + if ( FMS.isOffline ) { this.navigate( 'offline' ); } else if ( FMS.currentDraft && ( FMS.currentDraft.get('title') || FMS.currentDraft.get('lat') || |