Subversion Repositories eFlore/Applications.cel

Rev

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

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