39,7 → 39,12 |
LichensLg.prototype.initForm = function() { |
const lthis = this; |
|
this.ajouterAutocompletionNoms(); |
this.surChangementTaxonListe(); |
$( '#taxon-liste' ).on( 'change', lthis.surChangementTaxonListe ); |
$( '#taxon-liste' ).on( 'change', lthis.surChangementValeurTaxon.bind( lthis ) ); |
if ( this.debug ) { |
console.log( 'Selected taxon:' + $( '#taxon-liste option:selected' ).val()); |
} |
this.configurerFormValidator(); |
this.definirReglesFormValidator(); |
}; |
131,7 → 136,6 |
scrollTop: $( '#charger-form' ).offset().top |
}, 300 ); |
}); |
|
// Alertes et tooltips |
$( '.alert .close' ).on( 'click', this.fermerPanneauAlert ); |
$( '#btn-aide' ).on( 'click', this.basculerAffichageAide ); |
164,6 → 168,73 |
} |
}; |
|
// uniquement utilisé si taxon-liste ******************************************/ |
// Affiche/Cache le champ taxon |
LichensLg.prototype.surChangementTaxonListe = function() { |
const utils = new UtilsApa(); |
if ( utils.valOk( $( '#taxon-liste' ).val() ) ) { |
if ( 'autre' !== $( '#taxon-liste' ).val() ) { |
$( '#taxon-input-groupe' ) |
.hide( 200, function () { |
$( this ).addClass( 'hidden' ).show(); |
}) |
.find( '#taxon-autre' ).val( '' ); |
} else { |
$( '#taxon-input-groupe' ) |
.hide() |
.removeClass( 'hidden' ) |
.show(200) |
.find( '#taxon-autre' ) |
.focus() |
.on( 'change', function() { |
if( !utils.valOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) { |
$( '#taxon' ).val( $( '#taxon-autre' ).val() ); |
$( '#taxon' ).removeData( 'value' ) |
.removeData( 'numNomSel' ) |
.removeData( 'nomRet' ) |
.removeData( 'numNomRet' ) |
.removeData( 'nt' ) |
.removeData( 'famille' ); |
} |
$( '#taxon' ).trigger( 'change' ); |
}); |
} |
} |
}; |
|
LichensLg.prototype.surChangementValeurTaxon = function() { |
var numNomSel = 0; |
|
if( this.utils.valOk( $( '#taxon-liste' ).val() ) ) { |
if( 'autre' === $( '#taxon-liste' ).val() ) { |
this.ajouterAutocompletionNoms(); |
} else { |
var optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' ); |
// $( '#taxon' ).val( $( '#taxon-liste' ).val() ); |
$( '#taxon' ).val( $( '#taxon-liste' ).val() ) |
.data( 'value', $( '#taxon-liste' ).val() ) |
.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) ) |
.data( 'nomRet', optionRetenue.data( 'nom-ret' ) ) |
.data( 'numNomRet', optionRetenue.data( 'num-nom-ret' ) ) |
.data( 'nt', optionRetenue.data( 'nt' ) ) |
.data( 'famille', optionRetenue.data( 'famille' ) ); |
$( '#taxon' ).trigger( 'change' ); |
|
numNomSel = $( '#taxon' ).data( 'numNomSel' ); |
// Si l'espèce est mal déterminée la certitude est "à déterminer" |
if( !this.utils.valOk( numNomSel ) ) { |
$( '#certitude' ).find( 'option' ).each( function() { |
if ( $( this ).hasClass( 'aDeterminer' ) ) { |
$( this ).attr( 'selected', true ); |
} else { |
$( this ).attr( 'selected', false ); |
} |
}); |
} |
} |
} |
}; |
|
// Autocompletion taxons ******************************************************/ |
/** |
* Initialise l'autocompletion taxons |
171,7 → 242,12 |
LichensLg.prototype.ajouterAutocompletionNoms = function() { |
const lthis = this; |
|
$( '#taxon' ).autocomplete({ |
var taxonSelecteur = '#taxon'; |
if ( this.utils.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) { |
taxonSelecteur += '-autre'; |
} |
|
$( taxonSelecteur ).autocomplete({ |
source: function( requete, add ) { |
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté |
requete = ''; |
194,11 → 270,15 |
}, |
html: true |
}); |
$( '#taxon' ).on( 'autocompleteselect', this.surAutocompletionTaxon ); |
$( taxonSelecteur ).on( 'autocompleteselect', this.surAutocompletionTaxon ); |
}; |
|
LichensLg.prototype.getUrlAutocompletionNomsSci = function() { |
var mots = $( '#taxon' ).val(); |
var taxonSelecteur = '#taxon'; |
if ( this.utils.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) { |
taxonSelecteur += '-autre'; |
} |
var mots = $( taxonSelecteur ).val(); |
var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel ); |
url = url.replace( '{masque}', mots ); |
|
209,8 → 289,12 |
* Objet taxons pour autocompletion en fonction de la recherche |
*/ |
LichensLg.prototype.traiterRetourNomsSci = function( data ) { |
var taxonSelecteur = '#taxon'; |
var suggestions = []; |
|
if ( this.utils.valOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) { |
taxonSelecteur += '-autre'; |
} |
if ( undefined != data.resultat ) { |
$.each( data.resultat, function( i, val ) { |
val.nn = i; |
229,7 → 313,7 |
}; |
if ( suggestions.length >= this.autocompletionElementsNbre ) { |
nom.label = '...'; |
nom.value = $( '#taxon' ).val(); |
nom.value = $( taxonSelecteur ).val(); |
suggestions.push( nom ); |
return false; |
} else { |
256,7 → 340,7 |
* charge les données dans #taxon |
*/ |
LichensLg.prototype.surAutocompletionTaxon = function( event, ui ) { |
const utils = new UtilsLg(); |
const utils = new UtilsApa(); |
|
if ( utils.valOk( ui ) ) { |
$( '#taxon' ).val( ui.item.value ); |
393,14 → 477,7 |
// Résumé obs et stockage en data de "#list-obs" pour envoi |
this.afficherObs( obsData ); |
this.stockerObsData( obsData ); |
this.supprimerMiniatures(); |
$( '#taxon' ).val( '' ); |
$( '#taxon' ).removeData( 'value' ) |
.removeData( 'numNomSel' ) |
.removeData( 'nomRet' ) |
.removeData( 'numNomRet' ) |
.removeData( 'nt' ) |
.removeData( 'famille' ); |
this.reinitialiserFormLichens(); |
$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre ); |
$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.utils.msgTraduction( 'observations-transmises' ) ); |
} else { |
408,6 → 485,28 |
} |
}; |
|
LichensLg.prototype.reinitialiserFormLichens = function() { |
this.supprimerMiniatures(); |
$( '#taxon,#taxon-autre,#commentaire' ).val( '' ); |
$( '#taxon' ).removeData( 'value' ) |
.removeData( 'numNomSel' ) |
.removeData( 'nomRet' ) |
.removeData( 'numNomRet' ) |
.removeData( 'nt' ) |
.removeData( 'famille' ); |
$( '#taxon-liste,#certitude' ).find( 'option' ).each( function() { |
if ( $( this ).hasClass( 'choisir' ) ) { |
$( this ).attr( 'selected', true ); |
} else { |
$( this ).attr( 'selected', false ); |
} |
}); |
$( '#taxon-input-groupe' ).addClass( 'hidden' ); |
$( 'input[name=lichens-tronc]:checked' ).each( function() { |
$( this ).prop( 'checked', false ); |
}); |
}; |
|
/** |
* Formatage des données du formulaire pour stockage et envoi |
*/ |
1043,10 → 1142,6 |
const taxonOuImage = this.validerTaxonImage( taxon, images ); |
const observateur = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() ) |
const obs = $( '#form-lichens' ).valid(); |
console.log('images : ' + images); |
console.log('taxon : ' + taxon); |
console.log('taxonOuImage : ' + taxonOuImage); |
console.log(obs); |
|
// panneau observateur |
if ( observateur ) { |