Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 320 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 320 Rev 324
1
function getUrlBaseJrest() {
1
function getUrlBaseJrest() {
2
	return urlBaseJrest;
2
	return urlBaseJrest;
3
}
3
}
4
 
4
 
5
/**
5
/**
6
	************************************************************************************************
6
	************************************************************************************************
7
	************************************************************************************************
7
	************************************************************************************************
8
 
8
 
9
	   Fonction permettant de transformer les élements de la classe pliage en accordéon
9
	   Fonction permettant de transformer les élements de la classe pliage en accordéon
10
 
10
 
11
	************************************************************************************************
11
	************************************************************************************************
12
	************************************************************************************************
12
	************************************************************************************************
13
**/
13
**/
14
function initialiserElementsPliables() {
14
function initialiserElementsPliables() {
15
 
15
 
16
	$('.pliage h4').addClass('lien_pliage');
16
	$('.pliage h4').addClass('lien_pliage');
17
 
17
 
18
	$('.pliage ul').hide();
18
	$('.pliage ul').hide();
19
	$('.pliage > ul:first-child').hide();
19
	$('.pliage > ul:first-child').hide();
20
 
20
 
21
	$('.1er_element_date ul').show();
21
	$('.1er_element_date ul').show();
22
	$('.1er_element_date > ul:first-child').show();
22
	$('.1er_element_date > ul:first-child').show();
23
 
23
 
24
	$('.lien_pliage').bind('click', function() {
24
	$('.lien_pliage').bind('click', function() {
25
 
25
 
26
		$(this).nextAll('ul').slideToggle();
26
		$(this).nextAll('ul').slideToggle();
27
		return false;
27
		return false;
28
	});
28
	});
29
}
29
}
30
 
30
 
31
$('.pliage').ready(function() {
31
$('.pliage').ready(function() {
32
	initialiserElementsPliables();
32
	initialiserElementsPliables();
33
});
33
});
34
 
34
 
35
 
35
 
36
/**
36
/**
37
	************************************************************************************************
37
	************************************************************************************************
38
	************************************************************************************************
38
	************************************************************************************************
39
 
39
 
40
	   Fonctions de gestion des onglets du formulaire de saisie d'espèce
40
	   Fonctions de gestion des onglets du formulaire de saisie d'espèce
41
 
41
 
42
	************************************************************************************************
42
	************************************************************************************************
43
	************************************************************************************************
43
	************************************************************************************************
44
**/
44
**/
45
function initialiserOnglets() {
45
function initialiserOnglets() {
46
	$(".contenu_onglet").hide();
46
	$(".contenu_onglet").hide();
47
	$("ul.liste_onglets li:first").addClass("active").show();
47
	$("ul.liste_onglets li:first").addClass("active").show();
48
	$(".contenu_onglet:first").show();
48
	$(".contenu_onglet:first").show();
49
 
49
 
50
	$("ul.liste_onglets li").click(function() {
50
	$("ul.liste_onglets li").click(function() {
51
 
51
 
52
		$("ul.liste_onglets li").removeClass("active");
52
		$("ul.liste_onglets li").removeClass("active");
53
		$(this).addClass("active");
53
		$(this).addClass("active");
54
		$(".contenu_onglet").hide();
54
		$(".contenu_onglet").hide();
55
 
55
 
56
		var activeTab = $(this).find("a").attr("href");
56
		var activeTab = $(this).find("a").attr("href");
57
		$(activeTab).fadeIn();
57
		$(activeTab).fadeIn();
58
		return false;
58
		return false;
59
	});
59
	});
60
}
60
}
61
 
61
 
62
$('.contenu_onglet').ready(function() {
62
$('.contenu_onglet').ready(function() {
63
	initialiserOnglets();
63
	initialiserOnglets();
64
});
64
});
65
 
65
 
66
function agrandirZoneCLicBoutonsRadios() {
66
function agrandirZoneClicBoutonsRadios() {
67
 
67
 
68
	$('.formulaire_informations_espece_mini').addClass("element_cliquable");
68
	$('.formulaire_informations_espece_mini').addClass("element_cliquable");
69
 
69
 
70
	$('#form_saisie_espece').children('input[type="submit"]').hide();
70
	$('#form_saisie_espece').children('input[type="submit"]').hide();
71
	$('.formulaire_informations_espece_mini').children('input[type="radio"]').hide();
71
	$('.formulaire_informations_espece_mini').children('input[type="radio"]').hide();
72
	$('.titre_type').hide();
72
	$('.titre_type').hide();
73
 
73
 
74
	$('.formulaire_informations_espece_mini').bind('click',function() {
74
	$('.formulaire_informations_espece_mini').bind('click',function() {
75
		$(this).children('input[type="radio"]').attr('checked','checked');
75
		$(this).children('input[type="radio"]').attr('checked','checked');
76
		$('.formulaire_informations_espece_mini').removeClass('element_clique');
76
		$('.formulaire_informations_espece_mini').removeClass('element_clique');
77
		$(this).addClass('element_clique');
77
		$(this).addClass('element_clique');
78
 
78
 
79
		$('#form_saisie_espece').submit();
79
		$('#form_saisie_espece').submit();
80
	});
80
	});
81
}
81
}
82
 
82
 
83
$('#form_saisie_espece').ready(function() {
83
$('#form_saisie_espece').ready(function() {
84
	agrandirZoneCLicBoutonsRadios();
84
	agrandirZoneClicBoutonsRadios();
85
});
85
});
86
 
86
 
87
 
87
 
88
 
88
 
89
 
89
 
90
/**
90
/**
91
	************************************************************************************************
91
	************************************************************************************************
92
	************************************************************************************************
92
	************************************************************************************************
93
 
93
 
94
	   Fonctions permettant de transformer les cases du tableau d'évenements en mini formulaire
94
	   Fonctions permettant de transformer les cases du tableau d'évenements en mini formulaire
95
 
95
 
96
	************************************************************************************************
96
	************************************************************************************************
97
	************************************************************************************************
97
	************************************************************************************************
98
**/
98
**/
99
 
-
 
100
htmlEnCours = '';
-
 
101
elementEnCours = null;
-
 
102
ancienneValeurEnCours = null;
-
 
103
id_formulaire = null;
-
 
104
 
99
 
105
function initialiserLignesCliquables() {
100
function initialiserLignesCliquables() {
106
 
101
 
107
	$('.conteneur_element_modifier').hide();
102
	$('.conteneur_element_modifier').hide();
108
 
103
 
109
	$(".date_observation_individu").live("click", function(e) {
104
	$(".date_observation_individu").live("click", function(e) {
110
		e.preventDefault();
105
		e.preventDefault();
-
 
106
 
111
 
107
		var est_absence_observation = $(e.target).parents('[data-absence-observation="1"]').length > 0;
-
 
108
		if($(e.target).hasClass('conteneur_supprimer_observation') ||
-
 
109
				$(e.target).hasClass('supprimer_observation') ||
112
		if($(e.target).hasClass('conteneur_supprimer_observation') || $(e.target).hasClass('supprimer_observation')) {
110
				est_absence_observation) {
113
			return;
111
			return;
114
		}
112
		}
115
 
113
 
116
		$('.element_clique').removeClass('element_clique');
114
		$('.element_clique').removeClass('element_clique');
117
		if($(this).hasClass('element_clique')) {
115
		if($(this).hasClass('element_clique')) {
118
			fermerDatePicker();
116
			fermerDatePicker();
119
			return false;
117
			return false;
120
		} else {
118
		} else {
121
			$(this).addClass('element_clique');
119
			$(this).addClass('element_clique');
122
			afficherSaisieObservation($(this));
120
			afficherSaisieObservation($(this));
123
			return false;
121
			return false;
124
		}
122
		}
125
	});
123
	});
126
 
124
 
127
	$(".date_observation_individu .conteneur_supprimer_observation").live("click", function(e) {
125
	$(".date_observation_individu .conteneur_supprimer_observation").live("click", function(e) {
128
		e.preventDefault();
126
		e.preventDefault();
129
		if(window.confirm('Êtes-vous sûr de vouloir supprimer cette observation ?')) {
127
		if(window.confirm('Êtes-vous sûr.e de vouloir supprimer cette observation ?')) {
130
			// les obs ne sont jamais vraiment supprimées
128
			// les obs ne sont jamais vraiment supprimées
131
			// mais seulement remplacées par des dates au format 00/00/yyyy
129
			// mais seulement remplacées par des dates au format 00/00/yyyy
132
			envoyerRequeteAjaxSaisieObservation('', $(this).parent('.date_observation_individu'));
130
			envoyerRequeteAjaxSaisieObservation('', $(this).parent('.date_observation_individu'));
133
		}
131
		}
-
 
132
 
-
 
133
		return false;
-
 
134
	});
-
 
135
 
-
 
136
	$(".date_observation_individu .absence_observation").live("click", function(e) {
-
 
137
		e.preventDefault();
-
 
138
		var avertissement_absence_evenement = 'Attention ! Vous êtes sur le point de signaler que ce stade n\'a pas eu lieu dans l\'année. '+"\n"+
-
 
139
																					'C\'est-à-dire que vous êtes certain.e de ne pas l\'avoir raté. '+"\n"+
-
 
140
																					'Êtes-vous sûr.e ?';
-
 
141
		if(window.confirm(avertissement_absence_evenement)) {
-
 
142
			$(this).parent('.date_observation_individu').data('absence-observation', '1');
-
 
143
			var date_absence_evenement = '';
-
 
144
			var dateEnCours = new Date();
-
 
145
			if(getAnneeEnCoursDeConsultation() == dateEnCours.getFullYear()) {
-
 
146
				date_absence_evenement = dateEnCours.getDate()+'/'+dateEnCours.getMonth()+'/'+dateEnCours.getFullYear();
-
 
147
			} else {
-
 
148
				date_absence_evenement = '01/01/'+dateEnCours.getFullYear();
-
 
149
			}
-
 
150
			envoyerRequeteAjaxSaisieObservation(date_absence_evenement, $(this).parent('.date_observation_individu'));
-
 
151
		}
-
 
152
 
-
 
153
		return false;
134
	});
154
	});
135
 
155
 
136
	// pour fermer le datepicker sur esc
156
	// pour fermer le datepicker sur esc
137
	$(document).keyup(function(e) {
157
	$(document).keyup(function(e) {
138
	  if (e.keyCode === 27) {
158
	  if (e.keyCode === 27) {
139
			$('.element_clique').removeClass('element_clique');
159
			$('.element_clique').removeClass('element_clique');
140
			fermerDatePicker();   // esc
160
			fermerDatePicker();   // esc
141
		}
161
		}
142
	});
162
	});
143
}
163
}
144
 
164
 
145
function afficherSaisieObservation($obs) {
165
function afficherSaisieObservation($obs) {
146
 
166
 
147
	fermerDatePicker();
167
	fermerDatePicker();
148
 
168
 
149
	var dateMin = getDateMinCalendrier();
169
	var dateMin = getDateMinCalendrier();
150
	var dateMax = getDateMaxCalendrier();
170
	var dateMax = getDateMaxCalendrier();
151
 
171
 
152
	var dateCouranteStr = $obs.data('date-observation');
172
	var dateCouranteStr = $obs.data('date-observation');
153
	var dateCourante = new Date();
173
	var dateCourante = new Date();
154
	if(!!dateCouranteStr && dateCouranteStr != '' && dateCouranteStr != '+') {
174
	if(!!dateCouranteStr && dateCouranteStr != '' && dateCouranteStr != '+') {
155
		var jour   = parseInt(dateCouranteStr.substring(0,2));
175
		var jour   = parseInt(dateCouranteStr.substring(0,2));
156
		var mois  = parseInt(dateCouranteStr.substring(3,5));
176
		var mois  = parseInt(dateCouranteStr.substring(3,5));
157
		var annee   = parseInt(dateCouranteStr.substring(6,10));
177
		var annee   = parseInt(dateCouranteStr.substring(6,10));
158
		dateCourante = new Date(annee, mois-1, jour);
178
		dateCourante = new Date(annee, mois-1, jour);
159
	}
179
	}
160
 
180
 
161
	$obs.find('.datepicker_container').datepicker({
181
	$obs.find('.datepicker_container').datepicker({
162
		disabled: true,
182
		disabled: true,
163
		constrainInput: true,
183
		constrainInput: true,
164
		altFormat: 'dd/mm/yyyy',
184
		altFormat: 'dd/mm/yyyy',
165
		minDate: dateMin,
185
		minDate: dateMin,
166
		maxDate: dateMax,
186
		maxDate: dateMax,
167
		changeMonth: true,
187
		changeMonth: true,
168
		defaultDate: dateCourante,
188
		defaultDate: dateCourante,
169
		onSelect: function(dateText, inst) {
189
		onSelect: function(dateText, inst) {
170
			validerSaisieObservation(dateText, $obs)
190
			validerSaisieObservation(dateText, $obs)
171
		},
191
		},
172
		beforeShowDay: function(date) {
192
		beforeShowDay: function(date) {
173
			var dates_a_exclure = getDatesSaisiesPourStadeEtIndividu($obs.data('id-individu'), $obs.data('id-stade-observation'));
193
			var dates_a_exclure = getDatesSaisiesPourStadeEtIndividu($obs.data('id-individu'), $obs.data('id-stade-observation'));
174
      var string = jQuery.datepicker.formatDate('dd/mm/yy', date);
194
      var string = jQuery.datepicker.formatDate('dd/mm/yy', date);
175
      return [dates_a_exclure.indexOf(string) == -1]
195
      return [dates_a_exclure.indexOf(string) == -1]
176
    }
196
    }
177
	});
197
	});
178
 
198
 
179
	$obs.datepicker("show");
199
	$obs.datepicker("show");
180
	$('.ui-datepicker').attr("title", "Appuyez sur échap pour annuler l'édition");
200
	$('.ui-datepicker').attr("title", "Appuyez sur échap pour annuler l'édition");
181
}
201
}
182
 
202
 
183
function validerSaisieObservation(dateStr, $obs) {
203
function validerSaisieObservation(dateStr, $obs) {
184
 
204
 
185
	if(estUneDateValide(dateStr)) {
205
	if(estUneDateValide(dateStr)) {
186
		envoyerRequeteAjaxSaisieObservation(dateStr, $obs);
206
		envoyerRequeteAjaxSaisieObservation(dateStr, $obs);
187
	}
207
	}
188
}
208
}
189
 
209
 
190
function formaterDonneesObservationPourEnvoi(dateStr, $obs) {
210
function formaterDonneesObservationPourEnvoi(dateStr, $obs) {
191
 
211
 
192
	if(dateStr == null ) {
212
	if(dateStr == null ) {
193
		return false ;
213
		return false ;
194
	}
214
	}
195
 
215
 
196
	var anneeEnCours = getAnneeEnCoursDeConsultation();
216
	var anneeEnCours = getAnneeEnCoursDeConsultation();
197
	if(jQuery.trim(dateStr) == '') {
217
	if(jQuery.trim(dateStr) == '') {
198
		dateStr = '00/00/'+anneeEnCours;
218
		dateStr = '00/00/'+anneeEnCours;
199
	}
219
	}
200
 
220
 
201
	donnees_obs = {
221
	donnees_obs = {
202
		"id_individu": $obs.data('id-individu'),
222
		"id_individu": $obs.data('id-individu'),
203
		"id_evenement": $obs.data('id-stade-observation'),
223
		"id_evenement": $obs.data('id-stade-observation'),
204
		"date_evenement": dateStr,
224
		"date_evenement": dateStr,
205
		"annee_en_cours": anneeEnCours
225
		"annee_en_cours": anneeEnCours
206
	};
226
	};
-
 
227
 
-
 
228
	if(!!$obs.data('absence-observation')) {
-
 
229
		donnees_obs.absence_observation = $obs.data('absence-observation');
-
 
230
	}
207
 
231
 
208
	if(!!$obs.data('id-observation')) {
232
	if(!!$obs.data('id-observation')) {
209
		donnees_obs.id_observation = $obs.data('id-observation');
233
		donnees_obs.id_observation = $obs.data('id-observation');
210
	}
234
	}
211
 
235
 
212
	return donnees_obs;
236
	return donnees_obs;
213
}
237
}
214
 
238
 
215
 
239
 
216
/** 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 **/
217
function envoyerRequeteAjaxSaisieObservation(dateStr, $obs) {
241
function envoyerRequeteAjaxSaisieObservation(dateStr, $obs) {
218
 
242
 
219
	var est_obs_existante = !!$obs.data('id-observation');
243
	var est_obs_existante = !!$obs.data('id-observation');
220
	var donnees_obs = formaterDonneesObservationPourEnvoi(dateStr, $obs);
244
	var donnees_obs = formaterDonneesObservationPourEnvoi(dateStr, $obs);
221
 
245
 
222
	url_page_courante = document.URL;
246
	url_page_courante = document.URL;
223
	url_page_courante = url_page_courante.replace('module=Individu','module=Observation');
247
	url_page_courante = url_page_courante.replace('module=Individu','module=Observation');
224
	url_page_courante = url_page_courante.replace('action=afficherListeIndividu','action=validerFormulaireModificationObservationAjax');
248
	url_page_courante = url_page_courante.replace('action=afficherListeIndividu','action=validerFormulaireModificationObservationAjax');
225
	url_ajax = url_page_courante.replace('action=validerFormulaireSaisieIndividu','action=validerFormulaireModificationObservationAjax');
249
	url_ajax = url_page_courante.replace('action=validerFormulaireSaisieIndividu','action=validerFormulaireModificationObservationAjax');
226
 
250
 
227
	$conteneurAjout = null;
251
	$conteneurAjout = null;
228
	if(!est_obs_existante) {
252
	if(!est_obs_existante) {
229
		var id_conteneur_ajout = 'ajouter_observation_individu_'+donnees_obs['id_individu']+'_evenement_'+donnees_obs['id_evenement'];
253
		var id_conteneur_ajout = 'ajouter_observation_individu_'+donnees_obs['id_individu']+'_evenement_'+donnees_obs['id_evenement'];
230
		var $conteneurAjout = $('#'+id_conteneur_ajout).clone();
254
		var $conteneurAjout = $('#'+id_conteneur_ajout).clone();
231
	}
255
	}
-
 
256
 
-
 
257
	if(absenceStadePourIndividuEtAnneeEstSignalee($obs.data('id-individu'), $obs.data('id-stade'))) {
-
 
258
		$obs.find('.date-observation').text('Absent');
-
 
259
		return;
-
 
260
	}
232
 
261
 
-
 
262
	var donnees_obs = formaterDonneesObservationPourEnvoi(dateStr, $obs);
233
	var donnees_obs = formaterDonneesObservationPourEnvoi(dateStr, $obs);
263
	donnees_obs['id_participant'] = 3;
234
	$.post(url_ajax, donnees_obs, function(obj_retour) {
264
	$.post(url_ajax, donnees_obs, function(obj_retour) {
235
 
265
 
236
		if(obj_retour.data.erreurs) {
266
		if(!!obj_retour.data.erreurs) {
237
			var message = 'Une ou plusieurs erreurs se sont produites : '+"\n";
267
			var message = 'Une ou plusieurs erreurs se sont produites : '+"\n";
238
			for (var key in obj_retour.data.erreurs) {
268
			for (var key in obj_retour.data.erreurs) {
239
  		if (obj_retour.data.erreurs.hasOwnProperty(key))
269
  		if (obj_retour.data.erreurs.hasOwnProperty(key))
240
    		message += '- '+obj_retour.data.erreurs[key]+"\n";
270
    		message += '- '+obj_retour.data.erreurs[key]+"\n";
241
			}
271
			}
242
			window.alert(message);
272
			window.alert(message);
243
			return;
273
			return;
244
		}
274
		}
245
 
275
 
246
		if(obj_retour.reponse === 'OK') {
276
		if(obj_retour.reponse === 'OK') {
247
 
277
 
248
			// les obs ne sont jamais vraiment supprimées
278
			// les obs ne sont jamais vraiment supprimées
249
			// mais seulement remplacées par des dates au format 00/00/yyyy
279
			// mais seulement remplacées par des dates au format 00/00/yyyy
250
			if(estUneDateSuppressionObs(dateStr)) {
280
			if(estUneDateSuppressionObs(dateStr)) {
-
 
281
				// si l'on a supprimé le signalement de l'absence d'un stade, alors on peut de nouveau saisir des
-
 
282
				// observations pour ce stade (le signalement de l'absence d'un stade pour une année est une observation)
-
 
283
				if(estUneAbsenceObservation($obs)) {
-
 
284
					afficherOuCacherConteneurAjout($obs.data('id-individu'), $obs.data('id-stade-observation'), true);
-
 
285
					afficherOuCacherBoutonSignalerAbsenceObservation($obs.data('id-individu'), $obs.data('id-stade-observation'), true);
-
 
286
				}
-
 
287
 
251
				$obs.remove();
288
				$obs.remove();
252
				delete $obs;
289
				delete $obs;
253
				return;
-
 
254
			}
-
 
-
 
290
 
255
 
291
				// s'il l'on vient de supprimer la dernière obs d'une évènement pour un individu on peut également à nouveau
256
			$obs.find('.date_observation').text(dateStr);
292
				// saisir des observations pour celui-ci
-
 
293
				if(getDatesSaisiesPourStadeEtIndividu($obs.data('id-individu'), $obs.data('id-stade-observation')).length == 0) {
-
 
294
					afficherOuCacherBoutonSignalerAbsenceObservation($obs.data('id-individu'), $obs.data('id-stade-observation'), true);
257
			$obs.data('date-observation', dateStr);
295
				}
258
 
296
 
259
			if(!est_obs_existante) {
-
 
260
				$obs.removeClass('ajouter_observation');
-
 
261
				$obs.attr('title', 'Cliquez pour modifier la date de cette observation')
297
				return;
262
				$obs.data('id-observation', obj_retour.data.id_observation);
298
			}
-
 
299
 
-
 
300
			if(!!obj_retour.data.id_observation) {
263
 
301
				donnees_obs['id_observation'] = obj_retour.data.id_observation;
-
 
302
			}
-
 
303
 
-
 
304
			// sl'on vient de signaler que la stade n'a pas du tout eu lieu dans l'année
-
 
305
			if(estUneAbsenceObservation($obs)) {
-
 
306
				// alors on affiche une observation spéciale qui indique que le stade est absent
-
 
307
				// et qui bloque la saisie d'autres observations de ce stade pour cet individu et cette année
-
 
308
				afficherAbsenceObservationPourIndividuEtAnnee($obs, $conteneurAjout, donnees_obs);
-
 
309
			} else {
264
				var id_conteneur_observation = 'individu_'+donnees_obs['id_individu']+'_evenement_'+donnees_obs['id_evenement']+'_observation_'+obj_retour.data.id_observation;
310
				afficherObservation(dateStr, $obs, $conteneurAjout, donnees_obs, est_obs_existante);
265
				$obs.attr('id', id_conteneur_observation);
311
				// à partir du moment où l'on a au moins une observation pour un stade et un individu donné
266
 
312
				// on ne peut plus signaler que l'évènement n'a pas eu lieu cette année
267
				$obs.after($conteneurAjout);
313
				afficherOuCacherBoutonSignalerAbsenceObservation($obs.data('id-individu'), $obs.data('id-stade-observation'), false);
268
			}
314
			}
269
 
315
 
270
			$('.element_clique').removeClass('element_clique');
316
			$('.element_clique').removeClass('element_clique');
271
			fermerDatePicker();
317
			fermerDatePicker();
272
		}
318
		}
273
	});
319
	});
274
}
320
}
-
 
321
 
-
 
322
function afficherObservation(dateStr, $obs, $conteneurAjout, donnees_obs, est_obs_existante) {
-
 
323
	$obs.find('.date_observation').text(dateStr);
-
 
324
	$obs.data('date-observation', dateStr);
-
 
325
 
-
 
326
	if(!est_obs_existante) {
-
 
327
		$obs.removeClass('ajouter_observation');
-
 
328
		$obs.attr('title', 'Cliquez pour modifier la date de cette observation')
-
 
329
		$obs.data('id-observation', donnees_obs['id_observation']);
-
 
330
 
-
 
331
		var id_conteneur_observation = 'individu_'+donnees_obs['id_individu']+'_evenement_'+donnees_obs['id_evenement']+'_observation_'+donnees_obs['id_observation'];
-
 
332
		$obs.attr('id', id_conteneur_observation);
-
 
333
 
-
 
334
		$obs.after($conteneurAjout);
-
 
335
	}
-
 
336
}
-
 
337
 
-
 
338
function afficherAbsenceObservationPourIndividuEtAnnee($obs, $conteneurAjout, donnees_obs) {
-
 
339
	afficherObservation('Absent', $obs, $conteneurAjout, donnees_obs, false);
-
 
340
	$obs.attr('title', 'Vous avez indiqué que ce stade n\'a pas été observé pour cette année');
-
 
341
	$obs.data('absence-observation', '1');
-
 
342
	$obs.attr('data-absence-observation', '1');
-
 
343
	// on cache le conteneur d'ajout car une fois l'absence d'un stade signalée pour une année
-
 
344
	// et un individu, il est illogique de vouloir signaler des observations de ce stade
-
 
345
	afficherOuCacherConteneurAjout(donnees_obs['id_individu'], donnees_obs['id_evenement'], false);
-
 
346
}
-
 
347
 
-
 
348
function afficherOuCacherConteneurAjout(id_individu, id_evenement, afficher) {
-
 
349
	var $conteneurAjout = $('#ajouter_observation_individu_'+id_individu+'_evenement_'+id_evenement);
-
 
350
	$conteneurAjout.toggleClass('hide', !afficher);
-
 
351
}
-
 
352
 
-
 
353
function afficherOuCacherBoutonSignalerAbsenceObservation(id_individu, id_evenement, afficher) {
-
 
354
	var $conteneurSignalementAbsenceObs = $('#ajouter_observation_individu_'+id_individu+'_evenement_'+id_evenement+' .absence_observation');
-
 
355
	console.log($conteneurSignalementAbsenceObs);
-
 
356
	$conteneurSignalementAbsenceObs.toggleClass('hide', !afficher);
-
 
357
}
-
 
358
 
-
 
359
function estUneAbsenceObservation($obs) {
-
 
360
	return $obs.data('absence-observation') == 1;
-
 
361
}
275
 
362
 
276
function estUneDateSuppressionObs(dateStr) {
363
function estUneDateSuppressionObs(dateStr) {
277
	var date_vide_pattern = /^00\/00\/\d{4}$/;
364
	var date_vide_pattern = /^00\/00\/\d{4}$/;
278
	return dateStr == '' || date_vide_pattern.test(dateStr);
365
	return dateStr == '' || date_vide_pattern.test(dateStr);
279
}
366
}
280
 
367
 
281
function fermerDatePicker() {
368
function fermerDatePicker() {
282
	if($(".hasDatepicker").length == 0) {
369
	if($(".hasDatepicker").length == 0) {
283
		return;
370
		return;
284
	}
371
	}
285
 
372
 
286
	$(".hasDatepicker").each(function() {
373
	$(".hasDatepicker").each(function() {
287
		$(this).datepicker("destroy");
374
		$(this).datepicker("destroy");
288
		$(this).removeClass(".hasDatepicker").removeAttr('id');
375
		$(this).removeClass(".hasDatepicker").removeAttr('id');
289
	});
376
	});
290
}
377
}
291
 
378
 
292
function obtenirAttributsData(el) {
379
function obtenirAttributsData(el) {
293
	return [].filter.call(el.attributes, function(at) { return /^data-/.test(at.name); });
380
	return [].filter.call(el.attributes, function(at) { return /^data-/.test(at.name); });
294
}
381
}
295
 
382
 
296
// vérifie qu'une date est au format d/m/y
383
// vérifie qu'une date est au format d/m/y
297
// merci stacky https://stackoverflow.com/questions/5812220/how-to-validate-a-date
384
// merci stacky https://stackoverflow.com/questions/5812220/how-to-validate-a-date
298
function estUneDateValide(s) {
385
function estUneDateValide(s) {
299
  var bits = s.split('/');
386
  var bits = s.split('/');
300
  var d = new Date(bits[2], bits[1] - 1, bits[0]);
387
  var d = new Date(bits[2], bits[1] - 1, bits[0]);
301
  return d && (d.getMonth() + 1) == bits[1];
388
  return d && (d.getMonth() + 1) == bits[1];
302
}
389
}
-
 
390
 
-
 
391
function absenceStadePourIndividuEtAnneeEstSignalee(id_individu, id_stade) {
-
 
392
	var selecteur_data = '[data-id-individu="'+id_individu+'"]'+
-
 
393
												'[data-id-stade-observation="'+id_stade+'"]'+
-
 
394
												'[data-absence-observation="1"]';
-
 
395
 
-
 
396
	return $('.date_observation_individu'+selecteur_data).length >= 1;
-
 
397
}
303
 
398
 
304
function getDatesSaisiesPourStadeEtIndividu(id_individu, id_stade) {
399
function getDatesSaisiesPourStadeEtIndividu(id_individu, id_stade) {
305
	var selecteur_data = '[data-id-individu="'+id_individu+'"]'+
400
	var selecteur_data = '[data-id-individu="'+id_individu+'"]'+
306
												'[data-id-stade-observation="'+id_stade+'"]';
401
												'[data-id-stade-observation="'+id_stade+'"]';
307
 
402
 
308
	return $('.date_observation_individu'+selecteur_data).map(function() {
403
	return $('.date_observation_individu'+selecteur_data).map(function() {
309
    return $(this).data("date-observation");
404
    return $(this).data("date-observation");
310
	}).get();
405
	}).get();
311
}
406
}
312
 
407
 
313
function getAnneeEnCoursDeConsultation() {
408
function getAnneeEnCoursDeConsultation() {
314
 
409
 
315
	anneeEnCours = jQuery.trim($("#annee_en_cours").html());
410
	anneeEnCours = jQuery.trim($("#annee_en_cours").html());
316
 
411
 
317
	if(typeof(anneeEnCours)=='undefined'){
412
	if(typeof(anneeEnCours)=='undefined'){
318
		dateCourante = new Date();
413
		dateCourante = new Date();
319
		anneeEnCours = dateCourante.getFullYear();
414
		anneeEnCours = dateCourante.getFullYear();
320
	}
415
	}
321
 
416
 
322
	return anneeEnCours;
417
	return anneeEnCours;
323
}
418
}
324
 
419
 
325
function getDateMinCalendrier() {
420
function getDateMinCalendrier() {
326
	anneeEnCours = getAnneeEnCoursDeConsultation();
421
	anneeEnCours = getAnneeEnCoursDeConsultation();
327
	dateMin = '01/01/'+anneeEnCours;
422
	dateMin = '01/01/'+anneeEnCours;
328
 
423
 
329
	return dateMin;
424
	return dateMin;
330
}
425
}
331
 
426
 
332
function getDateMaxCalendrier() {
427
function getDateMaxCalendrier() {
333
 
428
 
334
	anneeEnCours = getAnneeEnCoursDeConsultation();
429
	anneeEnCours = getAnneeEnCoursDeConsultation();
335
 
430
 
336
	dateMax = '31/12/'+anneeEnCours;
431
	dateMax = '31/12/'+anneeEnCours;
337
 
432
 
338
	dateCourante = new Date();
433
	dateCourante = new Date();
339
 
434
 
340
	if(anneeEnCours == dateCourante.getFullYear()) {
435
	if(anneeEnCours == dateCourante.getFullYear()) {
341
		dateMax = dateCourante.getDate()+'/'+(dateCourante.getMonth()+ 1)+'/'+anneeEnCours;
436
		dateMax = dateCourante.getDate()+'/'+(dateCourante.getMonth()+ 1)+'/'+anneeEnCours;
342
	}
437
	}
343
 
438
 
344
	return dateMax;
439
	return dateMax;
345
}
440
}
346
 
441
 
347
$('#saisie_liste_evenements').ready(function() {
442
$('#saisie_liste_evenements').ready(function() {
348
	initialiserLignesCliquables();
443
	initialiserLignesCliquables();
349
});
444
});
350
 
445
 
351
 
446
 
352
 
447
 
353
 
448
 
354
/**
449
/**
355
	************************************************************************************************
450
	************************************************************************************************
356
	************************************************************************************************
451
	************************************************************************************************
357
 
452
 
358
	    Fonctions concernant la carte permettant de pointer d'afficher l'emplacement des stations
453
	    Fonctions concernant la carte permettant de pointer d'afficher l'emplacement des stations
359
 
454
 
360
	************************************************************************************************
455
	************************************************************************************************
361
	************************************************************************************************
456
	************************************************************************************************
362
**/
457
**/
363
var map;
458
var map;
364
var marker;
459
var marker;
365
var liste_localite_en_cours;
460
var liste_localite_en_cours;
366
var indice_commune_en_cours;
461
var indice_commune_en_cours;
367
var liste_auto_completion_a_le_focus;
462
var liste_auto_completion_a_le_focus;
368
var timerRequeteAutocompletion;
463
var timerRequeteAutocompletion;
369
var timerAffichageAutocompletion;
464
var timerAffichageAutocompletion;
370
 
465
 
371
 
466
 
372
function cacherElementsRafraichissables() {
467
function cacherElementsRafraichissables() {
373
	$('.rafraichissable input').attr('disabled', 'disabled');
468
	$('.rafraichissable input').attr('disabled', 'disabled');
374
	$('.rafraichissable input[type="text"]').addClass("chargement");
469
	$('.rafraichissable input[type="text"]').addClass("chargement");
375
}
470
}
376
 
471
 
377
function montrerElementsRafraichissables() {
472
function montrerElementsRafraichissables() {
378
	$('.rafraichissable input').removeAttr('disabled');
473
	$('.rafraichissable input').removeAttr('disabled');
379
	$('.chargement').removeClass("chargement");
474
	$('.chargement').removeClass("chargement");
380
}
475
}
381
 
476
 
382
function ajouterAutoCompletionCommune() {
477
function ajouterAutoCompletionCommune() {
383
 
478
 
384
	$('input#station_commune').after('<div class="conteneur_suggestions"></div>');
479
	$('input#station_commune').after('<div class="conteneur_suggestions"></div>');
385
	$('input#station_commune').parent().addClass('autocompletion');
480
	$('input#station_commune').parent().addClass('autocompletion');
386
	$('input#station_commune').attr('autocomplete','off');
481
	$('input#station_commune').attr('autocomplete','off');
387
	$('.conteneur_suggestions').hide();
482
	$('.conteneur_suggestions').hide();
388
	rendreListeAutoCompletionInteractive('input#station_commune');
483
	rendreListeAutoCompletionInteractive('input#station_commune');
389
}
484
}
390
 
485
 
391
function ajouterListenerFormulaireSaisieLatLon() {
486
function ajouterListenerFormulaireSaisieLatLon() {
392
 
487
 
393
	$('input#localiser_lat_lon').click(function() {
488
	$('input#localiser_lat_lon').click(function() {
394
		verifierEtLocaliserCoordonnees();
489
		verifierEtLocaliserCoordonnees();
395
	});
490
	});
396
}
491
}
397
 
492
 
398
function carteEstEnSaisie() {
493
function carteEstEnSaisie() {
399
	return ($('#conteneur_form_liens_lat_lon').length > 0);
494
	return ($('#conteneur_form_liens_lat_lon').length > 0);
400
}
495
}
401
 
496
 
402
function verifierEtLocaliserCoordonnees() {
497
function verifierEtLocaliserCoordonnees() {
403
 
498
 
404
	lat ;
499
	lat ;
405
	lon;
500
	lon;
406
 
501
 
407
	if(carteEstEnSaisie()) {
502
	if(carteEstEnSaisie()) {
408
		lat = $('#station_lat').val();
503
		lat = $('#station_lat').val();
409
		lon = $('#station_lon').val();
504
		lon = $('#station_lon').val();
410
 
505
 
411
		obtenirInformationsPourCoordonnees(lat, lon);
506
		obtenirInformationsPourCoordonnees(lat, lon);
412
	} else {
507
	} else {
413
		var lat = jQuery.trim($('#station_lat').html());
508
		var lat = jQuery.trim($('#station_lat').html());
414
		var lon = jQuery.trim($('#station_lon').html());
509
		var lon = jQuery.trim($('#station_lon').html());
415
	}
510
	}
416
 
511
 
417
	if(jQuery.trim(lat) == '' || jQuery.trim(lon) == '') {
512
	if(jQuery.trim(lat) == '' || jQuery.trim(lon) == '') {
418
		return;
513
		return;
419
	}
514
	}
420
 
515
 
421
	if(!isNaN(lat) && lat.length > 0 && !isNaN(lon) && lon.length > 0) {
516
	if(!isNaN(lat) && lat.length > 0 && !isNaN(lon) && lon.length > 0) {
422
 
517
 
423
	} else {
518
	} else {
424
		window.alert("coordonnées invalides");
519
		window.alert("coordonnées invalides");
425
	}
520
	}
426
 
521
 
427
	var positionMarker = new google.maps.LatLng(lat, lon);
522
	var positionMarker = new google.maps.LatLng(lat, lon);
428
 
523
 
429
	marker.setPosition(positionMarker);
524
	marker.setPosition(positionMarker);
430
	map.setCenter(positionMarker);
525
	map.setCenter(positionMarker);
431
	map.setZoom(12);
526
	map.setZoom(12);
432
}
527
}
433
 
528
 
434
function obtenirInformationsPourCoordonnees(lat, lon) {
529
function obtenirInformationsPourCoordonnees(lat, lon) {
435
 
530
 
436
	lat = jQuery.trim(lat);
531
	lat = jQuery.trim(lat);
437
	lon = jQuery.trim(lon);
532
	lon = jQuery.trim(lon);
438
 
533
 
439
	if(isNaN(lat) || lat.length <= 0 || isNaN(lon) || lon.length <= 0) {
534
	if(isNaN(lat) || lat.length <= 0 || isNaN(lon) || lon.length <= 0) {
440
		return;
535
		return;
441
	}
536
	}
442
 
537
 
443
	cacherElementsRafraichissables();
538
	cacherElementsRafraichissables();
444
 
539
 
445
	$.get(urlBaseJrest+'OdsCommune/informationsPourCoordonnees/?lat='+lat+'&lon='+lon, function(data) {
540
	$.get(urlBaseJrest+'OdsCommune/informationsPourCoordonnees/?lat='+lat+'&lon='+lon, function(data) {
446
 
541
 
447
		infos_localites = jQuery.parseJSON(data);
542
		infos_localites = jQuery.parseJSON(data);
448
		$('#station_alt').val(infos_localites.alt);
543
		$('#station_alt').val(infos_localites.alt);
449
 
544
 
450
		if(infos_localites.commune != null && infos_localites.commune != '') {
545
		if(infos_localites.commune != null && infos_localites.commune != '') {
451
		  $('#station_commune').val(infos_localites.commune);
546
		  $('#station_commune').val(infos_localites.commune);
452
		  $('#station_code_insee').val(infos_localites.code_insee);
547
		  $('#station_code_insee').val(infos_localites.code_insee);
453
		}
548
		}
454
 
549
 
455
		montrerElementsRafraichissables();
550
		montrerElementsRafraichissables();
456
 
551
 
457
	});
552
	});
458
 
553
 
459
}
554
}
460
 
555
 
461
function obtenirInformationsPourCommune(nom_commune) {
556
function obtenirInformationsPourCommune(nom_commune) {
462
 
557
 
463
	if(jQuery.trim(nom_commune) == '') {
558
	if(jQuery.trim(nom_commune) == '') {
464
		$('.conteneur_suggestions').hide();
559
		$('.conteneur_suggestions').hide();
465
		return;
560
		return;
466
	}
561
	}
467
 
562
 
468
	$.get(urlBaseJrest+'OdsCommune/informationsPourCommune/?commune='+nom_commune, function(data) {
563
	$.get(urlBaseJrest+'OdsCommune/informationsPourCommune/?commune='+nom_commune, function(data) {
469
 
564
 
470
		infos_localites = jQuery.parseJSON(data);
565
		infos_localites = jQuery.parseJSON(data);
471
		afficherListeAutoCompletion(infos_localites);
566
		afficherListeAutoCompletion(infos_localites);
472
	});
567
	});
473
}
568
}
474
 
569
 
475
function afficherListeAutoCompletion(tableau_localites) {
570
function afficherListeAutoCompletion(tableau_localites) {
476
 
571
 
477
	liste_localite_en_cours = tableau_localites;
572
	liste_localite_en_cours = tableau_localites;
478
 
573
 
479
	html_liste_localite = '<ul class="liste_suggestions">';
574
	html_liste_localite = '<ul class="liste_suggestions">';
480
 
575
 
481
	for(i = 0; i< tableau_localites.length; i++) {
576
	for(i = 0; i< tableau_localites.length; i++) {
482
		html_liste_localite += '<li id="commune_'+i+'" class="element_auto_completion_commune">'+tableau_localites[i]['commune']+'  ('+tableau_localites[i]['dpt']+')</li>';
577
		html_liste_localite += '<li id="commune_'+i+'" class="element_auto_completion_commune">'+tableau_localites[i]['commune']+'  ('+tableau_localites[i]['dpt']+')</li>';
483
	}
578
	}
484
 
579
 
485
	html_liste_localite += '</ul>';
580
	html_liste_localite += '</ul>';
486
 
581
 
487
	$('.conteneur_suggestions').html(html_liste_localite);
582
	$('.conteneur_suggestions').html(html_liste_localite);
488
 
583
 
489
	$('.element_auto_completion_commune').hover(function() {
584
	$('.element_auto_completion_commune').hover(function() {
490
		indice = $(this).attr('id').split('_')[1];
585
		indice = $(this).attr('id').split('_')[1];
491
		mettreEnSurbrillanceCommune(indice);
586
		mettreEnSurbrillanceCommune(indice);
492
	});
587
	});
493
 
588
 
494
	$('.element_auto_completion_commune').click(function() {
589
	$('.element_auto_completion_commune').click(function() {
495
		indice = $(this).attr('id').split('_')[1];
590
		indice = $(this).attr('id').split('_')[1];
496
		selectionnerCommune(indice);
591
		selectionnerCommune(indice);
497
	});
592
	});
498
 
593
 
499
	if(tableau_localites.length > 0) {
594
	if(tableau_localites.length > 0) {
500
		$('.conteneur_suggestions').show();
595
		$('.conteneur_suggestions').show();
501
 
596
 
502
		mettreEnSurbrillanceCommune(0);
597
		mettreEnSurbrillanceCommune(0);
503
	}
598
	}
504
}
599
}
505
 
600
 
506
function mettreEnSurbrillanceCommune(indice) {
601
function mettreEnSurbrillanceCommune(indice) {
507
 
602
 
508
	if(indice_commune_en_cours != null) {
603
	if(indice_commune_en_cours != null) {
509
		$('#commune_'+indice_commune_en_cours).removeClass('element_selectionne');
604
		$('#commune_'+indice_commune_en_cours).removeClass('element_selectionne');
510
	}
605
	}
511
	$('#commune_'+indice).addClass('element_selectionne');
606
	$('#commune_'+indice).addClass('element_selectionne');
512
	indice_commune_en_cours = indice;
607
	indice_commune_en_cours = indice;
513
 
608
 
514
	reprogrammerTimerPourCacherListeAutoCompletion();
609
	reprogrammerTimerPourCacherListeAutoCompletion();
515
}
610
}
516
 
611
 
517
function rendreListeAutoCompletionInteractive(selecteur) {
612
function rendreListeAutoCompletionInteractive(selecteur) {
518
 
613
 
519
	$(selecteur).keyup(function(event) {
614
	$(selecteur).keyup(function(event) {
520
		if(event.which == 8 || (event.which >= 48 && event.which <= 90)) {
615
		if(event.which == 8 || (event.which >= 48 && event.which <= 90)) {
521
 
616
 
522
			reprogrammerTimerPourCacherListeAutoCompletion();
617
			reprogrammerTimerPourCacherListeAutoCompletion();
523
			reprogrammerTimerPourLancerRequeteCommune();
618
			reprogrammerTimerPourLancerRequeteCommune();
524
		}
619
		}
525
	});
620
	});
526
 
621
 
527
	$(selecteur).keydown(function(event) {
622
	$(selecteur).keydown(function(event) {
528
 
623
 
529
		reprogrammerTimerPourCacherListeAutoCompletion();
624
		reprogrammerTimerPourCacherListeAutoCompletion();
530
 
625
 
531
		// entree
626
		// entree
532
		if(event.which==13){
627
		if(event.which==13){
533
			selectionnerCommune(indice_commune_en_cours);
628
			selectionnerCommune(indice_commune_en_cours);
534
			event.preventDefault();
629
			event.preventDefault();
535
		}
630
		}
536
 
631
 
537
		// haut
632
		// haut
538
		if(event.which == 38){
633
		if(event.which == 38){
539
			if(indice_commune_en_cours > 0) {
634
			if(indice_commune_en_cours > 0) {
540
				mettreEnSurbrillanceCommune(indice_commune_en_cours - 1);
635
				mettreEnSurbrillanceCommune(indice_commune_en_cours - 1);
541
			}
636
			}
542
		}
637
		}
543
 
638
 
544
		// bas
639
		// bas
545
		if(event.which == 40){
640
		if(event.which == 40){
546
			if(indice_commune_en_cours < liste_localite_en_cours.length - 1) {
641
			if(indice_commune_en_cours < liste_localite_en_cours.length - 1) {
547
				mettreEnSurbrillanceCommune(indice_commune_en_cours + 1);
642
				mettreEnSurbrillanceCommune(indice_commune_en_cours + 1);
548
			}
643
			}
549
		}
644
		}
550
	});
645
	});
551
 
646
 
552
	$('.conteneur_suggestions').blur(function() {
647
	$('.conteneur_suggestions').blur(function() {
553
		$('.conteneur_suggestions').hide();
648
		$('.conteneur_suggestions').hide();
554
	});
649
	});
555
}
650
}
556
 
651
 
557
function reprogrammerTimerPourCacherListeAutoCompletion() {
652
function reprogrammerTimerPourCacherListeAutoCompletion() {
558
 
653
 
559
	if(timerAffichageAutocompletion != null) {
654
	if(timerAffichageAutocompletion != null) {
560
		window.clearTimeout(timerAffichageAutocompletion);
655
		window.clearTimeout(timerAffichageAutocompletion);
561
	}
656
	}
562
 
657
 
563
	timerAffichageAutocompletion = window.setTimeout(function() {
658
	timerAffichageAutocompletion = window.setTimeout(function() {
564
		$('.conteneur_suggestions').hide();
659
		$('.conteneur_suggestions').hide();
565
	}, 2000);
660
	}, 2000);
566
}
661
}
567
 
662
 
568
function reprogrammerTimerPourLancerRequeteCommune() {
663
function reprogrammerTimerPourLancerRequeteCommune() {
569
 
664
 
570
	if(timerRequeteAutocompletion != null) {
665
	if(timerRequeteAutocompletion != null) {
571
		window.clearTimeout(timerRequeteAutocompletion);
666
		window.clearTimeout(timerRequeteAutocompletion);
572
	}
667
	}
573
 
668
 
574
	timerRequeteAutocompletion = window.setTimeout(function() {
669
	timerRequeteAutocompletion = window.setTimeout(function() {
575
		obtenirInformationsPourCommune($('input#station_commune').val());
670
		obtenirInformationsPourCommune($('input#station_commune').val());
576
	}, 350);
671
	}, 350);
577
}
672
}
578
 
673
 
579
function selectionnerCommune(indice) {
674
function selectionnerCommune(indice) {
580
 
675
 
581
	infos_commune = liste_localite_en_cours[indice];
676
	infos_commune = liste_localite_en_cours[indice];
582
 
677
 
583
	$('input#station_commune').val(infos_commune['commune']);
678
	$('input#station_commune').val(infos_commune['commune']);
584
	$('input#station_lat').val(infos_commune['lat']);
679
	$('input#station_lat').val(infos_commune['lat']);
585
	$('input#station_lon').val(infos_commune['lon']);
680
	$('input#station_lon').val(infos_commune['lon']);
586
	$('input#station_code_insee').val(infos_commune['code_insee']);
681
	$('input#station_code_insee').val(infos_commune['code_insee']);
587
 
682
 
588
	verifierEtLocaliserCoordonnees();
683
	verifierEtLocaliserCoordonnees();
589
 
684
 
590
	$('.conteneur_suggestions').hide();
685
	$('.conteneur_suggestions').hide();
591
}
686
}
592
 
687
 
593
function mettreAJourValeursFormulaire(latlon) {
688
function mettreAJourValeursFormulaire(latlon) {
594
 
689
 
595
	latlon = latlon.toString().split(',');
690
	latlon = latlon.toString().split(',');
596
 
691
 
597
	lat = latlon[0].replace('(', '');
692
	lat = latlon[0].replace('(', '');
598
	lon = latlon[1].replace(')', '');
693
	lon = latlon[1].replace(')', '');
599
 
694
 
600
	$('#station_lat').val(latlon[0].replace('(', ''));
695
	$('#station_lat').val(latlon[0].replace('(', ''));
601
	$('#station_lon').val(latlon[1].replace(')', ''));
696
	$('#station_lon').val(latlon[1].replace(')', ''));
602
 
697
 
603
	obtenirInformationsPourCoordonnees(lat, lon);
698
	obtenirInformationsPourCoordonnees(lat, lon);
604
}
699
}
605
 
700
 
606
function initialiserCarte() {
701
function initialiserCarte() {
607
 
702
 
608
	if($('#map_canvas').length == 0) {
703
	if($('#map_canvas').length == 0) {
609
		return;
704
		return;
610
	}
705
	}
611
 
706
 
612
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
707
	var latlng = new google.maps.LatLng(47.0504, 2.2347);
613
	var myOptions = {
708
	var myOptions = {
614
		zoom: 6,
709
		zoom: 6,
615
		center: latlng,
710
		center: latlng,
616
		mapTypeId: google.maps.MapTypeId.HYBRID
711
		mapTypeId: google.maps.MapTypeId.HYBRID
617
	};
712
	};
618
 
713
 
619
	map = new google.maps.Map(document.getElementById("map_canvas"),
714
	map = new google.maps.Map(document.getElementById("map_canvas"),
620
    	myOptions);
715
    	myOptions);
621
 
716
 
622
	marker = new google.maps.Marker({
717
	marker = new google.maps.Marker({
623
	      position: latlng,
718
	      position: latlng,
624
	      title:""
719
	      title:""
625
	});
720
	});
626
 
721
 
627
	if (carteEstEnSaisie()) {
722
	if (carteEstEnSaisie()) {
628
 
723
 
629
			marker.setDraggable(true);
724
			marker.setDraggable(true);
630
 
725
 
631
			google.maps.event.addListener(marker, 'dragend', function(event) {
726
			google.maps.event.addListener(marker, 'dragend', function(event) {
632
				mettreAJourValeursFormulaire(marker.getPosition());
727
				mettreAJourValeursFormulaire(marker.getPosition());
633
			});
728
			});
634
			$('#conteneur_form_liens_lat_lon').ready(function() {
729
			$('#conteneur_form_liens_lat_lon').ready(function() {
635
				verifierEtLocaliserCoordonnees();
730
				verifierEtLocaliserCoordonnees();
636
				ajouterListenerFormulaireSaisieLatLon();
731
				ajouterListenerFormulaireSaisieLatLon();
637
				ajouterAutoCompletionCommune();
732
				ajouterAutoCompletionCommune();
638
			});
733
			});
639
	} else {
734
	} else {
640
		marker.setDraggable(false);
735
		marker.setDraggable(false);
641
		$('#conteneur_liens_lat_lon').ready(function() {
736
		$('#conteneur_liens_lat_lon').ready(function() {
642
			verifierEtLocaliserCoordonnees();
737
			verifierEtLocaliserCoordonnees();
643
		});
738
		});
644
	}
739
	}
645
 
740
 
646
	marker.setClickable(true);
741
	marker.setClickable(true);
647
 
742
 
648
	// To add the marker to the map, call setMap();
743
	// To add the marker to the map, call setMap();
649
	marker.setMap(map);
744
	marker.setMap(map);
650
}
745
}
651
 
746
 
652
$('#map_canvas').ready(function() {
747
$('#map_canvas').ready(function() {
653
	initialiserCarte();
748
	initialiserCarte();
654
});
749
});
655
 
750
 
656
/**
751
/**
657
************************************************************************************************
752
************************************************************************************************
658
************************************************************************************************
753
************************************************************************************************
659
 
754
 
660
    Fonctions généralistes s'appliquant automatiquement à certaines classes css
755
    Fonctions généralistes s'appliquant automatiquement à certaines classes css
661
 
756
 
662
************************************************************************************************
757
************************************************************************************************
663
************************************************************************************************
758
************************************************************************************************
664
**/
759
**/
665
 
760
 
666
function initialiserLiensNouvelleFenetre() {
761
function initialiserLiensNouvelleFenetre() {
667
 
762
 
668
	$('a.lien_nouvelle_fenetre').each(function() {
763
	$('a.lien_nouvelle_fenetre').each(function() {
669
	  var titre = $(this).attr("title");
764
	  var titre = $(this).attr("title");
670
	  $(this).attr("title", titre+" (s'ouvre dans une nouvelle fenêtre)");
765
	  $(this).attr("title", titre+" (s'ouvre dans une nouvelle fenêtre)");
671
	});
766
	});
672
 
767
 
673
	$('a.lien_nouvelle_fenetre').click(function(event) {
768
	$('a.lien_nouvelle_fenetre').click(function(event) {
674
		event.preventDefault();
769
		event.preventDefault();
675
		window.open($(this).attr('href'));
770
		window.open($(this).attr('href'));
676
	});
771
	});
677
}
772
}
678
 
773
 
679
function initialiserLiensSuppression() {
774
function initialiserLiensSuppression() {
680
	$('.lien_suppression').click(function() {
775
	$('.lien_suppression').click(function() {
681
		return window.confirm('Êtes vous sur de vouloir supprimer ?');
776
		return window.confirm('Êtes vous sûr.e de vouloir supprimer ?');
682
	});
777
	});
683
}
778
}
684
 
779
 
685
$(document).ready(function() {
780
$(document).ready(function() {
686
	initialiserLiensSuppression();
781
	initialiserLiensSuppression();
687
	initialiserLiensNouvelleFenetre();
782
	initialiserLiensNouvelleFenetre();
688
});
783
});
689
 
784
 
690
 
785
 
691
 
786
 
692
/**
787
/**
693
************************************************************************************************
788
************************************************************************************************
694
************************************************************************************************
789
************************************************************************************************
695
 
790
 
696
    Fonctions de debug permattant d'afficher les objets javascript à la manière de print_r
791
    Fonctions de debug permattant d'afficher les objets javascript à la manière de print_r
697
 
792
 
698
************************************************************************************************
793
************************************************************************************************
699
************************************************************************************************
794
************************************************************************************************
700
**/
795
**/
701
 
796
 
702
function dump(arr,level) {
797
function dump(arr,level) {
703
	var dumped_text = "";
798
	var dumped_text = "";
704
	if(!level) level = 0;
799
	if(!level) level = 0;
705
 
800
 
706
	//The padding given at the beginning of the line.
801
	//The padding given at the beginning of the line.
707
	var level_padding = "";
802
	var level_padding = "";
708
	for(var j=0;j<level+1;j++) level_padding += "    ";
803
	for(var j=0;j<level+1;j++) level_padding += "    ";
709
 
804
 
710
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
805
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
711
	 for(var item in arr) {
806
	 for(var item in arr) {
712
	  var value = arr[item];
807
	  var value = arr[item];
713
 
808
 
714
	  if(typeof(value) == 'object') { //If it is an array,
809
	  if(typeof(value) == 'object') { //If it is an array,
715
	   dumped_text += level_padding + "'" + item + "' ...\n";
810
	   dumped_text += level_padding + "'" + item + "' ...\n";
716
	   dumped_text += dump(value,level+1);
811
	   dumped_text += dump(value,level+1);
717
	  } else {
812
	  } else {
718
	   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
813
	   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
719
	  }
814
	  }
720
	 }
815
	 }
721
	} else { //Stings/Chars/Numbers etc.
816
	} else { //Stings/Chars/Numbers etc.
722
	 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
817
	 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
723
	}
818
	}
724
	return dumped_text;
819
	return dumped_text;
725
}
820
}