aboutsummaryrefslogtreecommitdiffstats
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/views/offline.js91
-rw-r--r--www/js/views/photo.js23
2 files changed, 74 insertions, 40 deletions
diff --git a/www/js/views/offline.js b/www/js/views/offline.js
index c5264a1..a85bd71 100644
--- a/www/js/views/offline.js
+++ b/www/js/views/offline.js
@@ -9,7 +9,7 @@
events: {
'pagehide': 'destroy',
- 'pagebeforeshow': 'beforeShow',
+ 'pagebeforeshow': 'beforeDisplay',
'pageshow': 'afterDisplay',
'vclick .ui-btn-left': 'onClickButtonPrev',
'vclick .ui-btn-right': 'onClickButtonNext',
@@ -19,7 +19,8 @@
'vclick #locate': 'onClickLocate',
'vclick #locate_cancel': 'onClickCancel',
'blur input': 'toggleNextButton',
- 'blur textarea': 'toggleNextButton'
+ 'blur textarea': 'blurTextArea',
+ 'focus textarea': 'focusTextArea'
},
_back: function() {
@@ -30,7 +31,7 @@
var hasContent = false;
if ( $('#form_title').val() || $('#form_detail').val() ||
- this.model.get('lat') || this.model.get('file') ) {
+ this.model.get('lat') || this.model.get('files').length > 0 ) {
hasContent = true;
}
@@ -39,11 +40,22 @@
afterDisplay: function() {
$('body')[0].scrollTop = 0;
- $('div[data-role="content"]').show();
- },
- beforeShow: function() {
- $('div[data-role="content"]').hide();
+ // The height of the photos container needs to be adjusted
+ // depending on the number of photos - if the max number of
+ // photos have already been added then the 'add photo' UI isn't
+ // shown so we should use all the vertical space for the
+ // thumbnails.
+ var wrapperHeight = $(".ui-content").height();
+ wrapperHeight -= $(".ui-content .notopmargin").outerHeight(true);
+ wrapperHeight -= $(".ui-content #locate_result").outerHeight(true);
+ wrapperHeight -= $(".ui-content .inputcard").outerHeight(true);
+ wrapperHeight -= $(".ui-content #add_photo").outerHeight(true);
+ $(".photo-wrapper").height(wrapperHeight);
+ },
+
+ beforeDisplay: function() {
+ this.fixPageHeight();
this.toggleNextButton();
},
@@ -55,6 +67,15 @@
}
},
+ focusTextArea: function() {
+ $("textarea#form_detail").get(0).rows = 7;
+ },
+
+ blurTextArea: function(e) {
+ $("textarea#form_detail").get(0).rows = 2;
+ this.toggleNextButton();
+ },
+
failedLocation: function(details) {
this.finishedLocating();
this.locateCount = 21;
@@ -73,32 +94,47 @@
takePhoto: function() {
var that = this;
+ $.mobile.loading('show');
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;
+ $.mobile.loading('show');
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 move;
+ // on iOS the photos go into a temp folder in the apps own filespace so we
+ // can move them, and indeed have to as the tmp space is cleaned out by the OS
+ // so draft reports might have their images removed. on android you access the
+ // images where they are stored on the filesystem so if you move, and then delete
+ // them, you are moving and deleting the only copy of them which is likely to be
+ // surprising and unwelcome so we copy them instead.
+ var fileName = CONFIG.NAMESPACE + '_' + this.model.cid + '_' + moment().unix() + '.jpg';
+ if ( FMS.isAndroid ) {
+ move = FMS.files.copyURI( imgURI, fileName );
+ } else {
+ move = FMS.files.moveURI( imgURI, fileName );
+ }
var that = this;
move.done( function( file ) {
- $('.photo-wrapper .photo img').attr('src', file.toURL());
- that.model.set('file', file.toURL());
- FMS.saveCurrentDraft();
+ var files = that.model.get('files');
+ files.push(file.toURL());
+ that.model.set('files', files);
+ that.updateCurrentReport();
- $('#photo-next-btn .ui-btn-text').text(FMS.strings.next);
- $('#display_photo').show();
- $('#add_photo').hide();
+ $.mobile.loading('hide');
+ that.rerender();
});
move.fail( function() { that.addPhotoFail(); } );
},
addPhotoFail: function(message) {
+ $.mobile.loading('hide');
if ( message != 'no image selected' &&
message != 'Selection cancelled.' &&
message != 'Camera cancelled.' ) {
@@ -106,18 +142,22 @@
}
},
- deletePhoto: function() {
- var that = this;
- var del = FMS.files.deleteURI( this.model.get('file') );
+ deletePhoto: function(e) {
+ e.preventDefault();
+ $.mobile.loading('show');
+ var files = this.model.get('files');
+ var index = parseInt($(e.target).data('fileIndex'));
+ var deleted_file = files.splice(index, 1)[0];
+ var del = FMS.files.deleteURI( deleted_file );
+
+ var that = this;
del.done( function() {
- that.model.set('file', '');
- FMS.saveCurrentDraft();
- $('.photo-wrapper .photo img').attr('src', '');
+ that.model.set('files', files);
+ that.updateCurrentReport();
- $('#photo-next-btn .ui-btn-text').text('Skip');
- $('#display_photo').hide();
- $('#add_photo').show();
+ $.mobile.loading('hide');
+ that.rerender();
});
},
@@ -154,7 +194,12 @@
this.model.set('title', $('#form_title').val());
this.model.set('details', $('#form_detail').val());
FMS.saveCurrentDraft();
+ },
+
+ rerender: function() {
+ FMS.router.offline();
}
+
})
});
})(FMS, Backbone, _, $);
diff --git a/www/js/views/photo.js b/www/js/views/photo.js
index 6ba4a01..0b0c5e9 100644
--- a/www/js/views/photo.js
+++ b/www/js/views/photo.js
@@ -23,9 +23,10 @@
afterDisplay: function() {
// The height of the photos container needs to be adjusted
- // depending on the number of photos - if there are 3 photos
- // then the 'add photo' UI isn't shown so we should use all the
- // vertical space for the thumbnails.
+ // depending on the number of photos - if the max number of
+ // photos have already been added then the 'add photo' UI isn't
+ // shown so we should use all the vertical space for the
+ // thumbnails.
var wrapperHeight = $(".ui-content").height();
wrapperHeight -= $(".ui-content h2").outerHeight(true);
wrapperHeight -= $(".ui-content .bottom-btn").outerHeight(true)
@@ -95,11 +96,8 @@
files.push(file.toURL());
that.model.set('files', files);
FMS.saveCurrentDraft();
-
- window.setTimeout(function() {
- $.mobile.loading('hide');
- that.rerender();
- }, 100);
+ $.mobile.loading('hide');
+ that.rerender();
});
move.fail( function() { that.addPhotoFail(); } );
@@ -125,19 +123,10 @@
var that = this;
del.done( function() {
- // $('#photo_title').hide();
- // $('#nophoto_title').show();
- // $('.del_photo_button').hide();
that.model.set('files', files);
FMS.saveCurrentDraft(true);
that.rerender();
- // $('.photo-wrapper .photo img').attr('src', 'images/placeholder-photo.png').addClass('placeholder').removeClass('small');
- //
- // $('#photo-next-btn .ui-btn-text').text('Skip');
- // $('#id_photo_button').parents('.ui-btn').show();
- // $('#id_existing').parents('.ui-btn').show();
});
-
},
rerender: function() {