diff options
-rw-r--r-- | www/js/models/report.js | 3 | ||||
-rw-r--r-- | www/js/views/photo.js | 55 | ||||
-rw-r--r-- | www/templates/en/photo.html | 12 |
3 files changed, 67 insertions, 3 deletions
diff --git a/www/js/models/report.js b/www/js/models/report.js index 6fd48f9..063165a 100644 --- a/www/js/models/report.js +++ b/www/js/models/report.js @@ -11,7 +11,8 @@ may_show_name: '', category: '', phone: '', - pc: '' + pc: '', + file: '' }, sync: function(method, model, options) { diff --git a/www/js/views/photo.js b/www/js/views/photo.js new file mode 100644 index 0000000..1634cc0 --- /dev/null +++ b/www/js/views/photo.js @@ -0,0 +1,55 @@ +;(function (FMS, Backbone, _, $) { + _.extend( FMS, { + PhotoView: FMS.FMSView.extend({ + template: 'photo', + id: 'photo-page', + prev: 'around', + next: 'details', + + 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) { + $('#photo').attr('src', imgURI ); + this.model.set('file', imgURI); + + $('#display_photo').show(); + $('#add_photo').hide(); + }, + + addPhotoFail: function() { + if ( message != 'no image selected' && + message != 'Selection cancelled.' && + message != 'Camera cancelled.' + ) { + this.displayError(FMS.strings.photo_failed); + } + }, + + deletePhoto: function() { + this.model.set('file', ''); + $('#photo').attr('src', ''); + + $('#display_photo').hide(); + $('#add_photo').show(); + } + }) + }); +})(FMS, Backbone, _, $); diff --git a/www/templates/en/photo.html b/www/templates/en/photo.html index 580c83e..ef392f7 100644 --- a/www/templates/en/photo.html +++ b/www/templates/en/photo.html @@ -1,21 +1,29 @@ <div data-role="header" data-position="fixed" > <h1>Add Photo</h1> - <a id="next" data-icon="arrow-r" data-iconpos="right" class="ui-btn-right">Skip</a> + <a href="details.html" id="photo-next-btn" data-icon="arrow-r" data-iconpos="right" class="ui-btn-right">Skip</a> </div> <div class="container" data-enhance="false"> <div class="content" role="main"> <div id="side-form"> <fieldset> <div id="problem_form"> + <% if ( file != '' ) { %> + <div id="add_photo" style="display: none"> + <% } else { %> <div id="add_photo"> + <% } %> <label>Optionally Add a Photo</label> <input value="Take Photo" type="button" name="photo_button" id="id_photo_button" class="green-btn"> Or <input value="Choose" type="button" name="existing" id="id_existing" class="green-btn"> </div> + <% if ( file == '' ) { %> <div id="display_photo" style="display: none"> + <% } else { %> + <div id="display_photo"> + <% } %> <label>Your Photo</label> - <img id="photo" src="" width="200" /> + <img id="photo" src="<%= file %>" width="200" /> <input value="Remove Photo" type="button" name="del_photo_button" id="id_del_photo_button" class="green-btn"> </div> |