aboutsummaryrefslogtreecommitdiffstats
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/app.js2
-rw-r--r--www/js/router.js6
-rw-r--r--www/js/views/details.js6
-rw-r--r--www/js/views/save_offline.js29
-rw-r--r--www/js/views/submit.js12
5 files changed, 49 insertions, 6 deletions
diff --git a/www/js/app.js b/www/js/app.js
index 07be917..a62ec73 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -38,7 +38,7 @@ var tpl = {
(function (FMS, Backbone, _, $) {
_.extend(FMS, {
templates: [
- 'home', 'around', 'offline', 'reports', 'address_search', 'existing', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'sent'
+ 'home', 'around', 'offline', 'save_offline', 'reports', 'address_search', 'existing', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'sent'
],
isOffline: 0,
diff --git a/www/js/router.js b/www/js/router.js
index fe43d69..269f2e7 100644
--- a/www/js/router.js
+++ b/www/js/router.js
@@ -16,6 +16,7 @@
'submit-email': 'submitEmail',
'submit-name': 'submitName',
'submit-password': 'submitPassword',
+ 'save_offline': 'saveOffline',
'sent': 'sent',
'reports': 'reports'
},
@@ -90,6 +91,11 @@
this.changeView(submitPasswordView);
},
+ saveOffline: function(){
+ var saveOfflineView = new FMS.saveOfflineView({ model: FMS.currentDraft });
+ this.changeView(saveOfflineView);
+ },
+
sent: function(){
var sentView = new FMS.SentView({ model: FMS.currentDraft });
this.changeView(sentView);
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();
+ }
}
},