aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--www/js/app.js22
-rw-r--r--www/js/models/report.js18
-rw-r--r--www/js/router.js6
-rw-r--r--www/js/views/details.js10
4 files changed, 53 insertions, 3 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();
diff --git a/www/js/models/report.js b/www/js/models/report.js
index 341574c..3215449 100644
--- a/www/js/models/report.js
+++ b/www/js/models/report.js
@@ -2,6 +2,7 @@
_.extend( FMS, {
Report: Backbone.Model.extend({
urlRoot: CONFIG.FMS_URL + 'report/ajax',
+ localStorage: new Backbone.LocalStorage(CONFIG.NAMESPACE + '-reports'),
defaults: {
lat: 0,
@@ -15,6 +16,14 @@
file: ''
},
+ localSave: function() {
+ var method = 'create';
+ if ( this.id ) {
+ method = 'update';
+ }
+ Backbone.localSync(method, this);
+ },
+
sync: function(method, model, options) {
switch (method) {
case 'create':
@@ -152,3 +161,12 @@
})
});
})(FMS, Backbone, _, $);
+
+(function(FMS, Backbone, _, $) {
+ _.extend( FMS, {
+ Reports: Backbone.Collection.extend({
+ model: FMS.Report,
+ localStorage: new Backbone.LocalStorage(CONFIG.NAMESPACE + '-reports')
+ })
+ });
+})(FMS, Backbone, _, $);
diff --git a/www/js/router.js b/www/js/router.js
index e9bce54..b85b361 100644
--- a/www/js/router.js
+++ b/www/js/router.js
@@ -20,6 +20,12 @@
initialize: function() {
},
+ pause: function() {
+ if (this.currentView && this.currentView.updateCurrentReport) {
+ this.currentView.updateCurrentReport();
+ }
+ },
+
back: function() {
if (this.currentView && this.currentView.prev) {
this.currentView.onClickButtonPrev();
diff --git a/www/js/views/details.js b/www/js/views/details.js
index 54edb77..79bd886 100644
--- a/www/js/views/details.js
+++ b/www/js/views/details.js
@@ -35,11 +35,15 @@
if ( valid ) {
this.clearValidationErrors();
- this.model.set('title', $('#form_title').val());
- this.model.set('details', $('#form_detail').val());
- this.model.set('category', $('#form_category').val());
+ this.updateCurrentReport();
this.navigate( this.next );
}
+ },
+
+ updateCurrentReport: function() {
+ this.model.set('category', $('#form_category').val());
+ this.model.set('title', $('#form_title').val());
+ this.model.set('details', $('#form_detail').val());
}
})
});