Subversion Repositories eFlore/Applications.cel

Rev

Rev 1701 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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