Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1055 Rev 1346
Line 10... Line 10...
10
	if (evenement.stopPropagation) {
10
	if (evenement.stopPropagation) {
11
		evenement.stopPropagation();
11
		evenement.stopPropagation();
12
	}
12
	}
13
	return false;
13
	return false;
14
}
14
}
-
 
15
 
15
// TODO : voir si cette fonction est bien utile. Résoud le pb d'un warning sous chrome.
16
// TODO : voir si cette fonction est bien utile. Résoud le pb d'un warning sous chrome.
16
(function(){
17
(function(){
17
    // remove layerX and layerY
18
    // remove layerX and layerY
18
    var all = $.event.props,
19
    var all = $.event.props,
19
        len = all.length,
20
        len = all.length,
Line 26... Line 27...
26
}());
27
}());
Line 27... Line 28...
27
 
28
 
28
//+----------------------------------------------------------------------------------------------------------+
29
//+----------------------------------------------------------------------------------------------------------+
29
//UPLOAD PHOTO : Traitement de l'image 
30
//UPLOAD PHOTO : Traitement de l'image 
-
 
31
$(document).ready(function() {	
30
$(document).ready(function() {	
32
	
-
 
33
	$("#effacer-miniature").click(function () {
-
 
34
		supprimerMiniature();
-
 
35
	});
31
	//prepare the form when the DOM is ready 
36
	
-
 
37
	if (HTML5 && window.File && window.FileReader && isCanvasSupported()) {
-
 
38
		if (DEBUG) {
-
 
39
			console.log("Support OK pour : API File et Canvas.");
-
 
40
		}
-
 
41
		$('#fichier').bind('change', function(e) {
-
 
42
			afficherMiniatureHtml5(e);
-
 
43
		});	
-
 
44
	} else {
-
 
45
		$("#fichier").bind('change', function (e) {
32
	//create service object(proxy) using SMD (generated by the json result)
46
			arreter(e);
33
	var options = { 
47
			var options = { 
34
		success: afficherMiniature, // post-submit callback 
48
				success: afficherMiniature, // post-submit callback 
35
		dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type) 
49
				dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type) 
-
 
50
				resetForm: true // reset the form after successful submit 
-
 
51
			};
-
 
52
			$("#form-upload").ajaxSubmit(options);
-
 
53
			return false;
-
 
54
		});
-
 
55
	}	
-
 
56
});
-
 
57
function isCanvasSupported(){
-
 
58
	var elem = document.createElement('canvas');
-
 
59
	return !!(elem.getContext && elem.getContext('2d'));
-
 
60
}
-
 
61
 
-
 
62
function afficherMiniatureHtml5(evt) {
-
 
63
	supprimerMiniature();
-
 
64
	
-
 
65
	var selectedfiles = evt.target.files;
-
 
66
	var f = selectedfiles[0];// Nous récupérons seulement le premier fichier.
-
 
67
	if (f.type != 'image/jpeg') {
-
 
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.";
-
 
72
		$("#miniature-msg").append(message);
-
 
73
	} else {
-
 
74
		var reader = new FileReader();
-
 
75
		// Lit le fichier image commune url de données
-
 
76
		reader.readAsDataURL(f);
-
 
77
		var imgNom = f.name;
-
 
78
	
-
 
79
		// Closure pour capturer les infos du fichier
-
 
80
		reader.onload = (function(theFile) {
-
 
81
			return function(e) {
-
 
82
				// Rendre la miniature
-
 
83
				var imageBase64 = e.target.result;
-
 
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
			    };
-
 
93
			};
-
 
94
		})(f);
-
 
95
	}
-
 
96
	$("#effacer-miniature").show();
-
 
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 calculerDimensions(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;
36
		resetForm: true // reset the form after successful submit 
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);
Line 37... Line -...
37
	};
-
 
38
 
142
}
-
 
143
 
-
 
144
function afficherMiniature(reponse) { 
39
	// post-submit callback 
145
	supprimerMiniature();
-
 
146
	if (DEBUG) {
-
 
147
		var debogage = $("debogage", reponse).text();
40
	function afficherMiniature(reponse) { 
148
		console.log("Débogage upload : "+debogage);
-
 
149
	}
-
 
150
	var message = $("message", reponse).text();
-
 
151
	if (message != '') {
41
		// 'responseXML' is the XML document returned by the server; we use 
152
		$("#miniature-msg").append(message);
42
		// jQuery to extract the content of the message node from the XML doc 
153
	} else {
43
		var miniatureUrl = $("miniature-url", reponse).text();
-
 
44
		var imgNom = $("image-nom", reponse).text();
154
		var miniatureUrl = $("miniature-url", reponse).text();
45
		$("#miniature").empty();
155
		var imgNom = $("image-nom", reponse).text();
46
		$("#miniature").append('<img id="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>');
156
		$("#miniature").append('<img id="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>');
47
		console.log(imgNom);
157
	}
48
		console.log(miniatureUrl);		
158
	$("#effacer-miniature").show();		
49
	};
159
}
50
	
-
 
51
	$("#form-upload").submit(function() { 
-
 
52
		// inside event callbacks 'this' is the DOM element so we first 
160
 
53
		// wrap it in a jQuery object and then invoke ajaxSubmit 
-
 
54
		$(this).ajaxSubmit(options); 
161
function supprimerMiniature() {
55
		 
-
 
56
		// !!! Important !!! 
162
	$("#miniature").empty();
57
		// always return false to prevent standard browser submit and page navigation 
-
 
58
		return false; 
163
	$("#miniature-msg").empty();
Line 59... Line 164...
59
	});
164
	$("#effacer-miniature").hide();
60
});
165
}
61
 
166
 
62
//+----------------------------------------------------------------------------------------------------------+
167
//+----------------------------------------------------------------------------------------------------------+
-
 
168
// GOOGLE MAP
63
// GOOGLE MAP
169
var geocoder;
-
 
170
var map;
-
 
171
// marqueurs de début et fin de rue
64
var geocoder;
172
var marker;
-
 
173
var markerFin;
-
 
174
// coordonnées de début et fin de rue
-
 
175
var latLng;
-
 
176
var latLngFin;
-
 
177
// ligne reliant les deux points de début et fin
Line 65... Line 178...
65
var map;
178
var ligneRue;
66
var marker;
179
// Booléen de test afin de ne pas faire apparaitre la fin de rue à la premiere localisation
-
 
180
var premierDeplacement = true;
-
 
181
 
67
var latLng;
182
function initialiserGoogleMap(){
68
 
183
	// Carte
69
function initialize(){
184
	latLng = new google.maps.LatLng(48.8543, 2.3483);// Paris
-
 
185
	if (VILLE == 'Marseille') {
70
	// Carte
186
		latLng = new google.maps.LatLng(43.29545, 5.37458);
-
 
187
	} else if (VILLE == 'Montpellier') {
71
	var latLng = new google.maps.LatLng(43.29545, 5.37458);
188
		latLng = new google.maps.LatLng(43.61077, 3.87672);
72
	$('#adresse').val('1 rue de la canebiere, 13001');
189
	}
73
	$('#latitude').val('43.29545');
190
	latLngFin = latLng;
74
	$('#longitude').val('5.37458');
191
	
-
 
192
	var options = {
-
 
193
		zoom: 16,
75
	var options = {
194
		center: latLng,
-
 
195
		mapTypeId: google.maps.MapTypeId.HYBRID,
-
 
196
		mapTypeControlOptions: {
-
 
197
			mapTypeIds: ['OSM', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN]}
-
 
198
	};
-
 
199
 
-
 
200
	// Ajout de la couche OSM à la carte
-
 
201
	osmMapType = new google.maps.ImageMapType({
-
 
202
		getTileUrl: function(coord, zoom) {
-
 
203
			return "http://tile.openstreetmap.org/" +
-
 
204
			zoom + "/" + coord.x + "/" + coord.y + ".png";
-
 
205
		},
-
 
206
		tileSize: new google.maps.Size(256, 256),
-
 
207
		isPng: true,
Line -... Line 208...
-
 
208
		alt: 'OpenStreetMap',
76
		zoom: 16,
209
		name: 'OSM',
-
 
210
		maxZoom: 19
Line 77... Line 211...
77
		center: latLng,
211
	});
78
		mapTypeId: google.maps.MapTypeId.SATELLITE
212
	
79
	};
-
 
Line 80... Line 213...
80
	
213
	// Création de la carte Google
81
	map = new google.maps.Map(document.getElementById("map_canvas"), options); //affiche la google map dans la div map_canvas
214
	map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
82
	
215
	map.mapTypes.set('OSM', osmMapType);
83
	// Geocodeur
216
	
84
	geocoder = new google.maps.Geocoder();
217
	// Geocodeur
85
	console.log(GOOGLE_MAP_MARQUEUR_URL);
218
	geocoder = new google.maps.Geocoder();
86
 
219
 
87
	// Marqueur google draggable
220
	// Marqueur google draggable
-
 
221
	marker = new google.maps.Marker({
-
 
222
		map: map,
-
 
223
		draggable: true,
-
 
224
		title: 'Début de la portion de rue étudiée',
-
 
225
		icon: MARQUEUR_ICONE_DEBUT_URL,
-
 
226
		position: latLng
-
 
227
	});
-
 
228
	
-
 
229
	deplacerMarker(latLng);
-
 
230
	
-
 
231
	// Tentative de geocalisation
-
 
232
	if (navigator.geolocation) {
-
 
233
		navigator.geolocation.getCurrentPosition(function(position) {
-
 
234
			var latitude = position.coords.latitude;
-
 
235
			var longitude = position.coords.longitude;
88
	marker = new google.maps.Marker({
236
			latLng = new google.maps.LatLng(latitude, longitude);
Line -... Line 237...
-
 
237
			latLngFin = latLng;
-
 
238
			// si l'utilisateur géolocalise sa ville alors le premier déplacement doit être réinitialisé
-
 
239
			premierDeplacement = true;
89
		map: map,
240
			deplacerMarker(latLng);
90
		draggable: true,
-
 
91
		title: 'Ma station',
241
		});
92
		icon: GOOGLE_MAP_MARQUEUR_URL,
-
 
93
		position: latLng
-
 
94
	});
242
	}
95
}
-
 
96
 
-
 
97
$(document).ready(function() {
-
 
98
	initialize();
-
 
99
  
-
 
100
	$(function() {
243
}
101
		// Tentative de geocalisation
-
 
102
		if (navigator.geolocation) {
-
 
103
			navigator.geolocation.getCurrentPosition(function(position) {
-
 
104
				var latitude = position.coords.latitude;
-
 
105
				var longitude = position.coords.longitude;
-
 
106
				var altitude = position.coords.altitude;
-
 
107
				var geocalisation = new google.maps.LatLng(latitude, longitude);
244
 
108
				marker.setPosition(geocalisation);
245
 
109
				map.setCenter(geocalisation);
246
var valeurDefautRechercheLieu = "";
110
				$('#latitude').val(marker.getPosition().lat());
247
 
111
				$('#longitude').val(marker.getPosition().lng());
248
$(document).ready(function() {
112
				$('#adresse').val(codeLatLng(marker.getPosition()));
249
	
-
 
250
	initialiserGoogleMap();
113
			});
251
	gererAffichageValeursParDefaut();
-
 
252
 
-
 
253
	// Autocompletion du champ adresse
-
 
254
	$("#rue").autocomplete({
-
 
255
		//Cette partie utilise geocoder pour extraire des valeurs d'adresse
-
 
256
		source: function(request, response) {
-
 
257
			geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
114
		}   
258
				if (status == google.maps.GeocoderStatus.OK) {
115
		
259
					response($.map(results, function(item) {
116
		// Autocompletion du champ adresse
260
						var rue = "";
117
		$("#adresse").autocomplete({
261
						$.each(item.address_components, function(){
118
			//Cette partie utilise geocoder pour extraire des valeurs d'adresse
262
							if (this.types[0] == "route" || this.types[0] == "street_address" ) {
119
			source: function(request, response) {
263
								rue = this.short_name;
-
 
264
							}
120
				geocoder.geocode( {'address': request.term }, function(results, status) {
265
						});
121
					response($.map(results, function(item) {
266
						var retour = {
122
						return {
-
 
123
							label:  item.formatted_address,
-
 
124
							value: item.formatted_address,
-
 
125
							latitude: item.geometry.location.lat(),
-
 
126
							longitude: item.geometry.location.lng()
-
 
127
						}
-
 
128
					}));
267
							label: item.formatted_address,
129
				})
-
 
130
			},
-
 
131
			// Cette partie est executee a la selection d'une adresse
-
 
132
			select: function(event, ui) {
-
 
133
				$("#latitude").val(ui.item.latitude);
-
 
134
				$("#longitude").val(ui.item.longitude);
-
 
135
				var location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
-
 
136
				marker.setPosition(location);
-
 
137
				map.setCenter(location);
-
 
138
				map.setZoom(20);
-
 
139
			}
-
 
140
		});
-
 
141
 
-
 
142
		// Ajoute un ecouteur sur le marker pour le reverse geocoding
-
 
143
		google.maps.event.addListener(marker, 'drag', function() {
268
							value: rue,
144
			geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
269
							latitude: item.geometry.location.lat(),
-
 
270
							longitude: item.geometry.location.lng()
-
 
271
						};
-
 
272
						return retour;
-
 
273
					}));
-
 
274
				} else {
-
 
275
					afficherErreurGoogleMap(status);
-
 
276
				}
145
				if (status == google.maps.GeocoderStatus.OK) {
277
			});
-
 
278
		},
-
 
279
		// Cette partie est executee a la selection d'une adresse
-
 
280
		select: function(event, ui) {
-
 
281
			latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
-
 
282
			deplacerMarker(latLng);
-
 
283
			afficherEtapeGeolocalisation(2);
-
 
284
		}
-
 
285
	});
-
 
286
	
-
 
287
	$("#geolocaliser").click(function() {
-
 
288
		var latitude = $('#latitude').val();
-
 
289
		var longitude = $('#longitude').val();
-
 
290
		latLng = new google.maps.LatLng(latitude, longitude);
-
 
291
		deplacerMarker(latLng);
-
 
292
	});
-
 
293
	
146
					if (results[0]) {
294
	google.maps.event.addListener(marker, 'dragend', function() {
147
						$('#adresse').val(results[0].formatted_address);
295
		trouverCommune(marker.getPosition());
Line 148... Line 296...
148
						$('#latitude').val(Math.round(marker.getPosition().lat()*100000)/100000);
296
		mettreAJourMarkerPosition(marker.getPosition());
149
						$('#longitude').val(Math.round(marker.getPosition().lng()*100000)/100000);
297
		deplacerMarker(marker.getPosition());
-
 
298
	});
-
 
299
	
-
 
300
	google.maps.event.addListener(map, 'click', function(event) {
150
					}
301
		deplacerMarker(event.latLng);
151
				}
302
	});
-
 
303
});
-
 
304
 
-
 
305
function gererAffichageValeursParDefaut() {	
-
 
306
	afficherEtapeGeolocalisation(1);
152
			});
307
}
-
 
308
 
153
		});
309
function afficherEtapeGeolocalisation(numEtape) {
-
 
310
	$(".liste_indication_geolocalisation").children().hide();
154
	});
311
	$(".liste_indication_geolocalisation :nth-child("+numEtape+")").show();
-
 
312
}
-
 
313
 
-
 
314
function afficherErreurGoogleMap(status) {
-
 
315
	if (DEBUG) {
155
});
316
		$("#dialogue-google-map").empty();
156
 
317
		$("#dialogue-google-map").append('<pre class="msg-erreur">'+
157
// Transforme les coordonnés en adresse (reverse geocoder)
318
			"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
-
 
319
			'</pre>');
-
 
320
		$("#dialogue-google-map").dialog();
-
 
321
	}
-
 
322
}
-
 
323
 
158
function codeLatLng() {
324
function deplacerMarker(latLng) {
159
	var lat = parseFloat(document.getElementById("latitude").value);
325
	if (marker != undefined) {
-
 
326
		marker.setPosition(latLng);
-
 
327
		map.setCenter(latLng);
-
 
328
		//map.setZoom(18);
-
 
329
		trouverCommune(latLng);
-
 
330
		
-
 
331
		if(!premierDeplacement) {
-
 
332
			if(markerFin != undefined) {
-
 
333
				markerFin.setMap(null);
-
 
334
			}
-
 
335
			
-
 
336
			latLngFin = new google.maps.LatLng(latLng.lat(), latLng.lng() + 0.0010);
-
 
337
			// Marqueur google draggable
-
 
338
			markerFin = new google.maps.Marker({
-
 
339
				map: map,
-
 
340
				draggable: true,
-
 
341
				title: 'Fin de la portion de rue étudiée',
-
 
342
				icon: MARQUEUR_ICONE_FIN_URL,
-
 
343
				position: latLngFin
-
 
344
			});
-
 
345
			
-
 
346
			google.maps.event.addListener(markerFin, 'dragend', function() {
-
 
347
				dessinerLigneRue(marker.getPosition(), markerFin.getPosition());
-
 
348
				latLngFin = markerFin.getPosition();
-
 
349
				latLngCentre = new google.maps.LatLng((latLngFin.lat() + latLng.lat())/2, (latLngFin.lng() + latLng.lng())/2); 
160
	var lng = parseFloat(document.getElementById("longitude").value);
350
				mettreAJourMarkerPosition(latLngCentre);
161
	var latlng = new google.maps.LatLng(lat, lng);
351
				afficherEtapeGeolocalisation(4);
162
	geocoder.geocode({'latLng': latlng}, function(results, status) {
352
			});
-
 
353
			
-
 
354
			dessinerLigneRue(latLng, latLngFin);
-
 
355
			
-
 
356
			latLngCentre = new google.maps.LatLng((latLngFin.lat() + latLng.lat())/2, (latLngFin.lng() + latLng.lng())/2); 
-
 
357
			mettreAJourMarkerPosition(latLng);
-
 
358
			afficherEtapeGeolocalisation(3);
-
 
359
		} else {
-
 
360
			mettreAJourMarkerPosition(latLng);
-
 
361
		}
-
 
362
		premierDeplacement = false;
-
 
363
	}
-
 
364
}
-
 
365
 
-
 
366
function dessinerLigneRue(pointDebut, pointFin) {
-
 
367
	if(ligneRue != undefined) {
-
 
368
		ligneRue.setMap(null);
-
 
369
	}
-
 
370
	
-
 
371
	ligneRue = new google.maps.Polyline({
-
 
372
	    path: [pointDebut, pointFin],
-
 
373
	    strokeColor: "#FF0000",
-
 
374
	    strokeOpacity: 1.0,
-
 
375
	    strokeWeight: 2
-
 
376
	  });
-
 
377
 
-
 
378
	ligneRue.setMap(map);
-
 
379
}
-
 
380
 
-
 
381
function mettreAJourMarkerPosition(latLng) {
-
 
382
	var lat = latLng.lat().toFixed(5);
-
 
383
	var lng = latLng.lng().toFixed(5); 
-
 
384
	remplirChampLatitude(lat);
-
 
385
	remplirChampLongitude(lng);
-
 
386
}
-
 
387
 
-
 
388
function remplirChampLatitude(latDecimale) {
-
 
389
	var lat = Math.round(latDecimale*100000)/100000;
-
 
390
	$('#latitude').val(lat);
-
 
391
}
-
 
392
 
-
 
393
function remplirChampLongitude(lngDecimale) {
-
 
394
	var lng = Math.round(lngDecimale*100000)/100000;
-
 
395
	$('#longitude').val(lng);
-
 
396
}
-
 
397
 
-
 
398
function trouverCommune(pos) {
-
 
399
	$(function() {
-
 
400
		var urlNomCommuneFormatee = SERVICE_NOM_COMMUNE_URL.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
-
 
401
		$.ajax({
-
 
402
			url : urlNomCommuneFormatee,
-
 
403
			type : "GET",
-
 
404
			dataType : "jsonp",
-
 
405
			beforeSend : function() {
-
 
406
				$(".commune-info").empty();	
-
 
407
				$("#dialogue-erreur").empty();
-
 
408
			},
-
 
409
			success : function(data, textStatus, jqXHR) {
-
 
410
				$(".commune-info").empty();
-
 
411
				if(data != null) { 
-
 
412
					$("#commune-nom").append(data.nom);
-
 
413
					$("#commune-code-insee").append(data.codeINSEE);
-
 
414
					$("#marqueur-commune").data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
-
 
415
				}
-
 
416
			},
-
 
417
			statusCode : {
-
 
418
			    500 : function(jqXHR, textStatus, errorThrown) {
-
 
419
					if (DEBUG) {	
-
 
420
						$("#dialogue-erreur").append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissante le nom des communes.</p>');
-
 
421
						reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
422
						var erreurMsg = "";
-
 
423
						if (reponse != null) {
-
 
424
							$.each(reponse, function (cle, valeur) {
-
 
425
								erreurMsg += valeur + "<br />";
-
 
426
							});
-
 
427
						}
-
 
428
						
-
 
429
						$("#dialogue-erreur").append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
-
 
430
					}
-
 
431
			    }
-
 
432
			},
-
 
433
			error : function(jqXHR, textStatus, errorThrown) {
-
 
434
				if (DEBUG) {
-
 
435
					$("#dialogue-erreur").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
-
 
436
					reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
437
					var erreurMsg = "";
-
 
438
					if (reponse != null) {
-
 
439
						$.each(reponse, function (cle, valeur) {
-
 
440
							erreurMsg += valeur + "<br />";
-
 
441
						});
-
 
442
					}
-
 
443
					
-
 
444
					$("#dialogue-erreur").append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
-
 
445
				}
-
 
446
			},
-
 
447
			complete : function(jqXHR, textStatus) {
-
 
448
				if (DEBUG && jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
-
 
449
					var debugMsg = "";
-
 
450
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
-
 
451
					if (debugInfos != null) {
-
 
452
						$.each(debugInfos, function (cle, valeur) {
-
 
453
							debugMsg += valeur + "<br />";
163
		if (status == google.maps.GeocoderStatus.OK) {
454
						});
164
			if (results[0]) {
455
						$("#dialogue-erreur").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
Line 165... Line 456...
165
				marker.setPosition(latlng);
456
					}
166
				map.setCenter(latlng);
457
				}
167
				$('#adresse').val(results[0].formatted_address);
458
				if ($("#dialogue-erreur .msg").length > 0) {
-
 
459
					$("#dialogue-erreur").dialog();
-
 
460
				}
168
			}
461
			}
169
		} else {
462
		});
170
			alert("Geocoder failed due to: " + status);
463
	});
171
		}
464
}
172
	});
465
 
173
}
466
//+---------------------------------------------------------------------------------------------------------+
174
 
467
// FORMULAIRE
175
//+---------------------------------------------------------------------------------------------------------+
468
$(document).ready(function() {
176
// FORMULAIRE
469
	$("#date").datepicker($.datepicker.regional['fr']);
177
$(document).ready(function() {
470
	
-
 
471
	$("form#saisie-obs").validate({
178
	$("form#saisie-obs").validate({
472
		rules: {
-
 
473
			courriel : {
-
 
474
				required : true,
179
		rules: {
475
				email : true},
180
			courriel : {
476
			courriel_confirmation : {
181
				required : true,
477
				required : true,
182
				email : true},
478
				equalTo: "#courriel"
183
			courriel_confirmation : {
479
			},
184
				required : true,
480
			rue_cote : "required",
185
				equalTo: "#courriel"
481
			"milieu[]" : {
186
			},
482
			       required: true,
187
			milieu : "required",
483
			       minlength: 1
188
			adresse : "required",
484
			},
-
 
485
			latitude : {
-
 
486
				required: true,
-
 
487
				range: [-90, 90]},
189
			latitude : {
488
			longitude : {
190
				required: true,
489
				required: true,
Line 191... Line -...
191
				range: [-90, 90]},
-
 
192
			longitude : {
-
 
193
				required: true,
490
				range: [-180, 180]},
194
				range: [-180, 180]},
491
			date : {
195
			date : {
492
				required: true,
196
				required: true,
493
				date: true},
197
				date: true},
494
			taxon : "required"
198
			taxon : "required"
-
 
199
		}
-
 
200
	});
-
 
201
	
-
 
202
	$("#date").datepicker($.datepicker.regional['fr']);
-
 
203
	
-
 
204
	$("#courriel_confirmation").bind('paste', function(e) {
-
 
205
		$("#dialogue-bloquer-copier-coller").dialog();
-
 
206
		return false;
-
 
207
	});
495
		},
208
	
496
		messages: {
209
	/*---Afficher/cacher les coordonnees geographiques----*/	
-
 
210
	
-
 
211
	var showText=" -Afficher-";
-
 
212
	var hideText=" -Masquer- ";
-
 
213
	
497
			"milieu[]": "Vous devez sélectionner au moins un milieu"
214
	//créer le lien afficher/masquer
-
 
215
	$("#coordonnees-geo").before("<a href='#' id='toogle_link'>"+showText+"</a>")
-
 
216
	//masquer le contenu
498
		}
217
	$("#masque").hide();
499
	});
218
	//bascule le texte d'afficher à masquer
500
	
219
	$("a#toogle_link").click(function() {
501
	$("#courriel_confirmation").bind('paste', function(e) {
220
		//changer le texte du lien
-
 
221
		if($('a#toogle_link').text()==showText){
-
 
Line 222... Line 502...
222
			$('a#toogle_link').text(hideText);
502
		$("#dialogue-bloquer-copier-coller").dialog();
223
		} else{
503
		return false;
224
			$('a#toogle_link').text(showText);
504
	});
225
		}
505
		
226
	//basuler l'affichage
506
	//bascule le texte d'afficher à masquer
-
 
507
	$("a.afficher-coord").click(function() {
-
 
508
		$("a.afficher-coord").toggle();
-
 
509
		$("#coordonnees-geo").toggle('slow');
-
 
510
		//valeur false pour que le lien ne soit pas suivi
-
 
511
		return false;
-
 
512
	});
-
 
513
	
-
 
514
	var obsNumero = 0;
227
	$('#masque').toggle('slow');
515
	$("#ajouter-obs").bind('click', function(e) {
228
	//valeur false pour que le lien ne soit pas suivi
516
		if ($("#saisie-obs").valid() == false) {
229
	return false
517
			$("#dialogue-form-invalide").dialog();
230
	});
518
		} else {
231
 
519
			
232
	/*------obs-----------*/	
520
			var milieux = [];
233
	
521
			$('input:checked["name=milieux[]"]').each(function() {
234
	var obsNumero = 0;
522
				milieux.push($(this).val());
235
	$("#ajouter-obs").bind('click', function(e) {
-
 
236
		if ($("#saisie-obs").valid() == false) {
523
			});
237
			$("#dialogue-form-invalide").dialog();
524
			
238
		} else {
525
			var rue = ($("#rue").val() == valeurDefautRechercheLieu) ? 'non renseigné(e)' : $("#rue").val();
239
			//rassemble les obs dans un tableau html
526
			
240
			obsNumero = obsNumero + 1;
527
			//rassemble les obs dans un tableau html
241
			$("#liste-obs tbody").append(
528
			obsNumero = obsNumero + 1;
242
					'<tr id="obs'+obsNumero+'" class="obs">'+
529
			$("#liste-obs tbody").append(
243
					'<td>'+obsNumero+'</td>'+
530
					'<tr id="obs'+obsNumero+'" class="obs">'+
244
					'<td>'+$("#date").val()+'</td>'+
531
					'<td>'+obsNumero+'</td>'+
Line 262... Line 549...
262
				'nom_ret' : taxons[numNomSel]['nom_ret'],
549
				'nom_ret' : taxons[numNomSel]['nom_ret'],
263
				'num_nom_ret' : taxons[numNomSel]['num_nom_ret'],
550
				'num_nom_ret' : taxons[numNomSel]['num_nom_ret'],
264
				'num_taxon' : taxons[numNomSel]['num_taxon'],
551
				'num_taxon' : taxons[numNomSel]['num_taxon'],
265
				'famille' : taxons[numNomSel]['famille'],
552
				'famille' : taxons[numNomSel]['famille'],
266
				'nom_fr' : taxons[numNomSel]['nom_fr'],
553
				'nom_fr' : taxons[numNomSel]['nom_fr'],
267
				'station' : $("#adresse").val(),
-
 
268
				'milieu' : $('input[name=milieu]:checked').val(),
554
				'milieu' : milieux.join(','),
269
				'latitude' : $("#latitude").val(),
555
				'latitude' : $("#latitude").val(),
270
				'longitude' : $("#longitude").val(),
556
				'longitude' : $("#longitude").val(),
-
 
557
				'commune_nom' : $("#commune-nom").text(),
-
 
558
				'commune_code_insee' : $("#commune-code-insee").text(),
271
				'tag' : 'Sauvages',
559
				'lieudit' : rue,
-
 
560
				'station' : latLng.lat().toFixed(5)+','+latLng.lng().toFixed(5)+';'+latLngFin.lat().toFixed(5)+','+latLngFin.lng().toFixed(5)+';'+$("#rue_cote").val(),
-
 
561
				'notes' : $("#notes").val(),
272
				//Ajout du champ photo
562
				//Ajout des champs images
273
				'image_nom' : $("#miniature-img").attr('alt'),
563
				'image_nom' : $("#miniature-img").attr('alt'),
274
				//'image_b64' : $("#miniature-img").attr('alt'),
564
				'image_b64' : getB64ImgOriginal()
275
				'notes' : $("#notes").val()});
-
 
276
		}
-
 
277
	});
565
			});
278
	
-
 
279
	$(".supprimer-obs").live('click', function() {
-
 
280
		var obsId = $(this).val();
-
 
281
		// Problème avec IE 6 et 7
-
 
282
		if (obsId == "Supprimer") {
-
 
283
			obsId = $(this).attr("title");
-
 
284
		}
566
		}
285
		
-
 
286
		$('#obs'+obsId).remove();
-
 
287
		$("#liste-obs").removeData('obsId'+obsId)
-
 
288
	});
567
	});
289
 
-
 
290
	$("#effacer-miniature").click(function () {
-
 
291
		$("#miniature").empty();	    
-
 
292
	});	
-
 
Line 293... Line 568...
293
	
568
	
294
	// TODO : remplacer par du jquery
-
 
Line 295... Line 569...
295
	//document.getElementById('image_file').addEventListener('change', handleFileSelect, false);
569
	$(".supprimer-obs").live('click', supprimerObs);
296
	
570
	
-
 
571
	$("#transmettre-obs").click(function(e) {
297
	$("#transmettre-obs").click(function(e) {
572
		var observations = $("#liste-obs").data();
298
		var observations = $("#liste-obs").data();
573
		
299
		if (observations == undefined || jQuery.isEmptyObject(observations)) {
574
		if (observations == undefined || jQuery.isEmptyObject(observations)) {
300
			$("#dialogue-zero-obs").dialog();
575
			$("#dialogue-zero-obs").dialog();
301
		} else if ($("#saisie-obs").valid() == false) {
576
		} else if ($("#saisie-obs").valid() == false) {
-
 
577
			$("#dialogue-form-invalide").dialog();
-
 
578
		} else {
302
			$("#dialogue-form-invalide").dialog();
579
			observations['projet'] = 'Sauvages';
303
		} else {
580
			
304
			var utilisateur = new Object();
581
			var utilisateur = new Object();
305
			utilisateur.prenom = $("#prenom").val();
582
			utilisateur.prenom = $("#prenom").val();
306
			utilisateur.nom = $("#nom").val();
583
			utilisateur.nom = $("#nom").val();
307
			utilisateur.courriel = $("#courriel").val();
-
 
308
			observations['utilisateur'] = utilisateur;
-
 
309
					$.ajax({
-
 
310
						url : SERVICE_SAISIE_URL,
-
 
311
						type : "POST",
-
 
312
						data : observations,
-
 
313
						context : document.body,
-
 
314
						beforeSend : function() {
-
 
315
							$("#msg").remove();	
-
 
316
							$("#msg-erreur").remove();
-
 
317
							$("#msg-debug").remove();
-
 
318
						},
-
 
319
						statusCode : {
-
 
320
						    500 : function(jqXHR, textStatus, errorThrown) {
-
 
321
								$("#dialogue-obs-transaction").append('<p id="msg">Un problème est survenu lors de la transmission de vos observations.</p>');
-
 
322
								reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
323
								var erreurMsg = "";
-
 
324
								if (reponse != null) {
-
 
325
									$.each(reponse, function (cle, valeur) {
-
 
326
										erreurMsg += valeur + "<br />";
-
 
327
									});
-
 
328
								}
-
 
329
								
-
 
330
								$("#dialogue-obs-transaction").append('<p id="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
-
 
331
						    }
-
 
332
						},
-
 
333
						success : function(data, textStatus, jqXHR) {
-
 
334
							$("#dialogue-obs-transaction").append('<p id="msg">Vos observations ont bien été transmises.</p>');
-
 
335
						},
-
 
336
						complete : function(jqXHR, textStatus) {
-
 
337
							var debugMsg = "";
-
 
338
							if (DEBUG && jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
-
 
339
								debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
-
 
340
								if (debugInfos != null) {
-
 
341
									$.each(debugInfos, function (cle, valeur) {
-
 
342
										debugMsg += valeur + "<br />";
-
 
343
									});
-
 
344
									$("#dialogue-obs-transaction").append('<pre id="msg-debug">Débogage : '+debugMsg+'</pre>');
-
 
345
								}
-
 
346
							}
-
 
347
							
-
 
348
							$("#dialogue-obs-transaction").dialog();
-
 
349
							$("#liste-obs").removeData();
-
 
350
							$('.obs').remove();
-
 
Line -... Line 584...
-
 
584
			utilisateur.courriel = $("#courriel").val();
-
 
585
			observations['utilisateur'] = utilisateur;
-
 
586
			
-
 
587
			var erreurMsg = "";
-
 
588
			$.ajax({
-
 
589
				url : SERVICE_SAISIE_URL,
-
 
590
				type : "POST",
-
 
591
				data : observations,
-
 
592
				dataType : "json",
-
 
593
				beforeSend : function() {
-
 
594
					$(".msg").remove();	
-
 
595
					$(".msg-erreur").remove();
-
 
596
					$(".msg-debug").remove();
-
 
597
					$("#chargement").show();
-
 
598
				},
-
 
599
				success : function(data, textStatus, jqXHR) {
-
 
600
					var message = 'Merci Beaucoup! Vos observations ont bien été transmises aux chercheurs.<br />'+
-
 
601
				    'Elles sont désormais affichées sur la carte Sauvages de ma rue, <br />'+
-
 
602
				    'et s\'ajoutent aux données du Carnet en ligne (<a href="http://www.tela-botanica.org/widget:cel:carto">voir la carte</a>) de Tela Botanica <br />'+ 
-
 
603
					'<br />	'+		  	
-
 
604
					'Bonne continuation! <br />'+
-
 
605
					'<br /> '+
-
 
606
					'Si vous souhaitez modifier ou supprimer vos données, vous pouvez les retrouver en vous connectant au <a href="http://www.tela-botanica.org/page:cel">Carnet en ligne</a>. <br /> '+
-
 
607
					'(Attention, il est nécessaire de s\'inscrire gratuitement à Tela Botanica au préalable, si ce n\'est pas déjà fait). <br /> '+
-
 
608
					'<br /> '+
-
 
609
					'Pour toute question, n\'hésitez pas: notre contact: sauvages@tela-botanica.org ';
-
 
610
					$("#dialogue-obs-transaction").append('<p class="msg">'+message+'</p>');
-
 
611
					supprimerMiniature();
-
 
612
				},
-
 
613
				statusCode : {
-
 
614
					500 : function(jqXHR, textStatus, errorThrown) {
-
 
615
						$("#chargement").hide();
-
 
616
						erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
-
 
617
						if (DEBUG) {
-
 
618
							$("#dialogue-obs-transaction").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
-
 
619
						}
-
 
620
				    }
-
 
621
				},
-
 
622
				error : function(jqXHR, textStatus, errorThrown) {
-
 
623
					erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
-
 
624
					try {
-
 
625
						reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
626
						if (reponse != null) {
-
 
627
							$.each(reponse, function (cle, valeur) {
-
 
628
								erreurMsg += valeur + "\n";
-
 
629
							});
-
 
630
						}
-
 
631
					} catch(e) {
-
 
632
						erreurMsg += "L'erreur n'était pas en JSON.";
-
 
633
					}
-
 
634
					
-
 
635
					if (DEBUG) {
-
 
636
						$("#dialogue-obs-transaction").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
-
 
637
					}
-
 
638
				},
-
 
639
				complete : function(jqXHR, textStatus) {
-
 
640
					$("#chargement").hide();
-
 
641
					var debugMsg = '';
-
 
642
					if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
-
 
643
						debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
351
							obsNumero = 0;
644
						if (debugInfos != null) {
-
 
645
							$.each(debugInfos, function (cle, valeur) {
-
 
646
								debugMsg += valeur + "\n";
-
 
647
							});
-
 
648
						}
-
 
649
					}
-
 
650
					if (erreurMsg != '') {
-
 
651
						$("#dialogue-obs-transaction").append('<p class="msg">'+
-
 
652
								'Une erreur est survenue lors de la transmission de vos observations.'+'<br />'+
-
 
653
								'Vous pouvez signaler le disfonctionnement à <a href="'+
-
 
654
								'mailto:cel@tela-botanica.org'+'?'+
-
 
655
								'subject=Disfonctionnement du widget de saisie Biodiversite34'+
-
 
656
								"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
-
 
657
								'">cel@tela-botanica.org</a>.'+
-
 
658
								'</p>');
-
 
659
					}
-
 
660
					if (DEBUG) {
-
 
661
						$("#dialogue-obs-transaction").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
-
 
662
					}
-
 
663
					
-
 
664
					$("#dialogue-obs-transaction").dialog();
-
 
665
					$("#liste-obs").removeData();
-
 
666
					$('.obs').remove();
352
						},
667
					obsNumero = 0;
353
			
668
				}
354
					});
669
			});
355
		}
670
		}
Line -... Line 671...
-
 
671
		return false;
-
 
672
	});
-
 
673
});
-
 
674
 
-
 
675
function getB64ImgOriginal() {
-
 
676
	var b64 = '';
-
 
677
	if ($("#miniature-img").hasClass('b64')) {
-
 
678
		b64 = $("#miniature-img").attr('src');
-
 
679
	} else if ($("#miniature-img").hasClass('b64-canvas')) {
Line 356... Line 680...
356
		return false;
680
		b64 = $("#miniature-img").data('b64');
357
	});
-
 
358
});
-
 
359
 
-
 
360
 
-
 
361
function handleFileSelect(evt) {
-
 
362
	// Check for the various File API support.
-
 
363
	if (window.File && window.FileReader && window.FileList && window.Blob) {
681
	}
364
	// Great success! All the File APIs are supported.
-
 
365
		var selectedfiles = evt.target.files; // FileList object
682
	return b64;
366
		
683
}
367
		// Loop through the FileList and render image files as thumbnails.
684
 
368
		for (var i = 0, f; f = selectedfiles[i]; i++) {
685
function supprimerObs() {
369
		
686
	var obsId = $(this).val();
370
		  // Only process image files.
687
	// Problème avec IE 6 et 7
371
		  if (!f.type.match('image.*')) {
-
 
372
		    continue;
-
 
373
		  }
688
	if (obsId == "Supprimer") {
374
		
689
		obsId = $(this).attr("title");
375
		  var reader = new FileReader();
-
 
376
		
-
 
377
		  // Read in the image file as a data URL.
-
 
378
		  reader.readAsDataURL(f);
-
 
379
		  
-
 
380
		  // Closure to capture the file information.
-
 
381
		  reader.onload = (function(theFile) {
-
 
382
			 return function(e) {
-
 
383
		    	// Render thumbnail.
-
 
Line 384... Line -...
384
		    	document.getElementById('image').src = e.target.result;
-
 
-
 
690
	}
385
		    	//document.getElementById('list').insertBefore(img, null);
691
	
-
 
692
	$('#obs'+obsId).remove();
-
 
693
	$("#liste-obs").removeData('obsId'+obsId);
-
 
694
}
-
 
695
 
386
		    };
696
function ajouterImgMiniatureAuTransfert() {
387
		  })(f);
697
	var miniature = '';
-
 
698
	if ($("#miniature img").length == 1) {
388
		}
699
		var css = $("#miniature-img").hasClass('b64') ? 'miniature b64' : 'miniature';
389
 
700
		var src = $("#miniature-img").attr("src");