summaryrefslogtreecommitdiff
path: root/www/js/report.js
blob: 661d63f7bb7978488015d4c56669a5e773fd7e3a (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
41
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
	var ui = document.getElementById("camera-ui");
	if (navigator.camera) {
		ui.innerHTML = "<button onclick=\"takePhoto(true);return false\">Add Photo</button>"
	} 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 = "<input name=photo id=photo type=hidden /><button onclick=\"takePhoto(false);return false\">Change Photo</button><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);
	return false;
}