Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3263 Rev 3270
Line 368... Line 368...
368
// uniquement utilisé si taxon-liste ******************************************/
368
// uniquement utilisé si taxon-liste ******************************************/
369
// Affiche/Cache le champ taxon
369
// Affiche/Cache le champ taxon
370
WidgetSaisie.prototype.surChangementTaxonListe = function() {
370
WidgetSaisie.prototype.surChangementTaxonListe = function() {
371
	if ( valeurOk( $( '#taxon-liste' ).val() ) ) {
371
	if ( valeurOk( $( '#taxon-liste' ).val() ) ) {
372
		if ( 'autre' !== $( '#taxon-liste' ).val() ) {
372
		if ( 'autre' !== $( '#taxon-liste' ).val() ) {
373
			$( '#taxon-input-groupe' ).hide( 200, function () {
373
			$( '#taxon-input-groupe' )
-
 
374
				.hide( 200, function () {
374
				$( this ).addClass( 'hidden' ).show();
375
					$( this ).addClass( 'hidden' ).show();
375
			});
376
				})
-
 
377
				.find( '#taxon-autre' ).val( '' );
376
		} else {
378
		} else {
-
 
379
			$( '#taxon-input-groupe' )
-
 
380
				.hide()
-
 
381
				.removeClass( 'hidden' )
-
 
382
				.show(200)
-
 
383
				.find( '#taxon-autre' )
-
 
384
					.on( 'change', function() {
-
 
385
						if( !valeurOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
377
			$( '#taxon-input-groupe' ).hide().removeClass( 'hidden' ).show(200);
386
							$( '#taxon' ).val( $( '#taxon-autre' ).val() );
-
 
387
							$( '#taxon' ).data( 'numNomSel', '' )
-
 
388
								.data( 'nomRet','' )
-
 
389
								.data( 'numNomRet', '' )
-
 
390
								.data( 'nt', '' )
-
 
391
								.data( 'famille', '' );
-
 
392
						}
-
 
393
						$( '#taxon' ).trigger( 'change' );
-
 
394
					});
378
		}
395
		}
379
	}
396
	}
380
};
397
};
Line 394... Line 411...
394
				.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
411
				.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
395
				.data( 'nomRet', optionRetenue.data( 'nom-ret' ) )
412
				.data( 'nomRet', optionRetenue.data( 'nom-ret' ) )
396
				.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) )
413
				.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) )
397
				.data( 'nt', optionRetenue.data( 'nt' ) )
414
				.data( 'nt', optionRetenue.data( 'nt' ) )
398
				.data( 'famille', optionRetenue.data( 'famille' ) );
415
				.data( 'famille', optionRetenue.data( 'famille' ) );
-
 
416
			$( '#taxon' ).trigger( 'change' );
Line 399... Line 417...
399
 
417
 
400
			numNomSel = $( '#taxon' ).data( 'numNomSel' );
418
			numNomSel = $( '#taxon' ).data( 'numNomSel' );
401
			// Si l'espèce est mal déterminée la certitude est "à déterminer"
419
			// Si l'espèce est mal déterminée la certitude est "à déterminer"
402
			if( !valeurOk( numNomSel ) ) {
420
			if( !valeurOk( numNomSel ) ) {
Line 441... Line 459...
441
				});
459
				});
442
			}
460
			}
443
		},
461
		},
444
		html: true
462
		html: true
445
	});
463
	});
446
	$( taxonSelecteur ).on( 'autocompleteselect change', this.surAutocompletionTaxon );
464
	$( taxonSelecteur ).on( 'autocompleteselect', this.surAutocompletionTaxon );
447
};
465
};
Line 448... Line 466...
448
 
466
 
449
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
467
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
450
	var taxonSelecteur = '#taxon';
468
	var taxonSelecteur = '#taxon';
Line 504... Line 522...
504
	}
522
	}
505
	return suggestions;
523
	return suggestions;
506
};
524
};
Line 507... Line 525...
507
 
525
 
508
WidgetSaisie.prototype.surAutocompletionTaxon = function( event, ui ) {
-
 
509
 
526
WidgetSaisie.prototype.surAutocompletionTaxon = function( event, ui ) {
510
	if ( valeurOk( ui ) ) {
527
	if ( valeurOk( ui ) ) {
511
		$( '#taxon' ).val( ui.item.value );
528
		$( '#taxon' ).val( ui.item.value );
512
		$( '#taxon' ).data( 'value', ui.item.value )
529
		$( '#taxon' ).data( 'value', ui.item.value )
513
			.data( 'numNomSel', ui.item.numNomSel )
530
			.data( 'numNomSel', ui.item.numNomSel )
Line 530... Line 547...
530
					$( this ).attr( 'selected', false );
547
					$( this ).attr( 'selected', false );
531
				}
548
				}
532
			});
549
			});
533
		}
550
		}
534
	}
551
	}
-
 
552
	$( '#taxon' ).trigger( 'change' );
535
};
553
};
Line 536... Line 554...
536
 
554
 
537
// Form Validator *************************************************************/
555
// Form Validator *************************************************************/
538
WidgetSaisie.prototype.configurerFormValidator = function() {
556
WidgetSaisie.prototype.configurerFormValidator = function() {
Line 539... Line 557...
539
		var lthis = this;
557
	var lthis = this;
540
 
558
 
541
	$.validator.addMethod(
559
	$.validator.addMethod(
542
		'dateCel',
560
		'dateCel',
Line 572... Line 590...
572
	);
590
	);
Line 573... Line 591...
573
 
591
 
574
	$.extend( $.validator.defaults, {
592
	$.extend( $.validator.defaults, {
575
		errorElement: 'span',
593
		errorElement: 'span',
-
 
594
		onfocusout: function( element ) {
576
		onfocusout: function( element ) {
595
			if( valeurOk( element.id, false, 'taxon' ) ) {
577
			if ( $( element ).valid() ) {
596
				if ( $( element ).valid() ) {
578
				$( element ).closest( '.control-group' ).removeClass( 'error' );
597
					$( element ).closest( '.control-group' ).removeClass( 'error' );
579
			} else {
598
				} else {
-
 
599
					$( element ).closest( '.control-group' ).addClass( 'error' );
580
				$( element ).closest( '.control-group' ).addClass( 'error' );
600
				}
581
			}
601
			}
582
		},
602
		},
-
 
603
		onkeyup : function( element ) {
583
		onkeyup : function( element ) {
604
			if( valeurOk( element.id, false, 'taxon' ) ) {
-
 
605
				if ( $( element ).valid() ) {
-
 
606
					$( element ).closest( '.control-group' ).removeClass( 'error' );
-
 
607
				} else {
-
 
608
					$( element ).closest( '.control-group' ).addClass( 'error' );
-
 
609
				}
-
 
610
			}
-
 
611
		},
-
 
612
		unhighlight: function( element ) {
584
			if ( $( element ).valid() ) {
613
			if( valeurOk( element.id, false, 'taxon' ) ) {
585
				$( element ).closest( '.control-group' ).removeClass( 'error' );
-
 
586
			} else {
-
 
587
				$( element ).closest( '.control-group' ).addClass( 'error' );
614
				$( element ).closest( '.control-group' ).removeClass( 'error' );
588
			}
615
			}
589
		},
616
		},
590
		highlight: function( element ) {
617
		highlight: function( element ) {
591
			$( element ).closest( '.control-group' ).addClass( 'error' );
618
			$( element ).closest( '.control-group' ).addClass( 'error' );
592
		},
-
 
593
		unhighlight: function( element ) {
-
 
594
			$( element ).closest( '.control-group' ).removeClass( 'error' );
-
 
595
		},
-
 
596
 
619
		}
597
	});
620
	});
Line 598... Line -...
598
};
-
 
599
 
-
 
600
 
-
 
601
/**
-
 
602
 * validation des champs étendus
621
};
603
 */
622
 
604
WidgetSaisie.prototype.chpEtendusValidation = function() {
623
WidgetSaisie.prototype.chpEtendusValidation = function() {
605
	var lthis = this;
624
	var lthis = this;
606
	var $thisForm = $( '#form-supp' ),
625
	var $thisForm = $( '#form-supp' ),
Line 700... Line 719...
700
 
719
 
Line 701... Line 720...
701
};
720
};
702
 
721
 
-
 
722
 
Line 703... Line 723...
703
 
723
WidgetSaisie.prototype.definirReglesFormValidator = function() {
704
WidgetSaisie.prototype.definirReglesFormValidator = function() {
724
	var formSuppValidation = this.chpEtendusValidation(),
705
	var formSuppValidation = this.chpEtendusValidation();
725
		lthis = this;
706
 
726
 
Line 761... Line 781...
761
 
781
 
762
	$( 'input[type=date]' ).on( 'input', function() {
782
	$( 'input[type=date]' ).on( 'input', function() {
763
		$( this ).valid();
783
		$( this ).valid();
Line -... Line 784...
-
 
784
	});
-
 
785
 
-
 
786
	$( '#taxon' ).on( 'change', function() {
-
 
787
		var images = valeurOk( $( '#miniatures .miniature' ) );
-
 
788
		lthis.validerTaxonImage( valeurOk( $( this ).val() ), images );
-
 
789
	});
-
 
790
 
764
	});
791
	this.surPresenceAbsenceMiniature();
765
 
792
 
766
	$( '#form-observation' ).validate({
793
	$( '#form-observation' ).validate({
767
		rules : {
794
		rules : {
768
			date_releve : {
795
			date_releve : {
Line 791... Line 818...
791
			}
818
			}
792
		}
819
		}
793
	});
820
	});
794
};
821
};
Line -... Line 822...
-
 
822
 
-
 
823
WidgetSaisie.prototype.validerTaxonImage = function( taxon = false, images = false ) {
-
 
824
	var taxonOuImage = ( images || taxon );
-
 
825
	console.log();
-
 
826
	if ( images || taxon ) {
-
 
827
		this.masquerPanneau( '#dialogue-taxon-or-image' );
-
 
828
		$( '#bloc-taxon' ).removeClass( 'error' )
-
 
829
			.find( 'span.error' ).hide();
-
 
830
		$( '#fichier' ).parent( 'label.label-file' ).removeClass( 'error' );
-
 
831
		$( '#photos-conteneur').removeClass( 'error' ).find( 'span.error' ).hide();
-
 
832
	} else {
-
 
833
		this.afficherPanneau( '#dialogue-taxon-or-image' );
-
 
834
		$( '#bloc-taxon' ).addClass( 'error' )
-
 
835
			.find( 'span.error' ).show();
-
 
836
		$( '#fichier' ).parent( 'label.label-file' ).addClass( 'error' );
-
 
837
		$( '#photos-conteneur').addClass( 'error' ).find( 'span.error' ).show();
-
 
838
	}
-
 
839
	return ( images || taxon );
-
 
840
};
-
 
841
 
-
 
842
WidgetSaisie.prototype.surPresenceAbsenceMiniature = function() {
-
 
843
	var lthis = this;
-
 
844
	// Selectionne le noeud dont les mutations seront observées
-
 
845
	var targetNode = document.getElementById( 'miniatures' );
-
 
846
	// Fonction callback à éxécuter quand une mutation est observée
-
 
847
	var callback = function( mutationsList ) {
-
 
848
	    for( var mutation of mutationsList ) {
-
 
849
	    	var taxon = valeurOk( $( '#taxon' ).val() );
-
 
850
	        images = ( 0 < mutation.target.childElementCount );
-
 
851
		 	lthis.validerTaxonImage( taxon, images );
-
 
852
	    }
-
 
853
	};
-
 
854
	// Créé une instance de l'observateur lié à la fonction de callback
-
 
855
	var observer = new MutationObserver( callback );
-
 
856
	// Commence à observer le noeud cible pour les mutations précédemment configurées
-
 
857
	observer.observe( targetNode, { childList: true } );
-
 
858
};
795
 
859
 
796
WidgetSaisie.prototype.validerFormulaire = function() {
860
WidgetSaisie.prototype.validerFormulaire = function() {
797
	var observateur = $( '#form-observateur' ).valid();
861
	var observateur  = $( '#form-observateur' ).valid();
798
	var obs = $( '#form-observation' ).valid();
862
	var obs          = $( '#form-observation' ).valid();
799
	var images = valeurOk( $( '#miniatures .miniature' ) );
863
	var images       = valeurOk( $( '#miniatures .miniature' ) );
-
 
864
	var taxon        = valeurOk( $( '#taxon' ).val() );
800
	var taxon = ( valeurOk( $( '#taxon' ).data( 'numNomSel' ) ) || valeurOk( $( '#taxon-liste' ).data( 'numNomSel' ) ) );
865
	// validation et panneau taxon/images
-
 
866
 	var taxonOuImage = this.validerTaxonImage( taxon, images );
801
	var geoloc = ( $( '#latitude' ).valid() && $( '#longitude' ).valid() );
867
 	console.log(taxonOuImage);
802
	var chpsSupp = new Boolean();
868
	var chpsSupp     = new Boolean();
803
	if ( valeurOk( $( '#form-supp' ) ) ) {
869
	if ( valeurOk( $( '#form-supp' ) ) ) {
804
		chpsSupp = ( function () {
870
		chpsSupp = ( function () {
805
			var otherFlag = $( '#form-supp' ).valid();
871
			var otherFlag = $( '#form-supp' ).valid();
806
			if( valeurOk( $( '.other', $( '#form-supp' ) ) ) ) {
872
			if( valeurOk( $( '.other', $( '#form-supp' ) ) ) ) {
Line 814... Line 880...
814
			return otherFlag;
880
			return otherFlag;
815
		})();
881
		})();
816
	} else {
882
	} else {
817
		chpsSupp = true;
883
		chpsSupp = true;
818
	}
884
	}
819
 
-
 
-
 
885
	// panneau geoloc
820
	( geoloc ) ? this.masquerPanneau( '#dialogue-geoloc-ko' ) : this.afficherPanneau( '#dialogue-geoloc-ko' );
886
	( $( '#latitude' ).valid() && $( '#longitude' ).valid() ) ? this.masquerPanneau( '#dialogue-geoloc-ko' ) : this.afficherPanneau( '#dialogue-geoloc-ko' );
-
 
887
	// panneau observateur
821
	( observateur ) ? this.masquerPanneau( '#dialogue-utilisateur-non-identifie' ) : this.afficherPanneau( '#dialogue-utilisateur-non-identifie' );
888
	( observateur ) ? this.masquerPanneau( '#dialogue-utilisateur-non-identifie' ) : this.afficherPanneau( '#dialogue-utilisateur-non-identifie' );
822
	if ( images || taxon ) {
-
 
823
		this.masquerPanneau( '#dialogue-taxon-or-image' );
-
 
824
		this.masquerPanneau( '#dialogue-image-or-taxon' );
-
 
825
	} else {
-
 
826
		this.afficherPanneau( '#dialogue-taxon-or-image' );
-
 
827
		this.afficherPanneau( '#dialogue-image-or-taxon' );
-
 
828
	}
889
 
829
	return ( observateur && obs && ( images || taxon ) && chpsSupp );
890
	return ( observateur && obs && taxonOuImage && chpsSupp );
830
};
891
};
Line 831... Line 892...
831
 
892
 
832
// Fichier Images *************************************************************/
893
// Fichier Images *************************************************************/
833
/**
894
/**
Line 855... Line 916...
855
	var imgNom = $( 'image-nom', reponse ).text();
916
	var imgNom = $( 'image-nom', reponse ).text();
856
	var html =
917
	var html =
857
		'<div class="miniature mb-3 mr-3">'+
918
		'<div class="miniature mb-3 mr-3">'+
858
			'<img class="miniature-img" class="miniature img-rounded" alt="' + imgNom + '" src="' + miniatureUrl + '"/>'+
919
			'<img class="miniature-img" class="miniature img-rounded" alt="' + imgNom + '" src="' + miniatureUrl + '"/>'+
859
			'<a class="effacer-miniature"><i class="far fa-trash-alt"></i></a>'+
920
			'<a class="effacer-miniature"><i class="far fa-trash-alt"></i></a>'+
860
		'</div>'
921
		'</div>';
861
	return html;
922
	return html;
862
};
923
};
Line 863... Line 924...
863
 
924
 
864
/**
925
/**