Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 3843 → Rev 3844

/trunk/widget/modules/saisie/squelettes/js/WidgetsSaisiesCommun.js
1,15 → 1,18
const utils = new Utils;
import {Geoloc} from './tb-geoloc/js/Geoloc.js';
import {Utils,valOk} from './Utils.js';
 
export const utils = new Utils();
/**
* WidgetsSaisiesCommun
* Methodes communes aux widgets de saisie
*/
function WidgetsSaisiesCommun(){}
export function WidgetsSaisiesCommun(){}
 
WidgetsSaisiesCommun.prototype.init = function() {
this.geoloc = new Geoloc();
// ASL : APA, sTREETs, Lichen's Go!
// const ASL = ['tb_aupresdemonarbre','tb_streets','tb_lichensgo'];
// this.isASL = ( utils.valOk( this.projet ) && -1 < $.inArray( this.projet , ASL ) );
// this.isASL = ( valOk( this.projet ) && -1 < $.inArray( this.projet , ASL ) );
this.initForm();
this.initEvts();
};
73,7 → 76,7
$( '#courriel_confirmation' ).on( 'paste', this.bloquerCopierCollerCourriel.bind( this ) );
$( '#courriel_confirmation' ).on( 'blur', this.reduireVoletIdentite.bind( this ) );
$( '#courriel_confirmation' ).on( 'keypress', function( event ) {
if ( lthis.valOk( event.which, true, 13 ) ) {
if ( valOk( event.which, true, 13 ) ) {
lthis.reduireVoletIdentite();
event.preventDefault();
event.stopPropagation();
85,8 → 88,8
WidgetsSaisiesCommun.prototype.initEvtsFichier = function() {
const lthis = this;
 
function fileInputFonctionne() {
var ua = navigator.userAgent;
const fileInputFonctionne = () => {
const ua = navigator.userAgent;
 
if (
ua.match( /(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Windows Phone (OS 7|8.0))|(XBLWP)|(ZuneWP)|(w(eb)?OSBrowser)|(webOS)|(Kindle\/(1.0|2.0|2.5|3.0))/ ) ||
95,7 → 98,7
return false;
}
 
var elem = document.createElement( 'input' );
const elem = document.createElement( 'input' );
 
elem.type = 'file';
 
107,17 → 110,17
$( '#fichier' ).on( 'change', function ( event ) {
lthis.arreter ( event );
 
var options = {
beforeSend : function ( jqXHR, settings ) {
$( '#miniatures' ).on( 'click', '.effacer-miniature', function() {
jqXHR.abort(jqXHR);
});
const options = {
beforeSend : function ( jqXHR, settings ) {
$( '#miniatures' ).on( 'click', '.effacer-miniature', function() {
jqXHR.abort(jqXHR);
});
},
success: lthis.afficherMiniature.bind( lthis ), // post-submit callback
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
resetForm: true // reset the form after successful submit
},
success: lthis.afficherMiniature.bind( lthis ), // post-submit callback
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
resetForm: true // reset the form after successful submit
};
var imgCheminTmp = $( '#fichier' ).val(),
imgCheminTmp = $( '#fichier' ).val(),
parts = imgCheminTmp.split( '\\' ),
nomImage = parts[ parts.length - 1 ],
formatImgOk = lthis.verifierFormat( nomImage ),
136,10 → 139,10
} else {
$( '#form-upload' )[0].reset();
if ( !formatImgOk ) {
lthis.activerModale( lthis.msgTraduction( 'format-non-supporte' ) + ' : ' + $( '#fichier' ).attr( 'accept' ) );
utils.activerModale( lthis.msgTraduction( 'format-non-supporte' ) + ' : ' + $( '#fichier' ).attr( 'accept' ) );
}
if ( !imgNonDupliquee ) {
lthis.activerModale( lthis.msgTraduction( 'image-deja-chargee' ) );
utils.activerModale( lthis.msgTraduction( 'image-deja-chargee' ) );
}
}
return false;
146,7 → 149,7
});
$( 'body' ).on( 'click', '.effacer-miniature', function() {
$( this ).parent().remove();
if ( !lthis.valOk( $('.miniature-chargement' ) ) ) {
if ( !valOk( $('.miniature-chargement' ) ) ) {
$( '#ajouter-obs' ).removeClass( 'hidden' );
$( '#message-chargement' ).addClass( 'hidden' );
}
166,7 → 169,7
WidgetsSaisiesCommun.prototype.initEvtsGeoloc = function( isFormArbre = false ) {
const lthis = this;
 
var ancre = '-observation',
let ancre = '-observation',
complementSelecteur = '';
 
if ( isFormArbre ) {
173,13 → 176,17
ancre = '-arbres';
complementSelecteur = ancre;
}
// Empêcher que le module carto ne bind ses events partout
$( '#zone' + ancre ).on( 'submit blur click focus mousedown mouseleave mouseup change', '#tb-geolocation' + complementSelecteur + ' *', function( event ) {
event.preventDefault();
return false;
});
// evenement location
$( '#tb-geolocation' + complementSelecteur ).on( 'location' , this.locationHandler.bind( this ) );
 
const $mapEl = $( '#tb-geolocation' + complementSelecteur );
 
if( valOk( $mapEl ) ) {
const typeLocalisation = $mapEl.data( 'typeLocalisation' ) || 'point';
 
this.geoloc.init(complementSelecteur);
$( '#coord' ).toggleClass( 'hidden', 'point' !== typeLocalisation );
// evenement location
$mapEl.on( 'location' , this.locationHandler.bind( this ) );
}
};
 
WidgetsSaisiesCommun.prototype.initEvtsObs = function() {
197,7 → 204,7
});
// mécanisme de suppression d'une obs
$( '#liste-obs' ).on( 'click', '.supprimer-obs', function() {
var buttons = [
const buttons = [
{
label : 'Annuler',
class : 'btn-secondary',
210,10 → 217,10
}
];
// bricolage pour avoir les deux contextes en même temps (objet et elt. du DOM)
var that = this,
const that = this,
suppObs = lthis.supprimerObs.bind( lthis );
 
lthis.activerModale( lthis.msgTraduction( 'confirmation-suppression' ), '', buttons );
utils.activerModale( lthis.msgTraduction( 'confirmation-suppression' ), '', buttons );
$( '.confirmer' ).on( 'click', function() {
suppObs( that );
});
233,7 → 240,7
*/
WidgetsSaisiesCommun.prototype.chargerStatutSSO = function() {
const lthis = this;
var urlAuth = this.urlBaseAuth + '/identite';
let urlAuth = this.urlBaseAuth + '/identite';
 
if( 'local' !== this.mode ) {
this.connexion( urlAuth, true );
240,14 → 247,15
if( this.isASL) {
$( '#connexion' ).on( 'click', function( event ) {
event.preventDefault();
if( $( '#utilisateur-connecte' ).hasClass( 'hidden' ) || !lthis.valOk( $( '#nom-complet' ).text() ) ) {
var login = $( '#courriel' ).val(),
mdp = $( '#mdp' ).val();
if ( lthis.valOk( login ) && lthis.valOk( mdp ) ) {
if( $( '#utilisateur-connecte' ).hasClass( 'hidden' ) || !valOk( $( '#nom-complet' ).text() ) ) {
const login = $( '#courriel' ).val(),
mdp = $( '#mdp' ).val();
 
if ( valOk( login ) && valOk( mdp ) ) {
urlAuth = lthis.urlBaseAuth + '/connexion?login=' + login + '&password=' + mdp;
lthis.connexion( urlAuth, true );
} else {
lthis.activerModale( lthis.msgTraduction( 'non-connexion' ) );
utils.activerModale( lthis.msgTraduction( 'non-connexion' ) );
}
}
});
254,6 → 262,7
}
} else {
urlAuth = this.urlWidgets + 'modules/saisie/test-token.json';
// Pour tester le bouton de connexion :
// $( '#connexion' ).on( 'click', function( event ) {
// event.preventDefault();
// lthis.connexion( urlAuth, true );
266,7 → 275,7
* Déconnecte l'utilisateur du SSO
*/
WidgetsSaisiesCommun.prototype.deconnecterUtilisateur = function() {
var urlAuth = this.urlBaseAuth + '/deconnexion';
const urlAuth = this.urlBaseAuth + '/deconnexion';
 
if( 'local' === this.mode ) {
this.definirUtilisateur();
305,7 → 314,7
 
WidgetsSaisiesCommun.prototype.definirUtilisateur = function( jeton ) {
const thisObj = this;
var idUtilisateur = '',
let idUtilisateur = '',
prenom = '',
nom = '',
nomComplet = '',
340,8 → 349,8
$( '#courriel' ).val( courriel );
$( '#profil-utilisateur a' ).attr( 'href', this.urlSiteTb() + 'membres/me' );
if ( this.isASL ) {
if ( this.valOk( idUtilisateur ) ) {
var nomSquelette = $( '#charger-form' ).data( 'load' ) || 'arbres';
if ( valOk( idUtilisateur ) ) {
const nomSquelette = $( '#charger-form' ).data( 'load' ) || 'arbres';
this.chargerForm( nomSquelette, thisObj );
}
} else {
355,10 → 364,12
* JETON EST VALIDE, ne pas décoder n'importe quoi - pas trouvé de lib simple
*/
WidgetsSaisiesCommun.prototype.decoderJeton = function( jeton ) {
var parts = jeton.split( '.' ),
payload = parts[1];
const parts = jeton.split( '.' );
let payload = parts[1];
 
payload = this.b64d( payload );
payload = JSON.parse( payload, true );
 
return payload;
};
 
366,22 → 377,23
* Décodage "url-safe" des chaînes base64 retournées par le SSO (lib jwt)
*/
WidgetsSaisiesCommun.prototype.b64d = function( input ) {
var remainder = input.length % 4;
const remainder = input.length % 4;
 
if ( 0 !== remainder ) {
var padlen = 4 - remainder;
const padlen = 4 - remainder;
 
for ( var i = 0; i < padlen; i++ ) {
for ( let i = 0; i < padlen; i++ ) {
input += '=';
}
}
input = input.replace( '-', '+' );
input = input.replace( '_', '/' );
 
return atob( input );
};
 
WidgetsSaisiesCommun.prototype.urlSiteTb = function() {
var urlPart = ( 'test' === this.mode ) ? '/test/' : '/';
const urlPart = ( 'test' === this.mode ) ? '/test/' : '/';
 
return this.urlRacine + urlPart;
};
391,7 → 403,7
* Affiche/Cache le champ taxon
*/
WidgetsSaisiesCommun.prototype.surChangementTaxonListe = function() {
if ( utils.valOk( $( '#taxon-liste' ).val() ) ) {
if ( valOk( $( '#taxon-liste' ).val() ) ) {
if ( 'autre' !== $( '#taxon-liste' ).val() ) {
$( '#taxon-input-groupe' )
.hide( 200, function () {
405,7 → 417,7
.show(200)
.find( '#taxon-autre' )
.on( 'change', function() {
if( !utils.valOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
if( !valOk( $( '#taxon-autre' ).data( 'numNomSel' ) ) ) {
$( '#taxon' ).val( $( '#taxon-autre' ).val() )
.data( 'value', $( '#taxon-autre' ).val() )
.removeData([
423,13 → 435,12
};
 
WidgetsSaisiesCommun.prototype.surChangementValeurTaxon = function() {
var numNomSel = 0;
 
if( this.valOk( $( '#taxon-liste' ).val() ) ) {
if( valOk( $( '#taxon-liste' ).val() ) ) {
if( 'autre' === $( '#taxon-liste' ).val() ) {
this.ajouterAutocompletionNoms();
} else {
var optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' );
const optionRetenue = $( '#taxon-liste' ).find( 'option[value="' + $( '#taxon-liste' ).val() + '"]' );
 
$( '#taxon' ).val( $( '#taxon-liste' ).val() )
.data( 'value', $( '#taxon-liste' ).val() )
.data( 'numNomSel', optionRetenue.data( 'num-nom-sel' ) )
439,9 → 450,10
.data( 'famille', optionRetenue.data( 'famille' ) );
$( '#taxon' ).trigger( 'change' );
 
numNomSel = $( '#taxon' ).data( 'numNomSel' );
const numNomSel = $( '#taxon' ).data( 'numNomSel' );
 
// Si l'espèce est mal déterminée la certitude est "à déterminer"
if( !this.valOk( numNomSel ) ) {
if( !valOk( numNomSel ) ) {
$( '#certitude' ).find( 'option' ).each( function() {
if ( $( this ).hasClass( 'aDeterminer' ) ) {
$( this ).attr( 'selected', true );
460,9 → 472,9
*/
WidgetsSaisiesCommun.prototype.ajouterAutocompletionNoms = function() {
const lthis = this;
var taxonSelecteur = '#taxon';
let taxonSelecteur = '#taxon';
 
if ( this.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
if ( valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
taxonSelecteur += '-autre';
}
$( taxonSelecteur ).autocomplete({
469,12 → 481,12
source: function( requete, add ) {
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
requete = '';
if( lthis.valOk( $( '#referentiel' ).val(), false, 'autre' ) ) {
var url = lthis.getUrlAutocompletionNomsSci();
if( valOk( $( '#referentiel' ).val(), false, 'autre' ) ) {
const url = lthis.getUrlAutocompletionNomsSci();
 
$( '#taxon-autocomplete-label' ).addClass( 'loading' );
$( '#taxon-autocomplete-label' ).addClass( 'loading' );
$.getJSON( url, requete, function( data ) {
var suggestions = lthis.traiterRetourNomsSci( data );
let suggestions = lthis.traiterRetourNomsSci( data );
add( suggestions );
})
.fail( function() {
497,16 → 509,15
};
 
WidgetsSaisiesCommun.prototype.getUrlAutocompletionNomsSci = function() {
var taxonSelecteur = '#taxon';
let taxonSelecteur = '#taxon';
 
if ( this.valOk( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
if ( 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 );
const mots = $( taxonSelecteur ).val(),
url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
 
return url;
return url.replace( '{masque}', mots );
};
 
/**
513,10 → 524,10
* Objet taxons pour autocompletion en fonction de la recherche
*/
WidgetsSaisiesCommun.prototype.traiterRetourNomsSci = function( data ) {
var taxonSelecteur = '#taxon',
suggestions = [];
let taxonSelecteur = '#taxon',
suggestions = [];
 
if ( this.valOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
if ( valOk ( $( '#taxon-liste' ).val(), true, 'autre' ) ) {
taxonSelecteur += '-autre';
}
if ( undefined != data.resultat ) {
523,7 → 534,7
$.each( data.resultat, function( i, val ) {
val.nn = i;
 
var nom = {
const nom = {
label : '',
value : '',
nt : 0,
564,7 → 575,7
* charge les données dans #taxon
*/
WidgetsSaisiesCommun.prototype.surAutocompletionTaxon = function( event, ui ) {
if ( utils.valOk( ui ) ) {
if ( valOk( ui ) ) {
$( '#taxon' ).val( ui.item.value );
$( '#taxon' ).data( 'value', ui.item.value )
.data( 'numNomSel', ui.item.numNomSel )
578,7 → 589,7
$( '#taxon' ).removeClass( 'ns-retenu' );
}
// Si l'espèce est mal déterminée la certitude est "à déterminer"
if( !utils.valOk( $( '#taxon' ).data( 'numNomSel' ) ) ) {
if( !valOk( $( '#taxon' ).data( 'numNomSel' ) ) ) {
$( '#certitude' ).find( 'option' ).each( function() {
if ( $( this ).hasClass( 'aDeterminer' ) ) {
$( this ).attr( 'selected', true );
597,15 → 608,11
* la miniature d'une image ajoutée à l'obs
*/
WidgetsSaisiesCommun.prototype.afficherMiniature = function( reponse ) {
if ( this.debug ) {
var debogage = $( 'debogage', reponse ).text();
}
 
var message = $( 'message', reponse ).text();
const message = $( 'message', reponse ).text(),
$blocMiniature = $( '#miniatures .miniature.loading').first();
 
if( this.valOk( $blocMiniature ) ) {
if ( this.valOk( message ) ) {
if( valOk( $blocMiniature ) ) {
if ( valOk( message ) ) {
$( '.miniature-msg' ).text( message );
$blocMiniature.remove();
 
613,7 → 620,7
this.creerWidgetMiniature( reponse, $blocMiniature );
$blocMiniature.removeClass('loading');
}
if ( !lthis.valOk( $( '.miniature-chargement' ) ) ) {
if ( !valOk( $( '.miniature-chargement' ) ) ) {
$( '#ajouter-obs' ).removeClass( 'hidden' );
$( '#message-chargement' ).addClass( 'hidden' );
}
625,8 → 632,8
* Crée la miniature temporaire (formulaire) + bouton pour l'effacer
*/
WidgetsSaisiesCommun.prototype.creerWidgetMiniature = function( reponse, $blocMiniature ) {
var miniatureUrl = $( 'miniature-url', reponse ).text();
var imgNom = $( 'image-nom', reponse ).text();
const miniatureUrl = $( 'miniature-url', reponse ).text(),
imgNom = $( 'image-nom', reponse ).text();
 
$blocMiniature.removeClass( 'miniature-chargement' );
$( '.miniature-img', $blocMiniature )
641,7 → 648,7
* Retourne true si l'extension de l'image 'nom' est .jpg ou .jpeg
*/
WidgetsSaisiesCommun.prototype.verifierFormat = function( nomImage ) {
var parts = nomImage.split( '.' ),
const parts = nomImage.split( '.' ),
extension = parts[ parts.length - 1 ];
 
return ( 'jpeg' === extension.toLowerCase() || 'jpg' === extension.toLowerCase() );
654,8 → 661,7
*/
WidgetsSaisiesCommun.prototype.verifierDuplication = function( nomImage ) {
const lthis = this;
 
var thisSrcParts = [],
let thisSrcParts = [],
thisNomImage = '',
nonDupliquee = true;
 
663,18 → 669,21
 
$( 'img.miniature-img,img.miniature' ).each( function() {
// vérification avec alt de l'image
if ( lthis.valOk ( $( this ).attr( 'alt' ) ) && $( this ).attr('alt' ).toLowerCase() === nomImage ) {
if ( valOk ( $( this ).attr( 'alt' ) ) && $( this ).attr('alt' ).toLowerCase() === nomImage ) {
nonDupliquee = false;
 
return false;// Pas besoin de poursuivre la boucle
} else { // sinon vérifie aussi avec l'adresse (src) de l'image
thisSrcParts = $( this ).attr( 'src' ).split( '/' );
thisNomImage = thisSrcParts[ thisSrcParts.length - 1 ].replace( '_min', '' ).toLowerCase();
if ( lthis.valOk( thisNomImage, true, nomImage ) ) {
if ( valOk( thisNomImage, true, nomImage ) ) {
nonDupliquee = false;
 
return false;
}
}
});
 
return nonDupliquee;
};
 
687,38 → 696,47
 
// Geoloc *********************************************************************/
WidgetsSaisiesCommun.prototype.transfererCarto = function( donnees ) {
var typeLocalisation = donnees.typeLocalisation || 'point',
isPoint = ( typeLocalisation === 'point' ).toString(),
locationFilter = ( typeLocalisation === 'rue' ) ? 'linestring' : 'point',
suffixe = ( this.valOk( donnees.suffixe ) ) ? '-' + donnees.suffixe : '',
$cartoRemplacee = donnees.cartoRemplacee || $( '#tb-geolocation' ),
layer = donnees.layer || 'osm',
latitude = donnees.latitude || '46.5',
longitude = donnees.longitude || '2.9',
// 18 est le zoom max
zoomInit = donnees.zoomInit || 18;
const typeLocalisation = donnees.typeLocalisation || 'point',
suffixe = valOk( donnees.suffixe ) ? '-' + donnees.suffixe : '',
formSuffixe = '-arbres' === suffixe ? suffixe : '',
$cartoRemplacee = donnees.cartoRemplacee || $( '#tb-geolocation' ),
latitude = donnees.latitude || '',
longitude = donnees.longitude || '',
zoomInit = donnees.zoomInit || '',
$mapContainer = $cartoRemplacee.closest('#map-container');
 
$cartoRemplacee.remove();
$( '#geoloc' + suffixe ).append(
'<tb-geolocation-element'+
' id="tb-geolocation' + suffixe +'"'+
' layer="' + layer + '"'+
' zoom_init="' + zoomInit + '"'+
' lat_init="' + latitude + '"'+
' lng_init="' + longitude + '"'+
' marker="' + isPoint + '"'+
' polyline="' + !isPoint + '"'+
' polygon="false"'+
' show_lat_lng_elevation_inputs="' + isPoint + '"'+
' osm_class_filter=""'+
' geometry_filter="'+ locationFilter + '"'+
' elevation_provider="mapquest"'+
' map_quest_api_key="mG6oU5clZHRHrOSnAV0QboFI7ahnGg34"'+
' height="400px"'+
'>'+
'</tb-geolocation-element>'
);
this.initEvtsGeoloc( true );
if ( valOk( formSuffixe ) || 'point' !== typeLocalisation ) {
$mapContainer.siblings('#tb-places-zone').remove();
}
 
if ( 'tb-geolocation' + suffixe !== $cartoRemplacee.attr('id') ) {
$mapContainer.remove();
$( '#geoloc' + suffixe ).append(
'<div id="map-container">'+
'<div'+
' id="tb-geolocation' + suffixe +'"'+
' data-layer="' + donnees.layer + '"'+
' data-zoom="' + zoomInit + '"'+
' data-type-localisation="' + typeLocalisation + '"'+
' data-form-suffix="' + formSuffixe + '"'+
' style="height: 400px;width: 100%"'+
'>'+
'</div>'+
'</div>'
);
 
$( '#coord' ).toggleClass( 'hidden', 'point' !== typeLocalisation );
 
if( valOk( this.geoloc.map ) ) {
this.geoloc.closeMap();
}
 
this.initEvtsGeoloc( true );
} else {
this.geoloc.reSetDrawControl();
}
 
this.geoloc.setMapPosition({'lat': latitude, 'lng': longitude});
};
 
// Ajouter Obs ****************************************************************/
745,11 → 763,13
$( '.obs-nbre' ).text( this.obsNbre );
$( '.obs-nbre' ).triggerHandler( 'changement' );
//formatage des données
var obsData = this.formaterFormObsData();
const obsData = this.formaterFormObsData();
 
this.afficherObs( obsData );
this.stockerObsData( obsData );
if ( this.isASL && 'arbres' === this.sujet ) {
var arbreData = obsData.sujet;
const arbreData = obsData.sujet;
 
// Ajout de donnée utiles puis stockage dans input hidden "releve-data"
arbreData['date_rue_commune'] = obsData.releve.date + obsData.releve.rue + obsData.releve['commune-nom'];
arbreData['id_observation'] = 0;
771,16 → 791,16
* Formatage des données du formulaire pour stockage et envoi
*/
WidgetsSaisiesCommun.prototype.formaterFormObsData = function() {
var obsData = { obsNum : this.obsNbre, sujet : {}},
numNomSel = $( '#taxon' ).data( 'numNomSel' ),
nomSel = $( '#taxon' ).val(),
nomRet = $( '#taxon' ).data( 'nomRet' ),
numNomRet = $( '#taxon' ).data( 'numNomRet' ),
numTaxon = $( '#taxon' ).data( 'nt' ),
famille = $( '#taxon' ).data( 'famille' ),
referentiel = ( this.valOk( numNomSel ) ) ? this.nomSciReferentiel : 'autre',
certitude = ( this.valOk( numNomSel ) ) ? $( '#certitude' ).val() : 'à determiner',
imgB64 = [],
const obsData = { obsNum : this.obsNbre, sujet : {}},
numNomSel = $( '#taxon' ).data( 'numNomSel' ),
nomSel = $( '#taxon' ).val(),
nomRet = $( '#taxon' ).data( 'nomRet' ),
numNomRet = $( '#taxon' ).data( 'numNomRet' ),
numTaxon = $( '#taxon' ).data( 'nt' ),
famille = $( '#taxon' ).data( 'famille' ),
referentiel = ( valOk( numNomSel ) ) ? this.nomSciReferentiel : 'autre',
certitude = ( valOk( numNomSel ) ) ? $( '#certitude' ).val() : 'à determiner';
let imgB64 = [],
imgNom = [],
date = '',
notes = '',
794,18 → 814,19
obsEtendue = [];
 
if( !this.isASL ) {
notes = $( '#notes' ).val().trim() || '';
pays = $( '#pays' ).val() || '';
communeNom = $( '#commune-nom' ).val();
communeInsee = $( '#commune-insee' ).val() || '';
geometry = $( '#geometry' ).val();
latitude = $( '#latitude' ).val();
longitude = $( '#longitude' ).val();
altitude = $( '#altitude' ).val();
obsEtendue = this.getObsChpSpecifiques();
date = this.fournirDate( $('#date_releve').val());
notes = $( '#notes' ).val().trim() || '';
pays = $( '#pays' ).val() || '';
communeNom = $( '#commune-nom' ).val();
communeInsee = $( '#commune-insee' ).val() || '';
geometry = $( '#geometry' ).val();
latitude = $( '#latitude' ).val();
longitude = $( '#longitude' ).val();
altitude = $( '#altitude' ).val();
obsEtendue = this.getObsChpSpecifiques();
date = this.fournirDate( $('#date_releve').val());
} else {
var miniatureImg = [];
const miniatureImg = [];
 
notes = $( '#commentaire' ).val() || '';
if ( 'arbres' === this.sujet ) {
// Dans ce cas cette fonction doit renvoyer des données au même format que l'input hidden "releve-data"
864,7 → 885,8
obsData.releve['pres-lampadaires'] = $( '#pres-lampadaires input:checked' ).val() || '';
}
if ( 'tb_streets' !== this.projet ) {
var faceOmbre = [];
const faceOmbre = [];
 
$( '#face-ombre input' ).each( function() {
if( $( this ).is( ':checked' ) ) {
faceOmbre.push( $( this ).val() );
928,7 → 950,7
*/
WidgetsSaisiesCommun.prototype.afficherObs = function( datasObs ) {
// différences html liéees au responsive
var responsivDiff1 = '',
let responsivDiff1 = '',
responsivDiff2 = '',
responsivDiff3 = '',
responsivDiff4 = '',
944,8 → 966,8
responsivDiff6 = '</div>';
}
 
var obsNum = datasObs.obsNum,
numNomSel = datasObs.sujet['num_nom_sel'] || '',
const obsNum = datasObs.obsNum;
let numNomSel = datasObs.sujet['num_nom_sel'] || '',
taxon = '',
miniatures = '',
notes = '',
973,19 → 995,19
longitude = datasObs.sujet['longitude'] || '';
inseeCommune = datasObs.sujet['commune_code_insee'] || '';
commune = datasObs.sujet['commune_nom'] || '';
if ( this.valOk( inseeCommune ) ) {
if ( valOk( inseeCommune ) ) {
inseeCommuneText = '(INSEE Commune:' + inseeCommune + ') ';
}
if ( this.valOk( numNomSel ) ) {
if ( valOk( numNomSel ) ) {
referentiel = '<span class="referentiel-obs">' + '[' + datasObs.sujet['referentiel'] + ']' + '</span>';
}
if ( this.valOk( datasObs.sujet['lieudit'] ) ) {
if ( valOk( datasObs.sujet['lieudit'] ) ) {
lieudit = '<span>' + this.msgTraduction( 'lieu-dit' ) + ' :</span> ' + datasObs.sujet['lieudit'] + ' ';
}
if ( this.valOk( datasObs.sujet['station'] ) ) {
if ( valOk( datasObs.sujet['station'] ) ) {
station = '<span>' + this.msgTraduction( 'station' ) + ' :</span> ' + datasObs.sujet['station'] + ' ';
}
if ( this.valOk( datasObs.sujet['milieu'] ) ) {
if ( valOk( datasObs.sujet['milieu'] ) ) {
milieu = '<span>' + this.msgTraduction( 'milieu' ) + ' :</span> ' + datasObs.sujet['milieu'] + ' ';
}
nn = this.ajouterNumNomSel( numNomSel );
1016,14 → 1038,14
date = this.fournirDate( datasObs.sujet.date );
}
if( !this.isASL || 'arbres' === this.sujet ) {
if ( this.valOk( commune ) ) {
if ( valOk( commune ) ) {
lieuObs = ' ' + this.msgTraduction( 'lieu-obs' ) + ' ' + '<span class="commune">' + commune + '</span> ';
}
if ( this.valOk( latitude ) && this.valOk( longitude ) ) {
if ( valOk( latitude ) && valOk( longitude ) ) {
coordonnees = '[' + latitude + ' / ' + longitude + ']';
}
}
if ( this.valOk( notes ) ) {
if ( valOk( notes ) ) {
commentaires =
this.msgTraduction( 'commentaires' ) +
' : <span>'+
1075,7 → 1097,7
milieu +
'</li>'+
'<li>'+
// this.valOk( notes )
// valOk( notes )
commentaires +
'</li>'+
'</ul>'+
1093,7 → 1115,7
*/
WidgetsSaisiesCommun.prototype.ajouterImgMiniatureAuTransfert = function( chargerImages = undefined ) {
const lthis = this;
var html =
let html =
'<div class="defilement-miniatures">'+
'<figure class="centre">'+
'<img class="miniature align-middle" alt="Aucune photo" src="' + this.pasDePhotoIconeUrl + '" width="80%" />'+
1104,12 → 1126,11
defilVisible = '',
length = 0;
 
if ( this.valOk( chargerImages ) || this.valOk( $( '#miniatures img' ) ) ) {
if ( this.valOk( chargerImages ) ) {
if ( valOk( chargerImages ) || valOk( $( '#miniatures img' ) ) ) {
if ( valOk( chargerImages ) ) {
$.each( chargerImages, function( i, value ) {
var imgVisible = ( 0 < i ) ? 'miniature-cachee' : 'miniature-selectionnee';
 
var css = ( lthis.valOk( value['b64'] ) ) ? 'miniature b64' : 'miniature',
let imgVisible = ( 0 < i ) ? 'miniature-cachee' : 'miniature-selectionnee',
css = ( valOk( value['b64'] ) ) ? 'miniature b64' : 'miniature',
src = value.src,
alt = value.nom,
miniature = '<img class="' + css + ' ' + imgVisible + ' align-middle" alt="' + alt + '"src="' + src + '" width="80%" />';
1118,12 → 1139,13
});
length = chargerImages.length;
} else {
var premiere = true;
let premiere = true;
$( '#miniatures img' ).each( function() {
var imgVisible = ( premiere ) ? 'miniature-selectionnee' : 'miniature-cachee';
let imgVisible = ( premiere ) ? 'miniature-selectionnee' : 'miniature-cachee';
 
premiere = false;
 
var css = ( $( this ).hasClass( 'b64' ) ) ? 'miniature b64' : 'miniature',
let css = ( $( this ).hasClass( 'b64' ) ) ? 'miniature b64' : 'miniature',
src = $( this ).attr( 'src' ),
alt = $( this ).attr( 'alt' ),
miniature = '<img class="' + css + ' ' + imgVisible + ' align-middle" alt="' + alt + '"src="' + src + '" width="80%" />';
1136,7 → 1158,7
centre = 'centre';
defilVisible = ' defilement-miniatures-cache';
}
html =
html =
'<div class="defilement-miniatures">'+
'<a href="#" class="defilement-miniatures-gauche mr-1' + defilVisible + '"><i class="fas fa-chevron-circle-left"></i></a>'+
'<figure class="' + centre + '">'+
1153,9 → 1175,9
* Construit le html à afficher pour le numNom
*/
WidgetsSaisiesCommun.prototype.ajouterNumNomSel = function( numNomSel ) {
var nn = '<span class="nn">[nn' + numNomSel + ']</span>';
let nn = '<span class="nn">[nn' + numNomSel + ']</span>';
 
if ( !this.valOk( numNomSel ) ) {
if ( !valOk( numNomSel ) ) {
nn = '<span class="alert-error">[' + this.msgTraduction( 'non-lie-au-ref' ) + ']</span>';
}
 
1171,7 → 1193,7
// car les données peuvent provenir soit de la formaterFormObsData soit de cet input
const lthis = this;
// si releve dupliqué on ne stocke pas l'image :
var stockerImg = this.valOk( obsDatas.sujet['miniature-img'] ),
let stockerImg = valOk( obsDatas.sujet['miniature-img'] ),
imgNom = [],
imgB64 = [];
 
1187,10 → 1209,10
// Si les miniatures ne sont pas déjà stockées (résultat de la loop précédente)
if( stockerImg ) {
$.each( obsDatas.sujet['miniature-img'] , function( i, obj ) {
if( lthis.valOk( obj.nom ) ) {
if( valOk( obj.nom ) ) {
imgNom.push( obj.nom );
}
if( lthis.valOk( obj['b64'] ) ) {
if( valOk( obj['b64'] ) ) {
imgB64.push( obj['b64'] );
}
});
1230,7 → 1252,7
};
 
WidgetsSaisiesCommun.prototype.getNomsImgsOriginales = function() {
var noms = new Array();
const noms = [];
 
$( '.miniature-img' ).each( function() {
noms.push( $( this ).attr( 'alt' ) );
1240,7 → 1262,7
};
 
WidgetsSaisiesCommun.prototype.getB64ImgsOriginales = function() {
var b64 = new Array();
const b64 = [];
 
$( '.miniature-img' ).each( function() {
if ( $( this ).hasClass( 'b64' ) ) {
1289,12 → 1311,12
};
 
WidgetsSaisiesCommun.prototype.defilerMiniatures = function( element ) {
var miniatureSelectionne = element.siblings( 'figure' ).find( 'img.miniature-selectionnee' );
const miniatureSelectionne = element.siblings( 'figure' ).find( 'img.miniature-selectionnee' );
 
miniatureSelectionne.removeClass( 'miniature-selectionnee' );
miniatureSelectionne.addClass( 'miniature-cachee' );
 
var miniatureAffichee = miniatureSelectionne;
let miniatureAffichee = miniatureSelectionne;
 
if( element.hasClass( 'defilement-miniatures-gauche' ) ) {
if( 0 !== miniatureSelectionne.prev( '.miniature' ).length ) {
1314,7 → 1336,7
};
 
WidgetsSaisiesCommun.prototype.supprimerObs = function( selector ) {
var obsId = $( selector ).val();
let obsId = $( selector ).val();
 
// Problème avec IE 6 et 7
if ( 'Supprimer' === obsId ) {
1328,6 → 1350,9
* et remonte les suivantes d'un cran
*/
WidgetsSaisiesCommun.prototype.supprimerObsParId = function( obsId, transmission = false ) {
let arbreExId = 0,
arbreId = 0;
 
if ( this.isASL && 'arbres' === this.sujet ) {
if ( !transmission ) {
this.releveData = $.parseJSON( $( '#releve-data' ).val() );
1340,9 → 1365,6
if ( 1 > this.numArbre ) {
$( '#bloc-info-arbres-title' ).addClass( 'hidden' );
}
 
var arbreExId = 0,
arbreId = 0;
}
this.obsNbre -= 1;
$( '.obs-nbre' ).text( this.obsNbre );
1351,12 → 1373,12
obsId = parseInt(obsId);
 
if ( !transmission ) {
var listObsData = $( '#liste-obs' ).data(),
exId = 0,
indexObs = '',
exIndexObs = '';
const listObsData = $( '#liste-obs' ).data();
let exId = 0,
indexObs = '',
exIndexOb = '';
 
for ( var id = obsId; id <= ( this.obsNbre + 1 ); id++ ) {
for ( let id = obsId; id <= ( this.obsNbre + 1 ); id++ ) {
exId = parseInt(id) + 1;
indexObs = 'obsId' + id;
exIndexObs = 'obsId' + exId;
1378,7 → 1400,7
.data( 'arbre', arbreId )
.text( 'Arbre ' + arbreId );
// modification du numero d'arbre dans les obs étendues
if ( this.valOk( listObsData[exIndexObs] ) ) {
if ( valOk( listObsData[exIndexObs] ) ) {
$.each( listObsData[exIndexObs].obs_etendue, function( i, obsE ) {
if ('num_arbre' === obsE.cle ) {
listObsData[exIndexObs].obs_etendue[i].valeur = arbreId;
1389,7 → 1411,7
}
 
// Mise à jour des données à transmettre
if ( this.valOk( listObsData[exIndexObs] ) ) {
if ( valOk( listObsData[exIndexObs] ) ) {
$( '#liste-obs' ).data( indexObs, listObsData[exIndexObs] );
}
if ( parseInt( id ) !== this.obsNbre ) {
1402,13 → 1424,13
};
 
WidgetsSaisiesCommun.prototype.transmettreObs = function() {
const lthis = this;
var observations = $( '#liste-obs' ).data();
const lthis = this,
observations = $( '#liste-obs' ).data();
 
if ( this.debug ) {
console.dir( observations );
}
if ( !this.valOk( typeof observations, true, 'object' ) ) {
if ( !valOk( typeof observations, true, 'object' ) ) {
this.afficherPanneau( '#dialogue-zero-obs' );
} else {
this.nbObsEnCours = 1;
1423,30 → 1445,30
};
 
WidgetsSaisiesCommun.prototype.depilerObsPourEnvoi = function() {
var observations = $( '#liste-obs' ).data();
const observations = $( '#liste-obs' ).data();
// la boucle est factice car on utilise un tableau
// dont on a besoin de n'extraire que le premier élément
// or javascript n'a pas de méthode cross browsers pour extraire les clés
// TODO: utiliser var.keys quand ça sera plus répandu
// ou bien utiliser un vrai tableau et pas un objet
for ( var obsNum in observations ) {
var obsATransmettre = {
'id_projet' : this.idProjet,
'projet' : this.projet,
'tag-obs' : this.tagObs,
'tag-img' : this.tagImg
};
var utilisateur = {
id_utilisateur : $( '#id_utilisateur' ).val(),
prenom : $( '#prenom' ).val(),
nom : $( '#nom' ).val(),
courriel : $( '#courriel' ).val()
};
for ( let obsNum in observations ) {
const obsATransmettre = {
'id_projet' : this.idProjet,
'projet' : this.projet,
'tag-obs' : this.tagObs,
'tag-img' : this.tagImg
},
utilisateur = {
id_utilisateur : $( '#id_utilisateur' ).val(),
prenom : $( '#prenom' ).val(),
nom : $( '#nom' ).val(),
courriel : $( '#courriel' ).val()
};
 
obsATransmettre['utilisateur'] = utilisateur;
obsATransmettre[obsNum] = observations[obsNum];
 
var idObsNumerique = obsNum.replace( 'obsId', '' );
const idObsNumerique = obsNum.replace( 'obsId', '' );
 
if( '' !== idObsNumerique ) {
this.envoyerObsAuCel( idObsNumerique, obsATransmettre );
1457,9 → 1479,8
 
WidgetsSaisiesCommun.prototype.envoyerObsAuCel = function( idObs, observation ) {
const lthis = this;
let erreurMsg = '';
 
var erreurMsg = '';
 
$.ajax({
url : lthis.serviceSaisieUrl,
type : 'POST',
1506,7 → 1527,7
}
},
complete : function( jqXHR, textStatus ) {
var debugMsg = lthis.extraireEnteteDebug( jqXHR );
const debugMsg = lthis.extraireEnteteDebug( jqXHR );
 
if ( '' !== erreurMsg ) {
if ( lthis.debug ) {
1513,7 → 1534,7
$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-erreur">' + erreurMsg + '</pre>' );
$( '#dialogue-obs-transaction-ko .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
}
var hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?'+
const hrefCourriel = 'mailto:cel_remarques@tela-botanica.org?'+
'subject=Dysfonctionnement du widget de saisie ' + lthis.tagsMotsCles+
'&body=' + erreurMsg + '%0D%0ADébogage :%0D%0A' + debugMsg;
 
1560,7 → 1581,7
WidgetsSaisiesCommun.prototype.mettreAJourProgression = function() {
this.nbObsTransmises++;
 
var pct = ( this.nbObsTransmises / this.totalObsATransmettre ) * 100;
const pct = ( this.nbObsTransmises / this.totalObsATransmettre ) * 100;
 
$( '#barre-progression-upload' ).attr( 'aria-valuenow', this.nbObsTransmises );
$( '#barre-progression-upload' ).css( 'width', pct + '%' );
1586,7 → 1607,7
$.validator.addMethod(
'dateCel',
function ( value, element ) {
return ( lthis.valOk( value ) && ( /^(?:[0-9]{4}-[0-9]{2}-[0-9]{2})|(?:[0-9]{2}\/[0-9]{2}\/[0-9]{4})$/.test( value ) ) );
return ( valOk( value ) && ( /^(?:[0-9]{4}-[0-9]{2}-[0-9]{2})|(?:[0-9]{2}\/[0-9]{2}\/[0-9]{4})$/.test( value ) ) );
},
lthis.msgTraduction( 'date-incomplete' )
);
1593,7 → 1614,7
$.validator.addMethod(
'userEmailOk',
function ( value, element ) {
return ( lthis.valOk( value ) );
return ( valOk( value ) );
},
''
);
1608,7 → 1629,7
$.validator.addMethod(
'listFields',
function ( value, element ) {
return ( lthis.valOk( value ) );
return ( valOk( value ) );
},
''
);
1622,7 → 1643,7
}
},
onfocusout: function( element ) {
if( lthis.valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
if( valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
if ( $( element ).valid() ) {
$( element ).closest( '.control-group' ).removeClass( 'error' );
} else {
1631,7 → 1652,7
}
},
onkeyup : function( element ) {
if( lthis.valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
if( valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
if ( $( element ).valid() ) {
$( element ).closest( '.control-group' ).removeClass( 'error' );
} else {
1640,7 → 1661,7
}
},
unhighlight: function( element ) {
if( lthis.valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
if( valOk( element.id, false, 'taxon' ) || ( lthis.isASL && 'arbres' === lthis.sujet ) ) {
$( element ).closest( '.control-group' ).removeClass( 'error' );
}
},
1653,9 → 1674,11
// Formatage date *************************************************************/
WidgetsSaisiesCommun.prototype.fournirDate = function( dateObs ) {
if ( /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/.test( dateObs ) ) {
 
return dateObs;
} else if ( /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test( dateObs ) ) {
var dateArray = dateObs.split( '-' );
const dateArray = dateObs.split( '-' );
 
return dateArray[2] + '/' + dateArray[1] + '/' + dateArray[0]
} else {
console.dir( 'erreur date : ' + dateObs )
1664,12 → 1687,10
 
// scroll vers le formulaire
WidgetsSaisiesCommun.prototype.scrollFormTop = function( scrollSelecteur, focus = '' ) {
const lthis = this;
 
$( 'html, body' ).stop().animate({
scrollTop: $( scrollSelecteur ).offset().top
}, 300, function() {
if ( lthis.valOk( focus ) ) {
if ( valOk( focus ) ) {
$( focus ).focus();
} else {
return;
1704,13 → 1725,13
* défaut); si celle-ci n'exite pas, retourne "N/A".
*/
WidgetsSaisiesCommun.prototype.msgTraduction = function( cle ) {
var msg = 'N/A';
let msg = 'N/A';
 
if ( this.msgs ) {
if ( this.langue in this.msgs && cle in this.msgs[this.langue] ) {
msg = this.msgs[this.langue][cle];
} else if ( cle in this.msgs['fr'] ) {
msg = this.msgs['fr'][cle];
if ( utils.msgs ) {
if ( this.langue in utils.msgs && cle in utils.msgs[this.langue] ) {
msg = utils.msgs[this.langue][cle];
} else if ( cle in utils.msgs['fr'] ) {
msg = utils.msgs['fr'][cle];
}
}
return msg;
1737,10 → 1758,11
* @returns {String}
*/
WidgetsSaisiesCommun.prototype.extraireEnteteDebug = function( jqXHR ) {
var msgDebug = '';
let msgDebug = '';
 
if ( '' !== jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) ) {
var debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) );
const debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) );
 
if ( null !== debugInfos ) {
$.each( debugInfos, function( cle, valeur ) {
msgDebug += valeur + '\n';
1761,14 → 1783,6
});
};
 
WidgetsSaisiesCommun.prototype.valOk = function ( valeur, sensComparaison = true, comparer = undefined ) {
return utils.valOk( valeur, sensComparaison, comparer );
};
 
WidgetsSaisiesCommun.prototype.activerModale = function ( label, content = '', buttons = [] ) {
return utils.activerModale( label, content, buttons );
};
 
// Lib hors objet
 
/*
1782,11 → 1796,11
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
*/
( function( $ ) {
var proto = $.ui.autocomplete.prototype,
const proto = $.ui.autocomplete.prototype,
initSource = proto._initSource;
 
WidgetsSaisiesCommun.prototype.filter = function( array, term ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), 'i' );
const matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), 'i' );
 
return $.grep( array, function( value ) {