Subversion Repositories Sites.obs-saisons.fr

Rev

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

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