Subversion Repositories Sites.obs-saisons.fr

Rev

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

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