Subversion Repositories Sites.obs-saisons.fr

Rev

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

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