Subversion Repositories Sites.obs-saisons.fr

Rev

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

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