diff options
Diffstat (limited to 'www/js/views')
-rw-r--r-- | www/js/views/details.js | 6 | ||||
-rw-r--r-- | www/js/views/save_offline.js | 29 | ||||
-rw-r--r-- | www/js/views/submit.js | 12 |
3 files changed, 42 insertions, 5 deletions
diff --git a/www/js/views/details.js b/www/js/views/details.js index 5038d37..54aaca9 100644 --- a/www/js/views/details.js +++ b/www/js/views/details.js @@ -50,7 +50,11 @@ if ( valid ) { this.clearValidationErrors(); this.updateCurrentReport(); - this.navigate( this.next ); + if ( FMS.isOffline ) { + this.navigate( 'save_offline' ); + } else { + this.navigate( this.next ); + } } }, diff --git a/www/js/views/save_offline.js b/www/js/views/save_offline.js new file mode 100644 index 0000000..69cd7fc --- /dev/null +++ b/www/js/views/save_offline.js @@ -0,0 +1,29 @@ +(function (FMS, Backbone, _, $) { + _.extend( FMS, { + SaveOfflineView: FMS.FMSView.extend({ + template: 'save_offline', + id: 'save_offline', + + events: { + 'pagehide': 'destroy', + 'pageshow': 'afterDisplay', + 'click #save_report': 'saveReport', + 'click #discard': 'discardReport' + }, + + saveReport: function() { + this.navigate('reports'); + }, + + discardReport: function() { + var reset = FMS.removeDraft(FMS.currentDraft.id, true); + var that = this; + reset.done( function() { that.onDraftRemove(); } ); + }, + + onDraftRemove: function() { + this.navigate( 'around', 'left' ); + } + }) + }); +})(FMS, Backbone, _, $); diff --git a/www/js/views/submit.js b/www/js/views/submit.js index 27b21f7..09231be 100644 --- a/www/js/views/submit.js +++ b/www/js/views/submit.js @@ -35,10 +35,14 @@ if ( this.validate() ) { this.model.set('user', FMS.currentUser); - this.report = new FMS.Report( this.model.toJSON() ); - this.listenTo( this.report, 'sync', this.onReportSync ); - this.listenTo( this.report, 'error', this.onReportError ); - this.report.save(); + if ( FMS.isOffline ) { + this.navigate( 'save_offline' ); + } else { + this.report = new FMS.Report( this.model.toJSON() ); + this.listenTo( this.report, 'sync', this.onReportSync ); + this.listenTo( this.report, 'error', this.onReportError ); + this.report.save(); + } } }, |