Subversion Repositories Sites.obs-saisons.fr

Rev

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

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