From a19459b65a8dbbc3ee12fbf7852956a1b322e3e6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 8 Apr 2013 17:11:57 +0100 Subject: 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 --- www/js/app.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'www/js/app.js') 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(); }); -- cgit v1.2.3