diff options
author | Struan Donald <struan@exo.org.uk> | 2013-04-02 11:01:07 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-04-02 11:01:07 +0100 |
commit | 9f979f491570c6bbff8735bcfa391430543d0041 (patch) | |
tree | c6773e651e6cdcc163ea25a8724b1004308bb7cc /www/js/app.js | |
parent | a6dd616d2e6d57e1a7d9ad629b2dfbfc77320bec (diff) |
save and load current report on app pause and resume
Diffstat (limited to 'www/js/app.js')
-rw-r--r-- | www/js/app.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/www/js/app.js b/www/js/app.js index 00c178c..c8b0d82 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -48,9 +48,29 @@ var tpl = { currentPosition: null, currentReport: new FMS.Report(), + allReports: new FMS.Reports(), reportToView: null, + saveCurrentReport: function() { + this.router.pause(); + this.allReports.add( FMS.currentReport ); + FMS.currentReport.localSave(); + if ( this.currentReport.id ) { + localStorage.currentReportID = this.currentReport.id; + } else { + localStorage.currentReportID = this.currentReport.cid; + } + }, + + loadCurrentReport: function() { + console.log( 'loading report' ); + if ( localStorage.currentReportID ) { + this.currentReport = FMS.allReports.get( localStorage.currentReportID ); + } + localStorage.currentReportID = null; + }, + initialize: function () { if ( this.initialized == 1 ) { return this; @@ -72,6 +92,8 @@ var tpl = { FMS.currentUser = new FMS.User({id: 1}); } + document.addEventListener('pause', function() { FMS.saveCurrentReport(); }, false); + document.addEventListener('resume', function() { FMS.loadCurrentReport(); }, false); document.addEventListener('backbutton', function() { FMS.router.back(); }, true); Backbone.history.start(); |