Subversion Repositories Sites.obs-saisons.fr

Rev

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

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