Subversion Repositories Sites.obs-saisons.fr

Rev

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

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