Subversion Repositories Sites.obs-saisons.fr

Rev

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

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