Subversion Repositories eFlore/Applications.cel

Rev

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

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