Subversion Repositories eFlore/Applications.cel

Rev

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

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