Subversion Repositories Sites.obs-saisons.fr

Rev

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

Rev 90 Rev 100
1
/** 
1
/** 
2
	************************************************************************************************
2
	************************************************************************************************
3
	************************************************************************************************
3
	************************************************************************************************
4
	
4
	
5
	   Fonction permettant de transformer les élements de la classe pliage en accordéon
5
	   Fonction permettant de transformer les élements de la classe pliage en accordéon
6
	
6
	
7
	************************************************************************************************
7
	************************************************************************************************
8
	************************************************************************************************
8
	************************************************************************************************
9
**/  
9
**/  
10
function initialiserElementsPliables() {
10
function initialiserElementsPliables() {
11
 
11
 
12
	$('.pliage h4').addClass('lien_pliage');
12
	$('.pliage h4').addClass('lien_pliage');
13
 
13
 
14
	$('.pliage ul').hide();
14
	$('.pliage ul').hide();
15
	$('.pliage > ul:first-child').hide();
15
	$('.pliage > ul:first-child').hide();
16
 
16
 
17
	$('.lien_pliage').bind('click', function() {
17
	$('.lien_pliage').bind('click', function() {
18
		
18
		
19
		$(this).nextAll('ul').slideToggle();
19
		$(this).nextAll('ul').slideToggle();
20
		return false;
20
		return false;
21
	});
21
	});
22
}
22
}
23
 
23
 
24
$('.pliage').ready(function() {
24
$('.pliage').ready(function() {
25
	initialiserElementsPliables();
25
	initialiserElementsPliables();
26
});
26
});
27
 
27
 
28
 
28
 
29
 
29
 
30
 
30
 
31
/** 
31
/** 
32
	************************************************************************************************
32
	************************************************************************************************
33
	************************************************************************************************
33
	************************************************************************************************
34
	
34
	
35
	   Fonctions de gestion des onglets du formulaire de saisie d'espèce
35
	   Fonctions de gestion des onglets du formulaire de saisie d'espèce
36
	
36
	
37
	************************************************************************************************
37
	************************************************************************************************
38
	************************************************************************************************
38
	************************************************************************************************
39
**/  
39
**/  
40
function initialiserOnglets() {
40
function initialiserOnglets() {
41
	$(".contenu_onglet").hide(); 
41
	$(".contenu_onglet").hide(); 
42
	$("ul.liste_onglets li:first").addClass("active").show(); 
42
	$("ul.liste_onglets li:first").addClass("active").show(); 
43
	$(".contenu_onglet:first").show();
43
	$(".contenu_onglet:first").show();
44
 
44
 
45
	$("ul.liste_onglets li").click(function() {
45
	$("ul.liste_onglets li").click(function() {
46
 
46
 
47
		$("ul.liste_onglets li").removeClass("active"); 
47
		$("ul.liste_onglets li").removeClass("active"); 
48
		$(this).addClass("active"); 
48
		$(this).addClass("active"); 
49
		$(".contenu_onglet").hide();
49
		$(".contenu_onglet").hide();
50
 
50
 
51
		var activeTab = $(this).find("a").attr("href"); 
51
		var activeTab = $(this).find("a").attr("href"); 
52
		$(activeTab).fadeIn();
52
		$(activeTab).fadeIn();
53
		return false;
53
		return false;
54
	});
54
	});
55
}
55
}
56
 
56
 
57
$('.contenu_onglet').ready(function() {
57
$('.contenu_onglet').ready(function() {
58
	initialiserOnglets();
58
	initialiserOnglets();
59
});
59
});
60
 
60
 
61
function agrandirZoneCLicBoutonsRadios() {
61
function agrandirZoneCLicBoutonsRadios() {
62
	
62
	
63
	$('.formulaire_informations_espece_mini').addClass("element_cliquable");
63
	$('.formulaire_informations_espece_mini').addClass("element_cliquable");
64
	
64
	
65
	$('#form_saisie_espece').children('input[type="submit"]').hide();
65
	$('#form_saisie_espece').children('input[type="submit"]').hide();
66
	$('.formulaire_informations_espece_mini').children('input[type="radio"]').hide();
66
	$('.formulaire_informations_espece_mini').children('input[type="radio"]').hide();
67
	$('.titre_type').hide();
67
	$('.titre_type').hide();
68
	
68
	
69
	$('.formulaire_informations_espece_mini').bind('click',function() {
69
	$('.formulaire_informations_espece_mini').bind('click',function() {
70
		$(this).children('input[type="radio"]').attr('checked','checked');
70
		$(this).children('input[type="radio"]').attr('checked','checked');
71
		$('.formulaire_informations_espece_mini').removeClass('element_clique');
71
		$('.formulaire_informations_espece_mini').removeClass('element_clique');
72
		$(this).addClass('element_clique');
72
		$(this).addClass('element_clique');
73
		
73
		
74
		$('#form_saisie_espece').submit();
74
		$('#form_saisie_espece').submit();
75
	});	
75
	});	
76
}
76
}
77
 
77
 
78
$('#form_saisie_espece').ready(function() {
78
$('#form_saisie_espece').ready(function() {
79
	agrandirZoneCLicBoutonsRadios();
79
	agrandirZoneCLicBoutonsRadios();
80
});
80
});
81
 
81
 
82
 
82
 
83
 
83
 
84
 
84
 
85
/** 
85
/** 
86
	************************************************************************************************
86
	************************************************************************************************
87
	************************************************************************************************
87
	************************************************************************************************
88
	
88
	
89
	   Fonctions permettant de transformer les cases du tableau d'évenements en mini formulaire
89
	   Fonctions permettant de transformer les cases du tableau d'évenements en mini formulaire
90
	
90
	
91
	************************************************************************************************
91
	************************************************************************************************
92
	************************************************************************************************
92
	************************************************************************************************
93
**/
93
**/
94
 
94
 
95
htmlEnCours = '';
95
htmlEnCours = '';
96
elementEnCours = null;
96
elementEnCours = null;
97
 
97
 
98
function initialiserLignesCliquables() {
98
function initialiserLignesCliquables() {
99
	
99
	
100
	$('.conteneur_element_modifier').hide();
100
	$('.conteneur_element_modifier').hide();
101
	
101
	
102
	$(".date_observation_individu").each(function() {
102
	$(".date_observation_individu").each(function() {
103
		
103
		
104
		$(this).bind('click', function() {
104
		$(this).bind('click', function() {
105
			
105
			
106
			if($(this).hasClass('element_clique')) {
106
			if($(this).hasClass('element_clique')) {
107
				return false;
107
				return false;
108
			} else {
108
			} else {
109
				
109
				
110
				conteneur_obs = $(this).children('span');
110
				conteneur_obs = $(this).children('span');
111
				id_formulaire = conteneur_obs.attr('id');
111
				id_formulaire = conteneur_obs.attr('id');
112
				
112
				
113
				remplacerElementDateParFormulaireAjax(id_formulaire, $(this));
113
				remplacerElementDateParFormulaireAjax(id_formulaire, $(this));
114
										
114
										
115
				return false;
115
				return false;
116
			}
116
			}
117
		});
117
		});
118
	});	
118
	});	
119
}
119
}
120
 
120
 
121
function initialiserCalendrierFormulaire() {
121
function initialiserCalendrierFormulaire() {
122
	
122
	
123
	anneeEnCours = $("#annee_en_cours").attr("value");
123
	anneeEnCours = $("#annee_en_cours").attr("value");
124
	
124
	
125
	if(typeof(anneeEnCours)=='undefined'){ 
125
	if(typeof(anneeEnCours)=='undefined'){ 
126
		dateCourante = new Date(); 
126
		dateCourante = new Date(); 
127
		anneeEnCours = dateCourante.getFullYear(); 
127
		anneeEnCours = dateCourante.getFullYear(); 
128
	}
128
	}
129
	
129
	
130
	$(".calendrier").each(function() {
130
	$(".calendrier").each(function() {
131
		$(this).find("input").datepicker({
131
		$(this).find("input").datepicker({
132
			disabled: true,
132
			disabled: true,
133
			altFormat: 'dd/mm/yyyy',
133
			altFormat: 'dd/mm/yyyy',
134
			minDate: '01/01/'+anneeEnCours,
134
			minDate: '01/01/'+anneeEnCours,
135
			maxDate: '31/12/'+anneeEnCours
135
			maxDate: '31/12/'+anneeEnCours
136
		
136
		
137
		});
137
		});
138
	});
138
	});
139
}
139
}
140
 
140
 
141
$(document).ready(function() {
141
$(document).ready(function() {
142
	initialiserCalendrierFormulaire();
142
	initialiserCalendrierFormulaire();
143
 
143
 
144
});
144
});
145
 
145
 
146
function estUneDateValide(peutEtreUneDate) {
146
function estUneDateValide(peutEtreUneDate) {
147
	var reg= new RegExp("^[0-3][0-9][/]{1}[0-1][0-2][/]{1}[0-9]{4}$","g");
147
	var reg= new RegExp("^[0-3][0-9][/]{1}[0-1][0-2][/]{1}[0-9]{4}$","g");
148
	return reg.test(peutEtreUneDate);
148
	return reg.test(peutEtreUneDate);
149
}
149
}
150
 
150
 
151
/** Fonctions de manipulation des éléments du tableau pour les transformer en élements cliquables et calendriers **/
151
/** Fonctions de manipulation des éléments du tableau pour les transformer en élements cliquables et calendriers **/
152
function initialiserMiniCalendrierFormulaire(id_element) {
152
function initialiserMiniCalendrierFormulaire(id_element) {
153
	
153
	
154
	anneeEnCours = jQuery.trim($("#annee_en_cours").html());
154
	anneeEnCours = jQuery.trim($("#annee_en_cours").html());
155
	
155
	
156
	if(typeof(anneeEnCours)=='undefined'){ 
156
	if(typeof(anneeEnCours)=='undefined'){ 
157
		dateCourante = new Date(); 
157
		dateCourante = new Date(); 
158
		anneeEnCours = dateCourante.getFullYear(); 
158
		anneeEnCours = dateCourante.getFullYear(); 
159
	}
159
	}
160
	
160
	
161
	$('#'+id_element)
161
	$('#'+id_element)
162
	.datepicker({
162
	.datepicker({
163
		disabled: true,
163
		disabled: true,
164
		constrainInput: true,
164
		constrainInput: true,
165
		altFormat: 'dd/mm/yyyy',
165
		altFormat: 'dd/mm/yyyy',
166
		minDate: '01/01/'+anneeEnCours,
166
		minDate: '01/01/'+anneeEnCours,
167
		maxDate: '31/12/'+anneeEnCours,
167
		maxDate: '31/12/'+anneeEnCours,
168
		onSelect: function(dateText, inst) {
168
		onSelect: function(dateText, inst) {
169
			$('#'+id_element).val(dateText);
169
			$('#'+id_element).val(dateText);
170
			donnees_obs = collecterDonneesMiniFormulaire(id_formulaire);
170
			donnees_obs = collecterDonneesMiniFormulaire(id_formulaire);
171
			envoyerRequeteAjaxValidationMiniFormulaire(donnees_obs, id_formulaire);
171
			envoyerRequeteAjaxValidationMiniFormulaire(donnees_obs, id_formulaire);
172
		},
-
 
173
		onClose: function(dateText, inst) {
-
 
174
			remplacerMiniFormulaireParElementDate(id_element);
-
 
175
		}
172
		}
176
 
-
 
177
	});
173
	});
178
 
174
 
179
	$('#'+id_element).datepicker( "show" );
175
	$('#'+id_element).datepicker( "show" );
180
	
176
	
181
	/*$('#'+id_element).keypress(function() {
177
	/*$('#'+id_element).keypress(function() {
182
		if(estUneDateValide($('#'+id_element).val())) { 
178
		if(estUneDateValide($('#'+id_element).val())) { 
183
			$('#'+id_element).removeClass('erreur_valeur');
179
			$('#'+id_element).removeClass('erreur_valeur');
184
		} else {
180
		} else {
185
			$('#'+id_element).addClass('erreur_valeur');
181
			$('#'+id_element).addClass('erreur_valeur');
186
		}
182
		}
187
 
183
 
188
	});*/
184
	});*/
189
}
185
}
190
 
186
 
191
function remplacerElementDateParFormulaireAjax(id_element, conteneur_selectionne) {
187
function remplacerElementDateParFormulaireAjax(id_element, conteneur_selectionne) {
192
	
188
	
193
	if(elementEnCours != null) {
189
	if(elementEnCours != null) {
194
		elementEnCours.removeClass('element_clique');
190
		elementEnCours.removeClass('element_clique');
195
		elementEnCours.html(htmlEnCours);
191
		elementEnCours.html(htmlEnCours);
196
	}
192
	}
197
	
193
	
198
	elementEnCours = conteneur_selectionne;
194
	elementEnCours = conteneur_selectionne;
199
	htmlEnCours = conteneur_selectionne.html();
195
	htmlEnCours = conteneur_selectionne.html();
200
	
196
	
201
	conteneur_obs = $('#'+id_element);
197
	conteneur_obs = $('#'+id_element);
202
	valeur_date = conteneur_obs.html();
198
	valeur_date = conteneur_obs.html();
203
	valeur_date = valeur_date.replace('-','');
199
	valeur_date = valeur_date.replace('-','');
204
		
200
		
205
	conteneur_selectionne.addClass('element_clique');
201
	conteneur_selectionne.addClass('element_clique');
206
	conteneur_selectionne.html('<span class="calendrier"><input type="text" value="'+jQuery.trim(valeur_date)+'" class="calendrier" id="'+id_formulaire+'" size="7" maxlenght="10" /></div>');			
202
	conteneur_selectionne.html('<span class="calendrier"><input type="text" value="'+jQuery.trim(valeur_date)+'" class="calendrier" id="'+id_formulaire+'" size="7" maxlenght="10" /></div>');			
207
	initialiserMiniCalendrierFormulaire(id_formulaire);
203
	initialiserMiniCalendrierFormulaire(id_formulaire);
208
	
204
	
209
}
205
}
210
 
206
 
211
function remplacerMiniFormulaireParElementDate(id_element) { 
207
function remplacerMiniFormulaireParElementDate(id_element) { 
212
	
208
	
213
	valeur_date_pour_stade = $('#'+id_element).val();
209
	valeur_date_pour_stade = $('#'+id_element).val();
214
	
210
	
215
	/*if(!estUneDateValide(valeur_date_pour_stade)) {
211
	/*if(!estUneDateValide(valeur_date_pour_stade)) {
216
		valeur_date_pour_stade = htmlEnCours;
212
		valeur_date_pour_stade = htmlEnCours;
217
	}*/
213
	}*/
218
	
214
	
219
	elementEnCours.html('<span id="'+id_element+'">'+valeur_date_pour_stade+' </span>');
215
	elementEnCours.html('<span id="'+id_element+'">'+valeur_date_pour_stade+' </span>');
220
	
-
 
221
	elementEnCours.removeClass('element_clique');
216
	elementEnCours.removeClass('element_clique');
222
	elementEnCours = null;
217
	elementEnCours = null;
223
	elementEnCours = null; 
-
 
-
 
218
 
224
}
219
}
225
 
220
 
226
 
221
 
227
/** Fonctions d'envoi et de récupération des élements du formulaire ajax **/
222
/** Fonctions d'envoi et de récupération des élements du formulaire ajax **/
228
function envoyerRequeteAjaxValidationMiniFormulaire(donnees_obs, id_formulaire) {
223
function envoyerRequeteAjaxValidationMiniFormulaire(donnees_obs, id_formulaire) {
229
	
224
		
-
 
225
	url_page_courante = document.URL;
-
 
226
	url_page_courante = url_page_courante.replace('module=Individu','module=Observation');
230
	url_page_courante = document.URL.replace('module=Individu&action=afficherListeIndividu','module=Observation&action=validerFormulaireModificationObservationAjax');
227
	url_page_courante = url_page_courante.replace('action=afficherListeIndividu','action=validerFormulaireModificationObservationAjax');
-
 
228
	url_ajax = url_page_courante.replace('action=validerFormulaireSaisieIndividu','action=validerFormulaireModificationObservationAjax');
231
	
229
		
232
	$.post(url_page_courante, donnees_obs, function(obj_retour) {
230
	$.post(url_ajax, donnees_obs, function(obj_retour) {
233
		
231
		
234
		if(obj_retour.reponse === 'OK') {
-
 
235
			
232
		if(obj_retour.reponse === 'OK') {
236
			remplacerMiniFormulaireParElementDate(id_formulaire);
233
			remplacerMiniFormulaireParElementDate(id_formulaire);
237
		}
234
		}
238
	});
235
	});
239
}
236
}
240
 
237
 
241
function collecterDonneesMiniFormulaire(id_formulaire) {
238
function collecterDonneesMiniFormulaire(id_formulaire) {
242
	
239
	
243
	valeur_date_pour_stade = $('#'+id_formulaire).val();
240
	valeur_date_pour_stade = $('#'+id_formulaire).val();
244
	
241
	
245
	if(valeur_date_pour_stade == null || jQuery.trim(valeur_date_pour_stade) == '') {
242
	if(valeur_date_pour_stade == null || jQuery.trim(valeur_date_pour_stade) == '') {
246
		return false ;
243
		return false ;
247
	}
244
	}
248
	
245
	
249
	id_individu_stade_obs = id_formulaire.split('_');
246
	id_individu_stade_obs = id_formulaire.split('_');
250
	
247
	
251
	stade_obs = 'observation_'+id_individu_stade_obs[3];
248
	stade_obs = 'observation_'+id_individu_stade_obs[3];
252
	date_annee_en_cours = jQuery.trim($("#annee_en_cours").html());
249
	date_annee_en_cours = jQuery.trim($("#annee_en_cours").html());
253
	
250
	
254
	donnees_obs = { "id_individu": id_individu_stade_obs[1], 
251
	donnees_obs = { "id_individu": id_individu_stade_obs[1], 
255
					"annee_en_cours": date_annee_en_cours
252
					"annee_en_cours": date_annee_en_cours
256
					};
253
					};
257
	
254
	
258
	identifiant_observation = 'observation_'+id_individu_stade_obs[3];
255
	identifiant_observation = 'observation_'+id_individu_stade_obs[3];
259
	
256
	
260
	donnees_obs[identifiant_observation] = valeur_date_pour_stade;
257
	donnees_obs[identifiant_observation] = valeur_date_pour_stade;
261
	
258
	
262
	return donnees_obs;
259
	return donnees_obs;
263
}
260
}
264
 
261
 
265
 
262
 
266
$('#saisie_liste_evenements').ready(function() {
263
$('#saisie_liste_evenements').ready(function() {
267
	initialiserLignesCliquables();
264
	initialiserLignesCliquables();
268
});
265
});
269
 
266
 
270
 
267
 
271
 
268
 
272
 
269
 
273
/** 
270
/** 
274
	************************************************************************************************
271
	************************************************************************************************
275
	************************************************************************************************
272
	************************************************************************************************
276
	
273
	
277
	    Fonctions concernant la carte permettant de pointer d'afficher l'emplacement des stations
274
	    Fonctions concernant la carte permettant de pointer d'afficher l'emplacement des stations
278
	
275
	
279
	************************************************************************************************
276
	************************************************************************************************
280
	************************************************************************************************
277
	************************************************************************************************
281
**/  
278
**/  
282
var map;
279
var map;
283
var marker;
280
var marker;
-
 
281
var liste_localite_en_cours;
-
 
282
var indice_commune_en_cours;
-
 
283
var liste_auto_completion_a_le_focus;
-
 
284
var timerRequeteAutocompletion;
-
 
285
var timerAffichageAutocompletion;
284
 
-
 
285
function ajouterListenerFormulaireSaisieLatLon() {
286
 
286
	
287
 
287
	$('#cacher_afficher_lien').bind('click', function() {
288
function cacherElementsRafraichissables() {
288
		$('#conteneur_form_liens_lat_lon').slideToggle();
289
	$('.rafraichissable input').attr('disabled', 'disabled');
289
		return false;
290
	$('.rafraichissable input[type="text"]').addClass("chargement");
290
	});
291
}
-
 
292
 
291
	
293
function montrerElementsRafraichissables() {
292
	$('input#station_lat').bind('blur', function() {
294
	$('.rafraichissable input').removeAttr('disabled');
293
		verifierEtLocaliserCoordonnees();
295
	$('.chargement').removeClass("chargement");
294
	});
296
}
295
	
-
 
296
	$('input#station_lon').bind('blur', function() {
297
 
297
		verifierEtLocaliserCoordonnees();
-
 
-
 
298
function ajouterAutoCompletionCommune() {
-
 
299
	
-
 
300
	$('input#station_commune').after('<div class="conteneur_suggestions"></div>');
-
 
301
	$('input#station_commune').parent().addClass('autocompletion');
-
 
302
	$('input#station_commune').attr('autocomplete','off');
-
 
303
	$('.conteneur_suggestions').hide();
-
 
304
	rendreListeAutoCompletionInteractive('input#station_commune');
-
 
305
}
-
 
306
 
298
	});
307
function ajouterListenerFormulaireSaisieLatLon() {
299
	
308
				
300
	$('input#localiser_lat_lon').click(function() {
309
	$('input#localiser_lat_lon').click(function() {
301
		verifierEtLocaliserCoordonnees();
310
		verifierEtLocaliserCoordonnees();
302
	});
311
	});
303
	
-
 
304
	$('#conteneur_form_liens_lat_lon').hide();
-
 
305
}
312
}
306
 
313
 
307
function carteEstEnSaisie() {
314
function carteEstEnSaisie() {
308
	return ($('#conteneur_form_liens_lat_lon').length > 0);
315
	return ($('#conteneur_form_liens_lat_lon').length > 0);
309
}
316
}
310
 
317
 
311
function verifierEtLocaliserCoordonnees() {
318
function verifierEtLocaliserCoordonnees() {
312
	
319
	
313
	lat ;
320
	lat ;
314
	lon;
321
	lon;
315
	
322
	
316
	if(carteEstEnSaisie()) {
323
	if(carteEstEnSaisie()) {
317
		lat = $('#station_lat').val();
324
		lat = $('#station_lat').val();
318
		lon = $('#station_lon').val();
325
		lon = $('#station_lon').val();
-
 
326
		
-
 
327
		obtenirInformationsPourCoordonnees(lat, lon);
319
	} else {
328
	} else {
320
		var lat = jQuery.trim($('#station_lat').html());
329
		var lat = jQuery.trim($('#station_lat').html());
321
		var lon = jQuery.trim($('#station_lon').html());
330
		var lon = jQuery.trim($('#station_lon').html());
322
	}
331
	}
323
	
332
	
324
	if(jQuery.trim(lat) == '' || jQuery.trim(lon) == '') {
333
	if(jQuery.trim(lat) == '' || jQuery.trim(lon) == '') {
325
		return;
334
		return;
326
	}
335
	}
327
	
336
	
328
	if(!isNaN(lat) && lat.length > 0 && !isNaN(lon) && lon.length > 0) {
337
	if(!isNaN(lat) && lat.length > 0 && !isNaN(lon) && lon.length > 0) {
329
		
338
		
330
	} else {
339
	} else {
331
		window.alert("coordonnées invalides");
340
		window.alert("coordonnées invalides");
332
	}
341
	}
333
	
342
	
334
	var positionMarker = new google.maps.LatLng(lat, lon);
343
	var positionMarker = new google.maps.LatLng(lat, lon);
335
	
344
	
336
	marker.setPosition(positionMarker);
345
	marker.setPosition(positionMarker);
337
	map.setCenter(positionMarker);
346
	map.setCenter(positionMarker);
-
 
347
	map.setZoom(12);
-
 
348
}
-
 
349
 
-
 
350
function obtenirInformationsPourCoordonnees(lat, lon) {
-
 
351
		
-
 
352
	lat = jQuery.trim(lat);
-
 
353
	lon = jQuery.trim(lon);	
-
 
354
	
-
 
355
	if(isNaN(lat) || lat.length <= 0 || isNaN(lon) || lon.length <= 0) {
-
 
356
		return;
-
 
357
	}
-
 
358
	
-
 
359
	cacherElementsRafraichissables();
-
 
360
	
-
 
361
	$.get('http://162.38.234.9/obs_saisons/applications/jrest/OdsCommune/informationsPourCoordonnees/?lat='+lat+'&lon='+lon, function(data) {	
-
 
362
		
-
 
363
		infos_localites = jQuery.parseJSON(data);
-
 
364
		$('#station_alt').val(infos_localites.alt);
-
 
365
		
-
 
366
		if(jQuery.trim($('#station_commune').val()) == '') { 
-
 
367
			$('#station_commune').val(infos_localites.commune);
-
 
368
		}
-
 
369
		
-
 
370
		montrerElementsRafraichissables();
-
 
371
		
-
 
372
	});
-
 
373
 
-
 
374
}
-
 
375
 
-
 
376
function obtenirInformationsPourCommune(nom_commune) {
-
 
377
	
-
 
378
	if(jQuery.trim(nom_commune) == '') {
-
 
379
		$('.conteneur_suggestions').hide();
-
 
380
		return;
-
 
381
	}
-
 
382
	
-
 
383
	$.get('http://162.38.234.9/obs_saisons/applications/jrest/OdsCommune/informationsPourCommune/?commune='+nom_commune, function(data) {	
-
 
384
		
-
 
385
		infos_localites = jQuery.parseJSON(data);
-
 
386
		afficherListeAutoCompletion(infos_localites);		
-
 
387
	});
-
 
388
}
-
 
389
 
-
 
390
function afficherListeAutoCompletion(tableau_localites) {
-
 
391
	
-
 
392
	liste_localite_en_cours = tableau_localites;
-
 
393
	
-
 
394
	html_liste_localite = '<ul class="liste_suggestions">';
-
 
395
	
-
 
396
	for(i = 0; i< tableau_localites.length; i++) {
-
 
397
		html_liste_localite += '<li id="commune_'+i+'" class="element_auto_completion_commune">'+tableau_localites[i]['commune']+'  ('+tableau_localites[i]['dpt']+')</li>';
-
 
398
	}
-
 
399
	
-
 
400
	html_liste_localite += '</ul>';
-
 
401
	
-
 
402
	$('.conteneur_suggestions').html(html_liste_localite);
-
 
403
	
-
 
404
	$('.element_auto_completion_commune').hover(function() {
-
 
405
		indice = $(this).attr('id').split('_')[1];
-
 
406
		mettreEnSurbrillanceCommune(indice);
-
 
407
	});
-
 
408
	
-
 
409
	$('.element_auto_completion_commune').click(function() {
-
 
410
		indice = $(this).attr('id').split('_')[1];
-
 
411
		selectionnerCommune(indice);
-
 
412
	});
-
 
413
	
-
 
414
	if(tableau_localites.length > 0) {
-
 
415
		$('.conteneur_suggestions').show();
-
 
416
		
-
 
417
		mettreEnSurbrillanceCommune(0);
-
 
418
	}
-
 
419
}
-
 
420
 
-
 
421
function mettreEnSurbrillanceCommune(indice) {
-
 
422
	
-
 
423
	if(indice_commune_en_cours != null) { 
-
 
424
		$('#commune_'+indice_commune_en_cours).removeClass('element_selectionne');
-
 
425
	}
-
 
426
	$('#commune_'+indice).addClass('element_selectionne');
-
 
427
	indice_commune_en_cours = indice;
-
 
428
	
-
 
429
	reprogrammerTimerPourCacherListeAutoCompletion();
-
 
430
}
-
 
431
 
-
 
432
function rendreListeAutoCompletionInteractive(selecteur) {
-
 
433
	
-
 
434
	$(selecteur).keyup(function(event) {
-
 
435
		if(event.which == 8 || (event.which >= 48 && event.which <= 90)) { 
-
 
436
			
-
 
437
			reprogrammerTimerPourCacherListeAutoCompletion();
-
 
438
			reprogrammerTimerPourLancerRequeteCommune();
-
 
439
		}
-
 
440
	});
-
 
441
	
-
 
442
	$(selecteur).keydown(function(event) {
-
 
443
		
-
 
444
		reprogrammerTimerPourCacherListeAutoCompletion();
-
 
445
		
-
 
446
		// entree
-
 
447
		if(event.which==13){
-
 
448
			selectionnerCommune(indice_commune_en_cours);
-
 
449
			event.preventDefault();
-
 
450
		}
-
 
451
		
-
 
452
		// haut
-
 
453
		if(event.which == 38){
-
 
454
			if(indice_commune_en_cours > 0) { 
-
 
455
				mettreEnSurbrillanceCommune(indice_commune_en_cours - 1);
-
 
456
			}
-
 
457
		}
-
 
458
		
-
 
459
		// bas
-
 
460
		if(event.which == 40){
-
 
461
			if(indice_commune_en_cours < liste_localite_en_cours.length - 1) { 
-
 
462
				mettreEnSurbrillanceCommune(indice_commune_en_cours + 1);
-
 
463
			}
-
 
464
		}
-
 
465
	});
-
 
466
	
-
 
467
	$('.conteneur_suggestions').blur(function() {
-
 
468
		$('.conteneur_suggestions').hide();
-
 
469
	});
-
 
470
}
-
 
471
 
-
 
472
function reprogrammerTimerPourCacherListeAutoCompletion() {
-
 
473
	
-
 
474
	if(timerAffichageAutocompletion != null) {
-
 
475
		window.clearTimeout(timerAffichageAutocompletion);
-
 
476
	}
-
 
477
	
-
 
478
	timerAffichageAutocompletion = window.setTimeout(function() {
-
 
479
		$('.conteneur_suggestions').hide();
-
 
480
	}, 2000);
-
 
481
}
-
 
482
 
-
 
483
function reprogrammerTimerPourLancerRequeteCommune() {
-
 
484
	
-
 
485
	if(timerRequeteAutocompletion != null) {
-
 
486
		window.clearTimeout(timerRequeteAutocompletion);
-
 
487
	}
-
 
488
	
-
 
489
	timerRequeteAutocompletion = window.setTimeout(function() {
-
 
490
		obtenirInformationsPourCommune($('input#station_commune').val());
-
 
491
	}, 350);
-
 
492
}
-
 
493
 
-
 
494
function selectionnerCommune(indice) {
-
 
495
	
-
 
496
	infos_commune = liste_localite_en_cours[indice];
-
 
497
	
-
 
498
	$('input#station_commune').val(infos_commune['commune']);
-
 
499
	$('input#station_lat').val(infos_commune['lat']);
-
 
500
	$('input#station_lon').val(infos_commune['lon']);
-
 
501
	
-
 
502
	verifierEtLocaliserCoordonnees();
-
 
503
	
-
 
504
	$('.conteneur_suggestions').hide();
338
}
505
}
339
 
506
 
340
function mettreAJourValeursFormulaire(latlon) {
507
function mettreAJourValeursFormulaire(latlon) {
341
 
508
 
342
	latlon = latlon.toString().split(','); 
509
	latlon = latlon.toString().split(','); 
-
 
510
	
-
 
511
	lat = latlon[0].replace('(', '');
-
 
512
	lon = latlon[1].replace(')', '');
343
	
513
	
344
	$('#station_lat').val(latlon[0].replace('(', ''));
514
	$('#station_lat').val(latlon[0].replace('(', ''));
-
 
515
	$('#station_lon').val(latlon[1].replace(')', ''));
-
 
516
	
345
	$('#station_lon').val(latlon[1].replace(')', ''));
517
	obtenirInformationsPourCoordonnees(lat, lon);
346
}
518
}
347
 
519
 
348
function initialiserCarte() {
520
function initialiserCarte() {
349
 
521
 
350
	if($('#map_canvas').length == 0) {
522
	if($('#map_canvas').length == 0) {
351
		return;
523
		return;
352
	}
524
	}
353
 
525
 
354
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
526
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
355
	var myOptions = {
527
	var myOptions = {
356
		zoom: 6,
528
		zoom: 6,
357
		center: latlng,
529
		center: latlng,
358
		mapTypeId: google.maps.MapTypeId.HYBRID
530
		mapTypeId: google.maps.MapTypeId.HYBRID
359
	};
531
	};
360
 
532
 
361
	map = new google.maps.Map(document.getElementById("map_canvas"),
533
	map = new google.maps.Map(document.getElementById("map_canvas"),
362
    	myOptions);
534
    	myOptions);
363
	
535
	
364
	marker = new google.maps.Marker({
536
	marker = new google.maps.Marker({
365
	      position: latlng,
537
	      position: latlng,
366
	      title:""
538
	      title:""
367
	});
539
	});
368
	
540
	
369
	if (carteEstEnSaisie()) {
541
	if (carteEstEnSaisie()) {
370
	
542
	
371
			marker.setDraggable(true);
543
			marker.setDraggable(true);
372
			
544
			
373
			google.maps.event.addListener(marker, 'dragend', function() {	
545
			google.maps.event.addListener(marker, 'dragend', function(event) {	
374
				mettreAJourValeursFormulaire(marker.getPosition());
546
				mettreAJourValeursFormulaire(marker.getPosition());
375
			});
547
			});
376
			$('#conteneur_form_liens_lat_lon').ready(function() {
548
			$('#conteneur_form_liens_lat_lon').ready(function() {
377
				verifierEtLocaliserCoordonnees();
549
				verifierEtLocaliserCoordonnees();
378
				ajouterListenerFormulaireSaisieLatLon();
550
				ajouterListenerFormulaireSaisieLatLon();
-
 
551
				ajouterAutoCompletionCommune();
379
			});
552
			});
380
	} else {
553
	} else {
381
		marker.setDraggable(false);
554
		marker.setDraggable(false);
382
		$('#conteneur_liens_lat_lon').ready(function() {
555
		$('#conteneur_liens_lat_lon').ready(function() {
383
			verifierEtLocaliserCoordonnees();
556
			verifierEtLocaliserCoordonnees();
384
		});
557
		});
385
	}
558
	}
386
	
559
	
387
	marker.setClickable(true);
560
	marker.setClickable(true);
388
		
561
		
389
	// To add the marker to the map, call setMap();
562
	// To add the marker to the map, call setMap();
390
	marker.setMap(map); 
563
	marker.setMap(map); 
391
}
564
}
392
 
565
 
393
$('#map_canvas').ready(function() {
566
$('#map_canvas').ready(function() {
394
	initialiserCarte();
567
	initialiserCarte();
395
});
-
 
396
568
});
-
 
569
 
-
 
570
 
-
 
571
/** 
-
 
572
************************************************************************************************
-
 
573
************************************************************************************************
-
 
574
 
-
 
575
    Fonctions de debug permattant d'afficher les objets javascript à la manière de print_r
-
 
576
 
-
 
577
************************************************************************************************
-
 
578
************************************************************************************************
-
 
579
**/ 
-
 
580
 
-
 
581
function dump(arr,level) {
-
 
582
	var dumped_text = "";
-
 
583
	if(!level) level = 0;
-
 
584
 
-
 
585
	//The padding given at the beginning of the line.
-
 
586
	var level_padding = "";
-
 
587
	for(var j=0;j<level+1;j++) level_padding += "    ";
-
 
588
 
-
 
589
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
-
 
590
	 for(var item in arr) {
-
 
591
	  var value = arr[item];
-
 
592
	 
-
 
593
	  if(typeof(value) == 'object') { //If it is an array,
-
 
594
	   dumped_text += level_padding + "'" + item + "' ...\n";
-
 
595
	   dumped_text += dump(value,level+1);
-
 
596
	  } else {
-
 
597
	   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
-
 
598
	  }
-
 
599
	 }
-
 
600
	} else { //Stings/Chars/Numbers etc.
-
 
601
	 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
-
 
602
	}
-
 
603
	return dumped_text;
-
 
604
} 
-
 
605