Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
3312 idir 1
/**
2
 * Constructeur PlantesApa par défaut
3
 */
4
function PlantesApa() {
5
	this.obsNbre = 0;
6
	this.nbObsEnCours = 1;
7
	this.totalObsATransmettre = 0;
8
	this.nbObsTransmises = 0;
9
	this.debug = null;
10
	this.html5 = null;
11
	this.tagProjet = null;
12
	this.tagImg = null;
13
	this.tagObs = null;
14
	this.separationTagImg = null;
15
	this.separationTagObs = null;
16
	this.serviceSaisieUrl = null;
17
	this.chargementImageIconeUrl = null;
18
	this.pasDePhotoIconeUrl = null;
19
	this.nomSciReferentiel = null;
20
	this.autocompletionElementsNbre = null;
21
	this.referentielImpose = null;
22
	this.serviceAutocompletionNomSciUrl = null;
23
	this.serviceAutocompletionNomSciUrlTpl = null;
24
	this.obsMaxNbre = null;
25
	this.dureeMessage = null;
26
	this.infosUtilisateur = {};
27
	this.releveDatas = null;
28
	this.utils = new UtilsApa();
29
}
30
 
31
PlantesApa.prototype.init = function() {
32
	this.initForm();
33
	this.initEvts();
34
};
35
 
36
/**
37
 * Initialise le formulaire, les validateurs, les listes de complétion...
38
 */
39
PlantesApa.prototype.initForm = function() {
40
	const lthis = this;
41
 
42
	this.surChangementTaxonListe();
43
	$( '#taxon-liste' ).on( 'change', lthis.surChangementTaxonListe );
44
	$( '#taxon-liste' ).on( 'change', lthis.surChangementValeurTaxon.bind( lthis ) );
45
	if ( this.debug ) {
46
		console.log( 'Selected taxon:' + $( '#taxon-liste option:selected' ).val());
47
	}
48
	this.configurerFormValidator();
49
	this.definirReglesFormValidator();
50
};
51
 
52
/**
53
 * Initialise les écouteurs d'événements
54
 */
55
PlantesApa.prototype.initEvts = function() {
56
	const lthis = this;
57
 
58
	var releveDatas = [];
59
	this.infosUtilisateur.id     = $( '#id_utilisateur' ).val();
60
	this.infosUtilisateur.prenom = $( '#prenom' ).val();
61
	this.infosUtilisateur.nom    = $( '#nom' ).val();
62
 
63
	$( '#bouton-nouveau-releve' ).click( function() {
64
		$( '#releve-data' ).val( '' );
65
		if ( lthis.utils.valOk( lthis.infosUtilisateur.id ) ) {
66
			lthis.utils.chargerForm( 'arbres', lthis );
67
			$( '#bouton-list-releves' ).removeClass( 'hidden' );
68
		}
69
		$( '#table-releves' ).addClass( 'hidden' );
70
	});
71
 
72
	if( this.utils.valOk( this.infosUtilisateur.id ) && this.utils.valOk( $( '#releve-data' ).val() ) ) {
73
		this.releveDatas = $.parseJSON( $( '#releve-data' ).val() );
74
		if ( this.utils.valOk( this.releveDatas[0].utilisateur, true, this.infosUtilisateur.id ) ) {
75
 
76
			// Sur téléchargement image
77
			$( '#fichier' ).on( 'change', function ( e ) {
78
				arreter( e );
79
 
80
				var options        = {
81
					success: lthis.afficherMiniature.bind( lthis ), // post-submit callback
82
					dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
83
					resetForm: true // reset the form after successful submit
84
				};
85
 
86
				$( '#miniature' ).append( '<img id="miniature-chargement" class="miniature" alt="chargement" src="' + this.chargementImageIconeUrl + '"/>' );
87
 
88
				var imgCheminTmp    = $( '#fichier' ).val(),
89
					formatImgOk     = lthis.verifierFormat( imgCheminTmp ),
90
					imgNonDupliquee = lthis.verifierDuplication( imgCheminTmp );
91
 
92
				if( formatImgOk && imgNonDupliquee ) {
93
					$( '#form-upload' ).ajaxSubmit( options );
94
				} else {
95
					$( '#form-upload' )[0].reset();
96
					if ( !formatImgOk ) {
97
						window.alert( lthis.utils.msgTraduction( 'format-non-supporte' ) + ' ' + $( '#fichier' ).attr( 'accept' ) );
98
					}
99
					if ( !imgNonDupliquee ) {
100
						window.alert( lthis.utils.msgTraduction( 'image-deja-chargee' ) );
101
					}
102
				}
103
				return false;
104
			});
105
			$( 'body' ).on( 'click', '.effacer-miniature', function() {
106
				$( this ).parent().remove();
107
			});
108
 
109
			$( '#ajouter-obs' ).on( 'click', this.ajouterObs.bind( this ) );
110
			$( '.obs-nbre' ).on( 'changement', this.surChangementNbreObs.bind( this ) );
111
			// défilement des miniatures dans le résumé obs
112
			$( 'body' ).on( 'click', '.defilement-miniatures-gauche', function( event ) {
113
				event.preventDefault();
114
				lthis.defilerMiniatures( $( this ) );
115
			});
116
			$( 'body' ).on( 'click', '.defilement-miniatures-droite', function( event ) {
117
				event.preventDefault();
118
				lthis.defilerMiniatures( $( this ) );
119
			});
120
			// mécanisme de suppression d'une obs
121
			$( '#liste-obs' ).on( 'click', '.supprimer-obs', function() {
122
				var that = this,
123
				suppObs = lthis.supprimerObs.bind( lthis );
124
				// bricolage pour avoir les deux contextes en même temps (objet et elt. du DOM)
125
				suppObs( that );
126
			});
127
 
128
			$( '#transmettre-obs' ).on( 'click', this.transmettreObs.bind( this ) );
129
 
130
			// chargement plantes ou lichens
131
			$( '#bouton-saisir-lichens,#bouton-poursuivre' ).on( 'click', function() {
132
				var nomSquelette = $( this ).data( 'load' );
133
				$( '#charger-form' ).data( 'load', nomSquelette );
134
				lthis.utils.chargerForm( nomSquelette, lthis );
135
				$( 'html, body' ).stop().animate({
136
					scrollTop: $( '#charger-form' ).offset().top
137
				}, 300 );
138
			});
139
 
140
			// Alertes et tooltips
141
			$( '.alert .close' ).on( 'click', this.fermerPanneauAlert );
142
			$( '#btn-aide' ).on( 'click', this.basculerAffichageAide );
143
			// $( '.has-tooltip' ).tooltip( 'enable' );
144
		}
145
	}
146
};
147
 
148
// Préchargement des infos-obs ************************************************/
149
 
150
/**
151
 * Callback dans le chargement du formulaire dans #charger-form
152
 */
153
PlantesApa.prototype.chargerSquelette = function( squelette, nomSquelette ) {
154
	switch( nomSquelette ) {
155
		case 'plantes' :
156
		case 'lichens' :
157
			this.utils.chargerFormPlantesOuLichens( squelette, nomSquelette );
158
			break;
159
		case 'arbres' :
160
		default :
161
			this.reinitialiserWidget( squelette );
162
		break;
163
	}
164
};
165
 
166
PlantesApa.prototype.reinitialiserWidget = function( squelette ) {
167
	$( '#charger-form' ).html( squelette );
168
	if ( this.utils.valOk( $( '#releve-data' ).val() ) ) {
169
		this.rechargerFormulaire();
170
	}
171
};
172
 
173
// uniquement utilisé si taxon-liste ******************************************/
174
// Affiche/Cache le champ taxon
175
PlantesApa.prototype.surChangementTaxonListe = function() {
176
	const utils = new UtilsApa();
177
	if ( utils.valOk( $( '#taxon-liste' ).val() ) ) {
178
		if ( 'autre' !== $( '#taxon-liste' ).val() ) {
179
			$( '#taxon-input-groupe' )
180
				.hide( 200, function () {
181
					$( this ).addClass( 'hidden' ).show();
182
				})
183
				.find( '#taxon-autre' ).val( '' );
184
		} else {
185
			$( '#taxon-input-groupe' )
186
				.hide()
187
				.removeClass( 'hidden' )
188
				.show(200)
189
				.find( '#taxon-autre' )
190
					.focus()
191
					.on( 'change', function() {
192
						if( !utils.valOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
193
							$( '#taxon' ).val( $( '#taxon-autre' ).val() );
194
							$( '#taxon' ).removeData( 'value' )
195
								.removeData( 'numNomSel' )
196
								.removeData( 'nomRet' )
197
								.removeData( 'numNomRet' )
198
								.removeData( 'nt' )
199
								.removeData( 'famille' );
200
						}
201
						$( '#taxon' ).trigger( 'change' );
202
					});
203
		}
204
	}
205
};
206
 
207
PlantesApa.prototype.surChangementValeurTaxon = function() {
208
	var numNomSel = 0;
209
 
210
	if( this.utils.valOk( $( '#taxon-liste' ).val() ) ) {
211
		if( 'autre' === $( '#taxon-liste' ).val() ) {
212
			this.ajouterAutocompletionNoms();
213
		} else {
214
			var optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' );
215
			// $( '#taxon' ).val( $( '#taxon-liste' ).val() );
216
			$( '#taxon' ).val( $( '#taxon-liste' ).val() )
217
				.data( 'value', $( '#taxon-liste' ).val() )
218
				.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
219
				.data( 'nomRet', optionRetenue.data( 'nom-ret' ) )
220
				.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) )
221
				.data( 'nt', optionRetenue.data( 'nt' ) )
222
				.data( 'famille', optionRetenue.data( 'famille' ) );
223
			$( '#taxon' ).trigger( 'change' );
224
 
225
			numNomSel = $( '#taxon' ).data( 'numNomSel' );
226
			// Si l'espèce est mal déterminée la certitude est "à déterminer"
227
			if( !this.utils.valOk( numNomSel ) ) {
228
				$( '#certitude' ).find( 'option' ).each( function() {
229
					if ( $( this ).hasClass( 'aDeterminer' ) ) {
230
						$( this ).attr( 'selected', true );
231
					} else {
232
						$( this ).attr( 'selected', false );
233
					}
234
				});
235
			}
236
		}
237
	}
238
};
239
 
240
// Autocompletion taxons ******************************************************/
241
/**
242
 * Initialise l'autocompletion taxons
243
 */
244
PlantesApa.prototype.ajouterAutocompletionNoms = function() {
245
	const lthis = this;
246
 
247
	var taxonSelecteur = '#taxon';
248
	if ( this.utils.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
249
		taxonSelecteur += '-autre';
250
	}
251
 
252
	$( taxonSelecteur ).autocomplete({
253
		source: function( requete, add ) {
254
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
255
			requete = '';
256
			if( lthis.utils.valOk( $( '#referentiel' ).val(), false, 'autre' ) ) {
257
				var url = lthis.getUrlAutocompletionNomsSci();
258
				$.getJSON( url, requete, function( data ) {
259
					var suggestions = lthis.traiterRetourNomsSci( data );
260
					add( suggestions );
261
				})
262
				.fail( function() {
263
					$( '#certitude' ).find( 'option' ).each( function() {
264
						if ( $( this ).hasClass( 'aDeterminer' ) ) {
265
							$( this ).attr( 'selected', true );
266
						} else {
267
							$( this ).attr( 'selected', false );
268
						}
269
					});
270
				});
271
			}
272
		},
273
		html: true
274
	});
275
	$( taxonSelecteur ).on( 'autocompleteselect', this.surAutocompletionTaxon );
276
};
277
 
278
PlantesApa.prototype.getUrlAutocompletionNomsSci = function() {
279
	var taxonSelecteur = '#taxon';
280
	if ( this.utils.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
281
		taxonSelecteur += '-autre';
282
	}
283
	var mots = $( taxonSelecteur ).val();
284
	var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
285
	url = url.replace( '{masque}', mots );
286
 
287
	return url;
288
};
289
 
290
/**
291
 * Objet taxons pour autocompletion en fonction de la recherche
292
 */
293
PlantesApa.prototype.traiterRetourNomsSci = function( data ) {
294
	var taxonSelecteur = '#taxon';
295
	var suggestions = [];
296
 
297
	if ( this.utils.valOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
298
		taxonSelecteur += '-autre';
299
	}
300
	if ( undefined != data.resultat ) {
301
		$.each( data.resultat, function( i, val ) {
302
			val.nn = i;
303
 
304
			var nom = {
305
				label : '',
306
				value : '',
307
				nt : 0,
308
				nomSel : '',
309
				nomSelComplet : '',
310
				numNomSel : 0,
311
				nomRet : '',
312
				numNomRet : 0,
313
				famille : '',
314
				retenu : false
315
			};
316
			if ( suggestions.length >= this.autocompletionElementsNbre ) {
317
				nom.label = '...';
318
				nom.value = $( taxonSelecteur ).val();
319
				suggestions.push( nom );
320
				return false;
321
			} else {
322
				nom.label = val.nom_sci_complet;
323
				nom.value = val.nom_sci_complet;
324
				nom.nt = val.num_taxonomique;
325
				nom.nomSel = val.nom_sci;
326
				nom.nomSelComplet = val.nom_sci_complet;
327
				nom.numNomSel = val.nn;
328
				nom.nomRet = val.nom_retenu_complet;
329
				nom.numNomRet = val['nom_retenu.id'];
330
				nom.famille = val.famille;
331
				// Tester dans ce sens, permet de considérer 'absent' comme 'false' => est-ce opportun ?
332
				// en tout cas c'est harmonisé avec le CeL
333
				nom.retenu = ( 'true' == val.retenu );
334
				suggestions.push( nom );
335
			}
336
		});
337
	}
338
	return suggestions;
339
};
340
 
341
/**
342
 * charge les données dans #taxon
343
 */
344
PlantesApa.prototype.surAutocompletionTaxon = function( event, ui ) {
345
	const utils = new UtilsApa();
346
 
347
	if ( utils.valOk( ui ) ) {
348
		$( '#taxon' ).val( ui.item.value );
349
		$( '#taxon' ).data( 'value', ui.item.value )
350
			.data( 'numNomSel', ui.item.numNomSel )
351
			.data( 'nomRet', ui.item.nomRet )
352
			.data( 'numNomRet', ui.item.numNomRet )
353
			.data( 'nt', ui.item.nt )
354
			.data( 'famille', ui.item.famille );
355
		if ( ui.item.retenu ) {
356
			$( '#taxon' ).addClass( 'ns-retenu' );
357
		} else {
358
			$( '#taxon' ).removeClass( 'ns-retenu' );
359
		}
360
		// Si l'espèce est mal déterminée la certitude est "à déterminer"
361
		if( !utils.valOk( $( '#taxon' ).data( 'numNomSel' ) ) ) {
362
			$( '#certitude' ).find( 'option' ).each( function() {
363
				if ( $( this ).hasClass( 'aDeterminer' ) ) {
364
					$( this ).attr( 'selected', true );
365
				} else {
366
					$( this ).attr( 'selected', false );
367
				}
368
			});
369
		}
370
	}
371
	$( '#taxon' ).change();
372
};
373
 
374
// Fichier Images *************************************************************/
375
/**
376
 * Affiche temporairement (formulaire)
377
 * la miniature d'une image ajoutée à l'obs
378
 */
379
PlantesApa.prototype.afficherMiniature = function( reponse ) {
380
	if ( this.debug ) {
381
		var debogage = $( 'debogage', reponse ).text();
382
	}
383
 
384
	var message = $( 'message', reponse ).text();
385
 
386
	if ( this.utils.valOk( message ) ) {
387
		$( '#miniature-msg' ).append( message );
388
	} else {
389
		$( '#miniatures' ).append( this.creerWidgetMiniature( reponse ) );
390
	}
391
	$( '#ajouter-obs' ).removeAttr( 'disabled' );
392
};
393
 
394
/**
395
 * Crée la miniature temporaire (formulaire) + bouton pour l'effacer
396
 */
397
PlantesApa.prototype.creerWidgetMiniature = function( reponse ) {
398
	var miniatureUrl = $( 'miniature-url', reponse ).text();
399
	var imgNom = $( 'image-nom', reponse ).text();
400
	var html =
401
		'<div class="miniature mb-3 mr-3">'+
402
			'<img class="miniature-img" class="miniature img-rounded" alt="' + imgNom + '" src="' + miniatureUrl + '"/>'+
403
			'<a class="effacer-miniature"><i class="fas fa-times"></i></a>'+
404
		'</div>';
405
 
406
	return html;
407
};
408
 
409
/**
410
 * Retourne true si l'extension de l'image 'nom' est .jpg ou .jpeg
411
 */
412
PlantesApa.prototype.verifierFormat = function( cheminTmp ) {
413
	var parts     = cheminTmp.split( '.' ),
414
		extension = parts[ parts.length - 1 ];
415
 
416
	return ( 'jpeg' === extension.toLowerCase() || 'jpg' === extension.toLowerCase() );
417
};
418
 
419
/**
420
 * Check les miniatures déjà téléchargées
421
 * renvoie false si le même nom est rencontré 2 fois
422
 * renvoie true sinon
423
 */
424
PlantesApa.prototype.verifierDuplication = function( cheminTmp ) {
425
	const lthis = this;
426
	var parts        = cheminTmp.split( '\\' ),
427
		nomImage     = parts[ parts.length - 1 ],
428
		thisSrcParts = [],
429
		thisNomImage = '',
430
		nonDupliquee = true;
431
 
432
	$( 'img.miniature-img,img.miniature' ).each( function() {
433
		// vérification avec alt de l'image
434
		if ( lthis.utils.valOk ( $( this ).attr ( 'alt' ), true, nomImage ) ) {
435
			nonDupliquee = false;
436
			return false;// Pas besoin de poursuivre la boucle
437
		} else { // sinon vérifie aussi avec l'adresse (src) de l'image
438
			thisSrcParts = $( this ).attr( 'src' ).split( '/' );
439
			thisNomImage = thisSrcParts[ thisSrcParts.length - 1 ].replace( '_min', '' );
440
			if ( lthis.utils.valOk ( thisNomImage, true, nomImage ) ) {
441
				nonDupliquee = false;
442
				return false;
443
			}
444
		}
445
	});
446
	return nonDupliquee;
447
};
448
 
449
/**
450
 * Efface une miniature (formulaire)
451
 */
452
PlantesApa.prototype.supprimerMiniature = function( miniature ) {
453
	miniature.parents( '.miniature' ).remove();
454
};
455
 
456
// Ajouter Obs ****************************************************************/
457
 
458
/**
459
 * Ajoute une observation à la liste des obs à transmettre
460
 * (résumé obs)
461
 */
462
PlantesApa.prototype.ajouterObs = function() {
463
	// Fermeture automatique des dialogue de transmission de données
464
	// @WARNING TEST
465
	$( '#dialogue-obs-transaction-ko' ).addClass( 'hidden' );
466
	$( '#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
467
	$( 'html, body' ).stop().animate({
468
		scrollTop: $( '#zone-plantes' ).offset().top
469
	}, 300);
470
 
471
	if ( this.validerPlantes() ) {
472
		this.masquerPanneau( '#dialogue-form-invalide' );
473
		this.obsNbre  += 1;
474
		$( '.obs-nbre' ).text( this.obsNbre );
475
		$( '.obs-nbre' ).triggerHandler( 'changement' );
476
		//formatage des données
477
		var obsData   = this.formaterFormObsData();
478
 
479
		// Résumé obs et stockage en data de "#list-obs" pour envoi
480
		this.afficherObs( obsData );
481
		this.stockerObsData( obsData );
482
		this.supprimerMiniatures();
483
		$( '#taxon' ).val( '' );
484
		$( '#taxon' ).removeData( 'value' )
485
			.removeData( 'numNomSel' )
486
			.removeData( 'nomRet' )
487
			.removeData( 'numNomRet' )
488
			.removeData( 'nt' )
489
			.removeData( 'famille' );
490
		$( '#taxon-liste' ).find( 'option' ).each( function() {
491
			if ( $( this ).hasClass( 'choisir' ) ) {
492
				$( this ).attr( 'selected', true );
493
			} else {
494
				$( this ).attr( 'selected', false );
495
			}
496
		});
497
		$( '#taxon-input-groupe' ).addClass( 'hidden' );
498
		$( '#taxon-autre' ).val( '' );
499
		$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
500
		$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.utils.msgTraduction( 'observations-transmises' ) );
501
	} else {
502
		this.afficherPanneau( '#dialogue-form-invalide' );
503
	}
504
};
505
 
506
/**
507
 * Formatage des données du formulaire pour stockage et envoi
508
 */
509
PlantesApa.prototype.formaterFormObsData = function() {
510
	var numArbre = $( '#choisir-arbre' ).val(),
511
		miniatureImg  = [],
512
		imgB64        = [],
513
		imgNom        = [],
514
		numNomSel     = $( '#taxon' ).data( 'numNomSel' ),
515
		referentiel   = ( !this.utils.valOk( numNomSel ) ) ? 'autre' : 'bdtfx';
516
 
517
	this.releveDatas = $.parseJSON( $( '#releve-data' ).val() );
518
	imgNom = this.getNomsImgsOriginales();
519
	imgB64 = this.getB64ImgsOriginales();
520
 
521
	var obsData = {
522
		obsNum   : this.obsNbre,
523
		numArbre : numArbre,
524
		plante   : {
525
			'num_nom_sel'   : numNomSel,
526
			'nom_sel'       : $( '#taxon' ).val(),
527
			'nom_ret'       : $( '#taxon' ).data( 'nomRet' ),
528
			'num_nom_ret'   : $( '#taxon' ).data( 'numNomRet' ),
529
			'num_taxon'     : $( '#taxon' ).data( 'nt' ),
530
			'famille'       : $( '#taxon' ).data( 'famille' ),
531
			'referentiel'   : referentiel,
532
			'certitude'     : ( !this.utils.valOk( numNomSel ) ) ? $( '#certitude' ).val() : 'à determiner',
533
			'date'          : this.utils.fournirDate( $( '#obs-date' ).val() ),
534
			'notes'         : $( '#commentaire' ).val(),
535
			'pays'          : this.releveDatas[0].pays,
536
			'commune_nom'   : this.releveDatas[0]['commune-nom'],
537
			'commune_code_insee' : this.releveDatas[0]['commune-insee'],
538
			'latitude'      : this.releveDatas[numArbre]['latitude-arbres'],
539
			'longitude'     : this.releveDatas[numArbre]['longitude-arbres'],
540
			'altitude'      : this.releveDatas[numArbre]['altitude-arbres'],
541
			//Ajout des champs images
542
			'image_nom'     : imgNom,
543
			'image_b64'     : imgB64,
544
			// Ajout des champs étendus de l'obs
545
			'obs_etendue'   : [
546
				{ cle : 'num-arbre', valeur : numArbre },
547
				{ cle : 'id_obs_arbre', valeur : this.releveDatas[numArbre]['id_observation'] },
548
				{ cle : 'rue' , valeur : this.releveDatas[0].rue  }
549
			]
550
		}
551
	};
552
	return obsData;
553
};
554
 
555
/**
556
 * Résumé obs
557
 */
558
PlantesApa.prototype.afficherObs = function( datasObs ) {
559
	var obsNum            = datasObs.obsNum,
560
		numArbre          = datasObs.numArbre,
561
		dateObs           = datasObs.plante.date,
562
		numNomSel         = datasObs.plante['num_nom_sel'],
563
		taxon             = datasObs.plante['nom_sel'],
564
		certitude         = datasObs.plante.certitude,
565
		miniatures        = this.ajouterImgMiniatureAuTransfert(),
566
		commentaires      = '';
567
 
568
	if ( this.utils.valOk( datasObs.plante.notes ) ) {
569
		commentaires =
570
			this.utils.msgTraduction( 'commentaires' ) +
571
			' : <span>'+
3313 idir 572
				datasObs.plante.notes +
3312 idir 573
			'</span> ';
574
	}
575
 
576
	var responsivDiff1 = '',
577
		responsivDiff2 = '',
578
		responsivDiff3 = '',
579
		responsivDiff4 = '',
580
		responsivDiff5 = '',
581
		responsivDiff6 = '';
582
 
583
	if ( window.matchMedia( '(min-width: 576px)' ).matches ) {
584
		/* La largeur minimum de l'affichage est 600 px inclus */
585
		responsivDiff1 = ' droite';
586
		responsivDiff2 = '<div></div>';
587
		responsivDiff3 = '<div class="row">';
588
		responsivDiff4 = ' col-md-4 col-sm-5';
589
		responsivDiff5 = ' class="col-md-7 col-sm-6"';
590
		responsivDiff6 = '</div>';
591
	}
592
	$( '#liste-obs' ).prepend(
593
		'<div id="obs' + obsNum + '" class="obs obs' + obsNum + ' mb-2">'+
594
			'<div '+
595
				'class="obs-action" '+
596
				'title="' + this.utils.msgTraduction( 'supprimer-observation-liste' ) + '"'+
597
			'>'+
598
				'<button class="btn btn-danger supprimer-obs' + responsivDiff1 + '" value="'+ obsNum + '" title="' + this.utils.msgTraduction( 'obs-numero' ) + obsNum + '">'+
599
				'<i class="far fa-trash-alt"></i>'+
600
				'</button>'+
601
				responsivDiff2 +
602
			'</div> '+
603
			responsivDiff3 +
604
				'<div class="thumbnail' + responsivDiff4 + '">'+
605
					miniatures+
606
				'</div>'+
607
				'<div' + responsivDiff5 + '>'+
608
					'<ul class="unstyled">'+
609
						'<li>'+
610
							'<span id="obs-arbre-' + numArbre + '" class="badge num-obs-arbre" data-arbre="' + numArbre + '">Arbre ' + numArbre + '</span>' +
611
							' <span class="nom-sci">' + taxon + '</span> '+
612
							this.ajouterNumNomSel( numNomSel ) +
613
							' [certitude : ' + certitude + ']'+
614
							' ' + this.utils.msgTraduction( 'obs-le' ) + ' ' +
615
							'<span class="date">' + dateObs + '</span>'+
616
						'</li>'+
617
						'<li>'+
618
							commentaires +
619
						'</li>'+
620
					'</ul>'+
621
				'</div>'+
622
			responsivDiff6+
623
		'</div>'
624
	);
625
	$( '#zone-liste-obs' ).removeClass( 'hidden' );
626
};
627
 
628
/**
629
 * Ajoute une boîte de miniatures avec défilement des images,
630
 * pour une obs de la liste des obs à transmettre
631
 */
632
PlantesApa.prototype.ajouterImgMiniatureAuTransfert = function() {
633
	var html        =
634
			'<div class="defilement-miniatures">'+
635
				'<figure class="centre">'+
636
					'<img class="miniature align-middle" alt="Aucune photo" src="' + this.pasDePhotoIconeUrl + '" width="80%" />'+
637
				'</figure>'+
638
			'</div>',
639
		miniatures   = '',
640
		premiere     = true,
641
		centre       = '';
642
		defilVisible = '';
643
 
644
	if ( this.utils.valOk( $( '#miniatures img' ) ) ) {
645
		$( '#miniatures img' ).each( function() {
646
			var imgVisible = ( premiere ) ? 'miniature-selectionnee' : 'miniature-cachee';
647
			premiere = false;
648
 
649
			var css        = ( $( this ).hasClass( 'b64' ) ) ? 'miniature b64' : 'miniature',
650
				src        = $( this ).attr( 'src' ),
651
				alt        = $( this ).attr( 'alt' ),
652
				miniature  = '<img class="' + css + ' ' + imgVisible + ' align-middle"  alt="' + alt + '"src="' + src + '" width="80%" />';
653
 
654
			miniatures += miniature;
655
		});
656
		if ( 1 === $( '#miniatures img' ).length ) {
657
			centre       = 'centre';
658
			defilVisible = ' defilement-miniatures-cache';
659
		}
660
		html             =
661
			'<div class="defilement-miniatures">'+
662
				'<a href="#" class="defilement-miniatures-gauche mr-1' + defilVisible + '"><i class="fas fa-chevron-circle-left"></i></a>'+
663
				'<figure class="' + centre + '">'+
664
					miniatures+
665
				'</figure>'+
666
				'<a href="#" class="defilement-miniatures-droite ml-1' + defilVisible + '"><i class="fas fa-chevron-circle-right"></i></a>'+
667
			'</div>';
668
	}
669
	return html;
670
};
671
 
672
/**
673
 * Construit le html à afficher pour le numNom
674
 */
675
PlantesApa.prototype.ajouterNumNomSel = function( numNomSel ) {
676
	var nn = '<span class="nn">[nn' + numNomSel + ']</span>';
677
 
678
	if ( !this.utils.valOk( numNomSel ) ) {
679
		nn = '<span class="alert-error">[' + this.utils.msgTraduction( 'non-lie-au-ref' ) + ']</span>';
680
	}
681
 
682
	return nn;
683
};
684
 
685
/**
686
 * Stocke des données d'obs à envoyer à la bdd
687
 */
688
PlantesApa.prototype.stockerObsData = function( datasObs ) {
689
	// Stockage en data des données d'obs à transmettre
690
	$( '#liste-obs' ).data( 'obsId' + datasObs.obsNum, datasObs.plante );
691
};
692
 
693
PlantesApa.prototype.getNomsImgsOriginales = function() {
694
	var noms = new Array();
695
 
696
	$( '.miniature-img' ).each( function() {
697
		noms.push( $( this ).attr( 'alt' ) );
698
	});
699
 
700
	return noms;
701
};
702
 
703
PlantesApa.prototype.getB64ImgsOriginales = function() {
704
	var b64 = new Array();
705
 
706
	$( '.miniature-img' ).each( function() {
707
		if ( $( this ).hasClass( 'b64' ) ) {
708
			b64.push( $( this ).attr( 'src' ) );
709
		} else if ( $( this ).hasClass( 'b64-canvas' ) ) {
710
			b64.push( $( this ).data( 'b64' ) );
711
		}
712
	});
713
 
714
	return b64;
715
};
716
 
717
/**
718
 * Efface toutes les miniatures (formulaire)
719
 */
720
PlantesApa.prototype.supprimerMiniatures = function() {
721
	$( '#miniatures' ).empty();
722
	$( '#miniature-msg' ).empty();
723
};
724
 
725
PlantesApa.prototype.surChangementNbreObs = function() {
726
	if ( 0 === this.obsNbre ) {
727
		$( '#transmettre-obs' ).attr( 'disabled', 'disabled' );
728
	} else if ( 0 < this.obsNbre && this.obsNbre < this.obsMaxNbre ) {
729
		$( '#ajouter-obs,#transmettre-obs' ).removeAttr( 'disabled' );
730
	} else if ( this.obsNbre >= this.obsMaxNbre ) {
731
		$( '#ajouter-obs' ).attr( 'disabled', 'disabled' );
732
		this.afficherPanneau( '#dialogue-bloquer-creer-obs' );
733
	}
734
};
735
 
736
PlantesApa.prototype.defilerMiniatures = function( element ) {
737
	var miniatureSelectionne  = element.siblings( 'figure' ).find( 'img.miniature-selectionnee' );
738
 
739
	miniatureSelectionne.removeClass( 'miniature-selectionnee' );
740
	miniatureSelectionne.addClass( 'miniature-cachee' );
741
 
742
	var miniatureAffichee     = miniatureSelectionne;
743
 
744
	if( element.hasClass( 'defilement-miniatures-gauche' ) ) {
745
		if( 0 !== miniatureSelectionne.prev( '.miniature' ).length ) {
746
			miniatureAffichee = miniatureSelectionne.prev( '.miniature' );
747
		} else {
748
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).last();
749
		}
750
	} else {
751
		if( 0 !== miniatureSelectionne.next('.miniature').length ) {
752
			miniatureAffichee = miniatureSelectionne.next( '.miniature' );
753
		} else {
754
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).first();
755
		}
756
	}
757
	miniatureAffichee.addClass( 'miniature-selectionnee' );
758
	miniatureAffichee.removeClass( 'miniature-cachee' );
759
};
760
 
761
PlantesApa.prototype.supprimerObs = function( selector ) {
762
	var obsId = $( selector ).val();
763
 
764
	// Problème avec IE 6 et 7
765
	if ( 'Supprimer' === obsId ) {
766
		obsId = $( selector ).attr( 'title' );
767
	}
768
	this.supprimerObsParId( obsId );
769
};
770
 
771
/**
772
 * Supprime l'obs et les data de l'obs
773
 * et remonte les suivantes d'un cran
774
 */
775
PlantesApa.prototype.supprimerObsParId = function( obsId ) {
776
	this.obsNbre  -= 1;
777
	$( '.obs-nbre' ).text( this.obsNbre );
778
	$( '.obs-nbre' ).triggerHandler( 'changement' );
779
	$( '.obs' + obsId ).remove();
780
 
781
	obsId = parseInt(obsId);
782
	var listObsData = $( '#liste-obs' ).data(),
783
		exId        = 0,
784
		indexObs    = '',
785
		exIndexObs  = '';
786
 
787
	for ( var id = obsId; id <= ( this.obsNbre + 1 ); id++ ) {
788
		exId       = parseInt(id) + 1;
789
		indexObs   = 'obsId' + id;
790
		exIndexObs = 'obsId' + exId;
791
		$( '#liste-obs' ).removeData( indexObs );
792
		if ( this.utils.valOk( listObsData[ exIndexObs ] ) ) {
793
			$( '#liste-obs' ).data( indexObs, listObsData[ exIndexObs ] );
794
		}
795
		$( '#obs' + exId )
796
			.attr( 'id', 'obs' + id )
797
			.removeClass( 'obs' + exId )
798
			.addClass( 'obs' + id )
799
			.find( '.supprimer-obs' )
800
				.attr( 'title', 'Observation n°' + id )
801
				.val( id );
802
		if ( parseInt( id ) !== this.obsNbre ) {
803
			id = parseInt( id );
804
		}
805
	}
806
};
807
 
808
PlantesApa.prototype.transmettreObs = function() {
809
	const lthis = this;
810
	var observations = $( '#liste-obs' ).data();
811
 
812
	if ( this.debug ) {
813
		console.log( observations );
814
	}
815
	if ( !this.utils.valOk( typeof observations, true, 'object' ) ) {
816
		this.afficherPanneau( '#dialogue-zero-obs' );
817
	} else {
818
		$( window ).on( 'beforeunload', function( event ) {
819
			return lthis.utils.msgTraduction( 'rechargement-page' );
820
		});
821
		this.nbObsEnCours         = 1;
822
		this.nbObsTransmises      = 0;
823
		this.totalObsATransmettre = $.map( observations, function( n, i ) {
824
			return i;
825
		}).length;
826
		this.depilerObsPourEnvoi();
827
	}
828
 
829
	return false;
830
};
831
 
832
PlantesApa.prototype.depilerObsPourEnvoi = function() {
833
	var observations = $( '#liste-obs' ).data();
834
 
835
	// la boucle est factice car on utilise un tableau
836
	// dont on a besoin de n'extraire que le premier élément
837
	// or javascript n'a pas de méthode cross browsers pour extraire les clés
838
	// TODO: utiliser var.keys quand ça sera plus répandu
839
	// ou bien utiliser un vrai tableau et pas un objet
840
	for ( var obsNum in observations ) {
841
		var obsATransmettre = {
842
			'projet'  : this.tagProjet,
843
			'tag-obs' : this.tagObs,
844
			'tag-img' : this.tagImg
845
		};
846
		var utilisateur = {
847
			id_utilisateur : this.infosUtilisateur.id,
848
			prenom         : this.infosUtilisateur.prenom,
849
			nom            : this.infosUtilisateur.nom,
850
			courriel       : $( '#courriel' ).val()
851
		};
852
 
853
		obsATransmettre['utilisateur'] = utilisateur;
854
		obsATransmettre[obsNum]        = observations[obsNum];
855
 
856
		var idObsNumerique = obsNum.replace( 'obsId', '' );
857
 
858
		if( '' !== idObsNumerique ) {
859
			this.envoyerObsAuCel( idObsNumerique, obsATransmettre );
860
		}
861
		break;
862
	}
863
};
864
 
865
PlantesApa.prototype.envoyerObsAuCel = function( idObs, observation ) {
866
	const lthis     = this;
867
	var erreurMsg = '';
868
 
869
	$.ajax({
870
		url        : lthis.serviceSaisieUrl,
871
		type       : 'POST',
872
		data       : observation,
873
		dataType   : 'json',
874
		beforeSend : function() {
875
			$( '#dialogue-obs-transaction-ko' ).addClass( 'hidden' );
876
			$( '#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
877
			$( '.alert-txt' ).empty();
878
			$( '.alert-txt .msg-erreur' ).remove();
879
			$( '.alert-txt .msg-debug' ).remove();
880
			$( '#chargement' ).removeClass( 'hidden' );
881
		},
882
		success    : function( data, textStatus, jqXHR ) {
883
			// mise à jour du nombre d'obs à transmettre
884
			// et suppression de l'obs
885
			lthis.supprimerObsParId( idObs );
886
			lthis.nbObsEnCours++;
887
			// mise à jour du statut
888
			lthis.mettreAJourProgression();
889
			if( 0 < lthis.obsNbre ) {
890
				// dépilement de la suivante
891
				lthis.depilerObsPourEnvoi();
892
			}
893
		},
894
		statusCode  : {
895
			500 : function( jqXHR, textStatus, errorThrown ) {
896
				erreurMsg += lthis.utils.msgTraduction( 'erreur' ) + ' 500 :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
897
				}
898
		},
899
		error        : function( jqXHR, textStatus, errorThrown ) {
900
			erreurMsg += lthis.utils.msgTraduction( 'erreur-ajax' ) + ' :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
901
			try {
902
				reponse = jQuery.parseJSON( jqXHR.responseText );
903
				if ( null !== reponse ) {
904
					$.each( reponse, function( cle, valeur ) {
905
						erreurMsg += valeur + '\n';
906
					});
907
				}
908
			} catch( e ) {
909
				erreurMsg += lthis.utils.msgTraduction( 'erreur-inconnue' ) + ' : ' + jqXHR.responseText;
910
			}
911
		},
912
		complete      : function( jqXHR, textStatus ) {
913
			var debugMsg = extraireEnteteDebug( jqXHR );
914
 
915
			if ( '' !== erreurMsg ) {
916
				if ( lthis.debug ) {
917
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-erreur">' + erreurMsg + '</pre>' );
918
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
919
				}
920
				var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?'+
921
					'subject=Dysfonctionnement du widget de saisie ' + lthis.tagProjet+
922
					'&body=' + erreurMsg + '%0D%0ADébogage :%0D%0A' + debugMsg;
923
 
924
				// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
925
				$( '#obs' + idObs + ' div div' ).addClass( 'obs-erreur' );
926
				// window.location.hash = 'obs' + idObs;
927
 
928
				$( '#dialogue-obs-transaction-ko .alert-txt' ).append(
929
					$( '#tpl-transmission-ko' ).clone()
930
						.find( '.courriel-erreur' )
931
						.attr( 'href', hrefCourriel )
932
						.end()
933
						.html()
934
				);
935
				$( '#dialogue-obs-transaction-ko' ).removeClass( 'hidden' );
936
				$( '#chargement' ).addClass( 'hidden' );
937
				lthis.initialiserBarreProgression;
938
			} else {
939
				if ( lthis.debug ) {
940
					$( '#dialogue-obs-transaction-ok .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
941
				}
942
				if( 0 === lthis.obsNbre ) {
943
					setTimeout( function() {
944
						$( '#chargement,#bloc-gauche,#bloc-controle-liste-obs' ).addClass( 'hidden' );
945
						$( '#dialogue-obs-transaction-ok .alert-txt' ).append( $( '#tpl-transmission-ok' ).clone().html() );
946
						$( '#dialogue-obs-transaction-ok,#bouton-poursuivre' ).removeClass( 'hidden' );
947
					}, 1500 );
948
				}
949
			}
950
		}
951
	});
952
};
953
 
954
PlantesApa.prototype.mettreAJourProgression = function() {
955
	this.nbObsTransmises++;
956
 
957
	var pct = ( this.nbObsTransmises / this.totalObsATransmettre ) * 100;
958
 
959
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', this.nbObsTransmises );
960
	$( '#barre-progression-upload' ).css( 'width', pct + '%' );
961
	$( '#barre-progression-upload .sr-only' ).text( this.nbObsTransmises + '/' + this.totalObsATransmettre + ' ' + this.utils.msgTraduction( 'observations-transmises' ) );
962
	if( 0 === this.obsNbre ) {
963
		$( '.progress' ).removeClass( 'active' );
964
		$( '.progress' ).removeClass( 'progress-bar-striped' );
965
	}
966
};
967
 
968
PlantesApa.prototype.initialiserBarreProgression = function() {
969
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', 0 );
970
	$( '#barre-progression-upload' ).css( 'width', '0%' );
971
	$( '#barre-progression-upload .sr-only' ).text( '0/0 ' + this.utils.msgTraduction( 'observations-transmises' ) );
972
	$( '.progress' ).addClass( 'active' );
973
	$( '.progress' ).addClass( 'progress-bar-striped' );
974
};
975
 
976
// Form Validator *************************************************************/
977
PlantesApa.prototype.configurerFormValidator = function() {
978
	const lthis = this;
979
 
980
	$.validator.addMethod(
981
		'dateCel',
982
		function ( value, element ) {
983
			return ( /^(?:[0-9]{4}-[0-9]{2}-[0-9]{2})|(?:[0-9]{2}\/[0-9]{2}\/[0-9]{4})$/.test( value ) );
984
		},
985
		lthis.utils.msgTraduction( 'date-incomplete' )
986
	);
987
 
988
	$.validator.addMethod(
989
		'userEmailOk',
990
		function ( value, element ) {
991
			return ( lthis.utils.valOk( value ) );
992
		},
993
		''
994
	);
995
 
996
	$.extend( $.validator.defaults, {
997
		errorElement: 'span',
998
		errorPlacement: function( error, element ) {
999
			element.after( error );
1000
		},
1001
		onfocusout: function( element ) {
1002
			if( lthis.utils.valOk( element.id, false, 'taxon' ) ) {
1003
				if ( $( element ).valid() ) {
1004
					$( element ).closest( '.control-group' ).removeClass( 'error' );
1005
				} else {
1006
					$( element ).closest( '.control-group' ).addClass( 'error' );
1007
				}
1008
			}
1009
		},
1010
		onkeyup : function( element ) {
1011
			if( lthis.utils.valOk( element.id, false, 'taxon' ) ) {
1012
				if ( $( element ).valid() ) {
1013
					$( element ).closest( '.control-group' ).removeClass( 'error' );
1014
				} else {
1015
					$( element ).closest( '.control-group' ).addClass( 'error' );
1016
				}
1017
			}
1018
		},
1019
		unhighlight: function( element ) {
1020
			if( lthis.utils.valOk( element.id, false, 'taxon' ) ) {
1021
				$( element ).closest( '.control-group' ).removeClass( 'error' );
1022
			}
1023
		},
1024
		highlight: function( element ) {
1025
			$( element ).closest( '.control-group' ).addClass( 'error' );
1026
		}
1027
	});
1028
};
1029
 
1030
PlantesApa.prototype.definirReglesFormValidator = function() {
1031
	const lthis = this;
1032
 
1033
	$( 'input[type=date]' ).on( 'input', function() {
1034
		$( this ).valid();
1035
	});
1036
	// Validation Taxon si pas de miniature
1037
	$( '#taxon' ).on( 'change', function() {
1038
		var images = lthis.utils.valOk( $( '#miniatures .miniature' ) );
1039
		lthis.validerTaxonImage( lthis.utils.valOk( $( this ).val() ), images );
1040
	});
1041
 
1042
	// // Validation miniatures avec MutationObserver
1043
	// this.surPresenceAbsenceMiniature();
1044
 
1045
	$( '#form-plantes' ).validate({
1046
		rules : {
1047
			'choisir-arbre' : {
1048
				required : true,
1049
				minlength : 1
1050
			},
1051
			'obs-date' : {
1052
				required : true,
1053
				'dateCel' : true
1054
			},
1055
			certitude : {
1056
				required : true,
1057
				minlength : 1
1058
			}
1059
		}
1060
	});
1061
	$( '#form-observateur' ).validate({
1062
		rules : {
1063
			courriel : {
1064
				required : true,
1065
				minlength : 1,
1066
				email : true,
1067
				'userEmailOk' : true
1068
			},
1069
			mdp : {
1070
				required : true,
1071
				minlength : 1
1072
			}
1073
		}
1074
	});
1075
	$( '#connexion,#inscription,#oublie' ).click( function() {
1076
		$( '#tb-observateur .control-group' ).removeClass( 'error' );
1077
	});
1078
};
1079
 
1080
PlantesApa.prototype.validerTaxonImage = function( taxon = false, images = false ) {
1081
	var taxonOuImage = ( images || taxon );
1082
	if ( images || taxon ) {
1083
		this.masquerPanneau( '#dialogue-taxon-or-image' );
1084
		$( '#bloc-taxon' ).removeClass( 'error' )
1085
			.find( 'span.error' ).hide();
1086
		$( '#fichier' ).parent( 'label.label-file' ).removeClass( 'error' );
1087
		$( '#photos-conteneur').removeClass( 'error' ).find( 'span.error' ).hide();
1088
		// faire passer la certitude à 'à déterminer' si on a une image et pas de taxon
1089
		if( !taxon ) {
1090
			$( '#certitude' ).find( 'option' ).each( function() {
1091
				if ( $( this ).hasClass( 'aDeterminer' ) ) {
1092
					$( this ).attr( 'selected', true );
1093
				} else {
1094
					$( this ).attr( 'selected', false );
1095
				}
1096
			});
1097
		}
1098
	} else {
1099
		this.afficherPanneau( '#dialogue-taxon-or-image' );
1100
		$( '#bloc-taxon' ).addClass( 'error' )
1101
			.find( 'span.error' ).show();
1102
		$( '#fichier' ).parent( 'label.label-file' ).addClass( 'error' );
1103
		$( '#photos-conteneur').addClass( 'error' ).find( 'span.error' ).show();
1104
	}
1105
	return ( images || taxon );
1106
};
1107
 
1108
/**
1109
 * Valide le formulaire au click sur un bouton "suivant"
1110
 */
1111
PlantesApa.prototype.validerPlantes = function() {
1112
	const images       = this.utils.valOk( $( '#miniatures .miniature' ) );
1113
	const taxon        = this.utils.valOk( $( '#taxon' ).val() );
1114
	const taxonOuImage = this.validerTaxonImage( taxon, images );
1115
	const observateur  = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() )
1116
	const obs          = $( '#form-plantes' ).valid();
1117
 
1118
	// panneau observateur
1119
	if ( observateur ) {
1120
		this.masquerPanneau( '#dialogue-utilisateur-non-identifie' );
1121
		$( '#tb-observateur .control-group' ).removeClass( 'error' );
1122
	} else {
1123
		this.afficherPanneau( '#dialogue-utilisateur-non-identifie' );
1124
		$( '#tb-observateur .control-group' ).addClass( 'error' );
1125
	}
1126
 
1127
	return ( observateur && obs && taxonOuImage );
1128
};
1129
 
1130
// Controle des panneaux d'infos **********************************************/
1131
 
1132
PlantesApa.prototype.afficherPanneau = function( selecteur ) {
1133
	$( selecteur )
1134
		.removeClass( 'hidden' )
1135
		.hide()
1136
		.show( 600 )
1137
		.delay( this.dureeMessage )
1138
		.hide( 600 );
1139
	$( 'html, body' ).stop().animate({scrollTop: $( selecteur ).offset().top}, 300);
1140
};
1141
 
1142
PlantesApa.prototype.masquerPanneau = function( selecteur ) {
1143
	$( selecteur ).addClass( 'hidden' );
1144
};
1145
 
1146
PlantesApa.prototype.fermerPanneauAlert = function() {
1147
	$( this ).parentsUntil( '.zone-alerte', '.alert' ).addClass( 'hidden' );
1148
};
1149
 
1150
// lib hors objet --
1151
 
1152
/**
1153
* Stope l'évènement courant quand on clique sur un lien.
1154
* Utile pour Chrome, Safari...
1155
*/
1156
function arreter( event ) {
1157
	if ( event.stopPropagation ) {
1158
		event.stopPropagation();
1159
	}
1160
	if ( event.preventDefault ) {
1161
		event.preventDefault();
1162
	}
1163
 
1164
	return false;
1165
}
1166
 
1167
/**
1168
 * Extrait les données de désinsectisation d'une requête AJAX de jQuery
1169
 * @param jqXHR
1170
 * @returns {String}
1171
 */
1172
function extraireEnteteDebug( jqXHR ) {
1173
	var msgDebug = '';
1174
 
1175
	if ( '' !== jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) ) {
1176
		var debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) );
1177
		if ( null !== debugInfos ) {
1178
			$.each( debugInfos, function( cle, valeur ) {
1179
				msgDebug += valeur + '\n';
1180
			});
1181
		}
1182
	}
1183
 
1184
	return msgDebug;
1185
}
1186
 
1187
/*
1188
 * jQuery UI Autocomplete HTML Extension
1189
 *
1190
 * Copyright 2010, Scott González (http://scottgonzalez.com)
1191
 * Dual licensed under the MIT or GPL Version 2 licenses.
1192
 *
1193
 * http://github.com/scottgonzalez/jquery-ui-extensions
1194
 *
1195
 * Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
1196
 */
1197
( function( $ ) {
1198
	var proto      = $.ui.autocomplete.prototype,
1199
		initSource = proto._initSource;
1200
 
1201
	PlantesApa.prototype.filter = function( array, term ) {
1202
		var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), 'i' );
1203
 
1204
		return $.grep( array, function( value ) {
1205
 
1206
			return matcher.test( $( '<div>' ).html( value.label || value.value || value ).text() );
1207
		});
1208
	}
1209
	$.extend( proto, {
1210
		_initSource: function() {
1211
			if ( this.options.html && $.isArray( this.options.source ) ) {
1212
				this.source = function( request, response ) {
1213
					response( filter( this.options.source, request.term ) );
1214
				};
1215
			} else {
1216
				initSource.call( this );
1217
			}
1218
		},
1219
		_renderItem: function( ul, item) {
1220
			if ( item.retenu ) {
1221
				item.label = '<strong>' + item.label + '</strong>';
1222
			}
1223
 
1224
			return $( '<li></li>' )
1225
				.data( 'item.autocomplete', item )
1226
				.append( $( '<a></a>' )[ ( this.options.html ) ? 'html' : 'text' ]( item.label ) )
1227
				.appendTo( ul );
1228
		}
1229
	});
1230
})( jQuery );