Subversion Repositories eFlore/Applications.cel

Rev

Rev 3312 | Rev 3354 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3312 Rev 3333
Line 37... Line 37...
37
 * Initialise le formulaire, les validateurs, les listes de complétion...
37
 * Initialise le formulaire, les validateurs, les listes de complétion...
38
 */
38
 */
39
LichensApa.prototype.initForm = function() {
39
LichensApa.prototype.initForm = function() {
40
	const lthis = this;
40
	const lthis = this;
Line 41... Line 41...
41
 
41
 
-
 
42
	this.surChangementTaxonListe();
-
 
43
	$( '#taxon-liste' ).on( 'change', lthis.surChangementTaxonListe );
-
 
44
	$( '#taxon-liste' ).on( 'change', lthis.surChangementValeurTaxon.bind( lthis ) );
-
 
45
	if ( this.debug ) {
-
 
46
		console.log( 'Selected taxon:' + $( '#taxon-liste option:selected' ).val());
42
	this.ajouterAutocompletionNoms();
47
	}
43
	this.configurerFormValidator();
48
	this.configurerFormValidator();
44
	this.definirReglesFormValidator();
49
	this.definirReglesFormValidator();
Line 45... Line 50...
45
};
50
};
Line 163... Line 168...
163
	if ( this.utils.valOk( $( '#releve-data' ).val() ) ) {
168
	if ( this.utils.valOk( $( '#releve-data' ).val() ) ) {
164
		this.rechargerFormulaire();
169
		this.rechargerFormulaire();
165
	}
170
	}
166
};
171
};
Line -... Line 172...
-
 
172
 
-
 
173
// uniquement utilisé si taxon-liste ******************************************/
-
 
174
// Affiche/Cache le champ taxon
-
 
175
LichensApa.prototype.surChangementTaxonListe = function() {
-
 
176
	const utils = new UtilsApa();
-
 
177
	if ( utils.valOk( $( '#taxon-liste' ).val() ) ) {
-
 
178
		if ( 'autre' !== $( '#taxon-liste' ).val() ) {
-
 
179
			$( '#taxon-input-groupe' )
-
 
180
				.hide( 200, function () {
-
 
181
					$( this ).addClass( 'hidden' ).show();
-
 
182
				})
-
 
183
				.find( '#taxon-autre' ).val( '' );
-
 
184
		} else {
-
 
185
			$( '#taxon-input-groupe' )
-
 
186
				.hide()
-
 
187
				.removeClass( 'hidden' )
-
 
188
				.show(200)
-
 
189
				.find( '#taxon-autre' )
-
 
190
					.focus()
-
 
191
					.on( 'change', function() {
-
 
192
						if( !utils.valOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
-
 
193
							$( '#taxon' ).val( $( '#taxon-autre' ).val() );
-
 
194
							$( '#taxon' ).removeData( 'value' )
-
 
195
								.removeData( 'numNomSel' )
-
 
196
								.removeData( 'nomRet' )
-
 
197
								.removeData( 'numNomRet' )
-
 
198
								.removeData( 'nt' )
-
 
199
								.removeData( 'famille' );
-
 
200
						}
-
 
201
						$( '#taxon' ).trigger( 'change' );
-
 
202
					});
-
 
203
		}
-
 
204
	}
-
 
205
};
-
 
206
 
-
 
207
LichensApa.prototype.surChangementValeurTaxon = function() {
-
 
208
	var numNomSel = 0;
-
 
209
 
-
 
210
	if( this.utils.valOk( $( '#taxon-liste' ).val() ) ) {
-
 
211
		if( 'autre' === $( '#taxon-liste' ).val() ) {
-
 
212
			this.ajouterAutocompletionNoms();
-
 
213
		} else {
-
 
214
			var optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' );
-
 
215
			// $( '#taxon' ).val( $( '#taxon-liste' ).val() );
-
 
216
			$( '#taxon' ).val( $( '#taxon-liste' ).val() )
-
 
217
				.data( 'value', $( '#taxon-liste' ).val() )
-
 
218
				.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
-
 
219
				.data( 'nomRet', optionRetenue.data( 'nom-ret' ) )
-
 
220
				.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) )
-
 
221
				.data( 'nt', optionRetenue.data( 'nt' ) )
-
 
222
				.data( 'famille', optionRetenue.data( 'famille' ) );
-
 
223
			$( '#taxon' ).trigger( 'change' );
-
 
224
 
-
 
225
			numNomSel = $( '#taxon' ).data( 'numNomSel' );
-
 
226
			// Si l'espèce est mal déterminée la certitude est "à déterminer"
-
 
227
			if( !this.utils.valOk( numNomSel ) ) {
-
 
228
				$( '#certitude' ).find( 'option' ).each( function() {
-
 
229
					if ( $( this ).hasClass( 'aDeterminer' ) ) {
-
 
230
						$( this ).attr( 'selected', true );
-
 
231
					} else {
-
 
232
						$( this ).attr( 'selected', false );
-
 
233
					}
-
 
234
				});
-
 
235
			}
-
 
236
		}
-
 
237
	}
-
 
238
};
167
 
239
 
168
// Autocompletion taxons ******************************************************/
240
// Autocompletion taxons ******************************************************/
169
/**
241
/**
170
 * Initialise l'autocompletion taxons
242
 * Initialise l'autocompletion taxons
171
 */
243
 */
172
LichensApa.prototype.ajouterAutocompletionNoms = function() {
244
LichensApa.prototype.ajouterAutocompletionNoms = function() {
Line -... Line 245...
-
 
245
	const lthis = this;
-
 
246
 
-
 
247
	var taxonSelecteur = '#taxon';
-
 
248
	if ( this.utils.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
-
 
249
		taxonSelecteur += '-autre';
173
	const lthis = this;
250
	}
174
 
251
 
175
	$( '#taxon' ).autocomplete({
252
	$( taxonSelecteur ).autocomplete({
176
		source: function( requete, add ) {
253
		source: function( requete, add ) {
177
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
254
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
178
			requete = '';
255
			requete = '';
Line 193... Line 270...
193
				});
270
				});
194
			}
271
			}
195
		},
272
		},
196
		html: true
273
		html: true
197
	});
274
	});
198
	$( '#taxon' ).on( 'autocompleteselect', this.surAutocompletionTaxon );
275
	$( taxonSelecteur ).on( 'autocompleteselect', this.surAutocompletionTaxon );
199
};
276
};
Line 200... Line 277...
200
 
277
 
-
 
278
LichensApa.prototype.getUrlAutocompletionNomsSci = function() {
-
 
279
	var taxonSelecteur = '#taxon';
-
 
280
	if ( this.utils.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
-
 
281
		taxonSelecteur += '-autre';
201
LichensApa.prototype.getUrlAutocompletionNomsSci = function() {
282
	}
202
	var mots = $( '#taxon' ).val();
283
	var mots = $( taxonSelecteur ).val();
203
	var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
284
	var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
Line 204... Line 285...
204
	url = url.replace( '{masque}', mots );
285
	url = url.replace( '{masque}', mots );
205
 
286
 
Line 206... Line 287...
206
	return url;
287
	return url;
207
};
288
};
208
 
289
 
209
/**
290
/**
-
 
291
 * Objet taxons pour autocompletion en fonction de la recherche
210
 * Objet taxons pour autocompletion en fonction de la recherche
292
 */
Line -... Line 293...
-
 
293
LichensApa.prototype.traiterRetourNomsSci = function( data ) {
-
 
294
	var taxonSelecteur = '#taxon';
-
 
295
	var suggestions = [];
211
 */
296
 
212
LichensApa.prototype.traiterRetourNomsSci = function( data ) {
297
	if ( this.utils.valOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
213
	var suggestions = [];
298
		taxonSelecteur += '-autre';
Line 214... Line 299...
214
 
299
	}
Line 228... Line 313...
228
				famille : '',
313
				famille : '',
229
				retenu : false
314
				retenu : false
230
			};
315
			};
231
			if ( suggestions.length >= this.autocompletionElementsNbre ) {
316
			if ( suggestions.length >= this.autocompletionElementsNbre ) {
232
				nom.label = '...';
317
				nom.label = '...';
233
				nom.value = $( '#taxon' ).val();
318
				nom.value = $( taxonSelecteur ).val();
234
				suggestions.push( nom );
319
				suggestions.push( nom );
235
				return false;
320
				return false;
236
			} else {
321
			} else {
237
				nom.label = val.nom_sci_complet;
322
				nom.label = val.nom_sci_complet;
238
				nom.value = val.nom_sci_complet;
323
				nom.value = val.nom_sci_complet;
Line 392... Line 477...
392
		var obsData   = this.formaterFormObsData();
477
		var obsData   = this.formaterFormObsData();
Line 393... Line 478...
393
 
478
 
394
		// Résumé obs et stockage en data de "#list-obs" pour envoi
479
		// Résumé obs et stockage en data de "#list-obs" pour envoi
395
		this.afficherObs( obsData );
480
		this.afficherObs( obsData );
396
		this.stockerObsData( obsData );
481
		this.stockerObsData( obsData );
397
		this.supprimerMiniatures();
-
 
398
		$( '#taxon' ).val( '' );
-
 
399
		$( '#taxon' ).removeData( 'value' )
-
 
400
			.removeData( 'numNomSel' )
-
 
401
			.removeData( 'nomRet' )
-
 
402
			.removeData( 'numNomRet' )
-
 
403
			.removeData( 'nt' )
-
 
404
			.removeData( 'famille' );
482
		this.reinitialiserFormLichens();
405
		$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
483
		$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
406
		$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.utils.msgTraduction( 'observations-transmises' ) );
484
		$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.utils.msgTraduction( 'observations-transmises' ) );
407
	} else {
485
	} else {
408
		this.afficherPanneau( '#dialogue-form-invalide' );
486
		this.afficherPanneau( '#dialogue-form-invalide' );
409
	}
487
	}
Line -... Line 488...
-
 
488
};
-
 
489
 
-
 
490
LichensApa.prototype.reinitialiserFormLichens = function() {
-
 
491
	this.supprimerMiniatures();
-
 
492
	$( '#taxon,#taxon-autre,#commentaire' ).val( '' );
-
 
493
	$( '#taxon' ).removeData( 'value' )
-
 
494
		.removeData( 'numNomSel' )
-
 
495
		.removeData( 'nomRet' )
-
 
496
		.removeData( 'numNomRet' )
-
 
497
		.removeData( 'nt' )
-
 
498
		.removeData( 'famille' );
-
 
499
	$( '#taxon-liste,#certitude' ).find( 'option' ).each( function() {
-
 
500
		if ( $( this ).hasClass( 'choisir' ) ) {
-
 
501
			$( this ).attr( 'selected', true );
-
 
502
		} else {
-
 
503
			$( this ).attr( 'selected', false );
-
 
504
		}
-
 
505
	});
-
 
506
	$( '#taxon-input-groupe' ).addClass( 'hidden' );
-
 
507
	$( 'input[name=lichens-tronc]:checked' ).each( function() {
-
 
508
		$( this ).prop( 'checked', false );
-
 
509
	});
410
};
510
};
411
 
511
 
412
/**
512
/**
413
 * Formatage des données du formulaire pour stockage et envoi
513
 * Formatage des données du formulaire pour stockage et envoi
414
 */
514
 */
Line 1042... Line 1142...
1042
	const images       = this.utils.valOk( $( '#miniatures .miniature' ) );
1142
	const images       = this.utils.valOk( $( '#miniatures .miniature' ) );
1043
	const taxon        = this.utils.valOk( $( '#taxon' ).val() );
1143
	const taxon        = this.utils.valOk( $( '#taxon' ).val() );
1044
	const taxonOuImage = this.validerTaxonImage( taxon, images );
1144
	const taxonOuImage = this.validerTaxonImage( taxon, images );
1045
	const observateur  = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() )
1145
	const observateur  = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() )
1046
	const obs          = $( '#form-lichens' ).valid();
1146
	const obs          = $( '#form-lichens' ).valid();
1047
	console.log('images : ' + images);
-
 
1048
	console.log('taxon : ' + taxon);
-
 
1049
	console.log('taxonOuImage : ' + taxonOuImage);
-
 
1050
	console.log(obs);
-
 
Line 1051... Line 1147...
1051
 
1147
 
1052
	// panneau observateur
1148
	// panneau observateur
1053
	if ( observateur ) {
1149
	if ( observateur ) {
1054
		this.masquerPanneau( '#dialogue-utilisateur-non-identifie' );
1150
		this.masquerPanneau( '#dialogue-utilisateur-non-identifie' );