1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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, _, $);
|