Subversion Repositories eFlore/Applications.cel

Rev

Rev 1123 | Rev 1130 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1123 Rev 1125
Line 32... Line 32...
32
	
32
	
33
	$("#effacer-miniature").click(function () {
33
	$("#effacer-miniature").click(function () {
34
		supprimerMiniature();
34
		supprimerMiniature();
Line 35... Line 35...
35
	});
35
	});
36
	
36
	
37
	if (window.File && window.FileReader) {
37
	if (window.File && window.FileReader && isCanvasSupported()) {
38
		if (DEBUG) {
38
		if (DEBUG) {
39
			console.log("L'API File est supporté.");
39
			console.log("Support OK pour : API File et Canvas.");
40
		}
40
		}
41
		$('#fichier').bind('change', function(e) {
41
		$('#fichier').bind('change', function(e) {
42
			afficherMiniatureHtml5(e);
42
			afficherMiniatureHtml5(e);
Line 52... Line 52...
52
			$("#form-upload").ajaxSubmit(options);
52
			$("#form-upload").ajaxSubmit(options);
53
			return false;
53
			return false;
54
		});
54
		});
55
	}	
55
	}	
56
});
56
});
-
 
57
function isCanvasSupported(){
-
 
58
	var elem = document.createElement('canvas');
-
 
59
	return !!(elem.getContext && elem.getContext('2d'));
-
 
60
}
Line 57... Line 61...
57
 
61
 
58
function afficherMiniatureHtml5(evt) {
62
function afficherMiniatureHtml5(evt) {
-
 
63
	supprimerMiniature();
59
	supprimerMiniature();
64
	
60
	var selectedfiles = evt.target.files; // FileList object
65
	var selectedfiles = evt.target.files;
61
	var f = selectedfiles[0];// Nous récupérons seulement le premier fichier.
-
 
62
	// Only process image files.
66
	var f = selectedfiles[0];// Nous récupérons seulement le premier fichier.
63
	if (f.type.match('image.*') == false) {
67
	if (f.type != 'image/jpeg') {
64
		var message = "Seule les images JPEG sont supportées.";
68
		var message = "Seule les images JPEG sont supportées.";
-
 
69
		$("#miniature-msg").append(message);
-
 
70
	} else if (f.size > 5242880) {
-
 
71
		var message = "Votre image à un poids supérieur à 5Mo.";
65
		$("#miniature-msg").append(message);
72
		$("#miniature-msg").append(message);
66
	} else {
73
	} else {
67
		var reader = new FileReader();
74
		var reader = new FileReader();
68
		// Lit le fichier image commune url de données
75
		// Lit le fichier image commune url de données
69
		reader.readAsDataURL(f);
76
		reader.readAsDataURL(f);
Line 72... Line 79...
72
		// Closure pour capturer les infos du fichier
79
		// Closure pour capturer les infos du fichier
73
		reader.onload = (function(theFile) {
80
		reader.onload = (function(theFile) {
74
			return function(e) {
81
			return function(e) {
75
				// Rendre la miniature
82
				// Rendre la miniature
76
				var imageBase64 = e.target.result;
83
				var imageBase64 = e.target.result;
77
				$("#miniature").append('<img id="miniature-img" class="miniature b64" src="'+imageBase64+'" alt="'+imgNom+'"/>');	   
84
				//$("#miniature").append('<img id="miniature-img" class="miniature b64" src="'+imageBase64+'" alt="'+imgNom+'"/>');
-
 
85
				
-
 
86
				// HTML5 Canvas
-
 
87
				var img = new Image();
-
 
88
			    img.src = imageBase64;
-
 
89
			    img.alt = imgNom;
-
 
90
			    img.onload = function() {
-
 
91
			    	transformerImgEnCanvas(this, 100, 100, false, 'white');
-
 
92
			    };
78
			};
93
			};
79
		})(f);
94
		})(f);
80
	}
95
	}
81
	$("#effacer-miniature").show();
96
	$("#effacer-miniature").show();
82
}
97
}
-
 
98
function transformerImgEnCanvas(img, thumbwidth, thumbheight, crop, background) {
-
 
99
	var canvas = document.createElement('canvas');
-
 
100
	canvas.width = thumbwidth;
-
 
101
	canvas.height = thumbheight;
-
 
102
	var dimensions = calculerDimenssions(img.width, img.height, thumbwidth, thumbheight);
-
 
103
	if (crop) {
-
 
104
		canvas.width = dimensions.w;
-
 
105
		canvas.height = dimensions.h;
-
 
106
		dimensions.x = 0;
-
 
107
		dimensions.y = 0;
-
 
108
	}
-
 
109
	cx = canvas.getContext('2d');
-
 
110
	if (background !== 'transparent') {
-
 
111
		cx.fillStyle = background;
-
 
112
		cx.fillRect(0, 0, thumbwidth, thumbheight);
-
 
113
	}
-
 
114
	cx.drawImage(img, dimensions.x, dimensions.y, dimensions.w, dimensions.h);
-
 
115
	afficherMiniatureCanvas(img, canvas);
-
 
116
}
-
 
117
 
-
 
118
function calculerDimenssions(imagewidth, imageheight, thumbwidth, thumbheight) {
-
 
119
	var w = 0, h = 0, x = 0, y = 0,
-
 
120
	    widthratio = imagewidth / thumbwidth,
-
 
121
	    heightratio = imageheight / thumbheight,
-
 
122
	    maxratio = Math.max(widthratio, heightratio);
-
 
123
	if (maxratio > 1) {
-
 
124
	    w = imagewidth / maxratio;
-
 
125
	    h = imageheight / maxratio;
-
 
126
	} else {
-
 
127
	    w = imagewidth;
-
 
128
	    h = imageheight;
-
 
129
	}
-
 
130
	x = (thumbwidth - w) / 2;
-
 
131
	y = (thumbheight - h) / 2;
-
 
132
	return {w:w, h:h, x:x, y:y};
-
 
133
}
-
 
134
 
-
 
135
function afficherMiniatureCanvas(imgB64, canvas) {
-
 
136
	var url = canvas.toDataURL('image/jpeg' , 0.8);
-
 
137
	var alt = imgB64.alt;
-
 
138
	var title = Math.round(url.length / 1000 * 100) / 100 + ' KB';
-
 
139
	var miniature = '<img id="miniature-img" class="miniature b64-canvas" src="'+url+'" alt="'+alt+'" title="'+title+'" />';
-
 
140
	$("#miniature").append(miniature);
-
 
141
	$("#miniature-img").data('b64', imgB64.src);
-
 
142
}
Line 83... Line 143...
83
 
143
 
84
function afficherMiniature(reponse) { 
144
function afficherMiniature(reponse) { 
85
	supprimerMiniature();
145
	supprimerMiniature();
86
	if (DEBUG) {
146
	if (DEBUG) {
Line 195... Line 255...
195
						return retour;
255
						return retour;
196
					}));
256
					}));
197
				} else {
257
				} else {
198
					afficherErreurGoogleMap(status);
258
					afficherErreurGoogleMap(status);
199
				}
259
				}
200
			})
260
			});
201
		},
261
		},
202
		// Cette partie est executee a la selection d'une adresse
262
		// Cette partie est executee a la selection d'une adresse
203
		select: function(event, ui) {
263
		select: function(event, ui) {
204
			var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
264
			var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
205
			deplacerMarker(latLng);
265
			deplacerMarker(latLng);
Line 327... Line 387...
327
}
387
}
Line 328... Line 388...
328
 
388
 
329
//+---------------------------------------------------------------------------------------------------------+
389
//+---------------------------------------------------------------------------------------------------------+
330
// FORMULAIRE
390
// FORMULAIRE
-
 
391
$(document).ready(function() {
-
 
392
	$("#date").datepicker($.datepicker.regional['fr']);
331
$(document).ready(function() {
393
	
332
	$("form#saisie-obs").validate({
394
	$("form#saisie-obs").validate({
333
		rules: {
395
		rules: {
334
			courriel : {
396
			courriel : {
335
				required : true,
397
				required : true,
Line 360... Line 422...
360
				date: true},
422
				date: true},
361
			taxon : "required"
423
			taxon : "required"
362
		}
424
		}
363
	});
425
	});
Line 364... Line -...
364
	
-
 
365
	$("#date").datepicker($.datepicker.regional['fr']);
-
 
366
	
426
	
367
	$("#courriel_confirmation").bind('paste', function(e) {
427
	$("#courriel_confirmation").bind('paste', function(e) {
368
		$("#dialogue-bloquer-copier-coller").dialog();
428
		$("#dialogue-bloquer-copier-coller").dialog();
369
		return false;
429
		return false;
Line 370... Line 430...
370
	});
430
	});
371
		
431
		
372
	//bascule le texte d'afficher à masquer
432
	//bascule le texte d'afficher à masquer
373
	$("a.afficher-coord").click(function() {
433
	$("a.afficher-coord").click(function() {
374
		$("a.afficher-coord").toggle();
434
		$("a.afficher-coord").toggle();
375
		$("#coordonnees-geo").toggle('slow');
435
		$("#coordonnees-geo").toggle('slow');
376
		//valeur false pour que le lien ne soit pas suivi
436
		//valeur false pour que le lien ne soit pas suivi
Line 377... Line 437...
377
		return false
437
		return false;
378
	});
438
	});
379
	
439
	
Line 417... Line 477...
417
				'lieu_dit' : $("#rue").val(),
477
				'lieu_dit' : $("#rue").val(),
418
				'station' : $("#rue_num_debut").val()+'-'+$("#rue_num_fin").val()+'-'+$("#rue_cote").val(),
478
				'station' : $("#rue_num_debut").val()+'-'+$("#rue_num_fin").val()+'-'+$("#rue_cote").val(),
419
				'notes' : $("#notes").val(),
479
				'notes' : $("#notes").val(),
420
				//Ajout des champs images
480
				//Ajout des champs images
421
				'image_nom' : $("#miniature-img").attr('alt'),
481
				'image_nom' : $("#miniature-img").attr('alt'),
422
				'image_b64' : $("#miniature-img").hasClass('b64') ? $("#miniature-img").attr('src') : ''
482
				'image_b64' : getB64ImgOriginal()
423
			});
483
			});
424
			console.log("B64 : "+$("#miniature-img").hasClass('b64') ? $("#miniature-img").attr('src') : '');
-
 
425
		}
484
		}
426
	});
485
	});
Line 427... Line 486...
427
	
486
	
428
	$(".supprimer-obs").live('click', function() {
-
 
429
		var obsId = $(this).val();
-
 
430
		// Problème avec IE 6 et 7
-
 
431
		if (obsId == "Supprimer") {
-
 
432
			obsId = $(this).attr("title");
-
 
433
		}
-
 
434
		
-
 
435
		$('#obs'+obsId).remove();
-
 
436
		$("#liste-obs").removeData('obsId'+obsId)
-
 
437
	});
-
 
438
	
-
 
439
	// TODO : remplacer par du jquery
-
 
Line 440... Line 487...
440
	//document.getElementById('image_file').addEventListener('change', handleFileSelect, false);
487
	$(".supprimer-obs").live('click', supprimerObs);
441
	
488
	
Line 442... Line 489...
442
	$("#transmettre-obs").click(function(e) {
489
	$("#transmettre-obs").click(function(e) {
Line 531... Line 578...
531
		}
578
		}
532
		return false;
579
		return false;
533
	});
580
	});
534
});
581
});
Line -... Line 582...
-
 
582
 
-
 
583
function getB64ImgOriginal() {
-
 
584
	var b64 = '';
-
 
585
	if ($("#miniature-img").hasClass('b64')) {
-
 
586
		b64 = $("#miniature-img").attr('src');
-
 
587
	} else if ($("#miniature-img").hasClass('b64-canvas')) {
-
 
588
		b64 = $("#miniature-img").data('b64');
-
 
589
	}
-
 
590
	return b64;
-
 
591
}
-
 
592
 
-
 
593
function supprimerObs() {
-
 
594
	var obsId = $(this).val();
-
 
595
	// Problème avec IE 6 et 7
-
 
596
	if (obsId == "Supprimer") {
-
 
597
		obsId = $(this).attr("title");
-
 
598
	}
-
 
599
	
-
 
600
	$('#obs'+obsId).remove();
-
 
601
	$("#liste-obs").removeData('obsId'+obsId);
-
 
602
}
535
 
603
 
536
function ajouterImgMiniatureAuTransfert() {
604
function ajouterImgMiniatureAuTransfert() {
537
	var miniature = '';
605
	var miniature = '';
538
	if ($("#miniature img").length == 1) {
606
	if ($("#miniature img").length == 1) {
539
		var css = $("#miniature-img").hasClass('b64') ? 'miniature b64' : 'miniature';
607
		var css = $("#miniature-img").hasClass('b64') ? 'miniature b64' : 'miniature';