Subversion Repositories eFlore/Applications.cel

Rev

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

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