aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/views
diff options
context:
space:
mode:
Diffstat (limited to 'www/js/views')
-rw-r--r--www/js/views/home.js7
-rw-r--r--www/js/views/offline.js82
-rw-r--r--www/js/views/reports.js9
3 files changed, 96 insertions, 2 deletions
diff --git a/www/js/views/home.js b/www/js/views/home.js
index 9c169a9..383275e 100644
--- a/www/js/views/home.js
+++ b/www/js/views/home.js
@@ -26,8 +26,11 @@
if ( navigator && navigator.connection && ( navigator.connection.type == Connection.NONE ||
navigator.connection.type == Connection.UNKNOWN ) ) {
localStorage.offline = 1;
- this.navigate( 'no_connection' );
- } else if ( FMS.currentDraft && FMS.currentDraft.get('lat') ) {
+ this.navigate( 'offline' );
+ } else if ( FMS.currentDraft && (
+ FMS.currentDraft.get('title') || FMS.currentDraft.get('lat') ||
+ FMS.currentDraft.get('details') || FMS.currentDraft.get('file') )
+ ) {
this.navigate( 'existing' );
} else {
this.navigate( 'around' );
diff --git a/www/js/views/offline.js b/www/js/views/offline.js
new file mode 100644
index 0000000..d2af4e0
--- /dev/null
+++ b/www/js/views/offline.js
@@ -0,0 +1,82 @@
+(function (FMS, Backbone, _, $) {
+ _.extend( FMS, {
+ OfflineView: FMS.FMSView.extend({
+ template: 'offline',
+ id: 'offline',
+ prev: 'home',
+ next: 'reports',
+
+ events: {
+ 'pagehide': 'destroy',
+ 'pageshow': 'afterDisplay',
+ 'click .ui-btn-left': 'onClickButtonPrev',
+ 'click .ui-btn-right': 'onClickButtonNext',
+ 'click #id_photo_button': 'takePhoto',
+ 'click #id_existing': 'addPhoto',
+ 'click #id_del_photo_button': 'deletePhoto'
+ },
+
+ takePhoto: function() {
+ var that = this;
+ navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, { saveToPhotoAlbum: true, quality: 49, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.CAMERA, correctOrientation: true });
+ },
+
+ addPhoto: function() {
+ var that = this;
+ navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, { saveToPhotoAlbum: false, quality: 49, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, correctOrientation: true });
+ },
+
+ addPhotoSuccess: function(imgURI) {
+ var move = FMS.files.moveURI( imgURI );
+
+ var that = this;
+ move.done( function( file ) {
+ $('#photo').attr('src', file.toURL());
+ that.model.set('file', file.toURL());
+ FMS.saveCurrentDraft();
+
+ $('#photo-next-btn .ui-btn-text').text('Next');
+ $('#display_photo').show();
+ $('#add_photo').hide();
+ });
+
+ move.fail( function() { that.addPhotoFail(); } );
+ },
+
+ addPhotoFail: function() {
+ if ( message != 'no image selected' &&
+ message != 'Selection cancelled.' &&
+ message != 'Camera cancelled.' ) {
+ this.displayError(FMS.strings.photo_failed);
+ }
+ },
+
+ deletePhoto: function() {
+ var that = this;
+ var del = FMS.files.deleteURI( this.model.get('file') );
+
+ del.done( function() {
+ that.model.set('file', '');
+ FMS.saveCurrentDraft();
+ $('#photo').attr('src', '');
+
+ $('#photo-next-btn .ui-btn-text').text('Skip');
+ $('#display_photo').hide();
+ $('#add_photo').show();
+ });
+ },
+
+ onClickButtonNext: function() {
+ this.updateCurrentReport();
+ this.navigate( this.next, 'left' );
+ },
+
+ updateCurrentReport: function() {
+ this.model.set('title', $('#form_title').val());
+ this.model.set('details', $('#form_detail').val());
+ FMS.saveCurrentDraft();
+ localStorage.currentDraftID = FMS.currentDraft.id;
+ }
+ })
+ });
+})(FMS, Backbone, _, $);
diff --git a/www/js/views/reports.js b/www/js/views/reports.js
new file mode 100644
index 0000000..3ad2c01
--- /dev/null
+++ b/www/js/views/reports.js
@@ -0,0 +1,9 @@
+(function (FMS, Backbone, _, $) {
+ _.extend( FMS, {
+ ReportsView: FMS.FMSView.extend({
+ template: 'reports',
+ id: 'reports',
+ next: 'home'
+ })
+ });
+})(FMS, Backbone, _, $);