Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3432 Rev 3433
1
const utils = new Utils;
1
const utils = new Utils;
2
 
2
 
3
/**
3
/**
4
 * WidgetsSaisiesCommun
4
 * WidgetsSaisiesCommun
5
 * Methodes communes aux widgets de saisie
5
 * Methodes communes aux widgets de saisie
6
 */
6
 */
7
function WidgetsSaisiesCommun(){}
7
function WidgetsSaisiesCommun(){}
8
 
8
 
9
WidgetsSaisiesCommun.prototype.init = function() {
9
WidgetsSaisiesCommun.prototype.init = function() {
10
	// ASL : APA, sTREETs, Lichen's Go!
10
	// ASL : APA, sTREETs, Lichen's Go!
11
	// const ASL = ['tb_aupresdemonarbre','tb_streets','tb_lichensgo'];
11
	// const ASL = ['tb_aupresdemonarbre','tb_streets','tb_lichensgo'];
12
	// this.isASL = ( utils.valOk( this.module ) && -1 < $.inArray( this.module , ASL ) );
12
	// this.isASL = ( utils.valOk( this.module ) && -1 < $.inArray( this.module , ASL ) );
13
	this.initForm();
13
	this.initForm();
14
	this.initEvts();
14
	this.initEvts();
15
};
15
};
16
 
16
 
17
WidgetsSaisiesCommun.prototype.initFormConnection = function() {
17
WidgetsSaisiesCommun.prototype.initFormConnection = function() {
18
	this.urlBaseAuth = this.urlRacine + '/service:annuaire:auth';
18
	this.urlBaseAuth = this.urlRacine + '/service:annuaire:auth';
19
	$( '#inscription' ).attr( 'href',  this.urlSiteTb() + 'inscription' );
19
	$( '#inscription' ).attr( 'href',  this.urlSiteTb() + 'inscription' );
20
	if ( this.isASL ) {
20
	if ( this.isASL ) {
21
		$( '#mdp' ).val( '' );
21
		$( '#mdp' ).val( '' );
22
		$( '#oublie' ).attr( 'href',  this.urlSiteTb() + 'wp-login.php?action=lostpassword' );
22
		$( '#oublie' ).attr( 'href',  this.urlSiteTb() + 'wp-login.php?action=lostpassword' );
23
	}
23
	}
24
};
24
};
25
 
25
 
26
WidgetsSaisiesCommun.prototype.initFormTaxonListe = function() {
26
WidgetsSaisiesCommun.prototype.initFormTaxonListe = function() {
27
	const lthis = this;
27
	const lthis = this;
28
 
28
 
29
	this.surChangementTaxonListe();
29
	this.surChangementTaxonListe();
30
	$( '#taxon-liste' ).on( 'change', lthis.surChangementTaxonListe );
30
	$( '#taxon-liste' ).on( 'change', lthis.surChangementTaxonListe );
31
	$( '#taxon-liste' ).on( 'change', lthis.surChangementValeurTaxon.bind( lthis ) );
31
	$( '#taxon-liste' ).on( 'change', lthis.surChangementValeurTaxon.bind( lthis ) );
32
	if ( this.debug ) {
32
	if ( this.debug ) {
33
		console.dir( 'Selected taxon:' + $( '#taxon-liste option:selected' ).val());
33
		console.dir( 'Selected taxon:' + $( '#taxon-liste option:selected' ).val());
34
	}
34
	}
35
};
35
};
36
 
36
 
37
WidgetsSaisiesCommun.prototype.initEvtsConnection = function() {
37
WidgetsSaisiesCommun.prototype.initEvtsConnection = function() {
38
	const lthis = this;
38
	const lthis = this;
39
 
39
 
40
	this.chargerStatutSSO();
40
	this.chargerStatutSSO();
41
	$( '#utilisateur-connecte .volet-toggle, #profil-utilisateur a, #deconnexion a' ).on( 'click', function( event ) {
41
	$( '#utilisateur-connecte .volet-toggle, #profil-utilisateur a, #deconnexion a' ).on( 'click', function( event ) {
42
		if( $( this ).hasClass( 'volet-toggle' ) ) {
42
		if( $( this ).hasClass( 'volet-toggle' ) ) {
43
			event.preventDefault();
43
			event.preventDefault();
44
		}
44
		}
45
		$( '#utilisateur-connecte .volet-menu' ).toggleClass( 'hidden' );
45
		$( '#utilisateur-connecte .volet-menu' ).toggleClass( 'hidden' );
46
	});
46
	});
47
	$( '#deconnexion a' ).on( 'click', function( event ) {
47
	$( '#deconnexion a' ).on( 'click', function( event ) {
48
		event.preventDefault();
48
		event.preventDefault();
49
		lthis.deconnecterUtilisateur();
49
		lthis.deconnecterUtilisateur();
50
	});
50
	});
51
	if ( !this.isASL ) {
51
	if ( !this.isASL ) {
52
		$( '#bouton-anonyme' ).on( 'click', function( event ) {
52
		$( '#bouton-anonyme' ).on( 'click', function( event ) {
53
			lthis.arreter( event );
53
			lthis.arreter( event );
54
			$( this ).css({
54
			$( this ).css({
55
				'background-color': 'rgba(0, 159, 184, 0.7)',
55
				'background-color': 'rgba(0, 159, 184, 0.7)',
56
				'color': '#fff'
56
				'color': '#fff'
57
			});
57
			});
58
			$( '#identite' ).removeClass( 'hidden' );
58
			$( '#identite' ).removeClass( 'hidden' );
59
			$( '#courriel' ).focus();
59
			$( '#courriel' ).focus();
60
		});
60
		});
61
		if ( '' === $( '#nom-complet').text() ) {
61
		if ( '' === $( '#nom-complet').text() ) {
62
			$( '#courriel' ).on( 'blur', this.requeterIdentiteCourriel.bind( this ) );
62
			$( '#courriel' ).on( 'blur', this.requeterIdentiteCourriel.bind( this ) );
63
			$( '#courriel' ).on( 'keypress', this.testerLancementRequeteIdentite.bind( this ) );
63
			$( '#courriel' ).on( 'keypress', this.testerLancementRequeteIdentite.bind( this ) );
64
		}
64
		}
65
		$( '#prenom' ).on( 'change', function() {
65
		$( '#prenom' ).on( 'change', function() {
66
			lthis.formaterPrenom();
66
			lthis.formaterPrenom();
67
			lthis.reduireVoletIdentite();
67
			lthis.reduireVoletIdentite();
68
		});
68
		});
69
		$( '#nom' ).on( 'change', function() {
69
		$( '#nom' ).on( 'change', function() {
70
			lthis.formaterNom();
70
			lthis.formaterNom();
71
			lthis.reduireVoletIdentite();
71
			lthis.reduireVoletIdentite();
72
		});
72
		});
73
		$( '#courriel_confirmation' ).on( 'paste', this.bloquerCopierCollerCourriel.bind( this ) );
73
		$( '#courriel_confirmation' ).on( 'paste', this.bloquerCopierCollerCourriel.bind( this ) );
74
		$( '#courriel_confirmation' ).on( 'blur', this.reduireVoletIdentite.bind( this ) );
74
		$( '#courriel_confirmation' ).on( 'blur', this.reduireVoletIdentite.bind( this ) );
75
		$( '#courriel_confirmation' ).on( 'keypress', function( event ) {
75
		$( '#courriel_confirmation' ).on( 'keypress', function( event ) {
76
			if ( lthis.valOk( event.which, true, 13 ) ) {
76
			if ( lthis.valOk( event.which, true, 13 ) ) {
77
				lthis.reduireVoletIdentite();
77
				lthis.reduireVoletIdentite();
78
				event.preventDefault();
78
				event.preventDefault();
79
				event.stopPropagation();
79
				event.stopPropagation();
80
			}
80
			}
81
		});
81
		});
82
	}
82
	}
83
};
83
};
84
 
84
 
85
WidgetsSaisiesCommun.prototype.initEvtsFichier = function() {
85
WidgetsSaisiesCommun.prototype.initEvtsFichier = function() {
86
	const lthis = this;
86
	const lthis = this;
87
 
87
 
88
	// Sur téléchargement image
88
	// Sur téléchargement image
89
	$( '#fichier' ).on( 'change', function ( event ) {
89
	$( '#fichier' ).on( 'change', function ( event ) {
90
		lthis.arreter ( event );
90
		lthis.arreter ( event );
91
 
91
 
92
		var options        = {
92
		var options        = {
93
			success: lthis.afficherMiniature.bind( lthis ), // post-submit callback
93
			success: lthis.afficherMiniature.bind( lthis ), // post-submit callback
94
			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
94
			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
95
			resetForm: true // reset the form after successful submit
95
			resetForm: true // reset the form after successful submit
96
		};
96
		};
97
 
-
 
98
		$( '#miniature' ).append( '<img id="miniature-chargement" class="miniature" alt="chargement" src="' + this.chargementImageIconeUrl + '"/>' );
-
 
99
 
-
 
100
		var imgCheminTmp    = $( '#fichier' ).val(),
97
		var imgCheminTmp    = $( '#fichier' ).val(),
-
 
98
			parts           = imgCheminTmp.split( '\\' ),
-
 
99
			nomImage        = parts[ parts.length - 1 ],
101
			formatImgOk     = lthis.verifierFormat( imgCheminTmp ),
100
			formatImgOk     = lthis.verifierFormat( nomImage ),
102
			imgNonDupliquee = lthis.verifierDuplication( imgCheminTmp );
101
			imgNonDupliquee = lthis.verifierDuplication( nomImage );
-
 
102
 
103
 
103
 
104
		if( formatImgOk && imgNonDupliquee ) {
104
		if( formatImgOk && imgNonDupliquee ) {
105
			$( '#form-upload' ).ajaxSubmit( options );
105
			$( '#form-upload' ).ajaxSubmit( options );
-
 
106
			$( '#miniatures' ).append(
-
 
107
				'<div class="miniature mr-3 miniature-chargement" data-image="' + nomImage + '">'+
-
 
108
					'<img class="miniature-img chargement-img" alt="chargement" src="' + lthis.chargementImageIconeUrl + '" style="min-height:100%;"/>'+
-
 
109
					'<a class="effacer-miniature">Supprimer</a>'+
-
 
110
				'</div>'
-
 
111
			);
-
 
112
			$( '#ajouter-obs' ).addClass( 'hidden' );
-
 
113
			$( '#message-chargement' ).removeClass( 'hidden' );
106
		} else {
114
		} else {
107
			$( '#form-upload' )[0].reset();
115
			$( '#form-upload' )[0].reset();
108
			if ( !formatImgOk ) {
116
			if ( !formatImgOk ) {
109
				lthis.activerModale( lthis.msgTraduction( 'format-non-supporte' ) + ' : ' + $( '#fichier' ).attr( 'accept' ) );
117
				lthis.activerModale( lthis.msgTraduction( 'format-non-supporte' ) + ' : ' + $( '#fichier' ).attr( 'accept' ) );
110
			}
118
			}
111
			if ( !imgNonDupliquee ) {
119
			if ( !imgNonDupliquee ) {
112
				lthis.activerModale( lthis.msgTraduction( 'image-deja-chargee' ) );
120
				lthis.activerModale( lthis.msgTraduction( 'image-deja-chargee' ) );
113
			}
121
			}
114
		}
122
		}
115
		return false;
123
		return false;
116
	});
124
	});
117
	$( 'body' ).on( 'click', '.effacer-miniature', function() {
125
	$( 'body' ).on( 'click', '.effacer-miniature', function() {
118
		$( this ).parent().remove();
126
		$( this ).parent().remove();
-
 
127
		if ( !lthis.valOk( $('.miniature-chargement' ) ) ) {
-
 
128
			$( '#ajouter-obs' ).removeClass( 'hidden' );
-
 
129
			$( '#message-chargement' ).addClass( 'hidden' );
-
 
130
		}
119
	});
131
	});
120
};
132
};
121
 
133
 
122
WidgetsSaisiesCommun.prototype.initEvtsGeoloc = function( isFormArbre = false ) {
134
WidgetsSaisiesCommun.prototype.initEvtsGeoloc = function( isFormArbre = false ) {
123
	const lthis = this;
135
	const lthis = this;
124
 
136
 
125
	var ancre               = '-observation',
137
	var ancre               = '-observation',
126
		complementSelecteur = '';
138
		complementSelecteur = '';
127
 
139
 
128
	if ( isFormArbre ) {
140
	if ( isFormArbre ) {
129
		ancre               = '-arbres';
141
		ancre               = '-arbres';
130
		complementSelecteur = ancre;
142
		complementSelecteur = ancre;
131
	}
143
	}
132
	// Empêcher que le module carto ne bind ses events partout
144
	// Empêcher que le module carto ne bind ses events partout
133
	$( '#zone' + ancre ).on( 'submit blur click focus mousedown mouseleave mouseup change', '#tb-geolocation' + complementSelecteur + ' *', function( event ) {
145
	$( '#zone' + ancre ).on( 'submit blur click focus mousedown mouseleave mouseup change', '#tb-geolocation' + complementSelecteur + ' *', function( event ) {
134
		event.preventDefault();
146
		event.preventDefault();
135
		return false;
147
		return false;
136
	});
148
	});
137
	// evenement location
149
	// evenement location
138
	$( '#tb-geolocation' + complementSelecteur ).on( 'location' , this.locationHandler.bind( this ) );
150
	$( '#tb-geolocation' + complementSelecteur ).on( 'location' , this.locationHandler.bind( this ) );
139
};
151
};
140
 
152
 
141
WidgetsSaisiesCommun.prototype.initEvtsObs = function() {
153
WidgetsSaisiesCommun.prototype.initEvtsObs = function() {
142
	const lthis = this;
154
	const lthis = this;
143
 
155
 
144
	$( '#ajouter-obs' ).on( 'click', this.ajouterObs.bind( this ) );
156
	$( '#ajouter-obs' ).on( 'click', this.ajouterObs.bind( this ) );
145
	$( '.obs-nbre' ).on( 'changement', this.surChangementNbreObs.bind( this ) );
157
	$( '.obs-nbre' ).on( 'changement', this.surChangementNbreObs.bind( this ) );
146
	$( 'body' ).on( 'click', '.defilement-miniatures-gauche', function( event ) {
158
	$( 'body' ).on( 'click', '.defilement-miniatures-gauche', function( event ) {
147
		event.preventDefault();
159
		event.preventDefault();
148
		lthis.defilerMiniatures( $( this ) );
160
		lthis.defilerMiniatures( $( this ) );
149
	});
161
	});
150
	$( 'body' ).on( 'click', '.defilement-miniatures-droite', function( event ) {
162
	$( 'body' ).on( 'click', '.defilement-miniatures-droite', function( event ) {
151
		event.preventDefault();
163
		event.preventDefault();
152
		lthis.defilerMiniatures( $( this ) );
164
		lthis.defilerMiniatures( $( this ) );
153
	});
165
	});
154
	// mécanisme de suppression d'une obs
166
	// mécanisme de suppression d'une obs
155
	$( '#liste-obs' ).on( 'click', '.supprimer-obs', function() {
167
	$( '#liste-obs' ).on( 'click', '.supprimer-obs', function() {
156
		var buttons = [
168
		var buttons = [
157
				{
169
				{
158
					label   : 'Annuler',
170
					label   : 'Annuler',
159
					class   : 'btn-secondary',
171
					class   : 'btn-secondary',
160
					dismiss : true
172
					dismiss : true
161
				},
173
				},
162
				{
174
				{
163
					label   : 'Confirmer',
175
					label   : 'Confirmer',
164
					class   : 'btn-success confirmer',
176
					class   : 'btn-success confirmer',
165
					dismiss : true
177
					dismiss : true
166
				}
178
				}
167
			];
179
			];
168
		// bricolage pour avoir les deux contextes en même temps (objet et elt. du DOM)
180
		// bricolage pour avoir les deux contextes en même temps (objet et elt. du DOM)
169
		var that    = this,
181
		var that    = this,
170
			suppObs = lthis.supprimerObs.bind( lthis );
182
			suppObs = lthis.supprimerObs.bind( lthis );
171
 
183
 
172
		lthis.activerModale( lthis.msgTraduction( 'confirmation-suppression' ), '', buttons );
184
		lthis.activerModale( lthis.msgTraduction( 'confirmation-suppression' ), '', buttons );
173
		$( '.confirmer' ).on( 'click', function() {
185
		$( '.confirmer' ).on( 'click', function() {
174
			suppObs( that );
186
			suppObs( that );
175
		});
187
		});
176
	});
188
	});
177
	$( '#transmettre-obs' ).on( 'click', this.transmettreObs.bind( this ) );
189
	$( '#transmettre-obs' ).on( 'click', this.transmettreObs.bind( this ) );
178
};
190
};
179
 
191
 
180
// Alertes et aides
192
// Alertes et aides
181
WidgetsSaisiesCommun.prototype.initEvtsAlertes = function() {
193
WidgetsSaisiesCommun.prototype.initEvtsAlertes = function() {
182
	$( '.alert .close' ).on( 'click', this.fermerPanneauAlert );
194
	$( '.alert .close' ).on( 'click', this.fermerPanneauAlert );
183
	$( '#btn-aide' ).on( 'click', this.basculerAffichageAide );
195
	$( '#btn-aide' ).on( 'click', this.basculerAffichageAide );
184
};
196
};
185
 
197
 
186
/**
198
/**
187
 * Interroge le SSO pour connaître le statut de l'utilisateur, et change le menu
199
 * Interroge le SSO pour connaître le statut de l'utilisateur, et change le menu
188
 * à droite de la barre en fonction
200
 * à droite de la barre en fonction
189
 */
201
 */
190
WidgetsSaisiesCommun.prototype.chargerStatutSSO = function() {
202
WidgetsSaisiesCommun.prototype.chargerStatutSSO = function() {
191
	const lthis = this;
203
	const lthis = this;
192
	var urlAuth = this.urlBaseAuth + '/identite';
204
	var urlAuth = this.urlBaseAuth + '/identite';
193
 
205
 
194
	if( 'local' !== this.mode ) {
206
	if( 'local' !== this.mode ) {
195
		this.connexion( urlAuth, true );
207
		this.connexion( urlAuth, true );
196
		if( this.isASL) {
208
		if( this.isASL) {
197
			$( '#connexion' ).on( 'click', function( event ) {
209
			$( '#connexion' ).on( 'click', function( event ) {
198
				event.preventDefault();
210
				event.preventDefault();
199
				if( $( '#utilisateur-connecte' ).hasClass( 'hidden' ) || !lthis.valOk( $( '#nom-complet' ).text() ) ) {
211
				if( $( '#utilisateur-connecte' ).hasClass( 'hidden' ) || !lthis.valOk( $( '#nom-complet' ).text() ) ) {
200
					var login = $( '#courriel' ).val(),
212
					var login = $( '#courriel' ).val(),
201
						mdp   = $( '#mdp' ).val();
213
						mdp   = $( '#mdp' ).val();
202
					if ( lthis.valOk( login ) && lthis.valOk( mdp ) ) {
214
					if ( lthis.valOk( login ) && lthis.valOk( mdp ) ) {
203
						urlAuth = lthis.urlBaseAuth + '/connexion?login=' + login + '&password=' + mdp;
215
						urlAuth = lthis.urlBaseAuth + '/connexion?login=' + login + '&password=' + mdp;
204
						lthis.connexion( urlAuth, true );
216
						lthis.connexion( urlAuth, true );
205
					} else {
217
					} else {
206
						lthis.activerModale( lthis.msgTraduction( 'non-connexion' ) );
218
						lthis.activerModale( lthis.msgTraduction( 'non-connexion' ) );
207
					}
219
					}
208
				}
220
				}
209
			});
221
			});
210
		}
222
		}
211
	} else {
223
	} else {
212
		urlAuth = this.urlWidgets + 'modules/saisie2/test-token.json';
224
		urlAuth = this.urlWidgets + 'modules/saisie2/test-token.json';
213
		// $( '#connexion' ).on( 'click', function( event ) {
225
		// $( '#connexion' ).on( 'click', function( event ) {
214
		// 	event.preventDefault();
226
		// 	event.preventDefault();
215
			// lthis.connexion( urlAuth, true );
227
			// lthis.connexion( urlAuth, true );
216
			this.connexion( urlAuth, true );
228
			this.connexion( urlAuth, true );
217
		// });
229
		// });
218
	}
230
	}
219
};
231
};
220
 
232
 
221
/**
233
/**
222
 * Déconnecte l'utilisateur du SSO
234
 * Déconnecte l'utilisateur du SSO
223
 */
235
 */
224
WidgetsSaisiesCommun.prototype.deconnecterUtilisateur = function() {
236
WidgetsSaisiesCommun.prototype.deconnecterUtilisateur = function() {
225
	var urlAuth = this.urlBaseAuth + '/deconnexion';
237
	var urlAuth = this.urlBaseAuth + '/deconnexion';
226
 
238
 
227
	if( 'local' === this.mode ) {
239
	if( 'local' === this.mode ) {
228
		this.definirUtilisateur();
240
		this.definirUtilisateur();
229
		window.location.reload();
241
		window.location.reload();
230
		return;
242
		return;
231
	}
243
	}
232
	this.connexion( urlAuth, false );
244
	this.connexion( urlAuth, false );
233
};
245
};
234
 
246
 
235
WidgetsSaisiesCommun.prototype.connexion = function( urlAuth, connexionOnOff ) {
247
WidgetsSaisiesCommun.prototype.connexion = function( urlAuth, connexionOnOff ) {
236
	const lthis = this;
248
	const lthis = this;
237
 
249
 
238
	$.ajax({
250
	$.ajax({
239
		url: urlAuth,
251
		url: urlAuth,
240
		type: "GET",
252
		type: "GET",
241
		dataType: 'json',
253
		dataType: 'json',
242
		xhrFields: {
254
		xhrFields: {
243
			withCredentials: true
255
			withCredentials: true
244
		}
256
		}
245
	})
257
	})
246
	.done( function( data ) {
258
	.done( function( data ) {
247
		if( connexionOnOff ) {
259
		if( connexionOnOff ) {
248
			// connecté
260
			// connecté
249
			lthis.definirUtilisateur( data.token );
261
			lthis.definirUtilisateur( data.token );
250
		} else {
262
		} else {
251
			lthis.definirUtilisateur();
263
			lthis.definirUtilisateur();
252
			window.location.reload();
264
			window.location.reload();
253
		}
265
		}
254
	})
266
	})
255
	.fail( function( error ) {
267
	.fail( function( error ) {
256
		// @TODO gérer l'affichage de l'erreur, mais pas facile à placer
268
		// @TODO gérer l'affichage de l'erreur, mais pas facile à placer
257
		// dans l'interface actuelle sans que ce soit moche
269
		// dans l'interface actuelle sans que ce soit moche
258
		//afficherErreurServeur();
270
		//afficherErreurServeur();
259
	});
271
	});
260
};
272
};
261
 
273
 
262
WidgetsSaisiesCommun.prototype.definirUtilisateur = function( jeton ) {
274
WidgetsSaisiesCommun.prototype.definirUtilisateur = function( jeton ) {
263
	const thisObj = this;
275
	const thisObj = this;
264
	var idUtilisateur = '',
276
	var idUtilisateur = '',
265
		prenom        = '',
277
		prenom        = '',
266
		nom           = '',
278
		nom           = '',
267
		nomComplet    = '',
279
		nomComplet    = '',
268
		courriel      = '',
280
		courriel      = '',
269
		pseudo        = '';
281
		pseudo        = '';
270
 
282
 
271
	// affichage
283
	// affichage
272
	if ( undefined !== jeton ) {
284
	if ( undefined !== jeton ) {
273
		// décodage jeton
285
		// décodage jeton
274
		this.infosUtilisateur = this.decoderJeton( jeton );
286
		this.infosUtilisateur = this.decoderJeton( jeton );
275
		idUtilisateur = this.infosUtilisateur.id;
287
		idUtilisateur = this.infosUtilisateur.id;
276
		prenom        = this.infosUtilisateur.prenom;
288
		prenom        = this.infosUtilisateur.prenom;
277
		nom           = this.infosUtilisateur.nom;
289
		nom           = this.infosUtilisateur.nom;
278
		nomComplet    = this.infosUtilisateur.intitule;
290
		nomComplet    = this.infosUtilisateur.intitule;
279
		courriel      = this.infosUtilisateur.sub;
291
		courriel      = this.infosUtilisateur.sub;
280
		pseudo        = this.infosUtilisateur.pseudo;
292
		pseudo        = this.infosUtilisateur.pseudo;
281
		$( '#courriel' ).attr( 'disabled', 'disabled' );
293
		$( '#courriel' ).attr( 'disabled', 'disabled' );
282
		$( '#utilisateur-connecte, #identite' ).removeClass( 'hidden' );
294
		$( '#utilisateur-connecte, #identite' ).removeClass( 'hidden' );
283
		if ( this.isASL ) {
295
		if ( this.isASL ) {
284
			$( '#bloc-connexion' ).addClass( 'hidden' );
296
			$( '#bloc-connexion' ).addClass( 'hidden' );
285
		} else {
297
		} else {
286
			$( '#courriel_confirmation' ).attr( 'disabled', 'disabled' );
298
			$( '#courriel_confirmation' ).attr( 'disabled', 'disabled' );
287
			$( '#prenom' ).attr( 'disabled', 'disabled' );
299
			$( '#prenom' ).attr( 'disabled', 'disabled' );
288
			$( '#nom' ).attr( 'disabled', 'disabled' );
300
			$( '#nom' ).attr( 'disabled', 'disabled' );
289
			$( '#bouton-connexion, #creation-compte' ).addClass( 'hidden' );
301
			$( '#bouton-connexion, #creation-compte' ).addClass( 'hidden' );
290
			$( '#zone-courriel, #zone-prenom-nom' ).addClass( 'hidden' );
302
			$( '#zone-courriel, #zone-prenom-nom' ).addClass( 'hidden' );
291
			$( '#date-releve' ).focus();
303
			$( '#date-releve' ).focus();
292
		}
304
		}
293
	}
305
	}
294
	$( '#id_utilisateur' ).val( idUtilisateur );
306
	$( '#id_utilisateur' ).val( idUtilisateur );
295
	$( '#prenom' ).val( prenom );
307
	$( '#prenom' ).val( prenom );
296
	$( '#nom' ).val( nom );
308
	$( '#nom' ).val( nom );
297
	$( '#nom-complet' ).html( nomComplet );
309
	$( '#nom-complet' ).html( nomComplet );
298
	$( '#courriel' ).val( courriel );
310
	$( '#courriel' ).val( courriel );
299
	$( '#profil-utilisateur a' ).attr( 'href', this.urlSiteTb() + 'membres/' + pseudo.toLowerCase().replace( ' ', '-' ) );
311
	$( '#profil-utilisateur a' ).attr( 'href', this.urlSiteTb() + 'membres/' + pseudo.toLowerCase().replace( ' ', '-' ) );
300
	if ( this.isASL ) {
312
	if ( this.isASL ) {
301
		if ( this.valOk( idUtilisateur ) ) {
313
		if ( this.valOk( idUtilisateur ) ) {
302
			var nomSquelette = $( '#charger-form' ).data( 'load' ) || 'arbres';
314
			var nomSquelette = $( '#charger-form' ).data( 'load' ) || 'arbres';
303
			this.chargerForm( nomSquelette, thisObj );
315
			this.chargerForm( nomSquelette, thisObj );
304
		}
316
		}
305
	} else {
317
	} else {
306
		$( '.warning' ).remove();
318
		$( '.warning' ).remove();
307
		$( '#courriel_confirmation' ).val( courriel );
319
		$( '#courriel_confirmation' ).val( courriel );
308
	}
320
	}
309
};
321
};
310
 
322
 
311
/**
323
/**
312
 * Décodage à l'arrache d'un jeton JWT, ATTENTION CONSIDERE QUE LE
324
 * Décodage à l'arrache d'un jeton JWT, ATTENTION CONSIDERE QUE LE
313
 * JETON EST VALIDE, ne pas décoder n'importe quoi - pas trouvé de lib simple
325
 * JETON EST VALIDE, ne pas décoder n'importe quoi - pas trouvé de lib simple
314
 */
326
 */
315
WidgetsSaisiesCommun.prototype.decoderJeton = function( jeton ) {
327
WidgetsSaisiesCommun.prototype.decoderJeton = function( jeton ) {
316
	var parts = jeton.split( '.' ),
328
	var parts = jeton.split( '.' ),
317
		payload = parts[1];
329
		payload = parts[1];
318
	payload = this.b64d( payload );
330
	payload = this.b64d( payload );
319
	payload = JSON.parse( payload, true );
331
	payload = JSON.parse( payload, true );
320
	return payload;
332
	return payload;
321
};
333
};
322
 
334
 
323
/**
335
/**
324
 * Décodage "url-safe" des chaînes base64 retournées par le SSO (lib jwt)
336
 * Décodage "url-safe" des chaînes base64 retournées par le SSO (lib jwt)
325
 */
337
 */
326
WidgetsSaisiesCommun.prototype.b64d = function( input ) {
338
WidgetsSaisiesCommun.prototype.b64d = function( input ) {
327
  var remainder = input.length % 4;
339
  var remainder = input.length % 4;
328
 
340
 
329
  if ( 0 !== remainder ) {
341
  if ( 0 !== remainder ) {
330
	var padlen = 4 - remainder;
342
	var padlen = 4 - remainder;
331
 
343
 
332
	for ( var i = 0; i < padlen; i++ ) {
344
	for ( var i = 0; i < padlen; i++ ) {
333
	  input += '=';
345
	  input += '=';
334
	}
346
	}
335
  }
347
  }
336
  input = input.replace( '-', '+' );
348
  input = input.replace( '-', '+' );
337
  input = input.replace( '_', '/' );
349
  input = input.replace( '_', '/' );
338
  return atob( input );
350
  return atob( input );
339
};
351
};
340
 
352
 
341
WidgetsSaisiesCommun.prototype.urlSiteTb = function() {
353
WidgetsSaisiesCommun.prototype.urlSiteTb = function() {
342
	var urlPart = ( 'test' === this.mode ) ? '/test/' : '/';
354
	var urlPart = ( 'test' === this.mode ) ? '/test/' : '/';
343
 
355
 
344
	return this.urlRacine + urlPart;
356
	return this.urlRacine + urlPart;
345
};
357
};
346
 
358
 
347
// uniquement utilisé si taxon-liste ******************************************/
359
// uniquement utilisé si taxon-liste ******************************************/
348
/**
360
/**
349
 * Affiche/Cache le champ taxon
361
 * Affiche/Cache le champ taxon
350
 */
362
 */
351
WidgetsSaisiesCommun.prototype.surChangementTaxonListe = function() {
363
WidgetsSaisiesCommun.prototype.surChangementTaxonListe = function() {
352
	if ( utils.valOk( $( '#taxon-liste' ).val() ) ) {
364
	if ( utils.valOk( $( '#taxon-liste' ).val() ) ) {
353
		if ( 'autre' !== $( '#taxon-liste' ).val() ) {
365
		if ( 'autre' !== $( '#taxon-liste' ).val() ) {
354
			$( '#taxon-input-groupe' )
366
			$( '#taxon-input-groupe' )
355
				.hide( 200, function () {
367
				.hide( 200, function () {
356
					$( this ).addClass( 'hidden' ).show();
368
					$( this ).addClass( 'hidden' ).show();
357
				})
369
				})
358
				.find( '#taxon-autre' ).val( '' );
370
				.find( '#taxon-autre' ).val( '' );
359
		} else {
371
		} else {
360
			$( '#taxon-input-groupe' )
372
			$( '#taxon-input-groupe' )
361
				.hide()
373
				.hide()
362
				.removeClass( 'hidden' )
374
				.removeClass( 'hidden' )
363
				.show(200)
375
				.show(200)
364
				.find( '#taxon-autre' )
376
				.find( '#taxon-autre' )
365
					.on( 'change', function() {
377
					.on( 'change', function() {
366
						if( !utils.valOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
378
						if( !utils.valOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
367
							$( '#taxon' ).val( $( '#taxon-autre' ).val() )
379
							$( '#taxon' ).val( $( '#taxon-autre' ).val() )
368
								.data( 'value', $( '#taxon-autre' ).val() )
380
								.data( 'value', $( '#taxon-autre' ).val() )
369
								.removeData([
381
								.removeData([
370
									'numNomSel',
382
									'numNomSel',
371
									'nomRet',
383
									'nomRet',
372
									'numNomRet',
384
									'numNomRet',
373
									'nt',
385
									'nt',
374
									'famille'
386
									'famille'
375
								]);
387
								]);
376
						}
388
						}
377
						$( '#taxon' ).trigger( 'change' );
389
						$( '#taxon' ).trigger( 'change' );
378
					});
390
					});
379
		}
391
		}
380
	}
392
	}
381
};
393
};
382
 
394
 
383
WidgetsSaisiesCommun.prototype.surChangementValeurTaxon = function() {
395
WidgetsSaisiesCommun.prototype.surChangementValeurTaxon = function() {
384
	var numNomSel = 0;
396
	var numNomSel = 0;
385
 
397
 
386
	if( this.valOk( $( '#taxon-liste' ).val() ) ) {
398
	if( this.valOk( $( '#taxon-liste' ).val() ) ) {
387
		if( 'autre' === $( '#taxon-liste' ).val() ) {
399
		if( 'autre' === $( '#taxon-liste' ).val() ) {
388
			this.ajouterAutocompletionNoms();
400
			this.ajouterAutocompletionNoms();
389
		} else {
401
		} else {
390
			var optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' );
402
			var optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' );
391
			$( '#taxon' ).val( $( '#taxon-liste' ).val() )
403
			$( '#taxon' ).val( $( '#taxon-liste' ).val() )
392
				.data( 'value', $( '#taxon-liste' ).val() )
404
				.data( 'value', $( '#taxon-liste' ).val() )
393
				.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
405
				.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
394
				.data( 'nomRet', optionRetenue.data( 'nom-ret' ) )
406
				.data( 'nomRet', optionRetenue.data( 'nom-ret' ) )
395
				.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) )
407
				.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) )
396
				.data( 'nt', optionRetenue.data( 'nt' ) )
408
				.data( 'nt', optionRetenue.data( 'nt' ) )
397
				.data( 'famille', optionRetenue.data( 'famille' ) );
409
				.data( 'famille', optionRetenue.data( 'famille' ) );
398
			$( '#taxon' ).trigger( 'change' );
410
			$( '#taxon' ).trigger( 'change' );
399
 
411
 
400
			numNomSel = $( '#taxon' ).data( 'numNomSel' );
412
			numNomSel = $( '#taxon' ).data( 'numNomSel' );
401
			// Si l'espèce est mal déterminée la certitude est "à déterminer"
413
			// Si l'espèce est mal déterminée la certitude est "à déterminer"
402
			if( !this.valOk( numNomSel ) ) {
414
			if( !this.valOk( numNomSel ) ) {
403
				$( '#certitude' ).find( 'option' ).each( function() {
415
				$( '#certitude' ).find( 'option' ).each( function() {
404
					if ( $( this ).hasClass( 'aDeterminer' ) ) {
416
					if ( $( this ).hasClass( 'aDeterminer' ) ) {
405
						$( this ).attr( 'selected', true );
417
						$( this ).attr( 'selected', true );
406
					} else {
418
					} else {
407
						$( this ).attr( 'selected', false );
419
						$( this ).attr( 'selected', false );
408
					}
420
					}
409
				});
421
				});
410
			}
422
			}
411
		}
423
		}
412
	}
424
	}
413
};
425
};
414
 
426
 
415
// Autocompletion taxons ******************************************************/
427
// Autocompletion taxons ******************************************************/
416
/**
428
/**
417
 * Initialise l'autocompletion taxons
429
 * Initialise l'autocompletion taxons
418
 */
430
 */
419
WidgetsSaisiesCommun.prototype.ajouterAutocompletionNoms = function() {
431
WidgetsSaisiesCommun.prototype.ajouterAutocompletionNoms = function() {
420
	const lthis = this;
432
	const lthis = this;
421
	var taxonSelecteur = '#taxon';
433
	var taxonSelecteur = '#taxon';
422
 
434
 
423
	if ( this.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
435
	if ( this.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
424
		taxonSelecteur += '-autre';
436
		taxonSelecteur += '-autre';
425
	}
437
	}
426
	$( taxonSelecteur ).autocomplete({
438
	$( taxonSelecteur ).autocomplete({
427
		source: function( requete, add ) {
439
		source: function( requete, add ) {
428
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
440
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
429
			requete = '';
441
			requete = '';
430
			if( lthis.valOk( $( '#referentiel' ).val(), false, 'autre' ) ) {
442
			if( lthis.valOk( $( '#referentiel' ).val(), false, 'autre' ) ) {
431
				var url = lthis.getUrlAutocompletionNomsSci();
443
				var url = lthis.getUrlAutocompletionNomsSci();
432
				$.getJSON( url, requete, function( data ) {
444
				$.getJSON( url, requete, function( data ) {
433
					var suggestions = lthis.traiterRetourNomsSci( data );
445
					var suggestions = lthis.traiterRetourNomsSci( data );
434
					add( suggestions );
446
					add( suggestions );
435
				})
447
				})
436
				.fail( function() {
448
				.fail( function() {
437
					$( '#certitude' ).find( 'option' ).each( function() {
449
					$( '#certitude' ).find( 'option' ).each( function() {
438
						if ( $( this ).hasClass( 'aDeterminer' ) ) {
450
						if ( $( this ).hasClass( 'aDeterminer' ) ) {
439
							$( this ).prop( 'selected', true );
451
							$( this ).prop( 'selected', true );
440
						} else {
452
						} else {
441
							$( this ).prop( 'selected', false );
453
							$( this ).prop( 'selected', false );
442
						}
454
						}
443
					});
455
					});
444
				});
456
				});
445
			}
457
			}
446
		},
458
		},
447
		html: true
459
		html: true
448
	});
460
	});
449
	$( taxonSelecteur ).on( 'autocompleteselect', this.surAutocompletionTaxon );
461
	$( taxonSelecteur ).on( 'autocompleteselect', this.surAutocompletionTaxon );
450
};
462
};
451
 
463
 
452
WidgetsSaisiesCommun.prototype.getUrlAutocompletionNomsSci = function() {
464
WidgetsSaisiesCommun.prototype.getUrlAutocompletionNomsSci = function() {
453
	var taxonSelecteur = '#taxon';
465
	var taxonSelecteur = '#taxon';
454
 
466
 
455
	if ( this.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
467
	if ( this.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
456
		taxonSelecteur += '-autre';
468
		taxonSelecteur += '-autre';
457
	}
469
	}
458
	var mots = $( taxonSelecteur ).val();
470
	var mots = $( taxonSelecteur ).val();
459
	var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
471
	var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
460
	url = url.replace( '{masque}', mots );
472
	url = url.replace( '{masque}', mots );
461
 
473
 
462
	return url;
474
	return url;
463
};
475
};
464
 
476
 
465
/**
477
/**
466
 * Objet taxons pour autocompletion en fonction de la recherche
478
 * Objet taxons pour autocompletion en fonction de la recherche
467
 */
479
 */
468
WidgetsSaisiesCommun.prototype.traiterRetourNomsSci = function( data ) {
480
WidgetsSaisiesCommun.prototype.traiterRetourNomsSci = function( data ) {
469
	var taxonSelecteur = '#taxon',
481
	var taxonSelecteur = '#taxon',
470
		suggestions    = [];
482
		suggestions    = [];
471
 
483
 
472
	if ( this.valOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
484
	if ( this.valOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
473
		taxonSelecteur += '-autre';
485
		taxonSelecteur += '-autre';
474
	}
486
	}
475
	if ( undefined != data.resultat ) {
487
	if ( undefined != data.resultat ) {
476
		$.each( data.resultat, function( i, val ) {
488
		$.each( data.resultat, function( i, val ) {
477
			val.nn = i;
489
			val.nn = i;
478
 
490
 
479
			var nom = {
491
			var nom = {
480
				label : '',
492
				label : '',
481
				value : '',
493
				value : '',
482
				nt : 0,
494
				nt : 0,
483
				nomSel : '',
495
				nomSel : '',
484
				nomSelComplet : '',
496
				nomSelComplet : '',
485
				numNomSel : 0,
497
				numNomSel : 0,
486
				nomRet : '',
498
				nomRet : '',
487
				numNomRet : 0,
499
				numNomRet : 0,
488
				famille : '',
500
				famille : '',
489
				retenu : false
501
				retenu : false
490
			};
502
			};
491
			if ( suggestions.length >= this.autocompletionElementsNbre ) {
503
			if ( suggestions.length >= this.autocompletionElementsNbre ) {
492
				nom.label = '...';
504
				nom.label = '...';
493
				nom.value = $( taxonSelecteur ).val();
505
				nom.value = $( taxonSelecteur ).val();
494
				suggestions.push( nom );
506
				suggestions.push( nom );
495
				return false;
507
				return false;
496
			} else {
508
			} else {
497
				nom.label = val.nom_sci_complet;
509
				nom.label = val.nom_sci_complet;
498
				nom.value = val.nom_sci_complet;
510
				nom.value = val.nom_sci_complet;
499
				nom.nt = val.num_taxonomique;
511
				nom.nt = val.num_taxonomique;
500
				nom.nomSel = val.nom_sci;
512
				nom.nomSel = val.nom_sci;
501
				nom.nomSelComplet = val.nom_sci_complet;
513
				nom.nomSelComplet = val.nom_sci_complet;
502
				nom.numNomSel = val.nn;
514
				nom.numNomSel = val.nn;
503
				nom.nomRet = val.nom_retenu_complet;
515
				nom.nomRet = val.nom_retenu_complet;
504
				nom.numNomRet = val['nom_retenu.id'];
516
				nom.numNomRet = val['nom_retenu.id'];
505
				nom.famille = val.famille;
517
				nom.famille = val.famille;
506
				// Tester dans ce sens, permet de considérer 'absent' comme 'false' => est-ce opportun ?
518
				// Tester dans ce sens, permet de considérer 'absent' comme 'false' => est-ce opportun ?
507
				// en tout cas c'est harmonisé avec le CeL
519
				// en tout cas c'est harmonisé avec le CeL
508
				nom.retenu = ( 'true' == val.retenu );
520
				nom.retenu = ( 'true' == val.retenu );
509
				suggestions.push( nom );
521
				suggestions.push( nom );
510
			}
522
			}
511
		});
523
		});
512
	}
524
	}
513
	return suggestions;
525
	return suggestions;
514
};
526
};
515
 
527
 
516
/**
528
/**
517
 * charge les données dans #taxon
529
 * charge les données dans #taxon
518
 */
530
 */
519
WidgetsSaisiesCommun.prototype.surAutocompletionTaxon = function( event, ui ) {
531
WidgetsSaisiesCommun.prototype.surAutocompletionTaxon = function( event, ui ) {
520
	if ( utils.valOk( ui ) ) {
532
	if ( utils.valOk( ui ) ) {
521
		$( '#taxon' ).val( ui.item.value );
533
		$( '#taxon' ).val( ui.item.value );
522
		$( '#taxon' ).data( 'value', ui.item.value )
534
		$( '#taxon' ).data( 'value', ui.item.value )
523
			.data( 'numNomSel', ui.item.numNomSel )
535
			.data( 'numNomSel', ui.item.numNomSel )
524
			.data( 'nomRet', ui.item.nomRet )
536
			.data( 'nomRet', ui.item.nomRet )
525
			.data( 'numNomRet', ui.item.numNomRet )
537
			.data( 'numNomRet', ui.item.numNomRet )
526
			.data( 'nt', ui.item.nt )
538
			.data( 'nt', ui.item.nt )
527
			.data( 'famille', ui.item.famille );
539
			.data( 'famille', ui.item.famille );
528
		if ( ui.item.retenu ) {
540
		if ( ui.item.retenu ) {
529
			$( '#taxon' ).addClass( 'ns-retenu' );
541
			$( '#taxon' ).addClass( 'ns-retenu' );
530
		} else {
542
		} else {
531
			$( '#taxon' ).removeClass( 'ns-retenu' );
543
			$( '#taxon' ).removeClass( 'ns-retenu' );
532
		}
544
		}
533
		// Si l'espèce est mal déterminée la certitude est "à déterminer"
545
		// Si l'espèce est mal déterminée la certitude est "à déterminer"
534
		if( !utils.valOk( $( '#taxon' ).data( 'numNomSel' ) ) ) {
546
		if( !utils.valOk( $( '#taxon' ).data( 'numNomSel' ) ) ) {
535
			$( '#certitude' ).find( 'option' ).each( function() {
547
			$( '#certitude' ).find( 'option' ).each( function() {
536
				if ( $( this ).hasClass( 'aDeterminer' ) ) {
548
				if ( $( this ).hasClass( 'aDeterminer' ) ) {
537
					$( this ).attr( 'selected', true );
549
					$( this ).attr( 'selected', true );
538
				} else {
550
				} else {
539
					$( this ).attr( 'selected', false );
551
					$( this ).attr( 'selected', false );
540
				}
552
				}
541
			});
553
			});
542
		}
554
		}
543
	}
555
	}
544
	$( '#taxon' ).change();
556
	$( '#taxon' ).change();
545
};
557
};
546
 
558
 
547
// Fichier Images *************************************************************/
559
// Fichier Images *************************************************************/
548
/**
560
/**
549
 * Affiche temporairement (formulaire)
561
 * Affiche temporairement (formulaire)
550
 * la miniature d'une image ajoutée à l'obs
562
 * la miniature d'une image ajoutée à l'obs
551
 */
563
 */
552
WidgetsSaisiesCommun.prototype.afficherMiniature = function( reponse ) {
564
WidgetsSaisiesCommun.prototype.afficherMiniature = function( reponse ) {
553
	if ( this.debug ) {
565
	if ( this.debug ) {
554
		var debogage = $( 'debogage', reponse ).text();
566
		var debogage = $( 'debogage', reponse ).text();
555
	}
567
	}
556
 
568
 
-
 
569
	var message        = $( 'message', reponse ).text();
-
 
570
		$blocMiniature = $( '#miniatures .miniature[data-image="' + $( 'image-nom', reponse ).text() + '"]');
557
	var message = $( 'message', reponse ).text();
571
 
558
 
572
	if( this.valOk( $blocMiniature ) ) {
-
 
573
		if ( this.valOk( message ) ) {
-
 
574
			$( '#miniature-msg' ).append( message );
559
	if ( this.valOk( message ) ) {
575
			$blocMiniature.remove();
560
		$( '#miniature-msg' ).append( message );
576
 
-
 
577
		} else {
-
 
578
			this.creerWidgetMiniature( reponse, $blocMiniature );
-
 
579
		}
-
 
580
		if ( !lthis.valOk( $( '.miniature-chargement' ) ) ) {
-
 
581
			$( '#ajouter-obs' ).removeClass( 'hidden' );
-
 
582
			$( '#message-chargement' ).addClass( 'hidden' );
561
	} else {
583
		}
562
		$( '#miniatures' ).append( this.creerWidgetMiniature( reponse ) );
-
 
563
	}
584
		$( '#ajouter-obs' ).removeAttr( 'disabled' );
564
	$( '#ajouter-obs' ).removeAttr( 'disabled' );
585
	}
565
};
586
};
566
 
587
 
567
/**
588
/**
568
 * Crée la miniature temporaire (formulaire) + bouton pour l'effacer
589
 * Crée la miniature temporaire (formulaire) + bouton pour l'effacer
569
 */
590
 */
570
WidgetsSaisiesCommun.prototype.creerWidgetMiniature = function( reponse ) {
591
WidgetsSaisiesCommun.prototype.creerWidgetMiniature = function( reponse, $blocMiniature ) {
571
	var miniatureUrl = $( 'miniature-url', reponse ).text();
592
	var miniatureUrl = $( 'miniature-url', reponse ).text();
572
	var imgNom       = $( 'image-nom', reponse ).text();
593
	var imgNom       = $( 'image-nom', reponse ).text();
573
	var html =
-
 
574
		'<div class="miniature mr-3">'+
-
 
575
			'<img class="miniature-img" class="miniature img-rounded" alt="' + imgNom + '" src="' + miniatureUrl + '" style="min-height:100%;"/>'+
-
 
576
			'<a class="effacer-miniature">Supprimer</a>'+
-
 
577
		'</div>';
-
 
-
 
594
 
-
 
595
	$blocMiniature.removeClass( 'miniature-chargement' );
-
 
596
	$( '.miniature-img', $blocMiniature )
578
 
597
		.removeClass( 'chargement-img' )
-
 
598
		.attr({
-
 
599
			'alt' : imgNom,
-
 
600
			'src' : miniatureUrl
579
	return html;
601
		});
580
};
602
};
581
 
603
 
582
/**
604
/**
583
 * Retourne true si l'extension de l'image 'nom' est .jpg ou .jpeg
605
 * Retourne true si l'extension de l'image 'nom' est .jpg ou .jpeg
584
 */
606
 */
585
WidgetsSaisiesCommun.prototype.verifierFormat = function( cheminTmp ) {
607
WidgetsSaisiesCommun.prototype.verifierFormat = function( nomImage ) {
586
	var parts     = cheminTmp.split( '.' ),
608
	var parts     = nomImage.split( '.' ),
587
		extension = parts[ parts.length - 1 ];
609
		extension = parts[ parts.length - 1 ];
588
 
610
 
589
	return ( 'jpeg' === extension.toLowerCase() || 'jpg' === extension.toLowerCase() );
611
	return ( 'jpeg' === extension.toLowerCase() || 'jpg' === extension.toLowerCase() );
590
};
612
};
591
 
613
 
592
/**
614
/**
593
 * Check les miniatures déjà téléchargées
615
 * Check les miniatures déjà téléchargées
594
 * renvoie false si le même nom est rencontré 2 fois
616
 * renvoie false si le même nom est rencontré 2 fois
595
 * renvoie true sinon
617
 * renvoie true sinon
596
 */
618
 */
597
WidgetsSaisiesCommun.prototype.verifierDuplication = function( cheminTmp ) {
619
WidgetsSaisiesCommun.prototype.verifierDuplication = function( nomImage ) {
598
	const lthis = this;
620
	const lthis = this;
599
 
-
 
600
	var parts        = cheminTmp.split( '\\' ),
-
 
601
		nomImage     = parts[ parts.length - 1 ],
621
 
602
		thisSrcParts = [],
622
	var thisSrcParts = [],
603
		thisNomImage = '',
623
		thisNomImage = '',
604
		nonDupliquee = true;
624
		nonDupliquee = true;
605
 
625
 
606
	$( 'img.miniature-img,img.miniature' ).each( function() {
626
	$( 'img.miniature-img,img.miniature' ).each( function() {
607
		// vérification avec alt de l'image
627
		// vérification avec alt de l'image
608
		if ( lthis.valOk ( $( this ).attr ( 'alt' ), true, nomImage ) ) {
628
		if ( lthis.valOk ( $( this ).attr ( 'alt' ), true, nomImage ) ) {
609
			nonDupliquee = false;
629
			nonDupliquee = false;
610
			return false;// Pas besoin de poursuivre la boucle
630
			return false;// Pas besoin de poursuivre la boucle
611
		} else { // sinon vérifie aussi avec l'adresse (src) de l'image
631
		} else { // sinon vérifie aussi avec l'adresse (src) de l'image
612
			thisSrcParts = $( this ).attr( 'src' ).split( '/' );
632
			thisSrcParts = $( this ).attr( 'src' ).split( '/' );
613
			thisNomImage = thisSrcParts[ thisSrcParts.length - 1 ].replace( '_min', '' );
633
			thisNomImage = thisSrcParts[ thisSrcParts.length - 1 ].replace( '_min', '' );
614
			if ( lthis.valOk ( thisNomImage, true, nomImage ) ) {
634
			if ( lthis.valOk ( thisNomImage, true, nomImage ) ) {
615
				nonDupliquee = false;
635
				nonDupliquee = false;
616
				return false;
636
				return false;
617
			}
637
			}
618
		}
638
		}
619
	});
639
	});
620
	return nonDupliquee;
640
	return nonDupliquee;
621
};
641
};
622
 
642
 
623
/**
643
/**
624
 * Efface une miniature (formulaire)
644
 * Efface une miniature (formulaire)
625
 */
645
 */
626
WidgetsSaisiesCommun.prototype.supprimerMiniature = function( miniature ) {
646
WidgetsSaisiesCommun.prototype.supprimerMiniature = function( miniature ) {
627
	miniature.parents( '.miniature' ).remove();
647
	miniature.parents( '.miniature' ).remove();
628
};
648
};
629
 
649
 
630
// Geoloc *********************************************************************/
650
// Geoloc *********************************************************************/
631
WidgetsSaisiesCommun.prototype.transfererCarto = function( donnees ) {
651
WidgetsSaisiesCommun.prototype.transfererCarto = function( donnees ) {
632
	var typeLocalisation = donnees.typeLocalisation || 'point',
652
	var typeLocalisation = donnees.typeLocalisation || 'point',
633
		isPoint          = ( typeLocalisation === 'point' ).toString(),
653
		isPoint          = ( typeLocalisation === 'point' ).toString(),
634
		suffixe          = ( this.valOk( donnees.suffixe ) ) ? '-' + donnees.suffixe : '',
654
		suffixe          = ( this.valOk( donnees.suffixe ) ) ? '-' + donnees.suffixe : '',
635
		$cartoRemplacee  = donnees.cartoRemplacee || $( '#tb-geolocation' ),
655
		$cartoRemplacee  = donnees.cartoRemplacee || $( '#tb-geolocation' ),
636
		layer            = donnees.layer || 'osm',
656
		layer            = donnees.layer || 'osm',
637
		latitude         = donnees.latitude || '46.5',
657
		latitude         = donnees.latitude || '46.5',
638
		longitude        = donnees.longitude || '2.9',
658
		longitude        = donnees.longitude || '2.9',
639
		// 18 est le zoom max
659
		// 18 est le zoom max
640
		zoomInit         = donnees.zoomInit || 18;
660
		zoomInit         = donnees.zoomInit || 18;
641
 
661
 
642
	$cartoRemplacee.remove();
662
	$cartoRemplacee.remove();
643
	$( '#geoloc' + suffixe ).append(
663
	$( '#geoloc' + suffixe ).append(
644
		'<tb-geolocation-element'+
664
		'<tb-geolocation-element'+
645
			' id="tb-geolocation' + suffixe +'"'+
665
			' id="tb-geolocation' + suffixe +'"'+
646
			' layer="' + layer + '"'+
666
			' layer="' + layer + '"'+
647
			' zoom_init="' + zoomInit + '"'+
667
			' zoom_init="' + zoomInit + '"'+
648
			' lat_init="' + latitude + '"'+
668
			' lat_init="' + latitude + '"'+
649
			' lng_init="' + longitude + '"'+
669
			' lng_init="' + longitude + '"'+
650
			' marker="' + isPoint + '"'+
670
			' marker="' + isPoint + '"'+
651
			' polyline="' + !isPoint + '"'+
671
			' polyline="' + !isPoint + '"'+
652
			' polygon="false"'+
672
			' polygon="false"'+
653
			' show_lat_lng_elevation_inputs="' + isPoint + '"'+
673
			' show_lat_lng_elevation_inputs="' + isPoint + '"'+
654
			' osm_class_filter=""'+
674
			' osm_class_filter=""'+
655
			' elevation_provider="mapquest"'+
675
			' elevation_provider="mapquest"'+
656
			' map_quest_api_key="mG6oU5clZHRHrOSnAV0QboFI7ahnGg34"'+
676
			' map_quest_api_key="mG6oU5clZHRHrOSnAV0QboFI7ahnGg34"'+
657
		'>'+
677
		'>'+
658
		'</tb-geolocation-element>'
678
		'</tb-geolocation-element>'
659
	);
679
	);
660
	this.initEvtsGeoloc( true );
680
	this.initEvtsGeoloc( true );
661
};
681
};
662
 
682
 
663
// Ajouter Obs ****************************************************************/
683
// Ajouter Obs ****************************************************************/
664
/**
684
/**
665
 * Ajoute une observation à la liste des obs à transmettre
685
 * Ajoute une observation à la liste des obs à transmettre
666
 * (résumé obs)
686
 * (résumé obs)
667
 */
687
 */
668
WidgetsSaisiesCommun.prototype.ajouterObs = function() {
688
WidgetsSaisiesCommun.prototype.ajouterObs = function() {
669
	if ( this.isASL ) {
689
	if ( this.isASL ) {
670
		this.scrollFormTop( '#zone-' + this.sujet );
690
		this.scrollFormTop( '#zone-' + this.sujet );
671
	}
691
	}
672
	// Fermeture automatique des dialogue de transmission de données
692
	// Fermeture automatique des dialogue de transmission de données
673
	// @WARNING TEST
693
	// @WARNING TEST
674
	$( '#dialogue-obs-transaction-ko,#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
694
	$( '#dialogue-obs-transaction-ko,#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
675
	if ( this.validerForm() ) {
695
	if ( this.validerForm() ) {
676
		this.masquerPanneau( '#dialogue-form-invalide' );
696
		this.masquerPanneau( '#dialogue-form-invalide' );
677
		this.obsNbre += 1;
697
		this.obsNbre += 1;
678
		if ( this.isASL && 'arbres' === this.sujet ) {
698
		if ( this.isASL && 'arbres' === this.sujet ) {
679
			this.numArbre += 1;
699
			this.numArbre += 1;
680
			// bouton info de cet arbre et affichage numéro du prochain arbre
700
			// bouton info de cet arbre et affichage numéro du prochain arbre
681
			this.lienArbreInfo( this.numArbre );
701
			this.lienArbreInfo( this.numArbre );
682
			$( '#arbre-nb' ).text( this.numArbre + 1 );
702
			$( '#arbre-nb' ).text( this.numArbre + 1 );
683
		}
703
		}
684
		$( '.obs-nbre' ).text( this.obsNbre );
704
		$( '.obs-nbre' ).text( this.obsNbre );
685
		$( '.obs-nbre' ).triggerHandler( 'changement' );
705
		$( '.obs-nbre' ).triggerHandler( 'changement' );
686
		//formatage des données
706
		//formatage des données
687
		var obsData = this.formaterFormObsData();
707
		var obsData = this.formaterFormObsData();
688
		this.afficherObs( obsData );
708
		this.afficherObs( obsData );
689
		this.stockerObsData( obsData );
709
		this.stockerObsData( obsData );
690
		if ( this.isASL && 'arbres' === this.sujet ) {
710
		if ( this.isASL && 'arbres' === this.sujet ) {
691
			var arbreData = obsData.sujet;
711
			var arbreData = obsData.sujet;
692
			// Ajout de donnée utiles puis stockage dans input hidden "releve-data"
712
			// Ajout de donnée utiles puis stockage dans input hidden "releve-data"
693
			arbreData['date_rue_commune']  = obsData.releve.date + obsData.releve.rue + obsData.releve['commune-nom'];
713
			arbreData['date_rue_commune']  = obsData.releve.date + obsData.releve.rue + obsData.releve['commune-nom'];
694
			arbreData['id_observation']    = 0;
714
			arbreData['id_observation']    = 0;
695
			this.releveDatas               = $.parseJSON( $( '#releve-data' ).val() );
715
			this.releveDatas               = $.parseJSON( $( '#releve-data' ).val() );
696
			this.releveDatas[this.obsNbre] = arbreData;
716
			this.releveDatas[this.obsNbre] = arbreData;
697
			$( '#releve-data' ).val( JSON.stringify( this.releveDatas ) );
717
			$( '#releve-data' ).val( JSON.stringify( this.releveDatas ) );
698
			this.modeArbresBasculerActivation( false );
718
			this.modeArbresBasculerActivation( false );
699
		} else {
719
		} else {
700
			this.reinitialiserForm();
720
			this.reinitialiserForm();
701
		}
721
		}
702
		$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
722
		$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
703
		$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.msgTraduction( 'observations-transmises' ) );
723
		$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.msgTraduction( 'observations-transmises' ) );
704
	} else {
724
	} else {
705
		this.afficherPanneau( '#dialogue-form-invalide' );
725
		this.afficherPanneau( '#dialogue-form-invalide' );
706
	}
726
	}
707
};
727
};
708
 
728
 
709
/**
729
/**
710
 * Formatage des données du formulaire pour stockage et envoi
730
 * Formatage des données du formulaire pour stockage et envoi
711
 */
731
 */
712
WidgetsSaisiesCommun.prototype.formaterFormObsData = function() {
732
WidgetsSaisiesCommun.prototype.formaterFormObsData = function() {
713
	var obsData      = { obsNum : this.obsNbre, sujet : {}},
733
	var obsData      = { obsNum : this.obsNbre, sujet : {}},
714
		numNomSel    = $( '#taxon' ).data( 'numNomSel' ),
734
		numNomSel    = $( '#taxon' ).data( 'numNomSel' ),
715
		nomSel       = $( '#taxon' ).val(),
735
		nomSel       = $( '#taxon' ).val(),
716
		nomRet       = $( '#taxon' ).data( 'nomRet' ),
736
		nomRet       = $( '#taxon' ).data( 'nomRet' ),
717
		numNomRet    = $( '#taxon' ).data( 'numNomRet' ),
737
		numNomRet    = $( '#taxon' ).data( 'numNomRet' ),
718
		numTaxon     = $( '#taxon' ).data( 'nt' ),
738
		numTaxon     = $( '#taxon' ).data( 'nt' ),
719
		famille      = $( '#taxon' ).data( 'famille' ),
739
		famille      = $( '#taxon' ).data( 'famille' ),
720
		referentiel  = ( this.valOk( numNomSel ) ) ? this.nomSciReferentiel : 'autre',
740
		referentiel  = ( this.valOk( numNomSel ) ) ? this.nomSciReferentiel : 'autre',
721
		certitude    = ( this.valOk( numNomSel ) ) ? $( '#certitude' ).val() : 'à determiner',
741
		certitude    = ( this.valOk( numNomSel ) ) ? $( '#certitude' ).val() : 'à determiner',
722
		imgB64       = [],
742
		imgB64       = [],
723
		imgNom       = [],
743
		imgNom       = [],
724
		date         = '',
744
		date         = '',
725
		notes        = '',
745
		notes        = '',
726
		pays         = '',
746
		pays         = '',
727
		communeNom   = '',
747
		communeNom   = '',
728
		communeInsee = '',
748
		communeInsee = '',
729
		latitude     = '',
749
		latitude     = '',
730
		longitude    = '',
750
		longitude    = '',
731
		altitude     = '',
751
		altitude     = '',
732
		obsEtendue   = [];
752
		obsEtendue   = [];
733
 
753
 
734
	if( !this.isASL ) {
754
	if( !this.isASL ) {
735
		notes            = $( '#notes' ).val().trim() || '';
755
		notes            = $( '#notes' ).val().trim() || '';
736
		pays             = $( '#pays' ).val() || '';
756
		pays             = $( '#pays' ).val() || '';
737
		communeNom       = $( '#commune-nom' ).val();
757
		communeNom       = $( '#commune-nom' ).val();
738
		communeInsee     = $( '#commune-insee' ).val() || '';
758
		communeInsee     = $( '#commune-insee' ).val() || '';
739
		latitude         = $( '#latitude' ).val();
759
		latitude         = $( '#latitude' ).val();
740
		longitude        = $( '#longitude' ).val();
760
		longitude        = $( '#longitude' ).val();
741
		altitude         = $( '#altitude' ).val();
761
		altitude         = $( '#altitude' ).val();
742
		obsEtendue       = this.getObsChpSpecifiques();
762
		obsEtendue       = this.getObsChpSpecifiques();
743
		date             = this.fournirDate( $('#date_releve').val());
763
		date             = this.fournirDate( $('#date_releve').val());
744
	} else {
764
	} else {
745
		var miniatureImg = [];
765
		var miniatureImg = [];
746
		notes = $( '#commentaire' ).val() || '';
766
		notes = $( '#commentaire' ).val() || '';
747
		if ( 'arbres' === this.sujet ) {
767
		if ( 'arbres' === this.sujet ) {
748
		// Dans ce cas cette fonction doit renvoyer des données au même format que l'input hidden "releve-data"
768
		// Dans ce cas cette fonction doit renvoyer des données au même format que l'input hidden "releve-data"
749
		// car les données dans stockerObsData provenir soit de cette fonction soit de l'input
769
		// car les données dans stockerObsData provenir soit de cette fonction soit de l'input
750
			$( '.miniature-img' ).each( function() {
770
			$( '.miniature-img' ).each( function() {
751
				if ( $( this ).hasClass( 'b64' ) ) {
771
				if ( $( this ).hasClass( 'b64' ) ) {
752
					imgB64 = $( this ).attr( 'src' ) || '';
772
					imgB64 = $( this ).attr( 'src' ) || '';
753
				} else if ( $( this ).hasClass( 'b64-canvas' ) ) {
773
				} else if ( $( this ).hasClass( 'b64-canvas' ) ) {
754
					imgB64 = $( this ).data( 'b64' ) || '';
774
					imgB64 = $( this ).data( 'b64' ) || '';
755
				}
775
				}
756
				miniatureImg.push({
776
				miniatureImg.push({
757
					'nom' : $( this ).attr( 'alt' ),
777
					'nom' : $( this ).attr( 'alt' ),
758
					'src' : $( this ).attr( 'src' ),
778
					'src' : $( this ).attr( 'src' ),
759
					'b64' : imgB64
779
					'b64' : imgB64
760
				});
780
				});
761
			});
781
			});
762
			obsData.sujet = {
782
			obsData.sujet = {
763
				'num-arbre' : this.numArbre,
783
				'num-arbre' : this.numArbre,
764
				taxon       : {
784
				taxon       : {
765
					'numNomSel' : numNomSel,
785
					'numNomSel' : numNomSel,
766
					'value'     : nomSel,
786
					'value'     : nomSel,
767
					'nomRet'    : nomRet,
787
					'nomRet'    : nomRet,
768
					'numNomRet' : numNomRet,
788
					'numNomRet' : numNomRet,
769
					'nt'        : numTaxon,
789
					'nt'        : numTaxon,
770
					'famille'   : famille
790
					'famille'   : famille
771
				},
791
				},
772
				'referentiel'      : referentiel,
792
				'referentiel'      : referentiel,
773
				'certitude'        : certitude,
793
				'certitude'        : certitude,
774
				'rue-arbres'       : ( $( '#rue-arbres' ).val() ) ? $('#rue-arbres').val() : '',
794
				'rue-arbres'       : ( $( '#rue-arbres' ).val() ) ? $('#rue-arbres').val() : '',
775
				'latitude-arbres'  : $( '#latitude-arbres' ).val(),
795
				'latitude-arbres'  : $( '#latitude-arbres' ).val(),
776
				'longitude-arbres' : $( '#longitude-arbres' ).val(),
796
				'longitude-arbres' : $( '#longitude-arbres' ).val(),
777
				'altitude-arbres'  : $( '#altitude-arbres' ).val(),
797
				'altitude-arbres'  : $( '#altitude-arbres' ).val(),
778
				'circonference'    : $( '#circonference' ).val(),
798
				'circonference'    : $( '#circonference' ).val(),
779
				'com-arbres'       : ( $( '#com-arbres' ).val() ) ? $('#com-arbres').val() : '',
799
				'com-arbres'       : ( $( '#com-arbres' ).val() ) ? $('#com-arbres').val() : '',
780
				'miniature-img'    : miniatureImg
800
				'miniature-img'    : miniatureImg
781
			};
801
			};
782
			obsData.releve = {
802
			obsData.releve = {
783
				'date'                  : this.fournirDate( $( '#releve-date' ).val() ),
803
				'date'                  : this.fournirDate( $( '#releve-date' ).val() ),
784
				'rue'                   : $( '#rue' ).val(),
804
				'rue'                   : $( '#rue' ).val(),
785
				'latitude-releve'       : $( '#latitude-releve' ).val(),
805
				'latitude-releve'       : $( '#latitude-releve' ).val(),
786
				'longitude-releve'      : $( '#longitude-releve' ).val(),
806
				'longitude-releve'      : $( '#longitude-releve' ).val(),
787
				'altitude-releve'       : $( '#altitude-releve' ).val(),
807
				'altitude-releve'       : $( '#altitude-releve' ).val(),
788
				'commune-nom'           : $( '#commune-nom' ).val(),
808
				'commune-nom'           : $( '#commune-nom' ).val(),
789
				'commune-insee'         : ( $( '#commune-insee' ).val() ) ? $('#commune-insee').val() : '',
809
				'commune-insee'         : ( $( '#commune-insee' ).val() ) ? $('#commune-insee').val() : '',
790
				'pays'                  : ( $( '#pays' ).val() ) ? $('#pays').val() : '',
810
				'pays'                  : ( $( '#pays' ).val() ) ? $('#pays').val() : '',
791
				'commentaires'          : notes
811
				'commentaires'          : notes
792
			};
812
			};
793
			if ( 'tb_lichensgo' !== this.module ) {
813
			if ( 'tb_lichensgo' !== this.module ) {
794
				obsData.sujet['surface-pied']          = $( '#surface-pied' ).val();
814
				obsData.sujet['surface-pied']          = $( '#surface-pied' ).val();
795
				obsData.sujet['equipement-pied-arbre'] = $( '#equipement-pied-arbre' ).val();
815
				obsData.sujet['equipement-pied-arbre'] = $( '#equipement-pied-arbre' ).val();
796
				obsData.sujet['tassement']             = $( '#tassement' ).val() || '';
816
				obsData.sujet['tassement']             = $( '#tassement' ).val() || '';
797
				obsData.sujet['dejections']            = $( '#dejections input:checked' ).val() || '';
817
				obsData.sujet['dejections']            = $( '#dejections input:checked' ).val() || '';
798
				obsData.releve['zone-pietonne']        = $( '#zone-pietonne input:checked' ).val();
818
				obsData.releve['zone-pietonne']        = $( '#zone-pietonne input:checked' ).val();
799
				obsData.releve['pres-lampadaires']     = $( '#pres-lampadaires input:checked' ).val() || '';
819
				obsData.releve['pres-lampadaires']     = $( '#pres-lampadaires input:checked' ).val() || '';
800
			}
820
			}
801
			if ( 'tb_streets' !== this.module ) {
821
			if ( 'tb_streets' !== this.module ) {
802
				var faceOmbre = [];
822
				var faceOmbre = [];
803
				$( '#face-ombre input' ).each( function() {
823
				$( '#face-ombre input' ).each( function() {
804
					if( $( this ).is( ':checked' ) ) {
824
					if( $( this ).is( ':checked' ) ) {
805
						faceOmbre.push( $( this ).val() );
825
						faceOmbre.push( $( this ).val() );
806
					}
826
					}
807
				});
827
				});
808
				obsData.sujet['face-ombre'] = faceOmbre;
828
				obsData.sujet['face-ombre'] = faceOmbre;
809
			}
829
			}
810
		} else {
830
		} else {
811
			this.releveDatas = $.parseJSON( $( '#releve-data' ).val() );
831
			this.releveDatas = $.parseJSON( $( '#releve-data' ).val() );
812
			obsData.numArbre = $( '#choisir-arbre' ).val();
832
			obsData.numArbre = $( '#choisir-arbre' ).val();
813
			pays             = this.releveDatas[0].pays || '';
833
			pays             = this.releveDatas[0].pays || '';
814
			communeNom       = this.releveDatas[0]['commune-nom'];
834
			communeNom       = this.releveDatas[0]['commune-nom'];
815
			communeInsee     = this.releveDatas[0]['commune-insee'] || '';
835
			communeInsee     = this.releveDatas[0]['commune-insee'] || '';
816
			latitude         = this.releveDatas[obsData.numArbre]['latitude-arbres'];
836
			latitude         = this.releveDatas[obsData.numArbre]['latitude-arbres'];
817
			longitude        = this.releveDatas[obsData.numArbre]['longitude-arbres'];
837
			longitude        = this.releveDatas[obsData.numArbre]['longitude-arbres'];
818
			altitude         = this.releveDatas[obsData.numArbre]['altitude-arbres'];
838
			altitude         = this.releveDatas[obsData.numArbre]['altitude-arbres'];
819
			obsEtendue       = this.getObsChpSpecifiques( obsData.numArbre );
839
			obsEtendue       = this.getObsChpSpecifiques( obsData.numArbre );
820
			date             = this.fournirDate( $( '#obs-date' ).val() );
840
			date             = this.fournirDate( $( '#obs-date' ).val() );
821
		}
841
		}
822
	}
842
	}
823
	if ( !this.isASL || 'arbres' !== this.sujet ) {
843
	if ( !this.isASL || 'arbres' !== this.sujet ) {
824
		imgNom        = this.getNomsImgsOriginales();
844
		imgNom        = this.getNomsImgsOriginales();
825
		imgB64        = this.getB64ImgsOriginales();
845
		imgB64        = this.getB64ImgsOriginales();
826
 
846
 
827
		obsData.sujet = {
847
		obsData.sujet = {
828
			'num_nom_sel'        : numNomSel,
848
			'num_nom_sel'        : numNomSel,
829
			'nom_sel'            : nomSel,
849
			'nom_sel'            : nomSel,
830
			'nom_ret'            : nomRet,
850
			'nom_ret'            : nomRet,
831
			'num_nom_ret'        : numNomRet,
851
			'num_nom_ret'        : numNomRet,
832
			'num_taxon'          : numTaxon,
852
			'num_taxon'          : numTaxon,
833
			'famille'            : famille,
853
			'famille'            : famille,
834
			'referentiel'        : referentiel,
854
			'referentiel'        : referentiel,
835
			'certitude'          : certitude,
855
			'certitude'          : certitude,
836
			'date'               : date,
856
			'date'               : date,
837
			'notes'              : notes,
857
			'notes'              : notes,
838
			'pays'               : pays,
858
			'pays'               : pays,
839
			'commune_nom'        : communeNom,
859
			'commune_nom'        : communeNom,
840
			'commune_code_insee' : communeInsee,
860
			'commune_code_insee' : communeInsee,
841
			'latitude'           : latitude,
861
			'latitude'           : latitude,
842
			'longitude'          : longitude,
862
			'longitude'          : longitude,
843
			'altitude'           : altitude,
863
			'altitude'           : altitude,
844
			//Ajout des champs images
864
			//Ajout des champs images
845
			'image_nom'          : imgNom,
865
			'image_nom'          : imgNom,
846
			'image_b64'          : imgB64,
866
			'image_b64'          : imgB64,
847
			// Ajout des champs étendus de l'obs
867
			// Ajout des champs étendus de l'obs
848
			'obs_etendue'        : obsEtendue
868
			'obs_etendue'        : obsEtendue
849
		};
869
		};
850
		if ( !this.isASL ) {
870
		if ( !this.isASL ) {
851
			obsData.sujet['lieudit'] = $( '#lieudit' ).val() || '';
871
			obsData.sujet['lieudit'] = $( '#lieudit' ).val() || '';
852
			obsData.sujet['station'] = $( '#station' ).val() || '';
872
			obsData.sujet['station'] = $( '#station' ).val() || '';
853
			obsData.sujet['milieu']  = $( '#milieu' ).val() || '';
873
			obsData.sujet['milieu']  = $( '#milieu' ).val() || '';
854
		}
874
		}
855
	}
875
	}
856
	return obsData;
876
	return obsData;
857
};
877
};
858
 
878
 
859
/**
879
/**
860
 * Affiche une observation dans la liste des observations à transmettre
880
 * Affiche une observation dans la liste des observations à transmettre
861
 */
881
 */
862
WidgetsSaisiesCommun.prototype.afficherObs = function( datasObs ) {
882
WidgetsSaisiesCommun.prototype.afficherObs = function( datasObs ) {
863
	// différences html liéees au responsive
883
	// différences html liéees au responsive
864
	var responsivDiff1 = '',
884
	var responsivDiff1 = '',
865
		responsivDiff2 = '',
885
		responsivDiff2 = '',
866
		responsivDiff3 = '',
886
		responsivDiff3 = '',
867
		responsivDiff4 = '',
887
		responsivDiff4 = '',
868
		responsivDiff5 = '',
888
		responsivDiff5 = '',
869
		responsivDiff6 = '';
889
		responsivDiff6 = '';
870
	if ( window.matchMedia( '(min-width: 576px)' ).matches ) {
890
	if ( window.matchMedia( '(min-width: 576px)' ).matches ) {
871
		/* La largeur minimum de l'affichage est 600 px inclus */
891
		/* La largeur minimum de l'affichage est 600 px inclus */
872
		responsivDiff1 = ' droite';
892
		responsivDiff1 = ' droite';
873
		responsivDiff2 = '<div></div>';
893
		responsivDiff2 = '<div></div>';
874
		responsivDiff3 = '<div class="row">';
894
		responsivDiff3 = '<div class="row">';
875
		responsivDiff4 = ( !this.isASL ) ? ' col-md-2 col-sm-4' : ' col-md-4 col-sm-5';
895
		responsivDiff4 = ( !this.isASL ) ? ' col-md-2 col-sm-4' : ' col-md-4 col-sm-5';
876
		responsivDiff5 = ( !this.isASL ) ? ' class="col-md-9 col-sm-7"' : ' class="col-md-7 col-sm-6"';
896
		responsivDiff5 = ( !this.isASL ) ? ' class="col-md-9 col-sm-7"' : ' class="col-md-7 col-sm-6"';
877
		responsivDiff6 = '</div>';
897
		responsivDiff6 = '</div>';
878
	}
898
	}
879
 
899
 
880
	var obsNum           = datasObs.obsNum,
900
	var obsNum           = datasObs.obsNum,
881
		numNomSel        = datasObs.sujet['num_nom_sel'] || '',
901
		numNomSel        = datasObs.sujet['num_nom_sel'] || '',
882
		taxon            = '',
902
		taxon            = '',
883
		miniatures       = '',
903
		miniatures       = '',
884
		notes            = '',
904
		notes            = '',
885
		commentaires     = '',
905
		commentaires     = '',
886
		date             = '',
906
		date             = '',
887
		latitude         = '',
907
		latitude         = '',
888
		longitude        = '',
908
		longitude        = '',
889
		coordonnees      = '',
909
		coordonnees      = '',
890
		commune          = '',
910
		commune          = '',
891
		lieuObs          = '',
911
		lieuObs          = '',
892
		inseeCommuneText = '',
912
		inseeCommuneText = '',
893
		referentiel      = '',
913
		referentiel      = '',
894
		nn               = '',
914
		nn               = '',
895
		lieudit          = '',
915
		lieudit          = '',
896
		station          = '',
916
		station          = '',
897
		milieu           = '',
917
		milieu           = '',
898
		certitude        = '',
918
		certitude        = '',
899
		numArbre         = '',
919
		numArbre         = '',
900
		obsArbre         = '';
920
		obsArbre         = '';
901
 
921
 
902
	if ( !this.isASL ) {
922
	if ( !this.isASL ) {
903
		latitude     = datasObs.sujet['latitude'] || '';
923
		latitude     = datasObs.sujet['latitude'] || '';
904
		longitude    = datasObs.sujet['longitude'] || '';
924
		longitude    = datasObs.sujet['longitude'] || '';
905
		inseeCommune = datasObs.sujet['commune_code_insee'] || '';
925
		inseeCommune = datasObs.sujet['commune_code_insee'] || '';
906
		commune      = datasObs.sujet['commune_nom'] || '';
926
		commune      = datasObs.sujet['commune_nom'] || '';
907
		if ( this.valOk( inseeCommune ) ) {
927
		if ( this.valOk( inseeCommune ) ) {
908
			inseeCommuneText = '(INSEE Commune:' + inseeCommune + ') ';
928
			inseeCommuneText = '(INSEE Commune:' + inseeCommune + ') ';
909
		}
929
		}
910
		if ( this.valOk( numNomSel ) ) {
930
		if ( this.valOk( numNomSel ) ) {
911
			referentiel = '<span class="referentiel-obs">' + '[' + datasObs.sujet['referentiel'] + ']' + '</span>';
931
			referentiel = '<span class="referentiel-obs">' + '[' + datasObs.sujet['referentiel'] + ']' + '</span>';
912
		}
932
		}
913
		if ( this.valOk( datasObs.sujet['lieudit'] ) ) {
933
		if ( this.valOk( datasObs.sujet['lieudit'] ) ) {
914
			lieudit = '<span>' + this.msgTraduction( 'lieu-dit' ) + ' :</span> ' + datasObs.sujet['lieudit'] + ' ';
934
			lieudit = '<span>' + this.msgTraduction( 'lieu-dit' ) + ' :</span> ' + datasObs.sujet['lieudit'] + ' ';
915
		}
935
		}
916
		if ( this.valOk( datasObs.sujet['station'] ) ) {
936
		if ( this.valOk( datasObs.sujet['station'] ) ) {
917
			station = '<span>' + this.msgTraduction( 'station' ) + ' :</span> ' + datasObs.sujet['station'] + ' ';
937
			station = '<span>' + this.msgTraduction( 'station' ) + ' :</span> ' + datasObs.sujet['station'] + ' ';
918
		}
938
		}
919
		if ( this.valOk( datasObs.sujet['milieu'] ) ) {
939
		if ( this.valOk( datasObs.sujet['milieu'] ) ) {
920
			milieu = '<span>' + this.msgTraduction( 'milieu' ) + ' :</span> ' + datasObs.sujet['milieu'] + ' ';
940
			milieu = '<span>' + this.msgTraduction( 'milieu' ) + ' :</span> ' + datasObs.sujet['milieu'] + ' ';
921
		}
941
		}
922
		nn = this.ajouterNumNomSel( numNomSel );
942
		nn = this.ajouterNumNomSel( numNomSel );
923
	} else {
943
	} else {
924
		certitude = ' [certitude : ' + datasObs.sujet.certitude + ']';
944
		certitude = ' [certitude : ' + datasObs.sujet.certitude + ']';
925
		if ( 'arbres' === this.sujet ) {
945
		if ( 'arbres' === this.sujet ) {
926
			numArbre   = datasObs.sujet['num-arbre'];
946
			numArbre   = datasObs.sujet['num-arbre'];
927
			numNomSel  = datasObs.sujet.taxon.numNomSel;
947
			numNomSel  = datasObs.sujet.taxon.numNomSel;
928
			taxon      = datasObs.sujet.taxon.value;
948
			taxon      = datasObs.sujet.taxon.value;
929
			miniatures = this.ajouterImgMiniatureAuTransfert(datasObs.sujet['miniature-img'] );
949
			miniatures = this.ajouterImgMiniatureAuTransfert(datasObs.sujet['miniature-img'] );
930
			notes      = datasObs.sujet['com-arbres'] || '';
950
			notes      = datasObs.sujet['com-arbres'] || '';
931
			latitude   = datasObs.sujet['latitude-arbres'];
951
			latitude   = datasObs.sujet['latitude-arbres'];
932
			longitude  = datasObs.sujet['longitude-arbres'];
952
			longitude  = datasObs.sujet['longitude-arbres'];
933
			numArbre   = datasObs.sujet['num-arbre'];
953
			numArbre   = datasObs.sujet['num-arbre'];
934
			// s'assurer que la date est au bon format
954
			// s'assurer que la date est au bon format
935
			date       = this.fournirDate( datasObs.releve.date );
955
			date       = this.fournirDate( datasObs.releve.date );
936
			commune    = datasObs.releve['commune-nom'] || '';
956
			commune    = datasObs.releve['commune-nom'] || '';
937
		} else {
957
		} else {
938
			numArbre   = datasObs.numArbre;
958
			numArbre   = datasObs.numArbre;
939
		}
959
		}
940
		obsArbre = '<span id="obs-arbre-' + numArbre + '" class="badge num-obs-arbre" data-arbre="' + numArbre + '">Arbre ' + numArbre + '</span>';
960
		obsArbre = '<span id="obs-arbre-' + numArbre + '" class="badge num-obs-arbre" data-arbre="' + numArbre + '">Arbre ' + numArbre + '</span>';
941
	}
961
	}
942
	if ( !this.isASL || 'arbres' !== this.sujet ) {
962
	if ( !this.isASL || 'arbres' !== this.sujet ) {
943
		taxon      = datasObs.sujet['nom_sel'];
963
		taxon      = datasObs.sujet['nom_sel'];
944
		miniatures = this.ajouterImgMiniatureAuTransfert();
964
		miniatures = this.ajouterImgMiniatureAuTransfert();
945
		notes      = datasObs.sujet['notes'] || '';
965
		notes      = datasObs.sujet['notes'] || '';
946
		date       = this.fournirDate( datasObs.sujet.date );
966
		date       = this.fournirDate( datasObs.sujet.date );
947
	}
967
	}
948
	if( !this.isASL || 'arbres' === this.sujet ) {
968
	if( !this.isASL || 'arbres' === this.sujet ) {
949
		if ( this.valOk( commune ) ) {
969
		if ( this.valOk( commune ) ) {
950
			lieuObs = ' '  + this.msgTraduction( 'lieu-obs' ) + ' ' + '<span class="commune">' + commune + '</span> ';
970
			lieuObs = ' '  + this.msgTraduction( 'lieu-obs' ) + ' ' + '<span class="commune">' + commune + '</span> ';
951
		}
971
		}
952
		if ( this.valOk( latitude ) && this.valOk( longitude ) ) {
972
		if ( this.valOk( latitude ) && this.valOk( longitude ) ) {
953
			coordonnees = '[' + latitude + ' / ' + longitude + ']';
973
			coordonnees = '[' + latitude + ' / ' + longitude + ']';
954
		}
974
		}
955
	}
975
	}
956
	if ( this.valOk( notes ) ) {
976
	if ( this.valOk( notes ) ) {
957
		commentaires =
977
		commentaires =
958
			this.msgTraduction( 'commentaires' ) +
978
			this.msgTraduction( 'commentaires' ) +
959
			' : <span>'+
979
			' : <span>'+
960
				notes +
980
				notes +
961
			'</span> ';
981
			'</span> ';
962
	}
982
	}
963
	// html du bloc résumé de l'obs
983
	// html du bloc résumé de l'obs
964
	$( '#liste-obs' ).prepend(
984
	$( '#liste-obs' ).prepend(
965
		'<div id="obs' + obsNum + '" class="obs obs' + obsNum + ' mb-2">'+
985
		'<div id="obs' + obsNum + '" class="obs obs' + obsNum + ' mb-2">'+
966
			'<div '+
986
			'<div '+
967
				'class="obs-action" '+
987
				'class="obs-action" '+
968
				'title="' + this.msgTraduction( 'supprimer-observation-liste' ) + '"'+
988
				'title="' + this.msgTraduction( 'supprimer-observation-liste' ) + '"'+
969
			'>'+
989
			'>'+
970
				'<button class="btn btn-danger supprimer-obs' + responsivDiff1 + '" value="'+ obsNum + '" title="' + this.msgTraduction( 'obs-numero' ) + obsNum + '">'+
990
				'<button class="btn btn-danger supprimer-obs' + responsivDiff1 + '" value="'+ obsNum + '" title="' + this.msgTraduction( 'obs-numero' ) + obsNum + '">'+
971
				'<i class="far fa-trash-alt"></i>'+
991
				'<i class="far fa-trash-alt"></i>'+
972
				'</button>'+
992
				'</button>'+
973
				responsivDiff2 +
993
				responsivDiff2 +
974
			'</div> '+
994
			'</div> '+
975
			responsivDiff3 +
995
			responsivDiff3 +
976
				'<div class="thumbnail' + responsivDiff4 + '">'+
996
				'<div class="thumbnail' + responsivDiff4 + '">'+
977
					miniatures +
997
					miniatures +
978
				'</div>'+
998
				'</div>'+
979
				'<div' + responsivDiff5 + '>'+
999
				'<div' + responsivDiff5 + '>'+
980
					'<ul class="unstyled">'+
1000
					'<ul class="unstyled">'+
981
						'<li>'+
1001
						'<li>'+
982
							// isASL
1002
							// isASL
983
							obsArbre +
1003
							obsArbre +
984
							// toujours
1004
							// toujours
985
							'<span class="nom-sci">' + taxon + '</span> '+
1005
							'<span class="nom-sci">' + taxon + '</span> '+
986
							// !isASL
1006
							// !isASL
987
							nn +
1007
							nn +
988
							referentiel +
1008
							referentiel +
989
							// isASL
1009
							// isASL
990
							certitude +
1010
							certitude +
991
							// !this.isASL || 'arbres' === this.sujet
1011
							// !this.isASL || 'arbres' === this.sujet
992
							lieuObs +
1012
							lieuObs +
993
							// !isASL
1013
							// !isASL
994
							inseeCommuneText +
1014
							inseeCommuneText +
995
							// !this.isASL || 'arbres' === this.sujet
1015
							// !this.isASL || 'arbres' === this.sujet
996
							coordonnees +
1016
							coordonnees +
997
							// toujours
1017
							// toujours
998
							' ' + this.msgTraduction( 'obs-le' ) + ' '+
1018
							' ' + this.msgTraduction( 'obs-le' ) + ' '+
999
							'<span class="date">' + date + '</span>'+
1019
							'<span class="date">' + date + '</span>'+
1000
						'</li>'+
1020
						'</li>'+
1001
						'<li>'+
1021
						'<li>'+
1002
							// !isASL
1022
							// !isASL
1003
							lieudit +
1023
							lieudit +
1004
							station +
1024
							station +
1005
							milieu +
1025
							milieu +
1006
						'</li>'+
1026
						'</li>'+
1007
						'<li>'+
1027
						'<li>'+
1008
							// this.valOk( notes )
1028
							// this.valOk( notes )
1009
							commentaires +
1029
							commentaires +
1010
						'</li>'+
1030
						'</li>'+
1011
					'</ul>'+
1031
					'</ul>'+
1012
				'</div>'+
1032
				'</div>'+
1013
			responsivDiff6+
1033
			responsivDiff6+
1014
		'</div>'
1034
		'</div>'
1015
	);
1035
	);
1016
 
1036
 
1017
	$( '#zone-liste-obs' ).removeClass( 'hidden' );
1037
	$( '#zone-liste-obs' ).removeClass( 'hidden' );
1018
};
1038
};
1019
 
1039
 
1020
/**
1040
/**
1021
 * Ajoute une boîte de miniatures avec défilement des images,
1041
 * Ajoute une boîte de miniatures avec défilement des images,
1022
 * pour une obs de la liste des obs à transmettre
1042
 * pour une obs de la liste des obs à transmettre
1023
 */
1043
 */
1024
WidgetsSaisiesCommun.prototype.ajouterImgMiniatureAuTransfert = function( chargerImages = undefined ) {
1044
WidgetsSaisiesCommun.prototype.ajouterImgMiniatureAuTransfert = function( chargerImages = undefined ) {
1025
	const lthis = this;
1045
	const lthis = this;
1026
	var html         =
1046
	var html         =
1027
			'<div class="defilement-miniatures">'+
1047
			'<div class="defilement-miniatures">'+
1028
				'<figure class="centre">'+
1048
				'<figure class="centre">'+
1029
					'<img class="miniature align-middle" alt="Aucune photo" src="' + this.pasDePhotoIconeUrl + '" width="80%" />'+
1049
					'<img class="miniature align-middle" alt="Aucune photo" src="' + this.pasDePhotoIconeUrl + '" width="80%" />'+
1030
				'</figure>'+
1050
				'</figure>'+
1031
			'</div>',
1051
			'</div>',
1032
		miniatures   = '',
1052
		miniatures   = '',
1033
		centre       = '',
1053
		centre       = '',
1034
		defilVisible = '',
1054
		defilVisible = '',
1035
		length       = 0;
1055
		length       = 0;
1036
 
1056
 
1037
	if ( this.valOk( chargerImages ) || this.valOk( $( '#miniatures img' ) ) ) {
1057
	if ( this.valOk( chargerImages ) || this.valOk( $( '#miniatures img' ) ) ) {
1038
		if ( this.valOk( chargerImages ) ) {
1058
		if ( this.valOk( chargerImages ) ) {
1039
			$.each(  chargerImages, function( i, value ) {
1059
			$.each(  chargerImages, function( i, value ) {
1040
				var imgVisible = ( 0 < i ) ? 'miniature-cachee' : 'miniature-selectionnee';
1060
				var imgVisible = ( 0 < i ) ? 'miniature-cachee' : 'miniature-selectionnee';
1041
 
1061
 
1042
				var css        = ( lthis.valOk( value['b64'] ) ) ? 'miniature b64' : 'miniature',
1062
				var css        = ( lthis.valOk( value['b64'] ) ) ? 'miniature b64' : 'miniature',
1043
					src        = value.src,
1063
					src        = value.src,
1044
					alt        = value.nom,
1064
					alt        = value.nom,
1045
					miniature  = '<img class="' + css + ' ' + imgVisible + ' align-middle"  alt="' + alt + '"src="' + src + '" width="80%" />';
1065
					miniature  = '<img class="' + css + ' ' + imgVisible + ' align-middle"  alt="' + alt + '"src="' + src + '" width="80%" />';
1046
 
1066
 
1047
				miniatures += miniature;
1067
				miniatures += miniature;
1048
			});
1068
			});
1049
			length = chargerImages.length;
1069
			length = chargerImages.length;
1050
		} else {
1070
		} else {
1051
			var premiere     = true;
1071
			var premiere     = true;
1052
			$( '#miniatures img' ).each( function() {
1072
			$( '#miniatures img' ).each( function() {
1053
				var imgVisible = ( premiere ) ? 'miniature-selectionnee' : 'miniature-cachee';
1073
				var imgVisible = ( premiere ) ? 'miniature-selectionnee' : 'miniature-cachee';
1054
				premiere = false;
1074
				premiere = false;
1055
 
1075
 
1056
				var css        = ( $( this ).hasClass( 'b64' ) ) ? 'miniature b64' : 'miniature',
1076
				var css        = ( $( this ).hasClass( 'b64' ) ) ? 'miniature b64' : 'miniature',
1057
					src        = $( this ).attr( 'src' ),
1077
					src        = $( this ).attr( 'src' ),
1058
					alt        = $( this ).attr( 'alt' ),
1078
					alt        = $( this ).attr( 'alt' ),
1059
					miniature  = '<img class="' + css + ' ' + imgVisible + ' align-middle"  alt="' + alt + '"src="' + src + '" width="80%" />';
1079
					miniature  = '<img class="' + css + ' ' + imgVisible + ' align-middle"  alt="' + alt + '"src="' + src + '" width="80%" />';
1060
 
1080
 
1061
				miniatures += miniature;
1081
				miniatures += miniature;
1062
			});
1082
			});
1063
			length = $( '#miniatures img' ).length;
1083
			length = $( '#miniatures img' ).length;
1064
		}
1084
		}
1065
		if ( 1 === length ) {
1085
		if ( 1 === length ) {
1066
			centre       = 'centre';
1086
			centre       = 'centre';
1067
			defilVisible = ' defilement-miniatures-cache';
1087
			defilVisible = ' defilement-miniatures-cache';
1068
		}
1088
		}
1069
		html             =
1089
		html             =
1070
			'<div class="defilement-miniatures">'+
1090
			'<div class="defilement-miniatures">'+
1071
				'<a href="#" class="defilement-miniatures-gauche mr-1' + defilVisible + '"><i class="fas fa-chevron-circle-left"></i></a>'+
1091
				'<a href="#" class="defilement-miniatures-gauche mr-1' + defilVisible + '"><i class="fas fa-chevron-circle-left"></i></a>'+
1072
				'<figure class="' + centre + '">'+
1092
				'<figure class="' + centre + '">'+
1073
					miniatures+
1093
					miniatures+
1074
				'</figure>'+
1094
				'</figure>'+
1075
				'<a href="#" class="defilement-miniatures-droite ml-1' + defilVisible + '"><i class="fas fa-chevron-circle-right"></i></a>'+
1095
				'<a href="#" class="defilement-miniatures-droite ml-1' + defilVisible + '"><i class="fas fa-chevron-circle-right"></i></a>'+
1076
			'</div>';
1096
			'</div>';
1077
	}
1097
	}
1078
 
1098
 
1079
	return html;
1099
	return html;
1080
};
1100
};
1081
 
1101
 
1082
/**
1102
/**
1083
 * Construit le html à afficher pour le numNom
1103
 * Construit le html à afficher pour le numNom
1084
 */
1104
 */
1085
WidgetsSaisiesCommun.prototype.ajouterNumNomSel = function( numNomSel ) {
1105
WidgetsSaisiesCommun.prototype.ajouterNumNomSel = function( numNomSel ) {
1086
	var nn = '<span class="nn">[nn' + numNomSel + ']</span>';
1106
	var nn = '<span class="nn">[nn' + numNomSel + ']</span>';
1087
 
1107
 
1088
	if ( !this.valOk( numNomSel ) ) {
1108
	if ( !this.valOk( numNomSel ) ) {
1089
		nn = '<span class="alert-error">[' + this.msgTraduction( 'non-lie-au-ref' ) + ']</span>';
1109
		nn = '<span class="alert-error">[' + this.msgTraduction( 'non-lie-au-ref' ) + ']</span>';
1090
	}
1110
	}
1091
 
1111
 
1092
	return nn;
1112
	return nn;
1093
};
1113
};
1094
 
1114
 
1095
/**
1115
/**
1096
 * Stocke des données d'obs à envoyer à la bdd
1116
 * Stocke des données d'obs à envoyer à la bdd
1097
 */
1117
 */
1098
WidgetsSaisiesCommun.prototype.stockerObsData = function( obsDatas ) {
1118
WidgetsSaisiesCommun.prototype.stockerObsData = function( obsDatas ) {
1099
	if ( this.isASL && 'arbres' === this.sujet ) {
1119
	if ( this.isASL && 'arbres' === this.sujet ) {
1100
		// Dans ce cas la fonction formaterFormObsData renvoie des données au même format que l'input hidden "releve-data"
1120
		// Dans ce cas la fonction formaterFormObsData renvoie des données au même format que l'input hidden "releve-data"
1101
		// car les données peuvent provenir soit de la formaterFormObsData soit de cet input
1121
		// car les données peuvent provenir soit de la formaterFormObsData soit de cet input
1102
		const lthis = this;
1122
		const lthis = this;
1103
		// si releve dupliqué on ne stocke pas l'image :
1123
		// si releve dupliqué on ne stocke pas l'image :
1104
		var stockerImg  = this.valOk( obsDatas.sujet['miniature-img'] ),
1124
		var stockerImg  = this.valOk( obsDatas.sujet['miniature-img'] ),
1105
			imgNom      = [],
1125
			imgNom      = [],
1106
			imgB64      = [];
1126
			imgB64      = [];
1107
 
1127
 
1108
		// Si on a bien un 'miniature-img' dans les données
1128
		// Si on a bien un 'miniature-img' dans les données
1109
		if( stockerImg ) {
1129
		if( stockerImg ) {
1110
			$.each( obsDatas.sujet['miniature-img'], function( i, obj ) {
1130
			$.each( obsDatas.sujet['miniature-img'], function( i, obj ) {
1111
				if( obj.hasOwnProperty( 'id' ) ) {
1131
				if( obj.hasOwnProperty( 'id' ) ) {
1112
					stockerImg = false;
1132
					stockerImg = false;
1113
				}
1133
				}
1114
				return stockerImg;
1134
				return stockerImg;
1115
			});
1135
			});
1116
		}
1136
		}
1117
		// Si les miniatures ne sont pas déjà stockées (résultat de la loop précédente)
1137
		// Si les miniatures ne sont pas déjà stockées (résultat de la loop précédente)
1118
		if( stockerImg ) {
1138
		if( stockerImg ) {
1119
			$.each( obsDatas.sujet['miniature-img'] , function( i, obj ) {
1139
			$.each( obsDatas.sujet['miniature-img'] , function( i, obj ) {
1120
				if( lthis.valOk( obj.nom ) ) {
1140
				if( lthis.valOk( obj.nom ) ) {
1121
					imgNom.push( obj.nom );
1141
					imgNom.push( obj.nom );
1122
				}
1142
				}
1123
				if( lthis.valOk( obj['b64'] ) ) {
1143
				if( lthis.valOk( obj['b64'] ) ) {
1124
					imgB64.push( obj['b64'] );
1144
					imgB64.push( obj['b64'] );
1125
				}
1145
				}
1126
			});
1146
			});
1127
		} else {
1147
		} else {
1128
			imgNom = lthis.getNomsImgsOriginales();
1148
			imgNom = lthis.getNomsImgsOriginales();
1129
			imgB64 = lthis.getB64ImgsOriginales();
1149
			imgB64 = lthis.getB64ImgsOriginales();
1130
		}
1150
		}
1131
		// Stockage en data des données d'obs à transmettre
1151
		// Stockage en data des données d'obs à transmettre
1132
		$( '#liste-obs' ).data( 'obsId' + obsDatas.obsNum, {
1152
		$( '#liste-obs' ).data( 'obsId' + obsDatas.obsNum, {
1133
			'num_nom_sel'        : obsDatas.sujet.taxon.numNomSel,
1153
			'num_nom_sel'        : obsDatas.sujet.taxon.numNomSel,
1134
			'nom_sel'            : obsDatas.sujet.taxon.value,
1154
			'nom_sel'            : obsDatas.sujet.taxon.value,
1135
			'nom_ret'            : obsDatas.sujet.taxon.nomRet,
1155
			'nom_ret'            : obsDatas.sujet.taxon.nomRet,
1136
			'num_nom_ret'        : obsDatas.sujet.taxon.numNomRet,
1156
			'num_nom_ret'        : obsDatas.sujet.taxon.numNomRet,
1137
			'num_taxon'          : obsDatas.sujet.taxon.nt,
1157
			'num_taxon'          : obsDatas.sujet.taxon.nt,
1138
			'famille'            : obsDatas.sujet.taxon.famille,
1158
			'famille'            : obsDatas.sujet.taxon.famille,
1139
			'referentiel'        : obsDatas.sujet.referentiel,
1159
			'referentiel'        : obsDatas.sujet.referentiel,
1140
			'certitude'          : obsDatas.sujet.certitude,
1160
			'certitude'          : obsDatas.sujet.certitude,
1141
			// La date provenant de input "releve-data" n'est pas au bon format
1161
			// La date provenant de input "releve-data" n'est pas au bon format
1142
			'date'               : this.fournirDate( obsDatas.releve.date ),
1162
			'date'               : this.fournirDate( obsDatas.releve.date ),
1143
			'notes'              : obsDatas.releve.commentaires.trim(),
1163
			'notes'              : obsDatas.releve.commentaires.trim(),
1144
			'pays'               : obsDatas.releve.pays,
1164
			'pays'               : obsDatas.releve.pays,
1145
			'commune_nom'        : obsDatas.releve['commune-nom'],
1165
			'commune_nom'        : obsDatas.releve['commune-nom'],
1146
			'commune_code_insee' : obsDatas.releve['commune-insee'],
1166
			'commune_code_insee' : obsDatas.releve['commune-insee'],
1147
			'latitude'           : obsDatas.sujet['latitude-arbres'],
1167
			'latitude'           : obsDatas.sujet['latitude-arbres'],
1148
			'longitude'          : obsDatas.sujet['longitude-arbres'],
1168
			'longitude'          : obsDatas.sujet['longitude-arbres'],
1149
			'altitude'           : obsDatas.sujet['altitude-arbres'],
1169
			'altitude'           : obsDatas.sujet['altitude-arbres'],
1150
			'image_nom'          : imgNom,
1170
			'image_nom'          : imgNom,
1151
			'image_b64'          : imgB64,
1171
			'image_b64'          : imgB64,
1152
			// Ajout des champs étendus de l'obs
1172
			// Ajout des champs étendus de l'obs
1153
			'obs_etendue'        : lthis.getObsChpSpecifiques( obsDatas )
1173
			'obs_etendue'        : lthis.getObsChpSpecifiques( obsDatas )
1154
		});
1174
		});
1155
	} else {
1175
	} else {
1156
		// Stockage en data des données d'obs à transmettre
1176
		// Stockage en data des données d'obs à transmettre
1157
		$( '#liste-obs' ).data( 'obsId' + obsDatas.obsNum, obsDatas.sujet );
1177
		$( '#liste-obs' ).data( 'obsId' + obsDatas.obsNum, obsDatas.sujet );
1158
	}
1178
	}
1159
};
1179
};
1160
 
1180
 
1161
WidgetsSaisiesCommun.prototype.getNomsImgsOriginales = function() {
1181
WidgetsSaisiesCommun.prototype.getNomsImgsOriginales = function() {
1162
	var noms = new Array();
1182
	var noms = new Array();
1163
 
1183
 
1164
	$( '.miniature-img' ).each( function() {
1184
	$( '.miniature-img' ).each( function() {
1165
		noms.push( $( this ).attr( 'alt' ) );
1185
		noms.push( $( this ).attr( 'alt' ) );
1166
	});
1186
	});
1167
 
1187
 
1168
	return noms;
1188
	return noms;
1169
};
1189
};
1170
 
1190
 
1171
WidgetsSaisiesCommun.prototype.getB64ImgsOriginales = function() {
1191
WidgetsSaisiesCommun.prototype.getB64ImgsOriginales = function() {
1172
	var b64 = new Array();
1192
	var b64 = new Array();
1173
 
1193
 
1174
	$( '.miniature-img' ).each( function() {
1194
	$( '.miniature-img' ).each( function() {
1175
		if ( $( this ).hasClass( 'b64' ) ) {
1195
		if ( $( this ).hasClass( 'b64' ) ) {
1176
			b64.push( $( this ).attr( 'src' ) );
1196
			b64.push( $( this ).attr( 'src' ) );
1177
		} else if ( $( this ).hasClass( 'b64-canvas' ) ) {
1197
		} else if ( $( this ).hasClass( 'b64-canvas' ) ) {
1178
			b64.push( $( this ).data( 'b64' ) );
1198
			b64.push( $( this ).data( 'b64' ) );
1179
		}
1199
		}
1180
	});
1200
	});
1181
 
1201
 
1182
	return b64;
1202
	return b64;
1183
};
1203
};
1184
 
1204
 
1185
/**
1205
/**
1186
 * Efface toutes les miniatures (formulaire)
1206
 * Efface toutes les miniatures (formulaire)
1187
 */
1207
 */
1188
WidgetsSaisiesCommun.prototype.supprimerMiniatures = function() {
1208
WidgetsSaisiesCommun.prototype.supprimerMiniatures = function() {
1189
	if ( !this.isASL ) {
1209
	if ( !this.isASL ) {
1190
		// Déconnection MutationObserver miniatures
1210
		// Déconnection MutationObserver miniatures
1191
		// Sinon on a une erreur avant la création d'une nouvelle obs
1211
		// Sinon on a une erreur avant la création d'une nouvelle obs
1192
		this.observer.disconnect();
1212
		this.observer.disconnect();
1193
		$( '#miniatures' ).empty();
1213
		$( '#miniatures' ).empty();
1194
		// Validation miniatures reprend à 0 pour une nouvelle obs
1214
		// Validation miniatures reprend à 0 pour une nouvelle obs
1195
		this.surPresenceAbsenceMiniature();
1215
		this.surPresenceAbsenceMiniature();
1196
	} else {
1216
	} else {
1197
		$( '#miniatures' ).empty();
1217
		$( '#miniatures' ).empty();
1198
	}
1218
	}
1199
	$( '#miniature-msg' ).empty();
1219
	$( '#miniature-msg' ).empty();
1200
};
1220
};
1201
 
1221
 
1202
WidgetsSaisiesCommun.prototype.surChangementNbreObs = function() {
1222
WidgetsSaisiesCommun.prototype.surChangementNbreObs = function() {
1203
	if ( 0 === this.obsNbre ) {
1223
	if ( 0 === this.obsNbre ) {
1204
		$( '#transmettre-obs' ).attr( 'disabled', 'disabled' );
1224
		$( '#transmettre-obs' ).attr( 'disabled', 'disabled' );
1205
	} else if ( 0 < this.obsNbre && this.obsNbre < this.obsMaxNbre ) {
1225
	} else if ( 0 < this.obsNbre && this.obsNbre < this.obsMaxNbre ) {
1206
		$( '#ajouter-obs,#transmettre-obs' ).removeAttr( 'disabled' );
1226
		$( '#ajouter-obs,#transmettre-obs' ).removeAttr( 'disabled' );
1207
	} else if ( this.obsNbre >= this.obsMaxNbre ) {
1227
	} else if ( this.obsNbre >= this.obsMaxNbre ) {
1208
		$( '#ajouter-obs' ).attr( 'disabled', 'disabled' );
1228
		$( '#ajouter-obs' ).attr( 'disabled', 'disabled' );
1209
		this.afficherPanneau( '#dialogue-bloquer-creer-obs' );
1229
		this.afficherPanneau( '#dialogue-bloquer-creer-obs' );
1210
	}
1230
	}
1211
	if ( this.isASL && 'arbres' === this.sujet ) {
1231
	if ( this.isASL && 'arbres' === this.sujet ) {
1212
		if ( 0 <= this.obsNbre && this.obsNbre < this.obsMaxNbre ) {
1232
		if ( 0 <= this.obsNbre && this.obsNbre < this.obsMaxNbre ) {
1213
			$( '#bloc-form-arbres' ).removeClass( 'hidden' );
1233
			$( '#bloc-form-arbres' ).removeClass( 'hidden' );
1214
		} else {
1234
		} else {
1215
			$( '#bloc-form-arbres' ).addClass( 'hidden' );
1235
			$( '#bloc-form-arbres' ).addClass( 'hidden' );
1216
		}
1236
		}
1217
	}
1237
	}
1218
};
1238
};
1219
 
1239
 
1220
WidgetsSaisiesCommun.prototype.defilerMiniatures = function( element ) {
1240
WidgetsSaisiesCommun.prototype.defilerMiniatures = function( element ) {
1221
	var miniatureSelectionne  = element.siblings( 'figure' ).find( 'img.miniature-selectionnee' );
1241
	var miniatureSelectionne  = element.siblings( 'figure' ).find( 'img.miniature-selectionnee' );
1222
 
1242
 
1223
	miniatureSelectionne.removeClass( 'miniature-selectionnee' );
1243
	miniatureSelectionne.removeClass( 'miniature-selectionnee' );
1224
	miniatureSelectionne.addClass( 'miniature-cachee' );
1244
	miniatureSelectionne.addClass( 'miniature-cachee' );
1225
 
1245
 
1226
	var miniatureAffichee     = miniatureSelectionne;
1246
	var miniatureAffichee     = miniatureSelectionne;
1227
 
1247
 
1228
	if( element.hasClass( 'defilement-miniatures-gauche' ) ) {
1248
	if( element.hasClass( 'defilement-miniatures-gauche' ) ) {
1229
		if( 0 !== miniatureSelectionne.prev( '.miniature' ).length ) {
1249
		if( 0 !== miniatureSelectionne.prev( '.miniature' ).length ) {
1230
			miniatureAffichee = miniatureSelectionne.prev( '.miniature' );
1250
			miniatureAffichee = miniatureSelectionne.prev( '.miniature' );
1231
		} else {
1251
		} else {
1232
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).last();
1252
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).last();
1233
		}
1253
		}
1234
	} else {
1254
	} else {
1235
		if( 0 !== miniatureSelectionne.next('.miniature').length ) {
1255
		if( 0 !== miniatureSelectionne.next('.miniature').length ) {
1236
			miniatureAffichee = miniatureSelectionne.next( '.miniature' );
1256
			miniatureAffichee = miniatureSelectionne.next( '.miniature' );
1237
		} else {
1257
		} else {
1238
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).first();
1258
			miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).first();
1239
		}
1259
		}
1240
	}
1260
	}
1241
	miniatureAffichee.addClass( 'miniature-selectionnee' );
1261
	miniatureAffichee.addClass( 'miniature-selectionnee' );
1242
	miniatureAffichee.removeClass( 'miniature-cachee' );
1262
	miniatureAffichee.removeClass( 'miniature-cachee' );
1243
};
1263
};
1244
 
1264
 
1245
WidgetsSaisiesCommun.prototype.supprimerObs = function( selector ) {
1265
WidgetsSaisiesCommun.prototype.supprimerObs = function( selector ) {
1246
	var obsId = $( selector ).val();
1266
	var obsId = $( selector ).val();
1247
 
1267
 
1248
	// Problème avec IE 6 et 7
1268
	// Problème avec IE 6 et 7
1249
	if ( 'Supprimer' === obsId ) {
1269
	if ( 'Supprimer' === obsId ) {
1250
		obsId = $( selector ).attr( 'title' );
1270
		obsId = $( selector ).attr( 'title' );
1251
	}
1271
	}
1252
	this.supprimerObsParId( obsId );
1272
	this.supprimerObsParId( obsId );
1253
};
1273
};
1254
 
1274
 
1255
/**
1275
/**
1256
 * Supprime l'obs et les data de l'obs
1276
 * Supprime l'obs et les data de l'obs
1257
 * et remonte les suivantes d'un cran
1277
 * et remonte les suivantes d'un cran
1258
 */
1278
 */
1259
WidgetsSaisiesCommun.prototype.supprimerObsParId = function( obsId, transmission = false ) {
1279
WidgetsSaisiesCommun.prototype.supprimerObsParId = function( obsId, transmission = false ) {
1260
	if ( this.isASL && 'arbres' === this.sujet ) {
1280
	if ( this.isASL && 'arbres' === this.sujet ) {
1261
		if ( !transmission ) {
1281
		if ( !transmission ) {
1262
			this.releveData  = $.parseJSON( $( '#releve-data' ).val() );
1282
			this.releveData  = $.parseJSON( $( '#releve-data' ).val() );
1263
			this.releveData.splice( obsId , 1 );
1283
			this.releveData.splice( obsId , 1 );
1264
			$( '#releve-data' ).val( JSON.stringify( this.releveData ) );
1284
			$( '#releve-data' ).val( JSON.stringify( this.releveData ) );
1265
		}
1285
		}
1266
		$( '#arbre-info-' + ( this.numArbre ) ).remove();
1286
		$( '#arbre-info-' + ( this.numArbre ) ).remove();
1267
		$( '#arbre-nb' ).text( this.numArbre );
1287
		$( '#arbre-nb' ).text( this.numArbre );
1268
		this.numArbre -= 1;
1288
		this.numArbre -= 1;
1269
		if ( 1 > this.numArbre ) {
1289
		if ( 1 > this.numArbre ) {
1270
			$( '#bloc-info-arbres-title' ).addClass( 'hidden' );
1290
			$( '#bloc-info-arbres-title' ).addClass( 'hidden' );
1271
		}
1291
		}
1272
 
1292
 
1273
		var arbreExId   = 0,
1293
		var arbreExId   = 0,
1274
			arbreId     = 0;
1294
			arbreId     = 0;
1275
	}
1295
	}
1276
	this.obsNbre  -= 1;
1296
	this.obsNbre  -= 1;
1277
	$( '.obs-nbre' ).text( this.obsNbre );
1297
	$( '.obs-nbre' ).text( this.obsNbre );
1278
	$( '.obs-nbre' ).triggerHandler( 'changement' );
1298
	$( '.obs-nbre' ).triggerHandler( 'changement' );
1279
	$( '.obs' + obsId ).remove();
1299
	$( '.obs' + obsId ).remove();
1280
	obsId = parseInt(obsId);
1300
	obsId = parseInt(obsId);
1281
 
1301
 
1282
	if ( !transmission ) {
1302
	if ( !transmission ) {
1283
		var listObsData = $( '#liste-obs' ).data(),
1303
		var listObsData = $( '#liste-obs' ).data(),
1284
			exId        = 0,
1304
			exId        = 0,
1285
			indexObs    = '',
1305
			indexObs    = '',
1286
			exIndexObs  = '';
1306
			exIndexObs  = '';
1287
 
1307
 
1288
		for ( var id = obsId; id <= ( this.obsNbre + 1 ); id++ ) {
1308
		for ( var id = obsId; id <= ( this.obsNbre + 1 ); id++ ) {
1289
			exId       = parseInt(id) + 1;
1309
			exId       = parseInt(id) + 1;
1290
			indexObs   = 'obsId' + id;
1310
			indexObs   = 'obsId' + id;
1291
			exIndexObs = 'obsId' + exId;
1311
			exIndexObs = 'obsId' + exId;
1292
			$( '#liste-obs' ).removeData( indexObs );
1312
			$( '#liste-obs' ).removeData( indexObs );
1293
			$( '#obs' + exId )
1313
			$( '#obs' + exId )
1294
				.attr( 'id', 'obs' + id )
1314
				.attr( 'id', 'obs' + id )
1295
				.removeClass( 'obs' + exId )
1315
				.removeClass( 'obs' + exId )
1296
				.addClass( 'obs' + id )
1316
				.addClass( 'obs' + id )
1297
				.find( '.supprimer-obs' )
1317
				.find( '.supprimer-obs' )
1298
					.attr( 'title', 'Observation n°' + id )
1318
					.attr( 'title', 'Observation n°' + id )
1299
					.val( id );
1319
					.val( id );
1300
 
1320
 
1301
			if ( this.isASL && 'arbres' === this.sujet ) {
1321
			if ( this.isASL && 'arbres' === this.sujet ) {
1302
				arbreExId = parseInt( $( '#obs-arbre-' + exId ).data( 'arbre' ) );
1322
				arbreExId = parseInt( $( '#obs-arbre-' + exId ).data( 'arbre' ) );
1303
				arbreId   = arbreExId - 1;
1323
				arbreId   = arbreExId - 1;
1304
				$( '#obs-arbre-' + arbreExId )
1324
				$( '#obs-arbre-' + arbreExId )
1305
					.attr( 'id', 'obs-arbre-' + arbreId )
1325
					.attr( 'id', 'obs-arbre-' + arbreId )
1306
					.attr( 'data-arbre', arbreId )
1326
					.attr( 'data-arbre', arbreId )
1307
					.data( 'arbre', arbreId )
1327
					.data( 'arbre', arbreId )
1308
					.text( 'Arbre ' + arbreId );
1328
					.text( 'Arbre ' + arbreId );
1309
				// modification du numero d'arbre dans les obs étendues
1329
				// modification du numero d'arbre dans les obs étendues
1310
				if ( this.valOk( listObsData[exIndexObs] ) ) {
1330
				if ( this.valOk( listObsData[exIndexObs] ) ) {
1311
					$.each( listObsData[exIndexObs].obs_etendue, function( i, obsE ) {
1331
					$.each( listObsData[exIndexObs].obs_etendue, function( i, obsE ) {
1312
						if ('num_arbre' === obsE.cle ) {
1332
						if ('num_arbre' === obsE.cle ) {
1313
							listObsData[exIndexObs].obs_etendue[i].valeur = arbreId;
1333
							listObsData[exIndexObs].obs_etendue[i].valeur = arbreId;
1314
							return false;
1334
							return false;
1315
						}
1335
						}
1316
					});
1336
					});
1317
				}
1337
				}
1318
			}
1338
			}
1319
 
1339
 
1320
			// Mise à jour des données à transmettre
1340
			// Mise à jour des données à transmettre
1321
			if ( this.valOk( listObsData[exIndexObs] ) ) {
1341
			if ( this.valOk( listObsData[exIndexObs] ) ) {
1322
				$( '#liste-obs' ).data( indexObs, listObsData[exIndexObs] );
1342
				$( '#liste-obs' ).data( indexObs, listObsData[exIndexObs] );
1323
			}
1343
			}
1324
			if ( parseInt( id ) !== this.obsNbre ) {
1344
			if ( parseInt( id ) !== this.obsNbre ) {
1325
				id = parseInt(id);
1345
				id = parseInt(id);
1326
			}
1346
			}
1327
		}
1347
		}
1328
	} else {
1348
	} else {
1329
		$( '#liste-obs' ).removeData( 'obsId' + obsId );
1349
		$( '#liste-obs' ).removeData( 'obsId' + obsId );
1330
	}
1350
	}
1331
};
1351
};
1332
 
1352
 
1333
WidgetsSaisiesCommun.prototype.transmettreObs = function() {
1353
WidgetsSaisiesCommun.prototype.transmettreObs = function() {
1334
	const lthis = this;
1354
	const lthis = this;
1335
	var observations = $( '#liste-obs' ).data();
1355
	var observations = $( '#liste-obs' ).data();
1336
 
1356
 
1337
	if ( this.debug ) {
1357
	if ( this.debug ) {
1338
		console.dir( observations );
1358
		console.dir( observations );
1339
	}
1359
	}
1340
	if ( !this.valOk( typeof observations, true, 'object' ) ) {
1360
	if ( !this.valOk( typeof observations, true, 'object' ) ) {
1341
		this.afficherPanneau( '#dialogue-zero-obs' );
1361
		this.afficherPanneau( '#dialogue-zero-obs' );
1342
	} else {
1362
	} else {
1343
		this.nbObsEnCours         = 1;
1363
		this.nbObsEnCours         = 1;
1344
		this.nbObsTransmises      = 0;
1364
		this.nbObsTransmises      = 0;
1345
		this.totalObsATransmettre = $.map( observations, function( n, i ) {
1365
		this.totalObsATransmettre = $.map( observations, function( n, i ) {
1346
			return i;
1366
			return i;
1347
		}).length;
1367
		}).length;
1348
		this.depilerObsPourEnvoi();
1368
		this.depilerObsPourEnvoi();
1349
	}
1369
	}
1350
 
1370
 
1351
	return false;
1371
	return false;
1352
};
1372
};
1353
 
1373
 
1354
WidgetsSaisiesCommun.prototype.depilerObsPourEnvoi = function() {
1374
WidgetsSaisiesCommun.prototype.depilerObsPourEnvoi = function() {
1355
	var observations = $( '#liste-obs' ).data();
1375
	var observations = $( '#liste-obs' ).data();
1356
	// la boucle est factice car on utilise un tableau
1376
	// la boucle est factice car on utilise un tableau
1357
	// dont on a besoin de n'extraire que le premier élément
1377
	// dont on a besoin de n'extraire que le premier élément
1358
	// or javascript n'a pas de méthode cross browsers pour extraire les clés
1378
	// or javascript n'a pas de méthode cross browsers pour extraire les clés
1359
	// TODO: utiliser var.keys quand ça sera plus répandu
1379
	// TODO: utiliser var.keys quand ça sera plus répandu
1360
	// ou bien utiliser un vrai tableau et pas un objet
1380
	// ou bien utiliser un vrai tableau et pas un objet
1361
	for ( var obsNum in observations ) {
1381
	for ( var obsNum in observations ) {
1362
		var obsATransmettre = {
1382
		var obsATransmettre = {
1363
			'projet'  : this.tagsProjet,
1383
			'projet'  : this.tagsProjet,
1364
			'tag-obs' : this.tagObs,
1384
			'tag-obs' : this.tagObs,
1365
			'tag-img' : this.tagImg
1385
			'tag-img' : this.tagImg
1366
		};
1386
		};
1367
		var utilisateur = {
1387
		var utilisateur = {
1368
			id_utilisateur : $( '#id_utilisateur' ).val(),
1388
			id_utilisateur : $( '#id_utilisateur' ).val(),
1369
			prenom         : $( '#prenom' ).val(),
1389
			prenom         : $( '#prenom' ).val(),
1370
			nom            : $( '#nom' ).val(),
1390
			nom            : $( '#nom' ).val(),
1371
			courriel       : $( '#courriel' ).val()
1391
			courriel       : $( '#courriel' ).val()
1372
		};
1392
		};
1373
 
1393
 
1374
		obsATransmettre['utilisateur'] = utilisateur;
1394
		obsATransmettre['utilisateur'] = utilisateur;
1375
		obsATransmettre[obsNum]        = observations[obsNum];
1395
		obsATransmettre[obsNum]        = observations[obsNum];
1376
 
1396
 
1377
		var idObsNumerique = obsNum.replace( 'obsId', '' );
1397
		var idObsNumerique = obsNum.replace( 'obsId', '' );
1378
 
1398
 
1379
		if( '' !== idObsNumerique ) {
1399
		if( '' !== idObsNumerique ) {
1380
			this.envoyerObsAuCel( idObsNumerique, obsATransmettre );
1400
			this.envoyerObsAuCel( idObsNumerique, obsATransmettre );
1381
		}
1401
		}
1382
		break;
1402
		break;
1383
	}
1403
	}
1384
};
1404
};
1385
 
1405
 
1386
WidgetsSaisiesCommun.prototype.envoyerObsAuCel = function( idObs, observation ) {
1406
WidgetsSaisiesCommun.prototype.envoyerObsAuCel = function( idObs, observation ) {
1387
	const lthis = this;
1407
	const lthis = this;
1388
 
1408
 
1389
	var erreurMsg = '';
1409
	var erreurMsg = '';
1390
 
1410
 
1391
	$.ajax({
1411
	$.ajax({
1392
		url        : lthis.serviceSaisieUrl,
1412
		url        : lthis.serviceSaisieUrl,
1393
		type       : 'POST',
1413
		type       : 'POST',
1394
		data       : observation,
1414
		data       : observation,
1395
		dataType   : 'json',
1415
		dataType   : 'json',
1396
		beforeSend : function() {
1416
		beforeSend : function() {
1397
			$( '#dialogue-obs-transaction-ko,#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
1417
			$( '#dialogue-obs-transaction-ko,#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
1398
			$( '.alert-txt' ).empty();
1418
			$( '.alert-txt' ).empty();
1399
			$( '.alert-txt .msg-erreur,.alert-txt .msg-debug' ).remove();
1419
			$( '.alert-txt .msg-erreur,.alert-txt .msg-debug' ).remove();
1400
			$( '#chargement' ).removeClass( 'hidden' );
1420
			$( '#chargement' ).removeClass( 'hidden' );
1401
		},
1421
		},
1402
		success    : function( transfertDatas, textStatus, jqXHR ) {
1422
		success    : function( transfertDatas, textStatus, jqXHR ) {
1403
			if( lthis.isASL && 'arbres' === lthis.sujet ) {
1423
			if( lthis.isASL && 'arbres' === lthis.sujet ) {
1404
				// actualisation de id_observation dans '#releve-data'
1424
				// actualisation de id_observation dans '#releve-data'
1405
				lthis.actualiserReleveDataIdObs( idObs, transfertDatas.id );
1425
				lthis.actualiserReleveDataIdObs( idObs, transfertDatas.id );
1406
			}
1426
			}
1407
			// mise à jour du nombre d'obs à transmettre
1427
			// mise à jour du nombre d'obs à transmettre
1408
			// et suppression de l'obs
1428
			// et suppression de l'obs
1409
			lthis.supprimerObsParId( idObs, true );
1429
			lthis.supprimerObsParId( idObs, true );
1410
			lthis.nbObsEnCours++;
1430
			lthis.nbObsEnCours++;
1411
			// mise à jour du statut
1431
			// mise à jour du statut
1412
			lthis.mettreAJourProgression();
1432
			lthis.mettreAJourProgression();
1413
			if( 0 < lthis.obsNbre ) {
1433
			if( 0 < lthis.obsNbre ) {
1414
				// dépilement de la suivante
1434
				// dépilement de la suivante
1415
				lthis.depilerObsPourEnvoi();
1435
				lthis.depilerObsPourEnvoi();
1416
			}
1436
			}
1417
		},
1437
		},
1418
		statusCode  : {
1438
		statusCode  : {
1419
			500 : function( jqXHR, textStatus, errorThrown ) {
1439
			500 : function( jqXHR, textStatus, errorThrown ) {
1420
				erreurMsg += lthis.msgTraduction( 'erreur' ) + ' 500 :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
1440
				erreurMsg += lthis.msgTraduction( 'erreur' ) + ' 500 :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
1421
				}
1441
				}
1422
		},
1442
		},
1423
		error        : function( jqXHR, textStatus, errorThrown ) {
1443
		error        : function( jqXHR, textStatus, errorThrown ) {
1424
			erreurMsg += lthis.msgTraduction( 'erreur-ajax' ) + ' :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
1444
			erreurMsg += lthis.msgTraduction( 'erreur-ajax' ) + ' :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
1425
			try {
1445
			try {
1426
				reponse = jQuery.parseJSON( jqXHR.responseText );
1446
				reponse = jQuery.parseJSON( jqXHR.responseText );
1427
				if ( null !== reponse ) {
1447
				if ( null !== reponse ) {
1428
					$.each( reponse, function( cle, valeur ) {
1448
					$.each( reponse, function( cle, valeur ) {
1429
						erreurMsg += valeur + '\n';
1449
						erreurMsg += valeur + '\n';
1430
					});
1450
					});
1431
				}
1451
				}
1432
			} catch( e ) {
1452
			} catch( e ) {
1433
				erreurMsg += lthis.msgTraduction( 'erreur-inconnue' ) + ' : ' + jqXHR.responseText;
1453
				erreurMsg += lthis.msgTraduction( 'erreur-inconnue' ) + ' : ' + jqXHR.responseText;
1434
			}
1454
			}
1435
		},
1455
		},
1436
		complete      : function( jqXHR, textStatus ) {
1456
		complete      : function( jqXHR, textStatus ) {
1437
			var debugMsg = lthis.extraireEnteteDebug( jqXHR );
1457
			var debugMsg = lthis.extraireEnteteDebug( jqXHR );
1438
 
1458
 
1439
			if ( '' !== erreurMsg ) {
1459
			if ( '' !== erreurMsg ) {
1440
				if ( lthis.debug ) {
1460
				if ( lthis.debug ) {
1441
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-erreur">' + erreurMsg + '</pre>' );
1461
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-erreur">' + erreurMsg + '</pre>' );
1442
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
1462
					$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
1443
				}
1463
				}
1444
				var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?'+
1464
				var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?'+
1445
					'subject=Dysfonctionnement du widget de saisie ' + lthis.tagsProjet+
1465
					'subject=Dysfonctionnement du widget de saisie ' + lthis.tagsProjet+
1446
					'&body=' + erreurMsg + '%0D%0ADébogage :%0D%0A' + debugMsg;
1466
					'&body=' + erreurMsg + '%0D%0ADébogage :%0D%0A' + debugMsg;
1447
 
1467
 
1448
				$( '#obs' + idObs + ' div div' ).addClass( 'obs-erreur' );
1468
				$( '#obs' + idObs + ' div div' ).addClass( 'obs-erreur' );
1449
				$( '#dialogue-obs-transaction-ko .alert-txt' ).append(
1469
				$( '#dialogue-obs-transaction-ko .alert-txt' ).append(
1450
					$( '#tpl-transmission-ko' ).clone()
1470
					$( '#tpl-transmission-ko' ).clone()
1451
						.find( '.courriel-erreur' )
1471
						.find( '.courriel-erreur' )
1452
						.attr( 'href', hrefCourriel )
1472
						.attr( 'href', hrefCourriel )
1453
						.end()
1473
						.end()
1454
						.html()
1474
						.html()
1455
				);
1475
				);
1456
				$( '#dialogue-obs-transaction-ko' ).removeClass( 'hidden' );
1476
				$( '#dialogue-obs-transaction-ko' ).removeClass( 'hidden' );
1457
				$( '#chargement' ).addClass( 'hidden' );
1477
				$( '#chargement' ).addClass( 'hidden' );
1458
				lthis.initialiserBarreProgression;
1478
				lthis.initialiserBarreProgression;
1459
			} else {
1479
			} else {
1460
				if ( lthis.debug ) {
1480
				if ( lthis.debug ) {
1461
					$( '#dialogue-obs-transaction-ok .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
1481
					$( '#dialogue-obs-transaction-ok .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
1462
				}
1482
				}
1463
				if( 0 === lthis.obsNbre ) {
1483
				if( 0 === lthis.obsNbre ) {
1464
					setTimeout( function() {
1484
					setTimeout( function() {
1465
						if ( lthis.isASL ) {
1485
						if ( lthis.isASL ) {
1466
							if ( 'arbres' === lthis.sujet ) {
1486
							if ( 'arbres' === lthis.sujet ) {
1467
								if ( 'tb_streets' !== lthis.module ) {
1487
								if ( 'tb_streets' !== lthis.module ) {
1468
									$( '#bouton-saisir-lichens' ).removeClass( 'hidden' );
1488
									$( '#bouton-saisir-lichens' ).removeClass( 'hidden' );
1469
								}
1489
								}
1470
								if ( 'tb_lichensgo' !== lthis.module ) {
1490
								if ( 'tb_lichensgo' !== lthis.module ) {
1471
									$( '#bouton-saisir-plantes' ).removeClass( 'hidden' );
1491
									$( '#bouton-saisir-plantes' ).removeClass( 'hidden' );
1472
								}
1492
								}
1473
							} else {
1493
							} else {
1474
								$( '#bouton-poursuivre' ).removeClass( 'hidden' );
1494
								$( '#bouton-poursuivre' ).removeClass( 'hidden' );
1475
							}
1495
							}
1476
							$( '#bloc-controle-liste-obs,#bloc-gauche' ).addClass( 'hidden' );
1496
							$( '#bloc-controle-liste-obs,#bloc-gauche' ).addClass( 'hidden' );
1477
						}
1497
						}
1478
						$( '#chargement' ).addClass( 'hidden' );
1498
						$( '#chargement' ).addClass( 'hidden' );
1479
						$( '#dialogue-obs-transaction-ok .alert-txt' ).append( $( '#tpl-transmission-ok' ).clone().html() );
1499
						$( '#dialogue-obs-transaction-ok .alert-txt' ).append( $( '#tpl-transmission-ok' ).clone().html() );
1480
						$( '#dialogue-obs-transaction-ok' ).removeClass( 'hidden' );
1500
						$( '#dialogue-obs-transaction-ok' ).removeClass( 'hidden' );
1481
						if ( !lthis.isASL ) {
1501
						if ( !lthis.isASL ) {
1482
							lthis.initialiserObs.bind( lthis );
1502
							lthis.initialiserObs.bind( lthis );
1483
						}
1503
						}
1484
					}, 1500 );
1504
					}, 1500 );
1485
				}
1505
				}
1486
			}
1506
			}
1487
		}
1507
		}
1488
	});
1508
	});
1489
};
1509
};
1490
 
1510
 
1491
WidgetsSaisiesCommun.prototype.mettreAJourProgression = function() {
1511
WidgetsSaisiesCommun.prototype.mettreAJourProgression = function() {
1492
	this.nbObsTransmises++;
1512
	this.nbObsTransmises++;
1493
 
1513
 
1494
	var pct = ( this.nbObsTransmises / this.totalObsATransmettre ) * 100;
1514
	var pct = ( this.nbObsTransmises / this.totalObsATransmettre ) * 100;
1495
 
1515
 
1496
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', this.nbObsTransmises );
1516
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', this.nbObsTransmises );
1497
	$( '#barre-progression-upload' ).css( 'width', pct + '%' );
1517
	$( '#barre-progression-upload' ).css( 'width', pct + '%' );
1498
	$( '#barre-progression-upload .sr-only' ).text( this.nbObsTransmises + '/' + this.totalObsATransmettre + ' ' + this.msgTraduction( 'observations-transmises' ) );
1518
	$( '#barre-progression-upload .sr-only' ).text( this.nbObsTransmises + '/' + this.totalObsATransmettre + ' ' + this.msgTraduction( 'observations-transmises' ) );
1499
	if( 0 === this.obsNbre ) {
1519
	if( 0 === this.obsNbre ) {
1500
		$( '.progress' ).removeClass( 'active' );
1520
		$( '.progress' ).removeClass( 'active' );
1501
		$( '.progress' ).removeClass( 'progress-bar-striped' );
1521
		$( '.progress' ).removeClass( 'progress-bar-striped' );
1502
	}
1522
	}
1503
};
1523
};
1504
 
1524
 
1505
WidgetsSaisiesCommun.prototype.initialiserBarreProgression = function() {
1525
WidgetsSaisiesCommun.prototype.initialiserBarreProgression = function() {
1506
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', 0 );
1526
	$( '#barre-progression-upload' ).attr( 'aria-valuenow', 0 );
1507
	$( '#barre-progression-upload' ).css( 'width', '0%' );
1527
	$( '#barre-progression-upload' ).css( 'width', '0%' );
1508
	$( '#barre-progression-upload .sr-only' ).text( '0/0 ' + this.msgTraduction( 'observations-transmises' ) );
1528
	$( '#barre-progression-upload .sr-only' ).text( '0/0 ' + this.msgTraduction( 'observations-transmises' ) );
1509
	$( '.progress' ).addClass( 'active' );
1529
	$( '.progress' ).addClass( 'active' );
1510
	$( '.progress' ).addClass( 'progress-bar-striped' );
1530
	$( '.progress' ).addClass( 'progress-bar-striped' );
1511
};
1531
};
1512
 
1532
 
1513
// Form Validator *************************************************************/
1533
// Form Validator *************************************************************/
1514
WidgetsSaisiesCommun.prototype.configurerFormValidator = function() {
1534
WidgetsSaisiesCommun.prototype.configurerFormValidator = function() {
1515
	const lthis = this;
1535
	const lthis = this;
1516
 
1536
 
1517
	$.validator.addMethod(
1537
	$.validator.addMethod(
1518
		'dateCel',
1538
		'dateCel',
1519
		function ( value, element ) {
1539
		function ( value, element ) {
1520
			return ( lthis.valOk( value ) && ( /^(?:[0-9]{4}-[0-9]{2}-[0-9]{2})|(?:[0-9]{2}\/[0-9]{2}\/[0-9]{4})$/.test( value ) ) );
1540
			return ( lthis.valOk( value ) && ( /^(?:[0-9]{4}-[0-9]{2}-[0-9]{2})|(?:[0-9]{2}\/[0-9]{2}\/[0-9]{4})$/.test( value ) ) );
1521
		},
1541
		},
1522
		lthis.msgTraduction( 'date-incomplete' )
1542
		lthis.msgTraduction( 'date-incomplete' )
1523
	);
1543
	);
1524
	$.validator.addMethod(
1544
	$.validator.addMethod(
1525
		'userEmailOk',
1545
		'userEmailOk',
1526
		function ( value, element ) {
1546
		function ( value, element ) {
1527
			return ( lthis.valOk( value ) );
1547
			return ( lthis.valOk( value ) );
1528
		},
1548
		},
1529
		''
1549
		''
1530
	);
1550
	);
1531
	$.validator.addMethod(
1551
	$.validator.addMethod(
1532
		'minMaxOk',
1552
		'minMaxOk',
1533
		function ( value, element, param ) {
1553
		function ( value, element, param ) {
1534
			$.validator.messages.minMaxOk = lthis.validerMinMax( element ).message;
1554
			$.validator.messages.minMaxOk = lthis.validerMinMax( element ).message;
1535
			return lthis.validerMinMax( element ).cond;
1555
			return lthis.validerMinMax( element ).cond;
1536
		},
1556
		},
1537
		$.validator.messages.minMaxOk
1557
		$.validator.messages.minMaxOk
1538
	);
1558
	);
1539
	$.validator.addMethod(
1559
	$.validator.addMethod(
1540
		'listFields',
1560
		'listFields',
1541
		function ( value, element ) {
1561
		function ( value, element ) {
1542
			return ( lthis.valOk( value ) );
1562
			return ( lthis.valOk( value ) );
1543
		},
1563
		},
1544
		''
1564
		''
1545
	);
1565
	);
1546
	$.extend( $.validator.defaults, {
1566
	$.extend( $.validator.defaults, {
1547
		errorElement: 'span',
1567
		errorElement: 'span',
1548
		errorPlacement: function( error, element ) {
1568
		errorPlacement: function( error, element ) {
1549
			if ( lthis.isASL && 'arbres' === lthis.sujet && ( 'checkbox' === element.attr( 'type' ) || 'radio' === element.attr( 'type' ) ) ) {
1569
			if ( lthis.isASL && 'arbres' === lthis.sujet && ( 'checkbox' === element.attr( 'type' ) || 'radio' === element.attr( 'type' ) ) ) {
1550
				error.appendTo( element.closest( '.list' ) );
1570
				error.appendTo( element.closest( '.list' ) );
1551
			} else {
1571
			} else {
1552
				element.after( error );
1572
				element.after( error );
1553
			}
1573
			}
1554
		},
1574
		},
1555
		onfocusout: function( element ) {
1575
		onfocusout: function( element ) {
1556
			if( lthis.valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
1576
			if( lthis.valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
1557
				if ( $( element ).valid() ) {
1577
				if ( $( element ).valid() ) {
1558
					$( element ).closest( '.control-group' ).removeClass( 'error' );
1578
					$( element ).closest( '.control-group' ).removeClass( 'error' );
1559
				} else {
1579
				} else {
1560
					$( element ).closest( '.control-group' ).addClass( 'error' );
1580
					$( element ).closest( '.control-group' ).addClass( 'error' );
1561
				}
1581
				}
1562
			}
1582
			}
1563
		},
1583
		},
1564
		onkeyup : function( element ) {
1584
		onkeyup : function( element ) {
1565
			if( lthis.valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
1585
			if( lthis.valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
1566
				if ( $( element ).valid() ) {
1586
				if ( $( element ).valid() ) {
1567
					$( element ).closest( '.control-group' ).removeClass( 'error' );
1587
					$( element ).closest( '.control-group' ).removeClass( 'error' );
1568
				} else {
1588
				} else {
1569
					$( element ).closest( '.control-group' ).addClass( 'error' );
1589
					$( element ).closest( '.control-group' ).addClass( 'error' );
1570
				}
1590
				}
1571
			}
1591
			}
1572
		},
1592
		},
1573
		unhighlight: function( element ) {
1593
		unhighlight: function( element ) {
1574
			if( lthis.valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
1594
			if( lthis.valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
1575
				$( element ).closest( '.control-group' ).removeClass( 'error' );
1595
				$( element ).closest( '.control-group' ).removeClass( 'error' );
1576
			}
1596
			}
1577
		},
1597
		},
1578
		highlight: function( element ) {
1598
		highlight: function( element ) {
1579
			$( element ).closest( '.control-group' ).addClass( 'error' );
1599
			$( element ).closest( '.control-group' ).addClass( 'error' );
1580
		}
1600
		}
1581
	});
1601
	});
1582
};
1602
};
1583
 
1603
 
1584
// Formatage date *************************************************************/
1604
// Formatage date *************************************************************/
1585
WidgetsSaisiesCommun.prototype.fournirDate = function( dateObs ) {
1605
WidgetsSaisiesCommun.prototype.fournirDate = function( dateObs ) {
1586
	if ( /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/.test( dateObs ) ) {
1606
	if ( /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/.test( dateObs ) ) {
1587
		return dateObs;
1607
		return dateObs;
1588
	} else if ( /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test( dateObs ) ) {
1608
	} else if ( /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test( dateObs ) ) {
1589
		var dateArray = dateObs.split( '-' );
1609
		var dateArray = dateObs.split( '-' );
1590
		return dateArray[2] + '/' + dateArray[1] + '/' + dateArray[0]
1610
		return dateArray[2] + '/' + dateArray[1] + '/' + dateArray[0]
1591
	} else {
1611
	} else {
1592
		console.dir( 'erreur date : ' + dateObs )
1612
		console.dir( 'erreur date : ' + dateObs )
1593
	}
1613
	}
1594
};
1614
};
1595
 
1615
 
1596
// scroll vers le formulaire
1616
// scroll vers le formulaire
1597
WidgetsSaisiesCommun.prototype.scrollFormTop = function( scrollSelecteur, focus = '' ) {
1617
WidgetsSaisiesCommun.prototype.scrollFormTop = function( scrollSelecteur, focus = '' ) {
1598
	const lthis = this;
1618
	const lthis = this;
1599
 
1619
 
1600
	$( 'html, body' ).stop().animate({
1620
	$( 'html, body' ).stop().animate({
1601
		scrollTop: $( scrollSelecteur ).offset().top
1621
		scrollTop: $( scrollSelecteur ).offset().top
1602
	}, 300, function() {
1622
	}, 300, function() {
1603
		if ( lthis.valOk( focus ) ) {
1623
		if ( lthis.valOk( focus ) ) {
1604
			$( focus ).focus();
1624
			$( focus ).focus();
1605
		} else {
1625
		} else {
1606
			return;
1626
			return;
1607
		}
1627
		}
1608
	});
1628
	});
1609
};
1629
};
1610
 
1630
 
1611
// Controle des panneaux d'infos **********************************************/
1631
// Controle des panneaux d'infos **********************************************/
1612
 
1632
 
1613
WidgetsSaisiesCommun.prototype.afficherPanneau = function( selecteur ) {
1633
WidgetsSaisiesCommun.prototype.afficherPanneau = function( selecteur ) {
1614
	$( selecteur )
1634
	$( selecteur )
1615
		.removeClass( 'hidden' )
1635
		.removeClass( 'hidden' )
1616
		.hide()
1636
		.hide()
1617
		.show( 600 )
1637
		.show( 600 )
1618
		.delay( this.dureeMessage )
1638
		.delay( this.dureeMessage )
1619
		.hide( 600 );
1639
		.hide( 600 );
1620
	this.scrollFormTop( selecteur );
1640
	this.scrollFormTop( selecteur );
1621
};
1641
};
1622
 
1642
 
1623
WidgetsSaisiesCommun.prototype.masquerPanneau = function( selecteur ) {
1643
WidgetsSaisiesCommun.prototype.masquerPanneau = function( selecteur ) {
1624
	$( selecteur ).addClass( 'hidden' );
1644
	$( selecteur ).addClass( 'hidden' );
1625
};
1645
};
1626
 
1646
 
1627
WidgetsSaisiesCommun.prototype.fermerPanneauAlert = function() {
1647
WidgetsSaisiesCommun.prototype.fermerPanneauAlert = function() {
1628
	$( this ).parentsUntil( '.zone-alerte', '.alert' ).addClass( 'hidden' );
1648
	$( this ).parentsUntil( '.zone-alerte', '.alert' ).addClass( 'hidden' );
1629
};
1649
};
1630
 
1650
 
1631
/**
1651
/**
1632
 * Si la langue est définie dans this.langue, et si des messages sont définis
1652
 * Si la langue est définie dans this.langue, et si des messages sont définis
1633
 * dans this.msgs, tente de trouver le message dont la clé est [cle] dans la
1653
 * dans this.msgs, tente de trouver le message dont la clé est [cle] dans la
1634
 * langue en cours. S'il n'est pas trouvé, retourne la version française (par
1654
 * langue en cours. S'il n'est pas trouvé, retourne la version française (par
1635
 * défaut); si celle-ci n'exite pas, retourne "N/A".
1655
 * défaut); si celle-ci n'exite pas, retourne "N/A".
1636
 */
1656
 */
1637
WidgetsSaisiesCommun.prototype.msgTraduction = function( cle ) {
1657
WidgetsSaisiesCommun.prototype.msgTraduction = function( cle ) {
1638
	var msg = 'N/A';
1658
	var msg = 'N/A';
1639
 
1659
 
1640
	if ( this.msgs ) {
1660
	if ( this.msgs ) {
1641
		if ( this.langue in this.msgs && cle in this.msgs[this.langue] ) {
1661
		if ( this.langue in this.msgs && cle in this.msgs[this.langue] ) {
1642
			msg = this.msgs[this.langue][cle];
1662
			msg = this.msgs[this.langue][cle];
1643
		} else if ( cle in this.msgs['fr'] ) {
1663
		} else if ( cle in this.msgs['fr'] ) {
1644
			msg = this.msgs['fr'][cle];
1664
			msg = this.msgs['fr'][cle];
1645
		}
1665
		}
1646
	}
1666
	}
1647
	return msg;
1667
	return msg;
1648
};
1668
};
1649
 
1669
 
1650
/**
1670
/**
1651
* Stope l'évènement courant quand on clique sur un lien.
1671
* Stope l'évènement courant quand on clique sur un lien.
1652
* Utile pour Chrome, Safari...
1672
* Utile pour Chrome, Safari...
1653
*/
1673
*/
1654
WidgetsSaisiesCommun.prototype.arreter = function( event ) {
1674
WidgetsSaisiesCommun.prototype.arreter = function( event ) {
1655
	if ( event.stopPropagation ) {
1675
	if ( event.stopPropagation ) {
1656
		event.stopPropagation();
1676
		event.stopPropagation();
1657
	}
1677
	}
1658
	if ( event.preventDefault ) {
1678
	if ( event.preventDefault ) {
1659
		event.preventDefault();
1679
		event.preventDefault();
1660
	}
1680
	}
1661
 
1681
 
1662
	return false;
1682
	return false;
1663
};
1683
};
1664
 
1684
 
1665
/**
1685
/**
1666
 * Extrait les données de désinsectisation d'une requête AJAX de jQuery
1686
 * Extrait les données de désinsectisation d'une requête AJAX de jQuery
1667
 * @param jqXHR
1687
 * @param jqXHR
1668
 * @returns {String}
1688
 * @returns {String}
1669
 */
1689
 */
1670
WidgetsSaisiesCommun.prototype.extraireEnteteDebug = function( jqXHR ) {
1690
WidgetsSaisiesCommun.prototype.extraireEnteteDebug = function( jqXHR ) {
1671
	var msgDebug = '';
1691
	var msgDebug = '';
1672
 
1692
 
1673
	if ( '' !== jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) ) {
1693
	if ( '' !== jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) ) {
1674
		var debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) );
1694
		var debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) );
1675
		if ( null !== debugInfos ) {
1695
		if ( null !== debugInfos ) {
1676
			$.each( debugInfos, function( cle, valeur ) {
1696
			$.each( debugInfos, function( cle, valeur ) {
1677
				msgDebug += valeur + '\n';
1697
				msgDebug += valeur + '\n';
1678
			});
1698
			});
1679
		}
1699
		}
1680
	}
1700
	}
1681
 
1701
 
1682
	return msgDebug;
1702
	return msgDebug;
1683
};
1703
};
1684
 
1704
 
1685
 
1705
 
1686
WidgetsSaisiesCommun.prototype.confirmerSortie = function() {
1706
WidgetsSaisiesCommun.prototype.confirmerSortie = function() {
1687
	$( window ).off( 'beforeunload' ).on( 'beforeunload', function( event ) {
1707
	$( window ).off( 'beforeunload' ).on( 'beforeunload', function( event ) {
1688
		if ( !event ) {
1708
		if ( !event ) {
1689
			event = window.event;
1709
			event = window.event;
1690
		}
1710
		}
1691
		return false;
1711
		return false;
1692
	});
1712
	});
1693
};
1713
};
1694
 
1714
 
1695
WidgetsSaisiesCommun.prototype.valOk = function ( valeur, sensComparaison = true, comparer = undefined ) {
1715
WidgetsSaisiesCommun.prototype.valOk = function ( valeur, sensComparaison = true, comparer = undefined ) {
1696
	return utils.valOk( valeur, sensComparaison, comparer );
1716
	return utils.valOk( valeur, sensComparaison, comparer );
1697
};
1717
};
1698
 
1718
 
1699
WidgetsSaisiesCommun.prototype.activerModale = function ( label, content = '', buttons = [] ) {
1719
WidgetsSaisiesCommun.prototype.activerModale = function ( label, content = '', buttons = [] ) {
1700
	return utils.activerModale( label, content, buttons );
1720
	return utils.activerModale( label, content, buttons );
1701
};
1721
};
1702
 
1722
 
1703
// Lib hors objet
1723
// Lib hors objet
1704
 
1724
 
1705
/*
1725
/*
1706
 * jQuery UI Autocomplete HTML Extension
1726
 * jQuery UI Autocomplete HTML Extension
1707
 *
1727
 *
1708
 * Copyright 2010, Scott González (http://scottgonzalez.com)
1728
 * Copyright 2010, Scott González (http://scottgonzalez.com)
1709
 * Dual licensed under the MIT or GPL Version 2 licenses.
1729
 * Dual licensed under the MIT or GPL Version 2 licenses.
1710
 *
1730
 *
1711
 * http://github.com/scottgonzalez/jquery-ui-extensions
1731
 * http://github.com/scottgonzalez/jquery-ui-extensions
1712
 *
1732
 *
1713
 * Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
1733
 * Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
1714
 */
1734
 */
1715
( function( $ ) {
1735
( function( $ ) {
1716
	var proto      = $.ui.autocomplete.prototype,
1736
	var proto      = $.ui.autocomplete.prototype,
1717
		initSource = proto._initSource;
1737
		initSource = proto._initSource;
1718
 
1738
 
1719
	WidgetsSaisiesCommun.prototype.filter = function( array, term ) {
1739
	WidgetsSaisiesCommun.prototype.filter = function( array, term ) {
1720
		var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), 'i' );
1740
		var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), 'i' );
1721
 
1741
 
1722
		return $.grep( array, function( value ) {
1742
		return $.grep( array, function( value ) {
1723
 
1743
 
1724
			return matcher.test( $( '<div>' ).html( value.label || value.value || value ).text() );
1744
			return matcher.test( $( '<div>' ).html( value.label || value.value || value ).text() );
1725
		});
1745
		});
1726
	}
1746
	}
1727
	$.extend( proto, {
1747
	$.extend( proto, {
1728
		_initSource: function() {
1748
		_initSource: function() {
1729
			if ( this.options.html && $.isArray( this.options.source ) ) {
1749
			if ( this.options.html && $.isArray( this.options.source ) ) {
1730
				this.source = function( request, response ) {
1750
				this.source = function( request, response ) {
1731
					response( filter( this.options.source, request.term ) );
1751
					response( filter( this.options.source, request.term ) );
1732
				};
1752
				};
1733
			} else {
1753
			} else {
1734
				initSource.call( this );
1754
				initSource.call( this );
1735
			}
1755
			}
1736
		},
1756
		},
1737
		_renderItem: function( ul, item) {
1757
		_renderItem: function( ul, item) {
1738
			if ( item.retenu ) {
1758
			if ( item.retenu ) {
1739
				item.label = '<strong>' + item.label + '</strong>';
1759
				item.label = '<strong>' + item.label + '</strong>';
1740
			}
1760
			}
1741
 
1761
 
1742
			return $( '<li></li>' )
1762
			return $( '<li></li>' )
1743
				.data( 'item.autocomplete', item )
1763
				.data( 'item.autocomplete', item )
1744
				.append( $( '<a></a>' )[ ( this.options.html ) ? 'html' : 'text' ]( item.label ) )
1764
				.append( $( '<a></a>' )[ ( this.options.html ) ? 'html' : 'text' ]( item.label ) )
1745
				.appendTo( ul );
1765
				.appendTo( ul );
1746
		}
1766
		}
1747
	});
1767
	});
1748
})( jQuery );
1768
})( jQuery );