Subversion Repositories eFlore/Applications.cel

Rev

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

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