diff options
author | Struan Donald <struan@exo.org.uk> | 2013-04-08 17:11:57 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-04-08 18:55:37 +0100 |
commit | a19459b65a8dbbc3ee12fbf7852956a1b322e3e6 (patch) | |
tree | 51f3a9cf8365e9d74fab63a8acc09fe078598048 /www/js/app.js | |
parent | bd3a482f3c268c6f4e31c4be0e9b2b8d6045b680 (diff) |
Trying to use the same model for both remote and localStorage was
involving all sorts of hackery so it's easier and cleaner to move to
separate models for reports and drafts
Diffstat (limited to 'www/js/app.js')
-rw-r--r-- | www/js/app.js | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/www/js/app.js b/www/js/app.js index c8b0d82..8b94fbc 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -47,28 +47,27 @@ var tpl = { currentLocation: null, currentPosition: null, - currentReport: new FMS.Report(), - allReports: new FMS.Reports(), + currentDraft: new FMS.Draft(), + allDrafts: new FMS.Drafts(), 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; - } + saveCurrentDraft: function() { + FMS.router.pause(); + FMS.allDrafts.add( FMS.currentDraft ); + FMS.currentDraft.save(); + localStorage.currentDraftID = FMS.currentDraft.cid; }, - loadCurrentReport: function() { + loadCurrentDraft: function() { console.log( 'loading report' ); - if ( localStorage.currentReportID ) { - this.currentReport = FMS.allReports.get( localStorage.currentReportID ); + if ( localStorage.currentDraftID && localStorage.currentDraftID != 'null' ) { + var r = FMS.allDrafts.get( localStorage.currentDraftID ); + if ( r ) { + FMS.currentDraft = r; + } } - localStorage.currentReportID = null; + localStorage.currentDraftID = null; }, initialize: function () { @@ -92,10 +91,13 @@ 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('pause', function() { FMS.saveCurrentDraft(); }, false); + document.addEventListener('resume', function() { FMS.loadCurrentDraft(); }, false); document.addEventListener('backbutton', function() { FMS.router.back(); }, true); + FMS.allDrafts.fetch(); + FMS.loadCurrentDraft(); + Backbone.history.start(); navigator.splashscreen.hide(); }); |