41,7 → 41,9 |
WidgetSaisie.prototype.init = function() { |
this.initForm(); |
this.initEvts(); |
if ( '' === $( '#nom-complet').val() && '' !== $( '#courriel' ).val() ) { |
this.requeterIdentite(); |
} |
}; |
|
/** |
48,22 → 50,22 |
* 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.configurerDatePicker( '.date' ); |
this.ajouterAutocompletionNoms(); |
//this.configurerFormValidator(); |
//this.definirReglesFormValidator(); |
this.configurerFormValidator(); |
this.definirReglesFormValidator(); |
|
if(this.especeImposee) { |
$("#taxon").attr("disabled", "disabled"); |
$("#taxon-input-groupe").attr("title",""); |
$( '#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) { |
var nomRetenuComplet = this.infosEspeceImposee['nom_retenu_complet'], |
debutAnneRefBiblio = nomRetenuComplet.indexOf( ' [' ); |
if ( -1 !== debutAnneRefBiblio ) { |
nomRetenuComplet = nomRetenuComplet.substr(0, debutAnneRefBiblio); |
} |
// fin bricolage cracra |
75,11 → 77,11 |
nomSelComplet : this.infosEspeceImposee.nom_sci_complet, |
numNomSel : this.infosEspeceImposee.id, |
nomRet : nomRetenuComplet, |
numNomRet : this.infosEspeceImposee["nom_retenu.id"], |
numNomRet : this.infosEspeceImposee['nom_retenu.id'], |
famille : this.infosEspeceImposee.famille, |
retenu : (this.infosEspeceImposee.retenu == 'false') ? false : true |
retenu : ( 'false' === this.infosEspeceImposee.retenu ) ? false : true |
}; |
$("#taxon").data(infosAssociee); |
$( '#taxon' ).data( infosAssociee ); |
} |
}; |
|
88,10 → 90,23 |
*/ |
WidgetSaisie.prototype.initEvts = function() { |
var lthis = this; |
|
// console.log($( '#taxon' ).data('label') ); |
|
$('body').on('click', '.effacer-miniature', function() { |
$(this).parent().remove(); |
}); |
$("#fichier").bind('change', function (e) { |
|
$( '#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 |
98,48 → 113,52 |
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); |
$( '#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")); |
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)); |
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() { |
$( '#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) { |
$( '#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) { |
$( 'body' ).on( 'click', '.defilement-miniatures-droite', function( event ) { |
event.preventDefault(); |
lthis.defilerMiniatures($(this)); |
}); |
*/ |
|
// fermeture fenêtre |
if (this.debug == false) { |
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.'; |
}); |
148,12 → 167,12 |
}; |
|
/** |
* 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'); |
return ( 'jpeg' === extension.toLowerCase() || 'jpg' === extension.toLowerCase() ); |
}; |
|
/** |
161,14 → 180,14 |
*/ |
WidgetSaisie.prototype.afficherMiniature = function(reponse) { |
if (this.debug) { |
var debogage = $("debogage", reponse).text(); |
//console.log("Débogage upload : "+debogage); |
var debogage = $( 'debogage', reponse ).text(); |
//console.log( 'Débogage upload : '+debogage); |
} |
var message = $("message", reponse).text(); |
if (message != '') { |
$("#miniature-msg").append(message); |
var message = $( 'message', reponse ).text(); |
if ( '' !== message ) { |
$( '#miniature-msg' ).append( message ); |
} else { |
$("#miniatures").append(this.creerWidgetMiniature(reponse)); |
$( '#miniatures' ).append( this.creerWidgetMiniature( reponse ) ); |
} |
$('#ajouter-obs').removeAttr('disabled'); |
}; |
177,12 → 196,12 |
* 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 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 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; |
}; |
198,32 → 217,33 |
* 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) { |
if ( 13 == event.which ) { |
this.requeterIdentite(); |
this.event.preventDefault(); |
this.event.stopPropagation(); |
event.preventDefault(); |
event.stopPropagation(); |
} |
}; |
|
WidgetSaisie.prototype.requeterIdentite = function() { |
var lthis = this; |
var courriel = $("#courriel").val(); |
var courriel = $( '#courriel' ).val(); |
var urlAnnuaire = this.serviceAnnuaireIdUrl + courriel; |
if (courriel != '') { |
// console.log(urlAnnuaire); |
if ( '' !== courriel ) { |
$.ajax({ |
url : urlAnnuaire, |
type : "GET", |
type : 'GET', |
success : function(data, textStatus, jqXHR) { |
if (lthis.debug) { |
console.log('SUCCESS: '+textStatus); |
} |
if (data != undefined && data[courriel] != undefined) { |
if ( undefined != data && undefined != data[courriel] ) { |
var infos = data[courriel]; |
lthis.surSuccesCompletionCourriel(infos, courriel); |
} else { |
240,9 → 260,6 |
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(); |
} |
}); |
} |
249,41 → 266,65 |
}; |
|
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"); |
$( '#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()); |
}; |
|
WidgetSaisie.prototype.formaterPrenom = function() { |
var prenom = new Array(); |
var mots = $(this).val().split(' '); |
for (var i = 0; i < mots.length; i++) { |
var prenom = new Array(), |
mots = $( this ).val().split( ' ' ), |
motsLength = mots.length; |
|
|
for ( var i = 0; i < motsLength; 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); |
|
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); |
} |
} |
291,19 → 332,664 |
}; |
|
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() { |
this.afficherPanneau("#dialogue-bloquer-copier-coller"); |
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", |
dateFormat: 'dd/mm/yy', |
maxDate: new Date, |
onSelect: function(date) { |
$(this).valid(); |
317,10 → 1003,11 |
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); |
// 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); |
334,15 → 1021,15 |
} |
}); |
|
$("#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'); |
$( '#taxon' ).data( ui.item ); |
if ( ui.item.retenu ) { |
$( '#taxon' ).addClass( 'ns-retenu' ); |
} else { |
$("#taxon").removeClass('ns-retenu'); |
$( '#taxon' ).removeClass( 'ns-retenu' ); |
} |
}; |
|
355,14 → 1042,23 |
|
WidgetSaisie.prototype.traiterRetourNomsSci = function(data) { |
var suggestions = []; |
if (data.resultat != undefined) { |
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 |
var nom = { |
label : '', |
value : '', |
nt : '', |
nomSel : '', |
nomSelComplet : '', |
numNomSel : '', |
nomRet : '', |
numNomRet : '', |
famille : '', |
retenu : false |
}; |
if (suggestions.length >= this.autocompletionElementsNbre) { |
nom.label = "..."; |
nom.label = '...'; |
nom.value = $('#taxon').val(); |
suggestions.push(nom); |
return false; |
374,11 → 1070,11 |
nom.nomSelComplet = val.nom_sci_complet; |
nom.numNomSel = val.nn; |
nom.nomRet = val.nom_retenu_complet; |
nom.numNomRet = val["nom_retenu.id"]; |
nom.numNomRet = val['nom_retenu.id']; |
nom.famille = val.famille; |
// Tester dans ce sens, permet de considérer "absent" comme "false" => est-ce opportun ? |
// 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; |
nom.retenu = ( 'true' == val.retenu ) ? true : false; |
|
suggestions.push(nom); |
} |
389,6 → 1085,92 |
}; |
|
WidgetSaisie.prototype.afficherPanneau = function(selecteur) { |
$(selecteur).fadeIn("slow").delay(this.dureeMessage).fadeOut("slow"); |
$( 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 ); |