Subversion Repositories eFlore/Applications.cel

Rev

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

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