Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 3850 → Rev 3851

/trunk/widget/modules/saisie/squelettes/js/WidgetSaisie.js
571,11 → 571,10
$( 'input[type=date]' ).on( 'input', function() {
$( this ).valid();
});
// Validation Taxon si pas de miniature
$( '#taxon' ).on( 'change', function() {
const images = valOk( $( '#miniatures .miniature' ) );
 
lthis.validerTaxonImage( valOk( $( this ).val() ), images );
// Validation taxon
// et gestion des messages d'erreur taxon et images en fonction de la certitude
$( '#taxon, #certitude' ).on( 'change', function() {
lthis.validerTaxonRequis( valOk( $( '#taxon' ).val() ) );
});
// Validation miniatures avec MutationObserver
this.surPresenceAbsenceMiniature();
615,23 → 614,50
});
};
 
WidgetSaisie.prototype.validerTaxonImage = function( taxon = false, images = false ) {
const taxonOuImage = images || taxon;
 
if ( taxonOuImage ) {
WidgetSaisie.prototype.validerCertitudeTaxonImage = function( hasTaxon = false, hasImages = false ) {
if( 'certain' === $( '#certitude' ).val() ) {
return this.validerTaxonRequis( hasTaxon );
} else {
return this.validerImageRequise( hasImages );
}
};
 
WidgetSaisie.prototype.validerTaxonRequis = function( hasTaxon = false ) {
const taxonEstRequis = 'certain' === $( '#certitude' ).val();
 
$( '#photos-conteneur').removeClass( 'error' )
.find( 'span.error' ).hide();
 
if ( !hasTaxon && taxonEstRequis ) {
this.afficherPanneau( '#dialogue-taxon-or-image' );
$( '#bloc-taxon' ).addClass( 'error' )
.find( 'span.error' ).show();
} else {
this.masquerPanneau( '#dialogue-taxon-or-image' );
$( '#bloc-taxon' ).removeClass( 'error' )
.find( 'span.error' ).hide();
}
 
if ( taxonEstRequis ) {
return hasTaxon;
}
};
 
WidgetSaisie.prototype.validerImageRequise = function( hasImages = false ) {
$( '#bloc-taxon' ).removeClass( 'error' )
.find( 'span.error' ).hide();
 
if ( hasImages ) {
this.masquerPanneau( '#dialogue-taxon-or-image' );
$( '#fichier' ).parent( 'label.label-file' ).removeClass( 'error' );
$( '#photos-conteneur').removeClass( 'error' ).find( 'span.error' ).hide();
} else {
this.afficherPanneau( '#dialogue-taxon-or-image' );
$( '#bloc-taxon' ).addClass( 'error' )
.find( 'span.error' ).show();
$( '#fichier' ).parent( 'label.label-file' ).addClass( 'error' );
$( '#photos-conteneur').addClass( 'error' ).find( 'span.error' ).show();
}
return taxonOuImage;
return hasImages;
};
 
WidgetSaisie.prototype.surPresenceAbsenceMiniature = function() {
641,12 → 667,11
const targetNode = document.getElementById( 'miniatures' );
// Fonction callback à éxécuter quand une mutation est observée
const callback = mutationsList => {
let taxon;
 
for( let mutation of mutationsList ) {
taxon = valOk( $( '#taxon' ).val() );
images = ( 0 < mutation.target.childElementCount );
lthis.validerTaxonImage( taxon, images );
lthis.validerCertitudeTaxonImage(
valOk( $( '#taxon' ).val() ),
0 < mutation.target.childElementCount
);
}
};
// Créé une instance de l'observateur lié à la fonction de callback
659,10 → 684,11
const observateur = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() && $( '#courriel_confirmation' ).valid() ),
obs = $( '#form-observation' ).valid(),
geoloc = ( valOk( $( '#latitude' ).val() ) && valOk( $( '#longitude' ).val() ) ) ,
images = valOk( $( '#miniatures .miniature' ) ),
taxon = valOk( $( '#taxon' ).val() ),
// validation et panneau taxon/images
taxonOuImage = this.validerTaxonImage( taxon, images );
certitudeTaxonImage = this.validerCertitudeTaxonImage(
valOk( $( '#taxon' ).val() ),
valOk( $( '#miniatures .miniature' ) )
);
let chpsSupp = true;
 
if ( valOk( $( '#form-supp' ) ) ) {
698,7 → 724,7
this.afficherPanneau( '#dialogue-utilisateur-non-identifie' );
$( '.nav.control-group' ).addClass( 'error' );
}
return ( observateur && obs && geoloc && taxonOuImage && chpsSupp );
return ( observateur && obs && geoloc && certitudeTaxonImage && chpsSupp );
};
 
// Referentiel ****************************************************************/