Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3318 Rev 3334
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
LichensLg.prototype.initForm = function() {
39
LichensLg.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 129... Line 134...
129
				lthis.utils.chargerForm( nomSquelette, lthis );
134
				lthis.utils.chargerForm( nomSquelette, lthis );
130
				$( 'html, body' ).stop().animate({
135
				$( 'html, body' ).stop().animate({
131
					scrollTop: $( '#charger-form' ).offset().top
136
					scrollTop: $( '#charger-form' ).offset().top
132
				}, 300 );
137
				}, 300 );
133
			});
138
			});
134
 
-
 
135
			// Alertes et tooltips
139
			// Alertes et tooltips
136
			$( '.alert .close' ).on( 'click', this.fermerPanneauAlert );
140
			$( '.alert .close' ).on( 'click', this.fermerPanneauAlert );
137
			$( '#btn-aide' ).on( 'click', this.basculerAffichageAide );
141
			$( '#btn-aide' ).on( 'click', this.basculerAffichageAide );
138
			// $( '.has-tooltip' ).tooltip( 'enable' );
142
			// $( '.has-tooltip' ).tooltip( 'enable' );
139
		}
143
		}
Line 162... Line 166...
162
	if ( this.utils.valOk( $( '#releve-data' ).val() ) ) {
166
	if ( this.utils.valOk( $( '#releve-data' ).val() ) ) {
163
		this.rechargerFormulaire();
167
		this.rechargerFormulaire();
164
	}
168
	}
165
};
169
};
Line -... Line 170...
-
 
170
 
-
 
171
// uniquement utilisé si taxon-liste ******************************************/
-
 
172
// Affiche/Cache le champ taxon
-
 
173
LichensLg.prototype.surChangementTaxonListe = function() {
-
 
174
	const utils = new UtilsApa();
-
 
175
	if ( utils.valOk( $( '#taxon-liste' ).val() ) ) {
-
 
176
		if ( 'autre' !== $( '#taxon-liste' ).val() ) {
-
 
177
			$( '#taxon-input-groupe' )
-
 
178
				.hide( 200, function () {
-
 
179
					$( this ).addClass( 'hidden' ).show();
-
 
180
				})
-
 
181
				.find( '#taxon-autre' ).val( '' );
-
 
182
		} else {
-
 
183
			$( '#taxon-input-groupe' )
-
 
184
				.hide()
-
 
185
				.removeClass( 'hidden' )
-
 
186
				.show(200)
-
 
187
				.find( '#taxon-autre' )
-
 
188
					.focus()
-
 
189
					.on( 'change', function() {
-
 
190
						if( !utils.valOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
-
 
191
							$( '#taxon' ).val( $( '#taxon-autre' ).val() );
-
 
192
							$( '#taxon' ).removeData( 'value' )
-
 
193
								.removeData( 'numNomSel' )
-
 
194
								.removeData( 'nomRet' )
-
 
195
								.removeData( 'numNomRet' )
-
 
196
								.removeData( 'nt' )
-
 
197
								.removeData( 'famille' );
-
 
198
						}
-
 
199
						$( '#taxon' ).trigger( 'change' );
-
 
200
					});
-
 
201
		}
-
 
202
	}
-
 
203
};
-
 
204
 
-
 
205
LichensLg.prototype.surChangementValeurTaxon = function() {
-
 
206
	var numNomSel = 0;
-
 
207
 
-
 
208
	if( this.utils.valOk( $( '#taxon-liste' ).val() ) ) {
-
 
209
		if( 'autre' === $( '#taxon-liste' ).val() ) {
-
 
210
			this.ajouterAutocompletionNoms();
-
 
211
		} else {
-
 
212
			var optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' );
-
 
213
			// $( '#taxon' ).val( $( '#taxon-liste' ).val() );
-
 
214
			$( '#taxon' ).val( $( '#taxon-liste' ).val() )
-
 
215
				.data( 'value', $( '#taxon-liste' ).val() )
-
 
216
				.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
-
 
217
				.data( 'nomRet', optionRetenue.data( 'nom-ret' ) )
-
 
218
				.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) )
-
 
219
				.data( 'nt', optionRetenue.data( 'nt' ) )
-
 
220
				.data( 'famille', optionRetenue.data( 'famille' ) );
-
 
221
			$( '#taxon' ).trigger( 'change' );
-
 
222
 
-
 
223
			numNomSel = $( '#taxon' ).data( 'numNomSel' );
-
 
224
			// Si l'espèce est mal déterminée la certitude est "à déterminer"
-
 
225
			if( !this.utils.valOk( numNomSel ) ) {
-
 
226
				$( '#certitude' ).find( 'option' ).each( function() {
-
 
227
					if ( $( this ).hasClass( 'aDeterminer' ) ) {
-
 
228
						$( this ).attr( 'selected', true );
-
 
229
					} else {
-
 
230
						$( this ).attr( 'selected', false );
-
 
231
					}
-
 
232
				});
-
 
233
			}
-
 
234
		}
-
 
235
	}
-
 
236
};
166
 
237
 
167
// Autocompletion taxons ******************************************************/
238
// Autocompletion taxons ******************************************************/
168
/**
239
/**
169
 * Initialise l'autocompletion taxons
240
 * Initialise l'autocompletion taxons
170
 */
241
 */
171
LichensLg.prototype.ajouterAutocompletionNoms = function() {
242
LichensLg.prototype.ajouterAutocompletionNoms = function() {
Line -... Line 243...
-
 
243
	const lthis = this;
-
 
244
 
-
 
245
	var taxonSelecteur = '#taxon';
-
 
246
	if ( this.utils.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
-
 
247
		taxonSelecteur += '-autre';
172
	const lthis = this;
248
	}
173
 
249
 
174
	$( '#taxon' ).autocomplete({
250
	$( taxonSelecteur ).autocomplete({
175
		source: function( requete, add ) {
251
		source: function( requete, add ) {
176
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
252
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
177
			requete = '';
253
			requete = '';
Line 192... Line 268...
192
				});
268
				});
193
			}
269
			}
194
		},
270
		},
195
		html: true
271
		html: true
196
	});
272
	});
197
	$( '#taxon' ).on( 'autocompleteselect', this.surAutocompletionTaxon );
273
	$( taxonSelecteur ).on( 'autocompleteselect', this.surAutocompletionTaxon );
198
};
274
};
Line 199... Line 275...
199
 
275
 
-
 
276
LichensLg.prototype.getUrlAutocompletionNomsSci = function() {
-
 
277
	var taxonSelecteur = '#taxon';
-
 
278
	if ( this.utils.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
-
 
279
		taxonSelecteur += '-autre';
200
LichensLg.prototype.getUrlAutocompletionNomsSci = function() {
280
	}
201
	var mots = $( '#taxon' ).val();
281
	var mots = $( taxonSelecteur ).val();
202
	var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
282
	var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
Line 203... Line 283...
203
	url = url.replace( '{masque}', mots );
283
	url = url.replace( '{masque}', mots );
204
 
284
 
Line 205... Line 285...
205
	return url;
285
	return url;
206
};
286
};
207
 
287
 
208
/**
288
/**
-
 
289
 * Objet taxons pour autocompletion en fonction de la recherche
209
 * Objet taxons pour autocompletion en fonction de la recherche
290
 */
Line -... Line 291...
-
 
291
LichensLg.prototype.traiterRetourNomsSci = function( data ) {
-
 
292
	var taxonSelecteur = '#taxon';
-
 
293
	var suggestions = [];
210
 */
294
 
211
LichensLg.prototype.traiterRetourNomsSci = function( data ) {
295
	if ( this.utils.valOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
212
	var suggestions = [];
296
		taxonSelecteur += '-autre';
Line 213... Line 297...
213
 
297
	}
Line 227... Line 311...
227
				famille : '',
311
				famille : '',
228
				retenu : false
312
				retenu : false
229
			};
313
			};
230
			if ( suggestions.length >= this.autocompletionElementsNbre ) {
314
			if ( suggestions.length >= this.autocompletionElementsNbre ) {
231
				nom.label = '...';
315
				nom.label = '...';
232
				nom.value = $( '#taxon' ).val();
316
				nom.value = $( taxonSelecteur ).val();
233
				suggestions.push( nom );
317
				suggestions.push( nom );
234
				return false;
318
				return false;
235
			} else {
319
			} else {
236
				nom.label = val.nom_sci_complet;
320
				nom.label = val.nom_sci_complet;
237
				nom.value = val.nom_sci_complet;
321
				nom.value = val.nom_sci_complet;
Line 254... Line 338...
254
 
338
 
255
/**
339
/**
256
 * charge les données dans #taxon
340
 * charge les données dans #taxon
257
 */
341
 */
258
LichensLg.prototype.surAutocompletionTaxon = function( event, ui ) {
342
LichensLg.prototype.surAutocompletionTaxon = function( event, ui ) {
Line 259... Line 343...
259
	const utils = new UtilsLg();
343
	const utils = new UtilsApa();
260
 
344
 
261
	if ( utils.valOk( ui ) ) {
345
	if ( utils.valOk( ui ) ) {
262
		$( '#taxon' ).val( ui.item.value );
346
		$( '#taxon' ).val( ui.item.value );
Line 391... Line 475...
391
		var obsData   = this.formaterFormObsData();
475
		var obsData   = this.formaterFormObsData();
Line 392... Line 476...
392
 
476
 
393
		// Résumé obs et stockage en data de "#list-obs" pour envoi
477
		// Résumé obs et stockage en data de "#list-obs" pour envoi
394
		this.afficherObs( obsData );
478
		this.afficherObs( obsData );
395
		this.stockerObsData( obsData );
479
		this.stockerObsData( obsData );
396
		this.supprimerMiniatures();
-
 
397
		$( '#taxon' ).val( '' );
-
 
398
		$( '#taxon' ).removeData( 'value' )
-
 
399
			.removeData( 'numNomSel' )
-
 
400
			.removeData( 'nomRet' )
-
 
401
			.removeData( 'numNomRet' )
-
 
402
			.removeData( 'nt' )
-
 
403
			.removeData( 'famille' );
480
		this.reinitialiserFormLichens();
404
		$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
481
		$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
405
		$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.utils.msgTraduction( 'observations-transmises' ) );
482
		$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.utils.msgTraduction( 'observations-transmises' ) );
406
	} else {
483
	} else {
407
		this.afficherPanneau( '#dialogue-form-invalide' );
484
		this.afficherPanneau( '#dialogue-form-invalide' );
408
	}
485
	}
Line -... Line 486...
-
 
486
};
-
 
487
 
-
 
488
LichensLg.prototype.reinitialiserFormLichens = function() {
-
 
489
	this.supprimerMiniatures();
-
 
490
	$( '#taxon,#taxon-autre,#commentaire' ).val( '' );
-
 
491
	$( '#taxon' ).removeData( 'value' )
-
 
492
		.removeData( 'numNomSel' )
-
 
493
		.removeData( 'nomRet' )
-
 
494
		.removeData( 'numNomRet' )
-
 
495
		.removeData( 'nt' )
-
 
496
		.removeData( 'famille' );
-
 
497
	$( '#taxon-liste,#certitude' ).find( 'option' ).each( function() {
-
 
498
		if ( $( this ).hasClass( 'choisir' ) ) {
-
 
499
			$( this ).attr( 'selected', true );
-
 
500
		} else {
-
 
501
			$( this ).attr( 'selected', false );
-
 
502
		}
-
 
503
	});
-
 
504
	$( '#taxon-input-groupe' ).addClass( 'hidden' );
-
 
505
	$( 'input[name=lichens-tronc]:checked' ).each( function() {
-
 
506
		$( this ).prop( 'checked', false );
-
 
507
	});
409
};
508
};
410
 
509
 
411
/**
510
/**
412
 * Formatage des données du formulaire pour stockage et envoi
511
 * Formatage des données du formulaire pour stockage et envoi
413
 */
512
 */
Line 1041... Line 1140...
1041
	const images       = this.utils.valOk( $( '#miniatures .miniature' ) );
1140
	const images       = this.utils.valOk( $( '#miniatures .miniature' ) );
1042
	const taxon        = this.utils.valOk( $( '#taxon' ).val() );
1141
	const taxon        = this.utils.valOk( $( '#taxon' ).val() );
1043
	const taxonOuImage = this.validerTaxonImage( taxon, images );
1142
	const taxonOuImage = this.validerTaxonImage( taxon, images );
1044
	const observateur  = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() )
1143
	const observateur  = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() )
1045
	const obs          = $( '#form-lichens' ).valid();
1144
	const obs          = $( '#form-lichens' ).valid();
1046
	console.log('images : ' + images);
-
 
1047
	console.log('taxon : ' + taxon);
-
 
1048
	console.log('taxonOuImage : ' + taxonOuImage);
-
 
1049
	console.log(obs);
-
 
Line 1050... Line 1145...
1050
 
1145
 
1051
	// panneau observateur
1146
	// panneau observateur
1052
	if ( observateur ) {
1147
	if ( observateur ) {
1053
		this.masquerPanneau( '#dialogue-utilisateur-non-identifie' );
1148
		this.masquerPanneau( '#dialogue-utilisateur-non-identifie' );