Subversion Repositories Sites.obs-saisons.fr

Rev

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

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