Subversion Repositories eFlore/Applications.cel

Rev

Rev 3333 | Rev 3363 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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