summaryrefslogtreecommitdiff
path: root/www/js/report.js
blob: a825c218f607a4d9fb4d984ad3fd63458fb00117 (plain)
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
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
	var ui = document.getElementById("camera-ui");
	if (navigator.camera) {
		ui.innerHTML = "<a href=\"javascript:takePhoto(true)\">Add Photo</a>"
	} else {
		ui.innerHTML = "Camera not supported on your device";
	}
}
function takePhoto(firstrun) {
	var options = {
		/*quality: 50,*/
		destinationType: Camera.DestinationType.DATA_URL, /* DATA_URL, FILE_URI, NATIVE_URI */
		sourceType: Camera.PictureSourceType.CAMERA, /* PHOTOLIBRARY, CAMERA, SAVEDPHOTOALBUM */
		allowEdit: true,
		encodingType: Camera.EncodingType.JPEG, /* JPEG, PNG */
		/*targetWidth: 300,*/
		/*targetHeight: 300,*/
		mediaType: Camera.MediaType.PICTURE, /* PICTURE, VIDEO, ALLMEDIA */
		correctOrientation: true,
		/* saveToPhotoAlbum: false, */
		/* popoverOptions: (iOS only), */
		cameraDirection: Camera.Direction.BACK /* BACK, FRONT */
	};
	navigator.camera.getPicture(
		function(imgData) {
			if (firstrun) {
				var ui = document.getElementById("camera-ui");
				ui.innerHTML = "<a href=\"javascript:takePhoto(false)\">Change Photo</a><img id=thumbnail />"
			}
			var input = document.getElementById("photo");
			var img = document.getElementById("thumbnail");
			img.src = "data:image/jpeg;base64,"+imgData;
			input.value = imgData;
		},
		function() {
			alert("Error taking picture", "Error");
		},
		options);
}