Subversion Repositories eFlore/Applications.cel

Rev

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

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