Subversion Repositories Sites.obs-saisons.fr

Rev

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

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