Subversion Repositories Sites.obs-saisons.fr

Rev

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

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