Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1073 Rev 1093
Line 26... Line 26...
26
}());
26
}());
Line 27... Line 27...
27
 
27
 
28
//+----------------------------------------------------------------------------------------------------------+
28
//+----------------------------------------------------------------------------------------------------------+
29
//UPLOAD PHOTO : Traitement de l'image 
29
//UPLOAD PHOTO : Traitement de l'image 
-
 
30
$(document).ready(function() {	
-
 
31
 
-
 
32
	$("#effacer-miniature").click(function () {
-
 
33
		supprimerMiniature();
-
 
34
	});
-
 
35
	
-
 
36
	$("#fichier").bind('change', function () {
-
 
37
		$("#form-upload").ajaxSubmit(options);
-
 
38
		return false;
-
 
39
	});
30
$(document).ready(function() {	
40
	
31
	//prepare the form when the DOM is ready 
41
	//prepare the form when the DOM is ready 
32
	//create service object(proxy) using SMD (generated by the json result)
42
	//create service object(proxy) using SMD (generated by the json result)
33
	var options = { 
43
	var options = { 
34
		success: afficherMiniature, // post-submit callback 
44
		success: afficherMiniature, // post-submit callback 
35
		dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type) 
45
		dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type) 
36
		resetForm: true // reset the form after successful submit 
46
		resetForm: true // reset the form after successful submit 
37
	};
-
 
38
 
-
 
39
	// post-submit callback 
-
 
40
	function afficherMiniature(reponse) { 
-
 
41
		// 'responseXML' is the XML document returned by the server; we use 
-
 
42
		// jQuery to extract the content of the message node from the XML doc 
-
 
43
		var miniatureUrl = $("miniature-url", reponse).text();
-
 
44
		var imgNom = $("image-nom", reponse).text();
-
 
45
		$("#miniature").empty();
-
 
46
		$("#miniature").append('<img id="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>');
-
 
47
		console.log(imgNom);
-
 
48
		console.log(miniatureUrl);		
-
 
49
	};
-
 
50
	
-
 
51
	$("#form-upload").submit(function() { 
-
 
52
		// inside event callbacks 'this' is the DOM element so we first 
-
 
53
		// wrap it in a jQuery object and then invoke ajaxSubmit 
-
 
54
		$(this).ajaxSubmit(options); 
-
 
55
		 
-
 
56
		// !!! Important !!! 
-
 
57
		// always return false to prevent standard browser submit and page navigation 
-
 
58
		return false; 
-
 
59
	});
47
	};
Line -... Line 48...
-
 
48
});
-
 
49
 
-
 
50
function afficherMiniature(reponse) { 
-
 
51
	// 'responseXML' is the XML document returned by the server; we use 
-
 
52
	// jQuery to extract the content of the message node from the XML doc 
-
 
53
	var miniatureUrl = $("miniature-url", reponse).text();
-
 
54
	var imgNom = $("image-nom", reponse).text();
-
 
55
	$("#miniature").empty();
-
 
56
	$("#miniature").append('<img id="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>');
-
 
57
	$("#effacer-miniature").show();
-
 
58
	console.log(imgNom);
-
 
59
	console.log(miniatureUrl);		
-
 
60
}
-
 
61
 
-
 
62
function supprimerMiniature() {
-
 
63
	$("#miniature").empty();
-
 
64
	$("#effacer-miniature").hide();
60
});
65
}
61
 
66
 
62
//+----------------------------------------------------------------------------------------------------------+
67
//+----------------------------------------------------------------------------------------------------------+
63
// GOOGLE MAP
68
// GOOGLE MAP
64
var geocoder;
69
var geocoder;
65
var map;
70
var map;
Line 66... Line 71...
66
var marker;
71
var marker;
67
var latLng;
72
var latLng;
68
 
73
 
69
function initialize(){
74
function initialiserGoogleMap(){
70
	// Carte
75
	// Carte
-
 
76
	var latLng = new google.maps.LatLng(43.29545, 5.37458);
71
	var latLng = new google.maps.LatLng(43.29545, 5.37458);
77
	if (VILLE == 'Montpellier') {
-
 
78
		latLng = new google.maps.LatLng(43.61077, 3.87672);
-
 
79
	} else {
72
	$('#adresse').val('1 rue de la canebiere, 13001');
80
		console.log('Ville:'+VILLE);
73
	$('#latitude').val('43.29545');
81
	}
74
	$('#longitude').val('5.37458');
82
 
75
	var options = {
83
	var options = {
-
 
84
		zoom: 16,
-
 
85
		center: latLng,
76
		zoom: 16,
86
		mapTypeId: google.maps.MapTypeId.HYBRID,
-
 
87
		mapTypeControlOptions: {
-
 
88
			mapTypeIds: ['OSM', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN]}
-
 
89
	};
-
 
90
 
-
 
91
	// Ajout de la couche OSM à la carte
-
 
92
	osmMapType = new google.maps.ImageMapType({
-
 
93
		getTileUrl: function(coord, zoom) {
-
 
94
			return "http://tile.openstreetmap.org/" +
-
 
95
			zoom + "/" + coord.x + "/" + coord.y + ".png";
-
 
96
		},
-
 
97
		tileSize: new google.maps.Size(256, 256),
-
 
98
		isPng: true,
-
 
99
		alt: 'OpenStreetMap',
Line -... Line 100...
-
 
100
		name: 'OSM',
77
		center: latLng,
101
		maxZoom: 19
-
 
102
	});
Line 78... Line 103...
78
		mapTypeId: google.maps.MapTypeId.SATELLITE
103
	
79
	};
104
	// Création de la carte Google
80
	
105
	map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
Line 90... Line 115...
90
		draggable: true,
115
		draggable: true,
91
		title: 'Ma station',
116
		title: 'Ma station',
92
		icon: GOOGLE_MAP_MARQUEUR_URL,
117
		icon: GOOGLE_MAP_MARQUEUR_URL,
93
		position: latLng
118
		position: latLng
94
	});
119
	});
-
 
120
	
-
 
121
	deplacerMarker(latLng);
95
}
122
}
Line 96... Line 123...
96
 
123
 
-
 
124
$(document).ready(function() {
97
$(document).ready(function() {
125
	
Line 98... Line 126...
98
	initialize();
126
	initialiserGoogleMap();
99
  
127
  
100
	$(function() {
128
	$(function() {
101
		// Tentative de geocalisation
129
		// Tentative de geocalisation
Line 105... Line 133...
105
				var longitude = position.coords.longitude;
133
				var longitude = position.coords.longitude;
106
				var altitude = position.coords.altitude;
134
				var altitude = position.coords.altitude;
107
				var geocalisation = new google.maps.LatLng(latitude, longitude);
135
				var geocalisation = new google.maps.LatLng(latitude, longitude);
108
				marker.setPosition(geocalisation);
136
				marker.setPosition(geocalisation);
109
				map.setCenter(geocalisation);
137
				map.setCenter(geocalisation);
110
				$('#latitude').val(marker.getPosition().lat());
-
 
111
				$('#longitude').val(marker.getPosition().lng());
-
 
112
				$('#adresse').val(codeLatLng(marker.getPosition()));
138
				$('#adresse').val(codeLatLng(marker.getPosition()));
-
 
139
				mettreAJourMarkerPosition(marker.getPosition());
113
			});
140
			});
114
		}   
141
		}   
Line 115... Line 142...
115
		
142
		
116
		// Autocompletion du champ adresse
143
		// Autocompletion du champ adresse
117
		$("#adresse").autocomplete({
144
		$("#adresse").autocomplete({
118
			//Cette partie utilise geocoder pour extraire des valeurs d'adresse
145
			//Cette partie utilise geocoder pour extraire des valeurs d'adresse
119
			source: function(request, response) {
146
			source: function(request, response) {
-
 
147
				geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
120
				geocoder.geocode( {'address': request.term }, function(results, status) {
148
					if (status == google.maps.GeocoderStatus.OK) {
121
					response($.map(results, function(item) {
149
						response($.map(results, function(item) {
122
						return {
150
							return {
123
							label:  item.formatted_address,
151
								label: item.formatted_address,
124
							value: item.formatted_address,
152
								value: item.formatted_address,
125
							latitude: item.geometry.location.lat(),
153
								latitude: item.geometry.location.lat(),
126
							longitude: item.geometry.location.lng()
154
								longitude: item.geometry.location.lng()
127
						}
155
							}
-
 
156
						}));
-
 
157
					} else {
-
 
158
						afficherErreurGoogleMap(status);
128
					}));
159
					}
129
				})
160
				})
130
			},
161
			},
131
			// Cette partie est executee a la selection d'une adresse
162
			// Cette partie est executee a la selection d'une adresse
132
			select: function(event, ui) {
163
			select: function(event, ui) {
133
				$("#latitude").val(ui.item.latitude);
164
				remplirChampLatitude(ui.item.latitude);
134
				$("#longitude").val(ui.item.longitude);
165
				remplirChampLongitude(ui.item.longitude);
135
				var location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
166
				var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
136
				marker.setPosition(location);
167
				deplacerMarker(latLng);
137
				map.setCenter(location);
168
				map.setCenter(latLng);
138
				map.setZoom(20);
169
				map.setZoom(19);
139
			}
170
			}
140
		});
171
		});
141
 
172
		
142
		// Ajoute un ecouteur sur le marker pour le reverse geocoding
173
		google.maps.event.addListener(marker, 'dragend', function() {
143
		google.maps.event.addListener(marker, 'drag', function() {
174
			trouverCommune(marker.getPosition());
144
			geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
175
			geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
145
				if (status == google.maps.GeocoderStatus.OK) {
176
				if (status == google.maps.GeocoderStatus.OK) {
146
					if (results[0]) {
177
					if (results[0]) {
147
						$('#adresse').val(results[0].formatted_address);
178
						$('#adresse').val(results[0].formatted_address);
148
						$('#latitude').val(Math.round(marker.getPosition().lat()*100000)/100000);
-
 
149
						$('#longitude').val(Math.round(marker.getPosition().lng()*100000)/100000);
179
						mettreAJourMarkerPosition(marker.getPosition());
-
 
180
					}
-
 
181
				} else  {
150
					}
182
					afficherErreurGoogleMap(status);
151
				}
183
				}
152
			});
184
			});
153
		});
185
		});
154
	});
186
	});
Line 165... Line 197...
165
				marker.setPosition(latlng);
197
				marker.setPosition(latlng);
166
				map.setCenter(latlng);
198
				map.setCenter(latlng);
167
				$('#adresse').val(results[0].formatted_address);
199
				$('#adresse').val(results[0].formatted_address);
168
			}
200
			}
169
		} else {
201
		} else {
170
			alert("Geocoder failed due to: " + status);
202
			afficherErreurGoogleMap(status);
171
		}
203
		}
172
	});
204
	});
173
}
205
}
Line -... Line 206...
-
 
206
 
-
 
207
function afficherErreurGoogleMap(status) {
-
 
208
	if (DEBUG) {
-
 
209
		$("#dialogue-google-map").empty();
-
 
210
		$("#dialogue-google-map").append('<pre class="msg-erreur">'+
-
 
211
			"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
-
 
212
			'</pre>');
-
 
213
		$("#dialogue-google-map").dialog();
-
 
214
	}
-
 
215
}
-
 
216
 
-
 
217
function deplacerMarker(latLon) {
-
 
218
	if (marker != undefined) {
-
 
219
		marker.setPosition(latLon);
-
 
220
		mettreAJourMarkerPosition(marker.getPosition());
-
 
221
		trouverCommune(marker.getPosition());
-
 
222
	}
-
 
223
}
-
 
224
 
-
 
225
function mettreAJourMarkerPosition(latLng) {
-
 
226
	var lat = latLng.lat().toFixed(5);
-
 
227
	var lng = latLng.lng().toFixed(5); 
-
 
228
	remplirChampLatitude(lat);
-
 
229
	remplirChampLongitude(lng);
-
 
230
}
-
 
231
 
-
 
232
function remplirChampLatitude(latDecimale) {
-
 
233
	var lat = Math.round(latDecimale*100000)/100000;
-
 
234
	$('#latitude').val(lat);
-
 
235
}
-
 
236
 
-
 
237
function remplirChampLongitude(lngDecimale) {
-
 
238
	var lng = Math.round(lngDecimale*100000)/100000;
-
 
239
	$('#longitude').val(lng);
-
 
240
}
-
 
241
 
-
 
242
function trouverCommune(pos) {
-
 
243
	$(function() {
-
 
244
		var urlNomCommuneFormatee = SERVICE_NOM_COMMUNE_URL.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
-
 
245
		$.ajax({
-
 
246
			url : urlNomCommuneFormatee,
-
 
247
			type : "GET",
-
 
248
			dataType : "jsonp",
-
 
249
			beforeSend : function() {
-
 
250
				$(".commune-info").empty();	
-
 
251
				$("#dialogue-erreur").empty();
-
 
252
			},
-
 
253
			success : function(data, textStatus, jqXHR) {
-
 
254
				$(".commune-info").empty();
-
 
255
				$("#commune-nom").append(data.nom);
-
 
256
				$("#commune-code-insee").append(data.codeINSEE);
-
 
257
				$("#marqueur-commune").data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
-
 
258
			},
-
 
259
			statusCode : {
-
 
260
			    500 : function(jqXHR, textStatus, errorThrown) {
-
 
261
					if (DEBUG) {	
-
 
262
						$("#dialogue-erreur").append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissante le nom des communes.</p>');
-
 
263
						reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
264
						var erreurMsg = "";
-
 
265
						if (reponse != null) {
-
 
266
							$.each(reponse, function (cle, valeur) {
-
 
267
								erreurMsg += valeur + "<br />";
-
 
268
							});
-
 
269
						}
-
 
270
						
-
 
271
						$("#dialogue-erreur").append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
-
 
272
					}
-
 
273
			    }
-
 
274
			},
-
 
275
			error : function(jqXHR, textStatus, errorThrown) {
-
 
276
				if (DEBUG) {
-
 
277
					$("#dialogue-erreur").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
-
 
278
					reponse = jQuery.parseJSON(jqXHR.responseText);
-
 
279
					var erreurMsg = "";
-
 
280
					if (reponse != null) {
-
 
281
						$.each(reponse, function (cle, valeur) {
-
 
282
							erreurMsg += valeur + "<br />";
-
 
283
						});
-
 
284
					}
-
 
285
					
-
 
286
					$("#dialogue-erreur").append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
-
 
287
				}
-
 
288
			},
-
 
289
			complete : function(jqXHR, textStatus) {
-
 
290
				if (DEBUG && jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
-
 
291
					var debugMsg = "";
-
 
292
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
-
 
293
					if (debugInfos != null) {
-
 
294
						$.each(debugInfos, function (cle, valeur) {
-
 
295
							debugMsg += valeur + "<br />";
-
 
296
						});
-
 
297
						$("#dialogue-erreur").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
-
 
298
					}
-
 
299
				}
-
 
300
				if ($("#dialogue-erreur .msg").length > 0) {
-
 
301
					$("#dialogue-erreur").dialog();
-
 
302
				}
-
 
303
			}
-
 
304
		});
-
 
305
	});
-
 
306
}
174
 
307
 
175
//+---------------------------------------------------------------------------------------------------------+
308
//+---------------------------------------------------------------------------------------------------------+
176
// FORMULAIRE
309
// FORMULAIRE
177
$(document).ready(function() {
310
$(document).ready(function() {
178
	$("form#saisie-obs").validate({
311
	$("form#saisie-obs").validate({
Line 193... Line 326...
193
				required : true,
326
				required : true,
194
				digits : true,
327
				digits : true,
195
				min : 1},
328
				min : 1},
196
			rue_cote : "required",
329
			rue_cote : "required",
197
			milieu : "required",
330
			milieu : "required",
198
			adresse : "required",
-
 
199
			latitude : {
331
			latitude : {
200
				required: true,
332
				required: true,
201
				range: [-90, 90]},
333
				range: [-90, 90]},
202
			longitude : {
334
			longitude : {
203
				required: true,
335
				required: true,
Line 214... Line 346...
214
	$("#courriel_confirmation").bind('paste', function(e) {
346
	$("#courriel_confirmation").bind('paste', function(e) {
215
		$("#dialogue-bloquer-copier-coller").dialog();
347
		$("#dialogue-bloquer-copier-coller").dialog();
216
		return false;
348
		return false;
217
	});
349
	});
Line 218... Line -...
218
		
-
 
219
	/*---Afficher/cacher les coordonnees geographiques----*/	
-
 
220
	
-
 
221
	var showText=" -Afficher-";
-
 
222
	var hideText=" -Masquer- ";
-
 
223
	
-
 
224
	//créer le lien afficher/masquer
-
 
225
	$("#coordonnees-geo").before("<a href='#' id='toogle_link'>"+showText+"</a>")
-
 
226
	//masquer le contenu
-
 
227
	$("#masque").hide();
350
		
228
	//bascule le texte d'afficher à masquer
351
	//bascule le texte d'afficher à masquer
229
	$("a#toogle_link").click(function() {
-
 
230
		//changer le texte du lien
-
 
231
		if($('a#toogle_link').text()==showText){
-
 
232
			$('a#toogle_link').text(hideText);
-
 
233
		} else{
352
	$("a.afficher-coord").click(function() {
234
			$('a#toogle_link').text(showText);
-
 
235
		}
-
 
236
	//basuler l'affichage
353
		$("a.afficher-coord").toggle();
237
	$('#masque').toggle('slow');
354
		$("#coordonnees-geo").toggle('slow');
238
	//valeur false pour que le lien ne soit pas suivi
355
		//valeur false pour que le lien ne soit pas suivi
239
	return false
356
		return false
240
	});
-
 
241
 
-
 
Line 242... Line 357...
242
	/*------obs-----------*/	
357
	});
243
	
358
	
244
	var obsNumero = 0;
359
	var obsNumero = 0;
245
	$("#ajouter-obs").bind('click', function(e) {
360
	$("#ajouter-obs").bind('click', function(e) {
Line 253... Line 368...
253
					'<td>'+obsNumero+'</td>'+
368
					'<td>'+obsNumero+'</td>'+
254
					'<td>'+$("#date").val()+'</td>'+
369
					'<td>'+$("#date").val()+'</td>'+
255
					'<td>'+$("#adresse").val()+'</td>'+
370
					'<td>'+$("#adresse").val()+'</td>'+
256
					'<td>'+$("#taxon option:selected").text()+'</td>'+
371
					'<td>'+$("#taxon option:selected").text()+'</td>'+
257
					'<td>'+$('input[name=milieu]:checked').val()+'</td>'+
372
					'<td>'+$('input[name=milieu]:checked').val()+'</td>'+
258
					'<td>'+$("#latitude").val()+'</td>'+
-
 
259
					'<td>'+$("#longitude").val()+'</td>'+
373
					'<td>'+$("#latitude").val()+' / '+$("#longitude").val()+'</td>'+
260
					//Ajout du champ photo
374
					//Ajout du champ photo
261
					'<td><img class="miniature" alt="'+$("#miniature-img").attr("alt")+'"src="'+$("#miniature-img").attr("src")+'" /></td>'+
375
					'<td class="obs-miniature">'+ajouterImgMiniature()+'</td>'+
262
					'<td>'+$("#notes").val()+'</td>'+
376
					'<td>'+$("#notes").val()+'</td>'+
263
					'<td><button class="supprimer-obs" value="'+obsNumero+'" title="Supprimer l\'observation '+obsNumero+'">'+
377
					'<td><button class="supprimer-obs" value="'+obsNumero+'" title="Supprimer l\'observation '+obsNumero+'">'+
264
					'<img src="'+SUPPRIMER_ICONE_URL+'"/></button></td>'+
378
					'<img src="'+SUPPRIMER_ICONE_URL+'"/></button></td>'+
265
				'</tr>');
379
				'</tr>');
266
			//rassemble les obs dans #liste-obs
380
			//rassemble les obs dans #liste-obs
Line 297... Line 411...
297
		}
411
		}
Line 298... Line 412...
298
		
412
		
299
		$('#obs'+obsId).remove();
413
		$('#obs'+obsId).remove();
300
		$("#liste-obs").removeData('obsId'+obsId)
414
		$("#liste-obs").removeData('obsId'+obsId)
301
	});
-
 
302
 
-
 
303
	$("#effacer-miniature").click(function () {
-
 
304
		$("#miniature").empty();	    
-
 
Line 305... Line 415...
305
	});	
415
	});
306
	
416
	
Line 307... Line 417...
307
	// TODO : remplacer par du jquery
417
	// TODO : remplacer par du jquery
Line 334... Line 444...
334
					$(".msg-erreur").remove();
444
					$(".msg-erreur").remove();
335
					$(".msg-debug").remove();
445
					$(".msg-debug").remove();
336
				},
446
				},
337
				success : function(data, textStatus, jqXHR) {
447
				success : function(data, textStatus, jqXHR) {
338
					$("#dialogue-obs-transaction").append('<p class="msg">Vos observations ont bien été transmises.</p>');
448
					$("#dialogue-obs-transaction").append('<p class="msg">Vos observations ont bien été transmises.</p>');
-
 
449
					supprimerMiniature();
339
				},
450
				},
340
				statusCode : {
451
				statusCode : {
341
				    500 : function(jqXHR, textStatus, errorThrown) {
452
				    500 : function(jqXHR, textStatus, errorThrown) {
342
						erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
453
						erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
343
						reponse = jQuery.parseJSON(jqXHR.responseText);
454
						reponse = jQuery.parseJSON(jqXHR.responseText);
Line 397... Line 508...
397
		}
508
		}
398
		return false;
509
		return false;
399
	});
510
	});
400
});
511
});
Line -... Line 512...
-
 
512
 
-
 
513
function ajouterImgMiniature() {
-
 
514
	var miniature = '';
-
 
515
	if ($("#miniature img").length == 1) {
-
 
516
		var src = $("#miniature-img").attr("src");
-
 
517
		var alt = $("#miniature-img").attr("alt");
-
 
518
		miniature = '<img class="miniature" alt="'+alt+'"src="'+src+'" />';
-
 
519
	}
-
 
520
	return miniature;
Line 401... Line 521...
401
 
521
}
402
 
522
 
403
function handleFileSelect(evt) {
523
function handleFileSelect(evt) {
404
	// Check for the various File API support.
524
	// Check for the various File API support.