Subversion Repositories eFlore/Applications.cel

Rev

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

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