Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 90 | Rev 168 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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