diff options
Diffstat (limited to 'www/js/views/offline.js')
-rw-r--r-- | www/js/views/offline.js | 93 |
1 files changed, 69 insertions, 24 deletions
diff --git a/www/js/views/offline.js b/www/js/views/offline.js index ac007d1..3ce94a9 100644 --- a/www/js/views/offline.js +++ b/www/js/views/offline.js @@ -9,17 +9,18 @@ events: { 'pagehide': 'destroy', - 'pagebeforeshow': 'beforeShow', + 'pagebeforeshow': 'beforeDisplay', 'pageshow': 'afterDisplay', 'vclick .ui-btn-left': 'onClickButtonPrev', 'vclick .ui-btn-right': 'onClickButtonNext', 'vclick #id_photo_button': 'takePhoto', 'vclick #id_existing': 'addPhoto', - 'vclick #id_del_photo_button': 'deletePhoto', + 'vclick .del_photo_button': 'deletePhoto', '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').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').attr('src', ''); + that.model.set('files', files); + that.updateCurrentReport(); - $('#photo-next-btn .ui-btn-text').text(FMS.strings.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, _, $); |