Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 3843 → Rev 3844

/trunk/widget/modules/saisie/squelettes/js/WidgetSaisie.js
1,38 → 1,39
import {WidgetsSaisiesCommun,utils} from './WidgetsSaisiesCommun.js';
import {valOk} from './Utils.js';
 
/**
* Constructeur WidgetSaisie par défaut
*/
function WidgetSaisie( proprietes ) {
if ( valOk(proprietes) ) {
this.urlWidgets = proprietes.urlWidgets;
this.projet = proprietes.projet;
this.idProjet = proprietes.idProjet;
this.tagsMotsCles = proprietes.tagsMotsCles;
this.mode = proprietes.mode;
this.langue = proprietes.langue;
this.serviceAnnuaireIdUrl = proprietes.serviceAnnuaireIdUrl;
this.serviceNomCommuneUrl = proprietes.serviceNomCommuneUrl;
this.serviceNomCommuneUrlAlt = proprietes.serviceNomCommuneUrlAlt;
this.debug = proprietes.debug;
this.html5 = proprietes.html5;
this.serviceSaisieUrl = proprietes.serviceSaisieUrl;
this.serviceObsUrl = proprietes.serviceObsUrl;
this.chargementImageIconeUrl = proprietes.chargementImageIconeUrl;
this.pasDePhotoIconeUrl = proprietes.pasDePhotoIconeUrl;
this.autocompletionElementsNbre = proprietes.autocompletionElementsNbre;
this.serviceAutocompletionNomSciUrl = proprietes.serviceAutocompletionNomSciUrl;
this.serviceAutocompletionNomSciUrlTpl = proprietes.serviceAutocompletionNomSciUrlTpl;
this.dureeMessage = proprietes.dureeMessage;
this.obsMaxNbre = proprietes.obsMaxNbre;
this.tagImg = proprietes.tagImg;
this.tagObs = proprietes.tagObs;
this.obsId = proprietes.obsId;
this.nomSciReferentiel = proprietes.nomSciReferentiel;
this.especeImposee = proprietes.especeImposee;
this.infosEspeceImposee = proprietes.infosEspeceImposee;
this.referentielImpose = proprietes.referentielImpose;
this.isTaxonListe = proprietes.isTaxonListe;
this.utils = utils;
this.msgs = utils.msgs;
function WidgetSaisie( ) {
if ( valOk(widgetProp) ) {
this.urlWidgets = widgetProp.urlWidgets;
this.projet = widgetProp.projet;
this.idProjet = widgetProp.idProjet;
this.tagsMotsCles = widgetProp.tagsMotsCles;
this.mode = widgetProp.mode;
this.langue = widgetProp.langue;
this.serviceAnnuaireIdUrl = widgetProp.serviceAnnuaireIdUrl;
this.serviceNomCommuneUrl = widgetProp.serviceNomCommuneUrl;
this.serviceNomCommuneUrlAlt = widgetProp.serviceNomCommuneUrlAlt;
this.debug = widgetProp.debug;
this.html5 = widgetProp.html5;
this.serviceSaisieUrl = widgetProp.serviceSaisieUrl;
this.serviceObsUrl = widgetProp.serviceObsUrl;
this.chargementImageIconeUrl = widgetProp.chargementImageIconeUrl;
this.pasDePhotoIconeUrl = widgetProp.pasDePhotoIconeUrl;
this.autocompletionElementsNbre = widgetProp.autocompletionElementsNbre;
this.serviceAutocompletionNomSciUrl = widgetProp.serviceAutocompletionNomSciUrl;
this.serviceAutocompletionNomSciUrlTpl = widgetProp.serviceAutocompletionNomSciUrlTpl;
this.dureeMessage = widgetProp.dureeMessage;
this.obsMaxNbre = widgetProp.obsMaxNbre;
this.tagImg = widgetProp.tagImg;
this.tagObs = widgetProp.tagObs;
this.obsId = widgetProp.obsId;
this.nomSciReferentiel = widgetProp.nomSciReferentiel;
this.especeImposee = widgetProp.especeImposee;
this.infosEspeceImposee = widgetProp.infosEspeceImposee;
this.referentielImpose = widgetProp.referentielImpose;
this.isTaxonListe = widgetProp.isTaxonListe;
}
this.urlRacine = window.location.origin;
this.obsNbre = 0;
41,19 → 42,16
this.nbObsTransmises = 0;
this.observer = null;
this.isASL = false;
this.geoloc = {};
}
WidgetSaisie.prototype = new WidgetsSaisiesCommun();
 
var valOk = WidgetSaisie.prototype.valOk;
 
/**
* Initialise le formulaire, les validateurs, les listes de complétion...
*/
WidgetSaisie.prototype.initForm = function() {
const lthis = this;
 
this.initFormConnection();
if ( this.valOk( this.obsId ) ) {
if ( valOk( this.obsId ) ) {
this.chargerInfoObs();
}
if( this.isTaxonListe ) {
66,7 → 64,7
// c'est voulu après la création d'une obs mais pas quand la page est actualisée
// Déjà tenté: onbeforeunload avec un location.reload(true) n'a pas permis de le faire
$( 'input[type=date]' ).each( function () {
( lthis.valOk( $( this ).data( 'default' ) ) ) ? $( this ).val( $( this ).data( 'default' ) ) : $( this ).val( '' );
( valOk( $( this ).data( 'default' ) ) ) ? $( this ).val( $( this ).data( 'default' ) ) : $( this ).val( '' );
});
this.configurerFormValidator();
this.definirReglesFormValidator();
75,14 → 73,15
$( '#taxon' ).attr( 'disabled', 'disabled' );
$( '#taxon-input-groupe' ).attr( 'title', '' );
// Bricolage cracra pour avoir le nom retenu avec auteur (nom_retenu.libelle ne le mentionne pas)
var infosEspeceImposee = $.parseJSON( this.infosEspeceImposee );
nomRetenuComplet = infosEspeceImposee.nom_retenu_complet,
debutAnneRefBiblio = nomRetenuComplet.indexOf( ' [' );
const infosEspeceImposee = $.parseJSON( this.infosEspeceImposee );
let nomRetenuComplet = infosEspeceImposee.nom_retenu_complet;
const debutAnneRefBiblio = nomRetenuComplet.indexOf( ' [' );
 
if ( -1 !== debutAnneRefBiblio ) {
nomRetenuComplet = nomRetenuComplet.substr( 0, debutAnneRefBiblio );
}
// fin bricolage cracra
var infosAssociee = {
const infosAssociee = {
label : infosEspeceImposee.nom_sci_complet,
value : infosEspeceImposee.nom_sci_complet,
nt : infosEspeceImposee.num_taxonomique,
102,8 → 101,6
* Initialise les écouteurs d'événements
*/
WidgetSaisie.prototype.initEvts = function() {
const lthis = this;
 
// identité
this.initEvtsConnection();
// on location, initialisation de la géoloc
123,12 → 120,11
 
// Identité Observateur par courriel
WidgetSaisie.prototype.requeterIdentiteCourriel = function() {
const lthis = this;
const lthis = this,
courriel = $( '#courriel' ).val(),
urlAnnuaire = this.serviceAnnuaireIdUrl + courriel;
 
var courriel = $( '#courriel' ).val();
var urlAnnuaire = this.serviceAnnuaireIdUrl + courriel;
 
if ( this.valOk( courriel ) ) {
if ( valOk( courriel ) ) {
$.ajax({
url : urlAnnuaire,
type : 'GET',
136,8 → 132,8
if ( lthis.debug ) {
console.log( 'SUCCESS: ' + textStatus );
}
if ( lthis.valOk( data ) && lthis.valOk( data[courriel] ) ) {
var infos = data[courriel];
if ( valOk( data ) && valOk( data[courriel] ) ) {
const infos = data[courriel];
lthis.surSuccesCompletionCourriel( infos, courriel );
} else {
lthis.surErreurCompletionCourriel();
161,7 → 157,7
// se déclanche quand on choisit "Observation sans inscription" mais que le mail entré est incrit à Tela
WidgetSaisie.prototype.surSuccesCompletionCourriel = function( infos, courriel ) {
if ( $( '#utilisateur-connecte' ).hasClass( 'hidden' ) ) {// si quelque chose a foiré après actualisation
if ( !this.valOk( $( '#warning-identite' ) ) ) {
if ( !valOk( $( '#warning-identite' ) ) ) {
$( '#zone-courriel' ).before( '<p id="warning-identite" class="warning"><i class="fas fa-exclamation-triangle"></i> ' + this.msgTraduction( 'courriel-connu' ) + '</p>' );
}
$( '#inscription, #zone-prenom-nom, #zone-courriel-confirmation' ).addClass( 'hidden' );
179,7 → 175,7
};
 
WidgetSaisie.prototype.testerLancementRequeteIdentite = function( event ) {
if ( this.valOk( event.which, true, 13 ) ) {
if ( valOk( event.which, true, 13 ) ) {
this.requeterIdentiteCourriel();
event.preventDefault();
event.stopPropagation();
191,7 → 187,7
$( '#bouton-connexion, #creation-compte' ).addClass( 'hidden' );
$( '#bienvenue').removeClass( 'hidden' );
$( '#inscription, #zone-courriel' ).addClass( 'hidden' );
if ( lthis.valOk( $( '#nom' ).val() ) && lthis.valOk( $( '#prenom' ).val() ) ) {
if ( valOk( $( '#nom' ).val() ) && valOk( $( '#prenom' ).val() ) ) {
$( '#zone-prenom-nom' ).addClass( 'hidden' );
$( '#bienvenue-prenom' ).text( ' ' + $( '#prenom' ).val() );
$( '#bienvenue-nom' ).text( ' ' + $( '#nom' ).val() );
211,25 → 207,28
};
 
WidgetSaisie.prototype.formaterPrenom = function() {
var prenom = new Array(),
const prenom = [],
mots = $( '#prenom' ).val().split( ' ' ),
motsLength = mots.length;
 
for ( var i = 0; i < motsLength; i++ ) {
var mot = mots[i];
for ( let i = 0; i < motsLength; i++ ) {
let mot = mots[i],
motMajuscule = '';
 
if ( 0 <= mot.indexOf( '-' ) ) {
var prenomCompose = new Array(),
motsComposes = mot.split( '-' )
const prenomCompose = new Array(),
motsComposes = mot.split( '-' ),
motsComposesLength = motsComposes.length;
for ( var j = 0; j < motsComposesLength; j++ ) {
var motSimple = motsComposes[j],
motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
 
for ( let j = 0; j < motsComposesLength; j++ ) {
const motSimple = motsComposes[j];
 
motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
prenomCompose.push( motMajuscule );
}
prenom.push( prenomCompose.join( '-' ) );
} else {
var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
prenom.push( motMajuscule );
}
}
238,20 → 237,20
 
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() {
this.afficherPanneau( '#dialogue-bloquer-copier-coller' );
 
return false;
};
 
// Préchargement des infos-obs ************************************************/
WidgetSaisie.prototype.chargerInfoObs = function() {
const lthis = this;
const lthis = this,
urlObs = this.serviceObsUrl + '/' + this.obsId;
 
var urlObs = this.serviceObsUrl + '/' + this.obsId;
 
$.ajax({
url: urlObs,
type: 'GET',
success: function( data, textStatus, jqXHR ) {
if ( lthis.valOk( data ) ) {
if ( valOk( data ) ) {
lthis.prechargerForm( data );
} else {
lthis.surErreurChargementInfosObs.bind( lthis );
265,7 → 264,7
 
// @TODO faire mieux que ça !
WidgetSaisie.prototype.surErreurChargementInfosObs = function() {
this.activerModale( this.msgTraduction( 'erreur-chargement' ) );
utils.activerModale( this.msgTraduction( 'erreur-chargement' ) );
};
 
WidgetSaisie.prototype.prechargerForm = function( data ) {
281,11 → 280,12
// suffixe = '',
// layer = 'osm',
// zoomInit = 18
var typeLocalisation = $( '#top' ).data( 'type-loc' ),
donnesResetCarto = {
const typeLocalisation = $( '#top' ).data( 'type-loc' ),
donnesResetCarto = {
latitude : data.latitude,
longitude : data.longitude,
typeLocalisation : typeLocalisation
typeLocalisation : typeLocalisation,
zoom : 18
};
this.transfererCarto( donnesResetCarto );
}
296,9 → 296,8
* Retourne un Array contenant les valeurs des champs étendus
*/
WidgetSaisie.prototype.getObsChpSpecifiques = function() {
const lthis = this;
 
var champs = new Array(),
const lthis = this,
champs = [],
$thisForm = $( '#form-supp' ),
elements =
'input[type=text]:not(.collect-other),'+
310,12 → 309,12
'input[type=date],'+
'textarea,'+
'.select',
retour = new Array();
retour = [];
 
$( elements, $thisForm ).each( function() {
if ( lthis.valOk( $( this ).val() ) && ( lthis.valOk( $( this ).attr( 'name' ) ) || lthis.valOk( $( this ).data( 'name' ) ) ) ) {
var valeur = $( this ).val(),
cle = ( lthis.valOk( $( this ).attr( 'name' ) ) ) ? $( this ).attr( 'name' ) : $( this ).data( 'name' );
if ( valOk( $( this ).val() ) && ( valOk( $( this ).attr( 'name' ) ) || valOk( $( this ).data( 'name' ) ) ) ) {
const valeur = $( this ).val(),
cle = ( valOk( $( this ).attr( 'name' ) ) ) ? $( this ).attr( 'name' ) : $( this ).data( 'name' );
if ( cle in champs ) {
champs[cle] += ';' + valeur;
} else {
323,10 → 322,10
}
}
});
for ( var key in champs ) {
for ( let key in champs ) {
retour.push({ 'cle' : key , 'valeur' : champs[key] });
}
if ( this.valOk( $( '#coord-lineaire' ).val() ) ) {
if ( valOk( $( '#coord-lineaire' ).val() ) ) {
retour.push({ 'cle' : 'coordonnees-rue-ou-lineaire' , 'valeur' : $( '#coord-lineaire' ).val() });
}
return retour;
353,7 → 352,7
$('#taxon-autre').val('');
}
}
if ( this.valOk( $( '#form-supp' ) ) ) {
if ( valOk( $( '#form-supp' ) ) ) {
$( '#form-supp' ).validate().resetForm();
}
};
363,43 → 362,34
* Fonction handler de l'évenement location du module tb-geoloc
*/
WidgetSaisie.prototype.locationHandler = function( location ) {
var locDatas = location.originalEvent.detail;
const locDatas = location.originalEvent.detail;
 
if ( this.valOk( locDatas ) ) {
if ( valOk( locDatas ) ) {
console.log( locDatas );
var geometry = JSON.stringify( locDatas.geometry );
var altitude = ( this.valOk( locDatas.elevation ) ) ? locDatas.elevation : '';
var pays = ( this.valOk( locDatas.osmCountryCode ) ) ? locDatas.osmCountryCode.toUpperCase() : 'FR';
var latitude = '';
var longitude = '';
var coordLineaire = '';
var nomCommune = '';
var communeInsee = '';
 
if ( this.valOk( locDatas.geometry.coordinates ) ) {
if ( 'Point' === locDatas.geometry.type ) {
if ( this.valOk( locDatas.geometry.coordinates[0] ) ) {
longitude = locDatas.geometry.coordinates[0];
}
if ( this.valOk( locDatas.geometry.coordinates[1] ) ) {
latitude = locDatas.geometry.coordinates[1];
}
} else if ( 'LineString' === locDatas.geometry.type && this.valOk( locDatas.centroid.coordinates ) ) {
coordLineaire = JSON.stringify( locDatas.geometry.coordinates );
if ( this.valOk( locDatas.centroid.coordinates[0] ) ) {
longitude = locDatas.centroid.coordinates[0];
}
if ( this.valOk( locDatas.centroid.coordinates[1] ) ) {
latitude = locDatas.centroid.coordinates[1];
}
}
const geometry = JSON.stringify( locDatas.geometry ),
altitude = ( valOk( locDatas.elevation ) ) ? locDatas.elevation : '',
pays = ( valOk( locDatas.osmCountryCode ) ) ? locDatas.osmCountryCode.toUpperCase() : 'FR';
let latitude = '',
longitude = '',
coordLineaire = '',
nomCommune = '',
communeInsee = '';
 
if ( valOk( locDatas.geometry.coordinates ) &&
valOk( locDatas.centroid.coordinates ) &&
valOk( locDatas.centroid.coordinates[0] ) &&
valOk( locDatas.centroid.coordinates[1] )
) {
latitude = locDatas.centroid.coordinates[0];
longitude = locDatas.centroid.coordinates[1];
}
if ( this.valOk( locDatas.inseeData ) ) {
if ( valOk( locDatas.inseeData ) ) {
nomCommune = locDatas.inseeData.nom;
communeInsee = ( this.valOk( locDatas.inseeData.code ) ) ? locDatas.inseeData.code : '';
} else if ( this.valOk( locDatas.locality ) ) {
communeInsee = ( valOk( locDatas.inseeData.code ) ) ? locDatas.inseeData.code : '';
} else if ( valOk( locDatas.locality ) ) {
nomCommune = locDatas.locality;
} else if ( this.valOk( locDatas.locality ) ) {
} else if ( valOk( locDatas.locality ) ) {
nomCommune = locDatas.osmCounty;
}
$( '#geometry' ).val( geometry );
410,21 → 400,20
$( '#commune-insee' ).val( communeInsee );
$( '#altitude' ).val( altitude );
$( '#pays' ).val( pays );
if ( this.valOk( $( '#latitude' ).val() ) && this.valOk( $( '#longitude' ).val() ) ) {
if ( valOk( $( '#latitude' ).val() ) && valOk( $( '#longitude' ).val() ) ) {
$( '#geoloc' ).closest( '.control-group' ).removeClass( 'error' );
} else {
$( '#geoloc' ).closest( '.control-group' ).addClass( 'error' );
}
} else {
console.log( 'Error location' );
console.warn( 'Error location' );
}
}
 
// Form Validator *************************************************************/
WidgetSaisie.prototype.chpEtendusValidation = function() {
const lthis = this;
 
var $thisForm = $( '#form-supp' ),
const lthis = this,
$thisForm = $( '#form-supp' ),
elements =
'.checkbox,'+
'.radio,'+
444,18 → 433,17
minmax : []
},
errors = {},
namesListFields = [],
picked = '';
namesListFields = [];
let picked = '';
 
$( elements, $thisForm ).each( function() {
for( var fieldsClass = 0; spefieldsCount > fieldsClass; fieldsClass++ ) {
if ( lthis.valOk( $( this ).attr( 'required' ) ) && $( this ).hasClass( speFields[fieldsClass] ) && !lthis.valOk( chpSuppValidation.rules[ dataName ] ) ) {
for( let fieldsClass = 0; spefieldsCount > fieldsClass; fieldsClass++ ) {
const dataName = $( this ).data( 'name' );
 
var dataName = $( this ).data( 'name' );
 
if ( valOk( $( this ).attr( 'required' ) ) && $( this ).hasClass( speFields[fieldsClass] ) && !valOk( chpSuppValidation.rules[ dataName ] ) ) {
namesListFields.push( dataName );
chpSuppValidation.rules[ dataName ] = { required : true };
if ( lthis.valOk( $( '.other', $( this ) ) ) ) {
if ( valOk( $( '.other', $( this ) ) ) ) {
picked = ( 'select' === speFields[fieldsClass] ) ? ':selected' : ':checked';
chpSuppValidation.rules[ 'collect-other-' + dataName.replace( '[]', '' ) ] = {
required : '#other-' + dataName.replace( '[]', '' ) + picked,
468,11 → 456,11
errors[dataName] = '.' + speFields[fieldsClass];
}
}
if ( lthis.valOk( $( this ).attr( 'name' ) ) && lthis.valOk ( $( this ).attr( 'required' ) ) && 0 > $.inArray( $( this ).attr( 'name' ) , namesListFields ) ) {
if ( valOk( $( this ).attr( 'name' ) ) && valOk ( $( this ).attr( 'required' ) ) && 0 > $.inArray( $( this ).attr( 'name' ) , namesListFields ) ) {
chpSuppValidation.rules[ $( this ).attr( 'name' ) ] = { required : true, minlength: 1 };
if(
( lthis.valOk( $( this ).attr( 'type' ), true, 'number' ) || lthis.valOk( $( this ).attr( 'type' ), true, 'range' ) ) &&
( lthis.valOk( $( this )[0].min ) || lthis.valOk( $( this )[0].max ) )
( valOk( $( this ).attr( 'type' ), true, 'number' ) || valOk( $( this ).attr( 'type' ), true, 'range' ) ) &&
( valOk( $( this )[0].min ) || valOk( $( this )[0].max ) )
) {
chpSuppValidation.rules[ $( this ).attr('name') ]['minMaxOk'] = true;
chpSuppValidation.messages[ $( this ).attr('name') ] = lthis.validerMinMax( $( this )[0] ).message;
479,9 → 467,9
}
}
});
if ( this.valOk( chpSuppValidation.rules ) ) {
if ( valOk( chpSuppValidation.rules ) ) {
$.each( chpSuppValidation.rules, function( key ) {
if ( !lthis.valOk( chpSuppValidation.messages[key] ) ) {
if ( !valOk( chpSuppValidation.messages[key] ) ) {
chpSuppValidation.messages[key] = 'Ce champ est requis :\nVeuillez entrer une valeur valide.';
}
});
493,15 → 481,15
};
 
WidgetSaisie.prototype.validerMinMax = function( element ) {
var mMCond = new Boolean(),
minCond = parseFloat( element.value ) >= parseFloat( element.min ),
maxCond = parseFloat( element.value ) <= parseFloat( element.max ),
messageMnMx = 'La valeur entrée doit être',
returnMnMx = { cond : true , message : '' };
const minCond = parseFloat( element.value ) >= parseFloat( element.min ),
maxCond = parseFloat( element.value ) <= parseFloat( element.max ),
returnMnMx = { cond : true , message : '' };
let mnMxCond = new Boolean(),
messageMnMx = 'La valeur entrée doit être';
 
if(
( this.valOk( element.type, true, 'number' ) || this.valOk( element.type, true, 'range' ) ) &&
( this.valOk( element.min ) || this.valOk( element.max ) )
( valOk( element.type, true, 'number' ) || valOk( element.type, true, 'range' ) ) &&
( valOk( element.min ) || valOk( element.max ) )
) {
if ( element.min && element.max ) {
messageMnMx += ' comprise entre ' + element.min + ' et ' + element.max;
521,21 → 509,20
};
 
WidgetSaisie.prototype.definirReglesFormValidator = function() {
const lthis = this;
const lthis = this,
formSuppValidation = this.chpEtendusValidation();
 
var formSuppValidation = this.chpEtendusValidation();
 
$( '#form-supp' ).validate({
onclick : function( element ) {
if (
(
lthis.valOk( element.type, true, 'checkbox' ) ||
lthis.valOk( element.type, true, 'radio' )
valOk( element.type, true, 'checkbox' ) ||
valOk( element.type, true, 'radio' )
) &&
(
!lthis.valOk( $( '.' + $( element ).attr( 'name' ).replace( '[]', '' ) + ':checked' ) ) ||
lthis.valOk( $( '.' + $( element ).attr( 'name' ).replace( '[]', '' ) + ':not(.other):checked' ) ) ||
!lthis.valOk( $( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ) ) ||
!valOk( $( '.' + $( element ).attr( 'name' ).replace( '[]', '' ) + ':checked' ) ) ||
valOk( $( '.' + $( element ).attr( 'name' ).replace( '[]', '' ) + ':not(.other):checked' ) ) ||
!valOk( $( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ) ) ||
$( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ).is( ':checked' ) ||
(
$( '#other-' + $( element ).attr( 'name' ).replace( '[]', '' ) ).is( ':checked' ) &&
557,10 → 544,11
messages : formSuppValidation.messages,
errorPlacement : function( error , element ) {
if ( 0 < Object.keys( formSuppValidation.errors ).length ) {
var errorsKeys = Object.keys( formSuppValidation.errors ),
thisKey = '',
const errorsKeys = Object.keys( formSuppValidation.errors );
let thisKey = '',
errorsFlag = true;
for ( i = 0 ; i < errorsKeys.length ; i++ ) {
 
for ( let i = 0 ; i < errorsKeys.length ; i++ ) {
thisKey = errorsKeys[i];
if( $( element ).attr( 'name' ) === thisKey ) {
$( formSuppValidation.errors[thisKey] ).append( error );
583,8 → 571,9
});
// Validation Taxon si pas de miniature
$( '#taxon' ).on( 'change', function() {
var images = lthis.valOk( $( '#miniatures .miniature' ) );
lthis.validerTaxonImage( lthis.valOk( $( this ).val() ), images );
const images = valOk( $( '#miniatures .miniature' ) );
 
lthis.validerTaxonImage( valOk( $( this ).val() ), images );
});
// Validation miniatures avec MutationObserver
this.surPresenceAbsenceMiniature();
625,8 → 614,9
};
 
WidgetSaisie.prototype.validerTaxonImage = function( taxon = false, images = false ) {
var taxonOuImage = ( images || taxon );
if ( images || taxon ) {
const taxonOuImage = images || taxon;
 
if ( taxonOuImage ) {
this.masquerPanneau( '#dialogue-taxon-or-image' );
$( '#bloc-taxon' ).removeClass( 'error' )
.find( 'span.error' ).hide();
639,20 → 629,20
$( '#fichier' ).parent( 'label.label-file' ).addClass( 'error' );
$( '#photos-conteneur').addClass( 'error' ).find( 'span.error' ).show();
}
return ( images || taxon );
return taxonOuImage;
};
 
WidgetSaisie.prototype.surPresenceAbsenceMiniature = function() {
const lthis = this;
 
// voir : https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/disconnect
// Selectionne le noeud dont les mutations seront observées
var targetNode = document.getElementById( 'miniatures' );
const targetNode = document.getElementById( 'miniatures' );
// Fonction callback à éxécuter quand une mutation est observée
var callback = function( mutationsList ) {
for( var mutation of mutationsList ) {
var taxon = lthis.valOk( $( '#taxon' ).val() );
const callback = mutationsList => {
let taxon;
 
for( let mutation of mutationsList ) {
taxon = valOk( $( '#taxon' ).val() );
images = ( 0 < mutation.target.childElementCount );
lthis.validerTaxonImage( taxon, images );
}
664,31 → 654,31
};
 
WidgetSaisie.prototype.validerForm = function() {
const lthis = this;
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 );
let chpsSupp = true;
 
var observateur = ( $( '#form-observateur' ).valid() && $( '#courriel' ).valid() && $( '#courriel_confirmation' ).valid() );
var obs = $( '#form-observation' ).valid();
var geoloc = ( this.valOk( $( '#latitude' ).val() ) && this.valOk( $( '#longitude' ).val() ) ) ;
var images = this.valOk( $( '#miniatures .miniature' ) );
var taxon = this.valOk( $( '#taxon' ).val() );
// validation et panneau taxon/images
var taxonOuImage = this.validerTaxonImage( taxon, images );
var chpsSupp = new Boolean();
if ( this.valOk( $( '#form-supp' ) ) ) {
if ( valOk( $( '#form-supp' ) ) ) {
chpsSupp = ( function () {
var otherFlag = $( '#form-supp' ).valid();
if( lthis.valOk( $( '.other', $( '#form-supp' ) ) ) ) {
let otherFlag = $( '#form-supp' ).valid();
 
if( valOk( $( '.other', $( '#form-supp' ) ) ) ) {
$( '.other', $( '#form-supp' ) ).each( function() {
var picked = ( $( this ).data( 'element' ) !== 'select' ) ? ':checked' : ':selected';
if ( $( this ).is( picked ) && lthis.valOk( $( this ).val(), true, 'other' ) ) {
const picked = ( $( this ).data( 'element' ) !== 'select' ) ? ':checked' : ':selected';
 
if ( $( this ).is( picked ) && valOk( $( this ).val(), true, 'other' ) ) {
otherFlag = false;
}
});
}
 
return otherFlag;
})();
} else {
chpsSupp = true;
}
// panneau geoloc
if ( geoloc ) {
717,3 → 707,11
$( '#taxon' ).val( '' );
$( '#taxon' ).data( 'numNomSel', '' );
};
 
 
$( document ).ready( function() {
const widget = new WidgetSaisie();
widget.init();
// Fonctions de Style et Affichage des éléments "spéciaux"
utils.init();
});