Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 3207 → Rev 3208

/trunk/widget/modules/saisie2/squelettes/js/champs-supp.js
New file
0,0 → 1,269
"use strict";
 
/*************************************
* Fonctions de Style et Affichage *
* des éléments "spéciaux" *
*************************************/
 
// Logique d'affichage pour le input type=file
function inputFile( countFiles ) {
// Initialisation des variables
var $fileInput = $( '.input-file' ),
$button = $( '.label-file' );
// Action lorsque la "barre d'espace" ou "Entrée" est pressée
$( '.label-file' ).keydown( function( event ) {
if ( event.keyCode == 13 || event.keyCode == 32 ) {
$( '#' + $( this ).attr( 'for' ) + '.input-file' ).click();
}
});
// // Affiche un retour visuel dès que input:file change
// $('#form-supp').on( 'change', '.input-file', function( event ) {
// // Il est possible de supprimer un fichier
// // donc on vérifie que le 'change' est un ajout ou modification
// if( !$.isEmptyObject( event.target.files[0] ) ) {
// var file = event.target.files[0],
// fileId = $( this ).attr( 'id' ),
// $thisFile = $( this ).parent('.label-file.' + fileId ),
// $imageContainer = $( '#miniatures' ),
// $theReturn = $( '.' + fileId + 'Img') || false,
// fileImgHtml = '';
 
 
// if( file.type.match( 'image' ) ) {
// fileImgHtml =
// '<div class="' + fileId + 'Img mb-1">'+
// '<p> ' + file.name + '</p>'+
// '<img src="' + URL.createObjectURL( file ) + '">'+
// '</div>';
// }
// // Permettre d'enregistrer une nouvelle image
// if( 0 < $theReturn.length ) {
// // Changement du fichier
// $theReturn.html( fileImgHtml );
// } else {
// $imageContainer.append( fileImgHtml );
// $imageContainer.append( $thisFile );
 
// $( '#photos-conteneur' ).html(
// '<label for="fichier' + countFiles + '" class="label-file btn btn-default fichier' + countFiles + '">'+
// '<i class="fas fa-download"></i> Ajouter une image'+
// '<input type="file" id="fichier' + countFiles + '" name="fichier' + countFiles + '" class="input-file" accept="image/jpeg">'+
// '<input type="hidden" name="MAX_FILE_SIZE" value="5242880">'+
// '</label>'+
// '<hr>'
// );
// countFiles++;
// }
// // Changer le text
// $thisFile.find( '.label-text').html( '<i class="fas fa-exchange-alt"></i> Changer cette image');
// $thisFile.css( 'background-color', '#ea9973' );
// $thisFile.hover( function() {
// $( this ).css( 'background-color', 'rgba(234, 153, 115, 0.7)' );
// });
// $( '.' + fileId + 'Img img').attr( 'width', $thisFile.outerWidth() );
 
// }
// });
// // Annuler le téléchargement
// $( '.remove-file' ).click( function() {
// var $thisFileInput = $( this ).prev( '.input-file-container' ).find( '.input-file' );
// $thisFileInput.wrap( '<form>' ).closest( 'form' ).get(0).reset();
// $thisFileInput.triggerHandler( 'change' );
// $thisFileInput.unwrap();
// $( this ).next( '.file-return' ).addClass( 'hidden' ).empty();
// });
}
 
// Style et affichage des list-checkboxes
function inputListCheckbox() {
// On écoute le click sur une list-checkbox ('.selectBox')
// à tout moment de son insertion dans le dom
// Todo :
// _ S'assurer de bien viser la bonne list-checkbox
// _ Au click sur un autre champ remballer la list-checkbox
$( document ).click( function( event ) {
var target = event.target;
 
if ( !$( target ).is( '.overSelect' ) && 0 === $( target ).closest( '.checkboxes' ).length ) {
$( '.checkboxes' ).each( function () {
$( this ).addClass( 'hidden' );
});
$( '.selectBox select.focus' ).each( function() {
$( this ).removeClass( 'focus' );
});
}
});
 
$( '#zone-appli' ).on( 'click' , '.selectBox' , function() {
// $( '.checkboxes[data-id="' + $(this).attr( 'data-id' ) + '"]' ).toggleClass( 'hidden' );
$( this ).next().toggleClass( 'hidden' );
$( this ).find( 'select' ).toggleClass( 'focus' );
 
});
}
 
// Style et affichage des input type="range"
function inputRangeDisplayNumber() {
$( '#zone-supp' ).on( 'input' , '.range input[type="range"]' , function () {
$( this ).next( 'input[type="number"]' ).val ( $( this ).val() );
});
$( '#zone-supp' ).on( 'input' , '.range input[type="number"]' , function () {
$( this ).prev( 'input[type="range"]' ).val ( $( this ).val() );
});
}
 
// Activation/Desactivation et contenu de la modale Bootstrap
// https://getbootstrap.com/docs/3.3/javascript/#modals
function previewFieldHelpModal() {
$( '#zone-supp' ).on( 'click' , '.help-button' , function ( event ) {
var index = $( this ).closest( '.preview-fields' ).attr( 'data-id' ),
thisFieldset = $( '.new-field[data-id="' + index + '"]' ),
file = $( '.field-help' , thisFieldset )[0].files[0],
tmppath = URL.createObjectURL( file );
// Titre
$( '#help-modal-label' ).text( 'Aide pour : ' + $( '.field-name' , thisFieldset ).val() );
// Contenu
if( file.type.match( 'image' ) ) {
$( '#print_content' ).append( '<img src="' + tmppath + '" style="max-width:100%">' );
} else if( file.type.match( 'pdf' ) ) {
$( '#print_content' ).append( '<iframe src="' + tmppath + '" width="100%" height="650" align="middle" scrolling="no" frameborder="0"></iframe>' );
}
// Sortie avec la touche escape
$( '#help-modal' ).modal( { keyboard : true } );
// Affichage
$( '#help-modal' ).modal( 'show' );
// Remplacer l'autofocus qui ne fonctionne plus en HTML5
// Message dans la doc de bootstrap :
// Due to how HTML5 defines its semantics,
// the autofocus HTML attribute has no effect in Bootstrap modals.
// To achieve the same effect, use some custom JavaScript
$( '#help-modal' ).on( 'shown.bs.modal' , function () {
$( '#myInput' ).trigger( 'focus' );
})
// Réinitialisation
$( '#help-modal' ).on( 'hidden.bs.modal' , function () {
$( '#help-modal-label' ).text();
$( '#print_content' ).empty();
})
});
}
 
// Faire apparaitre un champ text "Autre"
function onOtherOption() {
 
const PREFIX = 'collect-other-';
 
// Ajouter un champ texte pour "Autre"
function optionAdd( otherId, $target, element ) {
$target.after(
'<label for="' + otherId + '" class="' + otherId + '">Autre option :</label>' +
'<input type="text" id="' + otherId + '" name="' + otherId + '" class="collect-other" data-element="' + element + '">'
);
}
 
// Supprimer un champ texte pour "Autre"
function optionRemove( otherId, $this ) {
$( '.' + otherId + ', #' + otherId ).remove();
}
 
$( '#form-supp .other' ).each( function() {
if( $( this ).hasClass( 'is-select' ) ) {
var otherId = PREFIX + $( this ).parent( 'select' ).attr( 'name' );
// Insertion du champ "Autre" après les boutons
optionAdd( otherId, $( this ).parent( '.select' ) , 'select' );
} else if ( $( this ).is( ':checked' ) ) {
var otherId = PREFIX + $( this ).attr( 'name' ),
element = $( this ).attr( 'data-element' );
// Insertion du champ "Autre" après les boutons
optionAdd( otherId, $( this ).parent( 'label' ) , element );
}
});
 
$( '#form-supp select' ).change( function () {
var otherId = PREFIX + $( this ).attr( 'name' );
 
if( 'other' === $( this ).val() ) {
// Insertion du champ "Autre" après les boutons
optionAdd( otherId, $( this ).parent( '.select' ), 'select' );
} else {
// Suppression du champ autre
optionRemove( otherId, $( this ) );
$( this ).find( '.other' ).val( 'other' );
}
});
 
$( '#form-supp input[type=radio]' ).change( function () {
var otherId = PREFIX + $( this ).attr( 'name' );
 
if( 'other' === $( this ).val() ) {
// Insertion du champ "Autre" après les boutons
optionAdd( otherId, $( this ).parent( 'label' ), 'radio' );
} else {
// Suppression du champ autre
optionRemove( otherId, $( this ) );
$( this ).closest( 'div.control-group.radio' ).find( '.other' ).val( 'other' );
}
});
 
$( '#form-supp .list-checkbox .other, #form-supp .checkbox .other' ).click( function () {
var otherId = PREFIX + $( this ).attr( 'name' ),
element = $( this ).attr( 'data-element' );
// console.log(element);
if( $( this ).is( ':checked' ) ) {
// Insertion du champ "Autre" après les boutons
optionAdd( otherId, $( this ).parent( 'label' ), element );
} else {
// Suppression du champ autre
optionRemove( otherId, $( this ) );
$( this ).val( 'other' );
}
});
}
 
function collectOtherOption() {
$( '#form-supp' ).on( 'change', '.collect-other', function () {
var otherIdSuffix = $( this ).attr( 'name' ).replace( 'collect-other-', '' ),
element = $( this ).attr( 'data-element' );
if ( '' === $( this ).val() ){
if ( 'select' === element ) {
$( '#' + otherIdSuffix ).find( '.other' ).prop( 'selected', false );
} else {
$( '#other-' + otherIdSuffix ).prop( 'checked', false );
}
} else {
if ( 'select' === element ) {
$( '#' + otherIdSuffix ).find( '.other' ).val( $( this ).val() );
$( '#' + otherIdSuffix + ' option').not( '.other' ).prop( 'selected', false );
$( '#' + otherIdSuffix ).find( '.other' ).prop( 'selected', true );
} else {
if ( 'radio' === element ) {
$( 'input[name=' + otherIdSuffix + ']' ).not( '#other-' + otherIdSuffix ).prop( 'checked', false );
}
// console.log( otherIdSuffix );
$( '#other-' + otherIdSuffix ).val( $( this ).val() );
$( '#other-' + otherIdSuffix ).prop( 'checked', true );
}
 
}
});
}
 
/***************************
* Lancement des scripts *
***************************/
jQuery( document ).ready( function() {
// var countFiles = 2;
// // Affichage des images ou nom des documents importés
// inputFile( countFiles );
// // Affichage des List-checkbox
inputListCheckbox();
// // Affichage des Range
// inputRangeDisplayNumber()
// // Modale "aide"
// previewFieldHelpModal();
// // Ajout/suppression d'un champ texte "Autre"
// if( $( '.option-other-value' , thisFieldset ).is( ':checked' ) ) {
onOtherOption();
collectOtherOption();
// }
});
/trunk/widget/modules/saisie2/squelettes/js/WidgetSaisie.js
2,37 → 2,37
* Constructeur WidgetSaisie par défaut
*/
function WidgetSaisie() {
this.langue = 'fr';
this.obsNbre = 0;
this.nbObsEnCours = 1;
this.totalObsATransmettre = 0;
this.nbObsTransmises = 0;
this.debug = null;
this.html5 = null;
this.tagProjet = null;
this.tagImg = null;
this.tagObs = null;
this.separationTagImg = null;
this.separationTagObs = null;
this.obsId = null;
this.serviceSaisieUrl = null;
this.serviceObsUrl = null;
this.nomSciReferentiel = null;
this.especeImposee = false;
this.infosEspeceImposee = null;
this.autocompletionElementsNbre = null;
this.referentielImpose = null;
this.serviceAutocompletionNomSciUrl = null;
this.serviceAutocompletionNomSciUrlTpl = null;
this.obsMaxNbre = null;
this.dureeMessage = null;
this.serviceAnnuaireIdUrl = null;
this.serviceNomCommuneUrl = null;
this.serviceNomCommuneUrlAlt = null;
this.chargementIconeUrl = null;
this.chargementImageIconeUrl = null;
this.calendrierIconeUrl = null;
this.pasDePhotoIconeUrl = null;
this.langue = 'fr';
this.obsNbre = 0;
this.nbObsEnCours = 1;
this.totalObsATransmettre = 0;
this.nbObsTransmises = 0;
this.debug = null;
this.html5 = null;
this.tagProjet = null;
this.tagImg = null;
this.tagObs = null;
this.separationTagImg = null;
this.separationTagObs = null;
this.obsId = null;
this.serviceSaisieUrl = null;
this.serviceObsUrl = null;
this.nomSciReferentiel = null;
this.especeImposee = false;
this.infosEspeceImposee = null;
this.autocompletionElementsNbre = null;
this.referentielImpose = null;
this.serviceAutocompletionNomSciUrl = null;
this.serviceAutocompletionNomSciUrlTpl = null;
this.obsMaxNbre = null;
this.dureeMessage = null;
this.serviceAnnuaireIdUrl = null;
this.serviceNomCommuneUrl = null;
this.serviceNomCommuneUrlAlt = null;
this.chargementIconeUrl = null;
this.chargementImageIconeUrl = null;
this.calendrierIconeUrl = null;
this.pasDePhotoIconeUrl = null;
}
 
/**
39,9 → 39,11
* Initialisation du widget
*/
WidgetSaisie.prototype.init = function() {
this.initForm();
this.initEvts();
this.requeterIdentite();
this.initForm();
this.initEvts();
if ( '' === $( '#nom-complet').val() && '' !== $( '#courriel' ).val() ) {
this.requeterIdentite();
}
};
 
/**
48,39 → 50,39
* Initialise le formulaire, les validateurs, les listes de complétion...
*/
WidgetSaisie.prototype.initForm = function() {
if (this.obsId != '') {
//this.chargerInfoObs();
}
if ( '' !== this.obsId ) {
this.chargerInfoObs();
}
 
this.configurerDatePicker('#date');
this.ajouterAutocompletionNoms();
//this.configurerFormValidator();
//this.definirReglesFormValidator();
this.configurerDatePicker( '.date' );
this.ajouterAutocompletionNoms();
this.configurerFormValidator();
this.definirReglesFormValidator();
 
if(this.especeImposee) {
$("#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 nomRetenuComplet = this.infosEspeceImposee["nom_retenu_complet"],
debutAnneRefBiblio = nomRetenuComplet.indexOf(" [");
if (debutAnneRefBiblio != -1) {
nomRetenuComplet = nomRetenuComplet.substr(0, debutAnneRefBiblio);
}
// fin bricolage cracra
var infosAssociee = {
label : this.infosEspeceImposee.nom_sci_complet,
value : this.infosEspeceImposee.nom_sci_complet,
nt : this.infosEspeceImposee.num_taxonomique,
nomSel : this.infosEspeceImposee.nom_sci,
nomSelComplet : this.infosEspeceImposee.nom_sci_complet,
numNomSel : this.infosEspeceImposee.id,
nomRet : nomRetenuComplet,
numNomRet : this.infosEspeceImposee["nom_retenu.id"],
famille : this.infosEspeceImposee.famille,
retenu : (this.infosEspeceImposee.retenu == 'false') ? false : true
};
$("#taxon").data(infosAssociee);
}
if( this.especeImposee ) {
$( '#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 nomRetenuComplet = this.infosEspeceImposee['nom_retenu_complet'],
debutAnneRefBiblio = nomRetenuComplet.indexOf( ' [' );
if ( -1 !== debutAnneRefBiblio ) {
nomRetenuComplet = nomRetenuComplet.substr( 0, debutAnneRefBiblio );
}
// fin bricolage cracra
var infosAssociee = {
label : this.infosEspeceImposee.nom_sci_complet,
value : this.infosEspeceImposee.nom_sci_complet,
nt : this.infosEspeceImposee.num_taxonomique,
nomSel : this.infosEspeceImposee.nom_sci,
nomSelComplet : this.infosEspeceImposee.nom_sci_complet,
numNomSel : this.infosEspeceImposee.id,
nomRet : nomRetenuComplet,
numNomRet : this.infosEspeceImposee['nom_retenu.id'],
famille : this.infosEspeceImposee.famille,
retenu : ( 'false' === this.infosEspeceImposee.retenu ) ? false : true
};
$( '#taxon' ).data( infosAssociee );
}
};
 
/**
87,111 → 89,128
* Initialise les écouteurs d'événements
*/
WidgetSaisie.prototype.initEvts = function() {
var lthis = this;
$('body').on('click', '.effacer-miniature', function() {
$(this).parent().remove();
});
$("#fichier").bind('change', function (e) {
arreter(e);
var options = {
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
};
$("#miniature").append('<img id="miniature-chargement" class="miniature" alt="chargement" src="'+this.chargementImageIconeUrl+'"/>');
$("#ajouter-obs").attr('disabled', 'disabled');
if(lthis.verifierFormat($("#fichier").val())) {
$("#form-upload").ajaxSubmit(options);
} else {
$('#form-upload')[0].reset();
window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+ $("#fichier").attr("accept"));
}
return false;
});
// identité
$("#courriel").on('blur', this.requeterIdentite.bind(this));
$("#courriel").on('keypress', this.testerLancementRequeteIdentite.bind(this));
$(".alert .close").on('click', this.fermerPanneauAlert);
$(".has-tooltip").tooltip('enable');
$("#btn-aide").on('click', this.basculerAffichageAide);
$("#prenom").on("change", this.formaterPrenom.bind(this));
$("#nom").on("change", this.formaterNom.bind(this));
var lthis = this;
 
$("#courriel_confirmation").on('paste', this.bloquerCopierCollerCourriel.bind(this));
/*$("#ajouter-obs").on('click', this.ajouterObs.bind(this));
$(".obs-nbre").on('changement', this.surChangementNbreObs.bind(this));
$("body").on('click', ".supprimer-obs", function() {
var that = this,
suppObs = lthis.supprimerObs.bind(lthis);
// bricolage pour avoir les deux contextes en même temps (objet et elt. du DOM)
suppObs(that);
});
$("#transmettre-obs").on('click', this.transmettreObs.bind(this));
$("#referentiel").on('change', this.surChangementReferentiel.bind(this));
// console.log($( '#taxon' ).data('label') );
 
$("body").on('click', ".defilement-miniatures-gauche", function(event) {
event.preventDefault();
lthis.defilerMiniatures($(this));
});
$("body").on('click', ".defilement-miniatures-droite", function(event) {
event.preventDefault();
lthis.defilerMiniatures($(this));
});
*/
// fermeture fenêtre
if (this.debug == false) {
$(window).on('beforeunload', function(event) {
return 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.';
});
}
$( 'body' ).on( 'click', '.effacer-miniature', function() {
$( this ).parent().remove();
});
 
$( '#bouton-anonyme' ).on( 'click', function() {
$( this ).css({
'background-color': 'rgba(0, 159, 184, 0.7)',
'color': '#fff'
});
$( '#anonyme' ).removeClass( 'hidden' );
$( '#courriel' ).focus();
});
 
$( '#fichier' ).bind( 'change', function ( e ) {
arreter( e );
var options = {
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
};
$( '#miniature' ).append( '<img id="miniature-chargement" class="miniature" alt="chargement" src="' + this.chargementImageIconeUrl + '">' );
$( '#ajouter-obs' ).attr( 'disabled', 'disabled' );
if( lthis.verifierFormat( $( '#fichier' ).val() ) ) {
$( '#form-upload' ).ajaxSubmit( options );
} else {
$( '#form-upload' )[0].reset();
window.alert( 'Le format de fichier n\'est pas supporté, les formats acceptés sont ' + $( '#fichier' ).attr( 'accept' ) );
}
return false;
});
 
// identité
if ( '' === $( '#nom-complet').val() ) {
$( '#courriel' ).on( 'blur', this.requeterIdentite.bind( this ) );
$( '#courriel' ).on( 'keypress', this.testerLancementRequeteIdentite.bind( this ) );
}
$( '.alert .close' ).on( 'click', this.fermerPanneauAlert );
$( '.has-tooltip' ).tooltip( 'enable' );
$( '#btn-aide' ).on( 'click', this.basculerAffichageAide);
$( '#prenom' ).on( 'change', this.formaterPrenom );
$( '#nom' ).on( 'change', this.formaterNom );
 
$( '#courriel_confirmation' ).on( 'paste', this.bloquerCopierCollerCourriel.bind( this ) );
$( '#ajouter-obs' ).on( 'click', this.ajouterObs.bind( this ) );
$( '.obs-nbre' ).on( 'changement', this.surChangementNbreObs.bind( this ) );
$( 'body' ).on( 'click', '.supprimer-obs', function() {
var that = this,
suppObs = lthis.supprimerObs.bind( lthis );
// bricolage pour avoir les deux contextes en même temps (objet et elt. du DOM)
suppObs( that );
});
 
$( '#transmettre-obs' ).on( 'click', this.transmettreObs.bind( this ) );
$( '#referentiel' ).on( 'change', this.surChangementReferentiel.bind( this ) );
 
$( 'body' ).on( 'click', '.defilement-miniatures-gauche', function( event ) {
event.preventDefault();
lthis.defilerMiniatures( $( this ) );
});
$( 'body' ).on( 'click', '.defilement-miniatures-droite', function( event ) {
event.preventDefault();
lthis.defilerMiniatures( $( this ) );
});
 
// fermeture fenêtre
if ( !this.debug ) {
$( window ).on( 'beforeunload', function( event ) {
return 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.';
});
}
 
};
 
/**
* Retourne true si l'extension de l'image "nom" est .jpg ou .jpeg
* Retourne true si l'extension de l'image 'nom' est .jpg ou .jpeg
*/
WidgetSaisie.prototype.verifierFormat = function(nom) {
var parts = nom.split('.');
extension = parts[parts.length - 1];
return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
WidgetSaisie.prototype.verifierFormat = function( nom ) {
var parts = nom.split( '.' );
extension = parts[ parts.length - 1 ];
return ( 'jpeg' === extension.toLowerCase() || 'jpg' === extension.toLowerCase() );
};
 
/**
* Affiche la miniature d'une image temporaire (formulaire) qu'on a ajoutée à l'obs
*/
WidgetSaisie.prototype.afficherMiniature = function(reponse) {
if (this.debug) {
var debogage = $("debogage", reponse).text();
//console.log("Débogage upload : "+debogage);
}
var message = $("message", reponse).text();
if (message != '') {
$("#miniature-msg").append(message);
} else {
$("#miniatures").append(this.creerWidgetMiniature(reponse));
}
$('#ajouter-obs').removeAttr('disabled');
WidgetSaisie.prototype.afficherMiniature = function( reponse ) {
if ( this.debug ) {
var debogage = $( 'debogage', reponse ).text();
//console.log( 'Débogage upload : '+debogage);
}
var message = $( 'message', reponse ).text();
if ( '' !== message ) {
$( '#miniature-msg' ).append( message );
} else {
$( '#miniatures' ).append( this.creerWidgetMiniature( reponse ) );
}
$( '#ajouter-obs' ).removeAttr( 'disabled' );
};
 
/**
* Crée la miniature d'une image temporaire (formulaire), avec le bouton pour l'effacer
*/
WidgetSaisie.prototype.creerWidgetMiniature = function(reponse) {
var miniatureUrl = $("miniature-url", reponse).text();
var imgNom = $("image-nom", reponse).text();
var html =
'<div class="miniature">'+
'<img class="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
'<button class="effacer-miniature" type="button">Effacer</button>'+
'</div>'
return html;
WidgetSaisie.prototype.creerWidgetMiniature = function( reponse ) {
var miniatureUrl = $( 'miniature-url', reponse ).text();
var imgNom = $( 'image-nom', reponse ).text();
var html =
'<div class="miniature mb-3 mr-3">'+
'<img class="miniature-img" class="miniature img-rounded" alt="' + imgNom + '" src="' + miniatureUrl + '">'+
'<a class="effacer-miniature"><i class="far fa-trash-alt"></i></a>'+
'</div>'
return html;
};
 
/**
* Efface une miniature (formulaire)
*/
WidgetSaisie.prototype.supprimerMiniature = function(miniature) {
miniature.parents('.miniature').remove();
WidgetSaisie.prototype.supprimerMiniature = function( miniature ) {
miniature.parents( '.miniature' ).remove();
};
 
/**
198,197 → 217,960
* Efface toutes les miniatures (formulaire)
*/
WidgetSaisie.prototype.supprimerMiniatures = function() {
$("#miniatures").empty();
$("#miniature-msg").empty();
$( '#miniatures' ).empty();
$( '#miniature-msg' ).empty();
};
 
/* Observateur */
WidgetSaisie.prototype.testerLancementRequeteIdentite = function(event) {
if (event.which == 13) {
this.requeterIdentite();
this.event.preventDefault();
this.event.stopPropagation();
}
WidgetSaisie.prototype.testerLancementRequeteIdentite = function( event ) {
if ( 13 == event.which ) {
this.requeterIdentite();
event.preventDefault();
event.stopPropagation();
}
};
 
WidgetSaisie.prototype.requeterIdentite = function() {
var lthis = this;
var courriel = $("#courriel").val();
var urlAnnuaire = this.serviceAnnuaireIdUrl + courriel;
if (courriel != '') {
$.ajax({
url : urlAnnuaire,
type : "GET",
success : function(data, textStatus, jqXHR) {
if (lthis.debug) {
console.log('SUCCESS: '+textStatus);
}
if (data != undefined && data[courriel] != undefined) {
var infos = data[courriel];
lthis.surSuccesCompletionCourriel(infos, courriel);
} else {
lthis.surErreurCompletionCourriel();
}
},
error : function(jqXHR, textStatus, errorThrown) {
if (lthis.debug) {
console.log('ERREUR: '+textStatus);
}
lthis.surErreurCompletionCourriel();
},
complete : function(jqXHR, textStatus) {
if (lthis.debug) {
console.log('COMPLETE: '+textStatus);
}
// @TODO harmoniser class="hidden" VS style="display:none;"
$("#zone-prenom-nom").removeClass("hidden").show();
$("#zone-courriel-confirmation").removeClass("hidden").show();
}
});
}
var lthis = this;
var courriel = $( '#courriel' ).val();
var urlAnnuaire = this.serviceAnnuaireIdUrl + courriel;
// console.log(urlAnnuaire);
if ( '' !== courriel ) {
$.ajax({
url : urlAnnuaire,
type : 'GET',
success : function( data, textStatus, jqXHR ) {
if ( lthis.debug ) {
console.log( 'SUCCESS: ' + textStatus );
}
if ( undefined != data && undefined != data[courriel] ) {
var infos = data[courriel];
lthis.surSuccesCompletionCourriel( infos, courriel );
} else {
lthis.surErreurCompletionCourriel();
}
},
error : function( jqXHR, textStatus, errorThrown ) {
if ( lthis.debug ) {
console.log( 'ERREUR: '+ textStatus );
}
lthis.surErreurCompletionCourriel();
},
complete : function( jqXHR, textStatus ) {
if ( lthis.debug ) {
console.log( 'COMPLETE: '+ textStatus );
}
}
});
}
};
 
WidgetSaisie.prototype.surSuccesCompletionCourriel = function(infos, courriel) {
$("#id_utilisateur").val(infos.id);
$("#prenom").val(infos.prenom);
$("#nom").val(infos.nom);
$("#courriel_confirmation").val(courriel);
$("#prenom, #nom, #courriel_confirmation").attr('disabled', 'disabled');
this.focusChampFormulaire();
this.masquerPanneau("#dialogue-courriel-introuvable");
WidgetSaisie.prototype.surSuccesCompletionCourriel = function( infos, courriel ) {
$( '#zone-courriel' ).before( '<p class="warning"><i class="fas fa-exclamation-triangle"></i> Un compte existe pour ce courriel, connectez-vous pour saisir votre observation</p>' );
$( '#creation-compte, #zone-prenom-nom, #zone-courriel-confirmation' ).addClass( 'hidden' );
$( '#bouton-connexion a' ).css( 'box-shadow', '0 0 1.5px 1px red' );
// // Traité par auth.js :
// $( '#id_utilisateur' ).val(infos.id);
// // console.log(infos);
// $( '#prenom' ).val(infos.prenom);
// $( '#nom' ).val(infos.nom);
// $( '#courriel_confirmation' ).val(courriel);
// $( '#prenom, #nom, #courriel_confirmation' ).attr( 'disabled', 'disabled' );
// this.focusChampFormulaire();
// // todo function masquerPanneau
// this.masquerPanneau( '#dialogue-courriel-introuvable' );
};
 
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
$("#prenom, #nom, #courriel_confirmation").val('');
$("#prenom, #nom, #courriel_confirmation").removeAttr('disabled');
this.afficherPanneau("#dialogue-courriel-introuvable");
$( '#creation-compte, #zone-prenom-nom, #zone-courriel-confirmation' ).removeClass( 'hidden' );
$( '.warning' ).remove();
$( '#bouton-connexion a' ).css( 'box-shadow', '' );
 
$( '#prenom, #nom, #courriel_confirmation' ).val( '' );
$( '#prenom, #nom, #courriel_confirmation' ).removeAttr( 'disabled' );
// // Traité par auth.js :
// // todo function afficherPanneau
// this.afficherPanneau( '#dialogue-courriel-introuvable' );
};
 
WidgetSaisie.prototype.fermerPanneauAlert = function() {
$( this ).parentsUntil( '.zone-alerte', '.alert' ).addClass( 'hidden' );
};
 
WidgetSaisie.prototype.formaterNom = function() {
$(this).val($(this).val().toUpperCase());
$( this ).val( $( this ).val().toUpperCase() );
};
 
WidgetSaisie.prototype.formaterPrenom = function() {
var prenom = new Array();
var mots = $(this).val().split(' ');
for (var i = 0; i < mots.length; i++) {
var mot = mots[i];
if (mot.indexOf('-') >= 0) {
var prenomCompose = new Array();
var motsComposes = mot.split('-');
for (var j = 0; j < motsComposes.length; j++) {
var motSimple = motsComposes[j];
var 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);
prenom.push(motMajuscule);
}
}
$(this).val(prenom.join(' '));
var prenom = new Array(),
mots = $( this ).val().split( ' ' ),
motsLength = mots.length;
 
 
for ( var i = 0; i < motsLength; i++ ) {
var mot = mots[i];
 
if ( 0 <= mot.indexOf( '-' ) ) {
var 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);
 
prenomCompose.push( motMajuscule );
}
prenom.push( prenomCompose.join( '-' ) );
} else {
var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
 
prenom.push( motMajuscule );
}
}
$( this ).val( prenom.join( ' ' ) );
};
 
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() {
this.afficherPanneau("#dialogue-bloquer-copier-coller");
return false;
this.afficherPanneau( '#dialogue-bloquer-copier-coller' );
return false;
};
 
WidgetSaisie.prototype.focusChampFormulaire = function() {
$("#date").focus();
/**
* Ajoute une observation saisie dans le formulaire à la liste des observations à transmettre
*/
WidgetSaisie.prototype.ajouterObs = function() {
// Fermeture automatique des dialogue de transmission de données
// @WARNING TEST
$( '#dialogue-obs-transaction-ko' ).addClass( 'hidden' );
$( '#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
 
if ( this.validerFormulaire() ) {
this.masquerPanneau( '#dialogue-form-invalide' );
this.obsNbre = this.obsNbre + 1;
$( '.obs-nbre' ).text( this.obsNbre );
$( '.obs-nbre' ).triggerHandler( 'changement' );
this.afficherObs();
this.stockerObsData();
this.supprimerMiniatures();
if( !this.especeImposee ) {
$( '#taxon' ).val( '' );
$( '#taxon' ).data( 'numNomSel', undefined );
}
$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre );
$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' observations transmises' );
} else {
this.afficherPanneau( '#dialogue-form-invalide' );
}
};
 
/**
* Affiche une observation dans la liste des observations à transmettre
*/
WidgetSaisie.prototype.afficherObs = function() {
 
// var commune = $( '#commune-nom' ).text();
// commune = ( '' !== commune.trim() ) ? commune : $( '#carte-recherche' ).val();
 
// var code_insee = $('#commune-code-insee').text();
// code_insee = ( '' !== code_insee.trim() ) ? '(' + code_insee + ')' : '';
 
// if ( this.debug ) {
// console.log( commune + ' - ' + code_insee );
// }
 
$( '#liste-obs' ).prepend(
'<div id="obs' + this.obsNbre + '" class="obs obs' + this.obsNbre + ' mb-2">'+
 
'<div '+
'class="obs-action droite" '+
'title="Supprimer cette observation de la liste à transmettre"'+
'>'+
'<button class="btn btn-danger supprimer-obs" value="'+ this.obsNbre + '" title="Observation n°' + this.obsNbre + '">'+
'<i class="far fa-trash-alt"></i>'+
'</button>'+
'</div> '+
 
'<div class="row">'+
'<div class="thumbnail col-md-2">'+
this.ajouterImgMiniatureAuTransfert()+
'</div>'+
'<div class="col-md-9">'+
'<ul class="unstyled">'+
'<li>'+
'<span class="nom-sci">' + $( '#taxon' ).val() + '</span> '+
this.ajouterNumNomSel() + '<span class="referentiel-obs">'+
( ( undefined == $('#taxon').data( 'numNomSel' ) ) ? '' : '[' + this.nomSciReferentiel + ']' ) + '</span>'+
// ' observé à '+
// '<span class="commune">' + commune + '</span> '+
// code_insee + ' [' + $( '#latitude' ).val() + ' / ' + $( '#longitude' ).val() + ']'+
// ' le '+
// '<span class="date">' + $( '#date' ).val() + '</span>'+
'</li>'+
'<li>'+
// '<span>Lieu-dit :</span> ' + $( '#lieudit' ).val() + ' '+
// '<span>Station :</span> ' + $( '#station' ).val() + ' '+
'<span>Milieu :</span> '+ $ ( '#milieu' ).val() + ' '+
'</li>'+
// '<li>'+
// 'Commentaires : <span class="discretion">' + $( '#notes' ).val() + '</span>'+
// '</li>'+
'</ul>'+
'</div>'+
'</div>'+
 
'</div>'
);
 
$( '#zone-liste-obs' ).removeClass( 'hidden' );
};
 
WidgetSaisie.prototype.stockerObsData = function() {
var lthis = this;
 
// var commune = $( '#commune-nom' ).text();
// commune = ( '' === commune.trim() ) ? commune : $( '#carte-recherche' ).val();
 
$( '#liste-obs' ).data( 'obsId' + this.obsNbre, {
'date' : $( '#date' ).val(),
// 'notes' : $( '#notes' ).val().trim(),
'nom_sel' : $( '#taxon' ).val(),
'num_nom_sel' : $( '#taxon' ).data( 'numNomSel' ),
'nom_ret' : $( '#taxon' ).data( 'nomRet' ),
'num_nom_ret' : $( '#taxon' ).data( 'numNomRet' ),
'num_taxon' : $( '#taxon' ).data( 'nt' ),
'famille' : $( '#taxon' ).data( 'famille' ),
'referentiel' : ( ( undefined === $( '#taxon' ).data( 'numNomSel' ) ) ? '' : lthis.nomSciReferentiel ),
// 'latitude' : $( '#latitude' ).val(),
// 'longitude' : $( '#longitude' ).val(),
// 'commune_nom' : commune,
// 'commune_code_insee' : $( '#commune-code-insee' ).text(),
// 'lieudit' : $( '#lieudit' ).val(),
// 'station' : $( '#station' ).val(),
'milieu' : $( '#milieu' ).val(),
 
//Ajout des champs images
'image_nom' : lthis.getNomsImgsOriginales(),
'image_b64' : lthis.getB64ImgsOriginales(),
 
// Ajout des champs étendus de l'obs
'obs_etendue': lthis.getObsChpEtendus()
});
};
 
/**
* Retourne un Array contenant les valeurs des champs étendus
*/
WidgetSaisie.prototype.getObsChpEtendus = function() {
var champs = [],
$thisForm = $( '#form-supp' ),
elements =
'input[type=text]:not(.collect-other),'+
'input[type=checkbox]:checked,'+
'input[type=radio]:checked,'+
'input[type=email],'+
'input[type=number],'+
'input[type=range]'+
'input[type=date],'+
'textarea,'+
'select';
 
$( elements, $thisForm ).each( function() {
var valeur = $( this ).val(),
cle = $( this ).attr( 'name' ),
label = $( this ).data( 'label' );
if ( '' !== valeur ) {
var chpEtendu = {
cle: cle,
label: label,
valeur: valeur
};
champs.push( chpEtendu );
}
});
return champs;
};
 
WidgetSaisie.prototype.surChangementReferentiel = function() {
this.nomSciReferentiel = $( '#referentiel' ).val();
$( '#taxon' ).val( '' );
this.initialiserAutocompleteCommune();
this.initialiserGoogleMap( false );
};
 
WidgetSaisie.prototype.surChangementNbreObs = function() {
if ( 0 === this.obsNbre ) {
$( '#transmettre-obs' ).attr( 'disabled', 'disabled' );
$( '#ajouter-obs' ).removeAttr( 'disabled' );
} else if ( 0 < this.obsNbre && this.obsNbre < this.obsMaxNbre ) {
$( '#transmettre-obs' ).removeAttr( 'disabled' );
$( '#ajouter-obs' ).removeAttr( 'disabled' );
} else if ( this.obsNbre >= this.obsMaxNbre ) {
$( '#ajouter-obs' ).attr( 'disabled', 'disabled' );
this.afficherPanneau( '#dialogue-bloquer-creer-obs' );
}
};
 
WidgetSaisie.prototype.transmettreObs = function() {
var observations = $( '#liste-obs' ).data();
if ( this.debug ) {
console.log( observations );
}
if ( undefined == observations || jQuery.isEmptyObject( observations ) ) {
this.afficherPanneau( '#dialogue-zero-obs' );
} else {
this.nbObsEnCours = 1;
this.nbObsTransmises = 0;
this.totalObsATransmettre = $.map( observations, function( n, i ) {
return i;
}).length;
this.depilerObsPourEnvoi();
}
return false;
};
 
WidgetSaisie.prototype.depilerObsPourEnvoi = function() {
var 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 = {
'projet' : this.tagProjet,
'tag-obs' : this.tagObs,
'tag-img' : this.tagImg
};
var 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', '' );
if( '' !== idObsNumerique ) {
this.envoyerObsAuCel( idObsNumerique, obsATransmettre );
}
break;
}
};
 
WidgetSaisie.prototype.envoyerObsAuCel = function( idObs, observation ) {
var lthis = this;
var erreurMsg = '';
$.ajax({
url : lthis.serviceSaisieUrl,
type : 'POST',
data : observation,
dataType : 'json',
beforeSend : function() {
$( '#dialogue-obs-transaction-ko' ).addClass( 'hidden' );
$( '#dialogue-obs-transaction-ok' ).addClass( 'hidden' );
$( '.alert-txt' ).empty();
$( '.alert-txt .msg-erreur' ).remove();
$( '.alert-txt .msg-debug' ).remove();
$( '#chargement' ).removeClass( 'hidden' );
},
success : function( data, textStatus, jqXHR ) {
// mise à jour du nombre d'obs à transmettre
// et suppression de l'obs
lthis.supprimerObsParId( idObs );
lthis.nbObsEnCours++;
// mise à jour du statut
lthis.mettreAJourProgression();
if( 0 < lthis.obsNbre ) {
// dépilement de la suivante
lthis.depilerObsPourEnvoi();
}
},
statusCode : {
500 : function( jqXHR, textStatus, errorThrown ) {
erreurMsg += 'Erreur 500 :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
}
},
error : function( jqXHR, textStatus, errorThrown ) {
erreurMsg += 'Erreur Ajax :\ntype : ' + textStatus + ' ' + errorThrown + '\n';
try {
reponse = jQuery.parseJSON( jqXHR.responseText );
if ( null !== reponse ) {
$.each( reponse, function( cle, valeur ) {
erreurMsg += valeur + '\n';
});
}
} catch( e ) {
erreurMsg += 'Erreur inconnue: ' + jqXHR.responseText;
}
},
complete : function( jqXHR, textStatus ) {
var debugMsg = extraireEnteteDebug( jqXHR );
 
if ( '' !== erreurMsg ) {
if ( this.debug ) {
$( '#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?'+
'subject=Dysfonctionnement du widget de saisie ' + this.tagProjet+
'&body=' + erreurMsg + '%0D%0ADébogage :%0D%0A' + debugMsg;
 
// mise en valeur de l'obs en erreur + scroll vers celle ci en changeant le hash
$( '#obs' + idObs + ' div div' ).addClass( 'obs-erreur' );
window.location.hash = 'obs' + idObs;
 
$( '#dialogue-obs-transaction-ko .alert-txt' ).append( $( '#tpl-transmission-ko' ).clone()
.find( '.courriel-erreur' )
.attr( 'href', hrefCourriel )
.end()
.html()
);
$( '#dialogue-obs-transaction-ko' ).removeClass( 'hidden' );
$( '#chargement' ).addClass( 'hidden' );
lthis.initialiserBarreProgression();
} else {
if ( lthis.debug ) {
$( '#dialogue-obs-transaction-ok .alert-txt' ).append( '<pre class="msg-debug">Débogage : ' + debugMsg + '</pre>' );
}
if( 0 === lthis.obsNbre ) {
setTimeout( function() {
$( '#chargement' ).addClass( 'hidden' );
$( '#dialogue-obs-transaction-ok .alert-txt' ).append( $( '#tpl-transmission-ok' ).clone().html());
$( '#dialogue-obs-transaction-ok' ).removeClass( 'hidden' );
window.location.hash = 'dialogue-obs-transaction-ok';
lthis.initialiserObs();
}, 1500 );
 
}
}
}
});
};
 
WidgetSaisie.prototype.mettreAJourProgression = function() {
this.nbObsTransmises++;
var pct = ( this.nbObsTransmises / this.totalObsATransmettre ) * 100;
$( '#barre-progression-upload' ).attr( 'aria-valuenow', this.nbObsTransmises );
$( '#barre-progression-upload' ).attr( 'style', 'width: ' + pct + '%' );
$( '#barre-progression-upload .sr-only' ).text( this.nbObsTransmises + '/' + this.totalObsATransmettre + ' observations transmises' );
 
if( 0 === this.obsNbre ) {
$( '.progress' ).removeClass( 'active' );
$( '.progress' ).removeClass( 'progress-striped' );
}
};
 
WidgetSaisie.prototype.validerFormulaire = function() {
observateur = $( '#form-observateur' ).valid();
// station = $( '#form-station' ).valid();
obs = ( '' !== $( '#nom-complet' ).text() || ( $( '#form-observation' ).valid() && !$( '#anonyme' ).hasClass( 'hidden' ) ) ) ? true : false;
( obs ) ? this.masquerPanneau( '#dialogue-utilisateur-non-identifie' ) : this.afficherPanneau( '#dialogue-utilisateur-non-identifie' );
 
return ( observateur /*&& station */&& obs ) ? true : false;
};
 
WidgetSaisie.prototype.getNomsImgsOriginales = function() {
var noms = new Array();
$( '.miniature-img' ).each( function() {
noms.push( $( this ).attr( 'alt' ) );
});
return noms;
};
 
WidgetSaisie.prototype.getB64ImgsOriginales = function() {
var b64 = new Array();
$( '.miniature-img' ).each( function() {
if ( $( this ).hasClass( 'b64' ) ) {
b64.push( $( this ).attr( 'src' ) );
} else if ( $( this ).hasClass( 'b64-canvas' ) ) {
b64.push( $( this ).data( 'b64' ) );
}
});
return b64;
};
 
WidgetSaisie.prototype.supprimerObs = function( selector ) {
var obsId = $( selector ).val();
// Problème avec IE 6 et 7
if ( 'Supprimer' === obsId ) {
obsId = $( selector ).attr( 'title' );
}
this.supprimerObsParId( obsId );
};
 
WidgetSaisie.prototype.supprimerObsParId = function( obsId ) {
this.obsNbre = this.obsNbre - 1;
$( '.obs-nbre' ).text( this.obsNbre );
$( '.obs-nbre' ).triggerHandler( 'changement' );
$( '.obs' + obsId ).remove();
$( '#liste-obs' ).removeData( 'obsId' + obsId );
};
 
WidgetSaisie.prototype.initialiserBarreProgression = function() {
$( '#barre-progression-upload' ).attr( 'aria-valuenow', 0 );
$( '#barre-progression-upload' ).attr( 'style', 'width: 0%' );
$( '#barre-progression-upload .sr-only' ).text( '0/0 observations transmises' );
$( '.progress' ).addClass( 'active' );
$( '.progress' ).addClass( 'progress-striped' );
};
 
WidgetSaisie.prototype.initialiserObs = function() {
this.obsNbre = 0;
this.nbObsTransmises = 0;
this.nbObsEnCours = 0;
this.totalObsATransmettre = 0;
this.initialiserBarreProgression();
$( '.obs-nbre' ).text( this.obsNbre );
$( '.obs-nbre' ).triggerHandler( 'changement' );
$( '#liste-obs' ).removeData();
$( '.obs' ).remove();
$( '#dialogue-bloquer-creer-obs' ).addClass( 'hidden' );
};
 
/**
* Ajoute une boîte de miniatures avec défilement des images,
* pour une obs de la liste des obs à transmettre
*/
WidgetSaisie.prototype.ajouterImgMiniatureAuTransfert = function() {
var html =
'<div class="defilement-miniatures">'+
'<figure class="centre">'+
'<img class="miniature align-middle" alt="Aucune photo" src="' + this.pasDePhotoIconeUrl + '" width="80%" />'+
'</figure>'+
'</div>',
miniatures = '',
premiere = true,
centre = '';
defilVisible = '';
 
if ( 0 < $( '#miniatures img' ).length ) {
$( '#miniatures img' ).each( function() {
var imgVisible = ( premiere ) ? 'miniature-selectionnee' : 'miniature-cachee';
premiere = false;
 
var 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%" />';
// miniature = '<div class="' + css + ' ' + imgVisible + '" alt="' + alt + '" style="background-image: url(' + src + ')" ></div>';
 
miniatures += miniature;
});
 
 
if ( 1 === $( '#miniatures img' ).length ) {
centre = 'centre';
defilVisible = ' defilement-miniatures-cache';
}
 
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 + '">'+
miniatures+
'</figure>'+
'<a href="#" class="defilement-miniatures-droite ml-1' + defilVisible + '"><i class="fas fa-chevron-circle-right"></i></a>'+
'</div>';
}
return html;
};
 
WidgetSaisie.prototype.defilerMiniatures = function( element ) {
 
 
var miniatureSelectionne = element.siblings( 'figure' ).find( 'img.miniature-selectionnee' );
miniatureSelectionne.removeClass( 'miniature-selectionnee' );
miniatureSelectionne.addClass( 'miniature-cachee' );
 
var miniatureAffichee = miniatureSelectionne;
 
if( element.hasClass( 'defilement-miniatures-gauche' ) ) {
if( 0 !== miniatureSelectionne.prev( '.miniature' ).length ) {
miniatureAffichee = miniatureSelectionne.prev( '.miniature' );
} else {
miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).last();
}
} else {
if( 0 !== miniatureSelectionne.next('.miniature').length ) {
miniatureAffichee = miniatureSelectionne.next( '.miniature' );
} else {
miniatureAffichee = miniatureSelectionne.siblings( '.miniature' ).first();
}
}
miniatureAffichee.addClass( 'miniature-selectionnee' );
miniatureAffichee.removeClass( 'miniature-cachee' );
};
 
WidgetSaisie.prototype.ajouterNumNomSel = function() {
var nn = '<span class="nn">[nn' + $( '#taxon' ).data( 'numNomSel' ) + ']</span>';
if ( undefined == $( '#taxon' ).data( 'numNomSel' ) ) {
nn = '<span class="alert-error">[non lié au référentiel]</span>';
}
return nn;
};
 
WidgetSaisie.prototype.ajouterAutocompletionNoms = function() {
var lthis = this;
$( '#taxon' ).autocomplete({
source: function( requete, add ) {
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
requete = '';
if( 'autre' !== $( '#referentiel' ).val() ) {
var url = lthis.getUrlAutocompletionNomsSci();
$.getJSON( url, requete, function( data ) {
var suggestions = lthis.traiterRetourNomsSci( data );
add( suggestions );
});
}
},
html: true
});
 
$( '#taxon' ).bind( 'autocompleteselect', this.surAutocompletionTaxon );
};
 
// WidgetSaisie.prototype.focusChampFormulaire = function() {
// $( '#date_releve' ).focus();
// };
 
WidgetSaisie.prototype.chargerInfoObs = function() {
var urlObs = this.serviceObsUrl + '/' + this.obsId;
var lthis = this;
$.ajax({
url: urlObs,
type: 'GET',
success: function( data, textStatus, jqXHR ) {
if ( undefined != data && '' !== data ) {
lthis.prechargerForm( data );
} else {
lthis.surErreurChargementInfosObs();
}
},
error: function( jqXHR, textStatus, errorThrown ) {
lthis.surErreurChargementInfosObs();
}
});
};
 
// @TODO faire mieux que ça !
WidgetSaisie.prototype.surErreurChargementInfosObs = function() {
alert( 'Erreur lors du chargement de l\'observation' );
};
 
WidgetSaisie.prototype.prechargerForm = function( data ) {
 
$( '#milieu' ).val( data.milieu );
 
// $( '#carte-recherche' ).val( data.zoneGeo );
// $( '#commune-nom' ).text( data.zoneGeo );
 
// if( data.hasOwnProperty( 'codeZoneGeo' ) ) {
// // TODO: trouver un moyen qui fonctionne lorsqu'on aura d'autres référentiels que INSEE
// $( '#commune-code-insee' ).text( data.codeZoneGeo.replace( 'INSEE-C:', '' ) );
// }
 
// if( data.hasOwnProperty( 'latitude' ) && data.hasOwnProperty( 'longitude' ) ) {
// var latLng = new google.maps.LatLng( data.latitude, data.longitude );
// this.mettreAJourMarkerPosition( latLng );
// this.marker.setPosition( latLng );
// this.map.setCenter( latLng );
// this.map.setZoom( 16 );
// }
};
 
WidgetSaisie.prototype.configurerFormValidator = function() {
var lthis = this;
$.validator.addMethod(
'dateCel',
function ( value, element ) {
return ( '' === value || ( /(^(((0[1-9]|1[0-9]|2[0-8])[\/](0[1-9]|1[012]))|((29|30|31)[\/](0[13578]|1[02]))|((29|30)[\/](0[4,6,9]|11)))[\/](19|[2-9][0-9])\d\d$)|(^29[\/]02[\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)/.test( value ) ) );
},
'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.'
);
 
$.validator.addMethod(
'userEmailOk',
function ( value, element ) {
return ( '' !== value );
},
''
);
 
$.extend( $.validator.defaults, {
errorElement: 'span',
 
onfocusout: function( element ){
if ( $( element ).valid() ) {
$( element ).closest( '.control-group' ).removeClass( 'error' );
} else {
$( element ).closest( '.control-group' ).addClass( 'error' );
}
},
onkeyup : function( element ){
if ( $( element ).valid() ) {
$( element ).closest( '.control-group' ).removeClass( 'error' );
} else {
$( element ).closest( '.control-group' ).addClass( 'error' );
}
},
onclick : function( element ){
if ( $( element ).valid() ) {
$( element ).closest( '.control-group' ).removeClass( 'error' );
} else {
$( element ).closest( '.control-group' ).addClass( 'error' );
}
},
 
highlight: function( element ) {
$( element ).closest( '.control-group' ).addClass( 'error' );
},
 
unhighlight: function( element ) {
if ( 'taxon' === $( element ).attr( 'id' ) ) {
if ( '' !== $( '#taxon' ).val() ) {
// Si le taxon n'est pas lié au référentiel, on vide le data associé
if ( $( '#taxon' ).data( 'value' ) != $( '#taxon' ).val() ) {
$( '#taxon' ).data( 'numNomSel', '' );
$( '#taxon' ).data( 'nomRet','' );
$( '#taxon' ).data( 'numNomRet', '' );
$( '#taxon' ).data( 'nt', '' );
$( '#taxon' ).data( 'famille', '' );
}
$( '#taxon-input-groupe' ).removeClass( 'error' );
$( element ).next( 'span.help-inline' ).remove();
}
} else {
$( element ).closest( '.control-group' ).removeClass( 'error' );
$( element ).next( 'span.help-inline' ).remove();
}
}
 
});
};
 
WidgetSaisie.prototype.definirReglesFormValidator = function() {
 
$( '#form-observateur' ).validate({
rules : {
courriel : {
required : true,
email : true,
'userEmailOk' : true
},
courriel_confirmation : {
required : true,
equalTo : '#courriel'
}
}
});
// $( '#form-station' ).validate({
// rules: {
// latitude : {
// range: [-90, 90]
// },
// longitude : {
// range: [-180, 180]
// }
// }
// });
$( '#form-observation' ).validate({
rules : {
date_releve : {
required : true,
'dateCel' : true
},
taxon : 'required'
}
});
};
 
/* calendrier */
WidgetSaisie.prototype.configurerDatePicker = function(selector) {
$.datepicker.setDefaults($.datepicker.regional[this.langue]);
$(selector).datepicker({
dateFormat: "dd/mm/yy",
maxDate: new Date,
onSelect: function(date) {
$(this).valid();
}
});
$(selector + ' + img.ui-datepicker-trigger').appendTo(selector + '-icone.add-on');
WidgetSaisie.prototype.configurerDatePicker = function( selector ) {
$.datepicker.setDefaults( $.datepicker.regional[ this.langue ] );
$( selector ).datepicker({
dateFormat: 'dd/mm/yy',
maxDate: new Date,
onSelect: function( date ) {
$( this ).valid();
}
});
$( selector + ' + img.ui-datepicker-trigger' ).appendTo( selector + '-icone.add-on' );
};
 
/* auto completion nom sci */
WidgetSaisie.prototype.ajouterAutocompletionNoms = function() {
var lthis = this;
$('#taxon').autocomplete({
source: function(requete, add){
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
requete = "";
if($("#referentiel").val() != "autre") {
var url = lthis.getUrlAutocompletionNomsSci();console.log(url);
$.getJSON(url, requete, function(data) {
var suggestions = lthis.traiterRetourNomsSci(data);
add(suggestions);
});
}
},
html: true,
position : {
my : 'top',
at : 'top'
}
});
var lthis = this;
$( '#taxon' ).autocomplete({
source: function( requete, add ) {
// la variable de requête doit être vidée car sinon le parametre 'term' est ajouté
requete = '';
if( 'autre' !== $( '#referentiel' ).val() ) {
var url = lthis.getUrlAutocompletionNomsSci();
// console.log( url );
$.getJSON( url, requete, function( data ) {
var suggestions = lthis.traiterRetourNomsSci( data );
add( suggestions );
});
}
},
html: true,
position : {
my : 'top',
at : 'top'
}
});
 
$("#taxon").bind("autocompleteselect", this.surAutocompletionTaxon);
$( '#taxon' ).bind( 'autocompleteselect', this.surAutocompletionTaxon );
};
 
WidgetSaisie.prototype.surAutocompletionTaxon = function(event, ui) {
$("#taxon").data(ui.item);
if (ui.item.retenu == true) {
$("#taxon").addClass('ns-retenu');
} else {
$("#taxon").removeClass('ns-retenu');
}
WidgetSaisie.prototype.surAutocompletionTaxon = function( event, ui ) {
$( '#taxon' ).data( ui.item );
if ( ui.item.retenu ) {
$( '#taxon' ).addClass( 'ns-retenu' );
} else {
$( '#taxon' ).removeClass( 'ns-retenu' );
}
};
 
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
var mots = $('#taxon').val();
var url = this.serviceAutocompletionNomSciUrlTpl.replace('{referentiel}', this.nomSciReferentiel);
url = url.replace('{masque}', mots);
return url;
var mots = $( '#taxon' ).val();
var url = this.serviceAutocompletionNomSciUrlTpl.replace( '{referentiel}', this.nomSciReferentiel );
url = url.replace( '{masque}', mots );
return url;
};
 
WidgetSaisie.prototype.traiterRetourNomsSci = function(data) {
var suggestions = [];
if (data.resultat != undefined) {
$.each(data.resultat, function(i, val) {
val.nn = i;
var nom = {label : '', value : '', nt : '', nomSel : '', nomSelComplet : '', numNomSel : '',
nomRet : '', numNomRet : '', famille : '', retenu : false
};
if (suggestions.length >= this.autocompletionElementsNbre) {
nom.label = "...";
nom.value = $('#taxon').val();
suggestions.push(nom);
return false;
} else {
nom.label = val.nom_sci_complet;
nom.value = val.nom_sci_complet;
nom.nt = val.num_taxonomique;
nom.nomSel = val.nom_sci;
nom.nomSelComplet = val.nom_sci_complet;
nom.numNomSel = val.nn;
nom.nomRet = val.nom_retenu_complet;
nom.numNomRet = val["nom_retenu.id"];
nom.famille = val.famille;
// Tester dans ce sens, permet de considérer "absent" comme "false" => est-ce opportun ?
// en tout cas c'est harmonisé avec le CeL
nom.retenu = (val.retenu == 'true') ? true : false;
WidgetSaisie.prototype.traiterRetourNomsSci = function( data ) {
var suggestions = [];
if ( undefined != data.resultat ) {
$.each( data.resultat, function( i, val ) {
val.nn = i;
var nom = {
label : '',
value : '',
nt : '',
nomSel : '',
nomSelComplet : '',
numNomSel : '',
nomRet : '',
numNomRet : '',
famille : '',
retenu : false
};
if ( suggestions.length >= this.autocompletionElementsNbre ) {
nom.label = '...';
nom.value = $( '#taxon' ).val();
suggestions.push( nom );
return false;
} else {
nom.label = val.nom_sci_complet;
nom.value = val.nom_sci_complet;
nom.nt = val.num_taxonomique;
nom.nomSel = val.nom_sci;
nom.nomSelComplet = val.nom_sci_complet;
nom.numNomSel = val.nn;
nom.nomRet = val.nom_retenu_complet;
nom.numNomRet = val['nom_retenu.id'];
nom.famille = val.famille;
// Tester dans ce sens, permet de considérer 'absent' comme 'false' => est-ce opportun ?
// en tout cas c'est harmonisé avec le CeL
nom.retenu = ( 'true' == val.retenu ) ? true : false;
 
suggestions.push(nom);
}
});
}
suggestions.push( nom );
}
});
}
 
return suggestions;
return suggestions;
};
 
WidgetSaisie.prototype.afficherPanneau = function(selecteur) {
$(selecteur).fadeIn("slow").delay(this.dureeMessage).fadeOut("slow");
WidgetSaisie.prototype.afficherPanneau = function( selecteur ) {
$( selecteur )
.removeClass( 'hidden')
.hide()
.show( 600 )
.delay( this.dureeMessage )
.hide( 600 );
};
 
WidgetSaisie.prototype.masquerPanneau = function( selecteur ) {
$( selecteur ).addClass( 'hidden' );
};
 
// lib hors objet --
 
/**
* Stope l'évènement courant quand on clique sur un lien.
* Utile pour Chrome, Safari...
*/
function arreter( evenement ) {
if ( evenement.stopPropagation ) {
evenement.stopPropagation();
}
if ( evenement.preventDefault ) {
evenement.preventDefault();
}
return false;
}
 
/**
* Extrait les données de désinsectisation d'une requête AJAX de jQuery
* @param jqXHR
* @returns {String}
*/
function extraireEnteteDebug( jqXHR ) {
var msgDebug = '';
if ( '' !== jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) ) {
var debugInfos = jQuery.parseJSON( jqXHR.getResponseHeader( 'X-DebugJrest-Data' ) );
if ( null !== debugInfos ) {
$.each( debugInfos, function( cle, valeur ) {
msgDebug += valeur + '\n';
});
}
}
return msgDebug;
}
 
/*
* jQuery UI Autocomplete HTML Extension
*
* Copyright 2010, Scott González (http://scottgonzalez.com)
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* http://github.com/scottgonzalez/jquery-ui-extensions
*
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
*/
( function( $ ) {
var proto = $.ui.autocomplete.prototype,
initSource = proto._initSource;
 
WidgetSaisie.prototype.filter = function( array, term ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), 'i' );
return $.grep( array, function( value ) {
return matcher.test( $( '<div>' ).html( value.label || value.value || value ).text() );
});
}
 
$.extend( proto, {
_initSource: function() {
if ( this.options.html && $.isArray( this.options.source ) ) {
this.source = function( request, response ) {
response( filter( this.options.source, request.term ) );
};
} else {
initSource.call( this );
}
},
_renderItem: function( ul, item) {
if ( item.retenu ) {
item.label = '<strong>' + item.label + '</strong>';
}
 
return $( '<li></li>' )
.data( 'item.autocomplete', item )
.append( $( '<a></a>' )[ ( this.options.html ) ? 'html' : 'text' ]( item.label ) )
.appendTo( ul );
}
});
})( jQuery );
/trunk/widget/modules/saisie2/squelettes/js/auth.js
1,19 → 1,35
// configuration
var urlRacine = 'https://www.tela-botanica.org',
config = {
prod: {
urlWidgetNavigation : urlRacine + '/widget:cel:saisie2',
urlBaseAuth : 'https://www.tela-botanica.org/service:annuaire:auth'
},
test: {
urlWidgetNavigation : urlRacine + '/widget-test:cel:saisie2',
urlBaseAuth : 'https://www.tela-botanica.org/service:annuaire-test:auth'
},
local: {
urlWidgetNavigation : 'https://localhost/widget:cel:saisie2',
urlBaseAuth : 'https://localhost/service:annuaire:auth'
}
}
config = {
prod: {
urlWidgetNavigation : urlRacine + '/widget:cel:saisie2',
urlBaseAuth : 'https://www.tela-botanica.org/service:annuaire:auth'
},
test: {
urlWidgetNavigation : urlRacine + '/widget-test:cel:saisie2',
urlBaseAuth : 'https://www.tela-botanica.org/service:annuaire-test:auth'
},
local: {
urlWidgetNavigation : 'https://localhost/widget:cel:saisie2',
urlBaseAuth : 'https://localhost/service:annuaire:auth'
}
}
// // Prod: décommenter ci-dessus et commenter ou supprimer ci-dessous
// var urlRacine = 'http://localhost',
// config = {
// prod: {
// urlWidgetNavigation : urlRacine + '/widget:cel:saisie2',
// urlBaseAuth : 'https://www.tela-botanica.org/service:annuaire:auth'
// },
// test: {
// urlWidgetNavigation : urlRacine + '/widget:cel:saisie2',
// urlBaseAuth : 'https://api.tela-botanica.test/service:annuaire:auth'
// },
// local: {
// urlWidgetNavigation : 'https://localhost/widget:cel:saisie2',
// urlBaseAuth : 'https://localhost/service:annuaire:auth'
// }
// }
 
/**
* Charge la barre de navigation depuis le widget:reseau:navigation dans un <div id="tb-navigation"> , s'il existe
31,37 → 47,39
* "?squelette=contenu-de-data-squelette"; se reporter à la documentation du widget:reseau:navigation
*/
 
$(document).ready(function() {
var div = $('#tb-navigation');
if (div) {
var squelette = div.data('squelette'),
courant = div.data('courant'),
mode = div.data('mode') || 'prod',
contenu = div.html();
$( document ).ready( function() {
var $div = $( '#tb-navigation' );
if ( $div ) {
var squelette = $div.data( 'squelette' ),
courant = $div.data( 'courant' ),
mode = $div.data( 'mode' ) || 'prod',
contenu = $div.html();
 
// chargement de la barre
var urlBarreNavigation = config[mode]['urlWidgetNavigation'];
if (squelette) {
urlBarreNavigation += '?squelette=' + squelette;
}
htmlBarre = $.ajax({
url: urlBarreNavigation,
type: 'get',
success: function(data) {
// remplacement de la zone contenu-source
var zoneSource = div.find('#contenu-source');
if (zoneSource) {
zoneSource.replaceWith(contenu);
// Chargement de sinformations de connexion SSO
var urlBaseAuth = config[mode]['urlBaseAuth'];
chargerStatutSSO(urlBaseAuth);
}
},
error: function() {
div.html('Erreur: impossible de charger la barre de navigation');
}
});
// chargement de la barre
var urlBarreNavigation = config[mode]['urlWidgetNavigation'];
 
if ( squelette ) {
urlBarreNavigation += '?squelette=' + squelette;
}
 
htmlBarre = $.ajax({
url: urlBarreNavigation,
type: 'get',
success: function( data ) {
// remplacement de la zone contenu-source
var $zoneSource = $div.find( '#contenu-source' );
if ( $zoneSource ) {
$zoneSource.replaceWith( contenu );
// Chargement des informations de connexion SSO
var urlBaseAuth = config[mode]['urlBaseAuth'];
chargerStatutSSO( urlBaseAuth );
}
},
error: function() {
$div.html( 'Erreur: impossible de charger la barre de navigation' );
}
});
}
});
 
/**
70,9 → 88,9
* widget de barre de navigation et pas de la page appelante)
*/
function definirPageOrigineDansLiens() {
var page = window.location.href;
$('#bouton-connexion a').attr('href', $('#bouton-connexion a').attr('href') + page);
$('#deconnexion a').attr('href', $('#deconnexion a').attr('href') + page);
var page = window.location.href;
$( '#bouton-connexion a' ).attr( 'href', $( '#bouton-connexion a' ).attr( 'href' ) + page );
$( '#deconnexion a' ).attr( 'href', $( '#deconnexion a' ).attr( 'href' ) + page );
}
 
/**
79,32 → 97,48
* Interroge le SSO pour connaître le statut de l'utilisateur, et change le menu
* à droite de la barre en fonction
*/
function chargerStatutSSO(urlBaseAuth) {
var urlAuth = urlBaseAuth + '/identite';
$.ajax({
url: urlAuth,
type: "GET",
dataType: 'json',
xhrFields: {
withCredentials: true
}
}).done(function(data) {
// connecté
definirUtilisateur(data.token);
});
function chargerStatutSSO( urlBaseAuth ) {
var urlAuth = urlBaseAuth + '/identite';
// definirUtilisateur( 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvd3d3LnRlbGEtYm90YW5pY2Eub3JnIiwidG9rZW5faWQiOiJ0Yl9hdXRoIiwic3ViIjoiaWRpckB0ZWxhLWJvdGFuaWNhLm9yZyIsImlhdCI6MTU0Mjk3MjIxNiwiZXhwIjoxNTQyOTg0NDQ1LCJzY29wZXMiOlsidGVsYS1ib3RhbmljYS5vcmciXSwiaWQiOiI0NDA4NCIsInByZW5vbSI6IklkaXIiLCJub20iOiJBbGxpY2hlIiwicHNldWRvIjoiSWRpciBBbGxpY2hlIiwicHNldWRvVXRpbGlzZSI6dHJ1ZSwiaW50aXR1bGUiOiJJZGlyIEFsbGljaGUiLCJhdmF0YXIiOiJcL1wvd3d3LmdyYXZhdGFyLmNvbVwvYXZhdGFyXC83ODU3ZmY2MWE5Yjk5NWE4NjIyMzdkMmEyYzYxODAyMT9zPTUwJnI9ZyZkPW1tIiwiZ3JvdXBlcyI6W10sInBlcm1pc3Npb25zIjpbImVkaXRvciJdLCJub21XaWtpIjoiSWRpckFsbGljaGUiLCJkYXRlRGVybmllcmVNb2RpZiI6MTQ5NTIwNjM3Nn0.D3rySwuCDsSl6JAmjncwgwg4gUJijZjeaYeDYHsw3uI' );
// Prod: décommenter $.ajax ci-dessous et supprimer la ligne ci-dessus
$.ajax({
url: urlAuth,
type: "GET",
dataType: 'json',
xhrFields: {
withCredentials: true
}
}).done( function( data ) {
// connecté
definirUtilisateur( data.token );
});
}
 
function definirUtilisateur(jeton) {
var nomComplet = '';
if (jeton != undefined) {
// décodage jeton
var jetonDecode = decoderJeton(jeton);
nomComplet = jetonDecode.intitule;
}
// affichage
$('#bouton-connexion').hide();
$('#utilisateur-connecte').show();
$('#nom-complet').html(nomComplet);
function definirUtilisateur( jeton ) {
var nomComplet = '',
idUtilisateur = '',
courriel = '',
nom = '',
prenom = '';
if ( undefined !== jeton ) {
// décodage jeton
var jetonDecode = decoderJeton( jeton );
nomComplet = jetonDecode.intitule;
idUtilisateur = jetonDecode.id;
courriel = jetonDecode.sub;
nom = jetonDecode.nom;
prenom = jetonDecode.prenom;
// console.log(jetonDecode);
}
// affichage
$( '#bouton-connexion, #creation-compte' ).addClass( 'hidden' );
$( '#utilisateur-connecte, #anonyme, #zone-courriel-confirmation, #zone-prenom-nom' ).removeClass( 'hidden' );
$( '#nom-complet' ).html( nomComplet );
$( '#courriel, #courriel_confirmation' ).val( courriel ).attr( 'disabled', 'disabled' );
$( '#id_utilisateur' ).val( idUtilisateur );
$( '#prenom' ).val( prenom ).attr( 'disabled', 'disabled' );
$( '#nom' ).val( nom ).attr( 'disabled', 'disabled' );
$( '#date-releve' ).focus();
}
 
/**
113,11 → 147,11
* Si pb de cross-browser, tenter ceci : https://code.google.com/p/javascriptbase64/
* ou ceci : https://code.google.com/p/crypto-js
*/
function decoderJeton(jeton) {
parts = jeton.split('.');
payload = parts[1];
payload = atob(payload);
payload = JSON.parse(payload, true);
function decoderJeton( jeton ) {
parts = jeton.split( '.' );
payload = parts[1];
payload = atob( payload );
payload = JSON.parse( payload, true );
 
return payload;
}
return payload;
}