33,53 → 33,7 |
this.chargementImageIconeUrl = null; |
this.calendrierIconeUrl = null; |
this.pasDePhotoIconeUrl = null; |
|
// système de traduction minimaliste |
this.msgs = { |
fr: { |
'format-non-supporte': 'Le format de fichier n\'est pas supporté, les formats acceptés sont', |
'date-incomplete': 'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.', |
'observations-transmises': 'observations transmises', |
'supprimer-observation-liste': 'Supprimer cette observation de la liste à transmettre', |
'milieu': 'Milieu', |
'commentaires': 'Commentaires', |
'erreur-inconnue': 'Erreur inconnue', |
'non-lie-au-ref': 'non lié au référentiel', |
'obs-le': 'le', |
'quitter-page' : 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.', |
'courriel-connu' : 'Un compte existe pour ce courriel, connectez-vous pour saisir votre observation', |
'obs-numero' : 'Observation n°', |
'erreur-ajax' : 'Erreur Ajax', |
'erreur' : 'Erreur', |
'erreur-chargement' : 'Erreur lors du chargement de l\'observation', |
'lieu-obs' : 'observé à', |
'lieu-dit' : 'Lieu-dit', |
'station' : 'Station' |
|
}, |
en: { |
'format-non-supporte': 'The file format is not supported, the accepted formats are', |
'date-incomplete': 'Format: dd / mm / yyyy. Incomplete date, use 0, example: 00/12/2011.', |
'observations-transmises': 'observations transmitted', |
'supprimer-observation-liste': 'Delete this observation from the list to be transmitted', |
'milieu': 'Environment', |
'commentaires': 'Comments', |
'erreur-inconnue': 'Unknown error', |
'non-lie-au-ref': 'unrelated to the referencial ', |
'obs-le': 'the', |
'quitter-page' : 'Are you sure you want to leave the page?\nThe observations entered but not transmitted will be lost.', |
'courriel-connu' : 'An account exists for this email, log in to enter your observation', |
'obs-numero' : 'Observation number ', |
'erreur-ajax' : 'Ajax Error', |
'erreur' : 'Error', |
'erreur-chargement' : 'Error loading the observation', |
'lieu-obs' : 'observed at', |
'lieu-dit' : 'Locality', |
'station' : 'Place' |
|
} |
}; |
} |
|
/** |
* Initialisation du widget |
101,7 → 55,7 |
this.chargerInfoObs(); |
} |
|
// this.configurerDatePicker( '.date' ); |
this.configurerDatePicker( '.date' ); |
this.ajouterAutocompletionNoms(); |
this.configurerFormValidator(); |
this.definirReglesFormValidator(); |
166,7 → 120,7 |
$( '#form-upload' ).ajaxSubmit( options ); |
} else { |
$( '#form-upload' )[0].reset(); |
window.alert( this.msgTraduction( 'format-non-supporte' ) + ' ' + $( '#fichier' ).attr( 'accept' ) ); |
window.alert( 'Le format de fichier n\'est pas supporté, les formats acceptés sont ' + $( '#fichier' ).attr( 'accept' ) ); |
} |
return false; |
}); |
207,7 → 161,7 |
// fermeture fenêtre |
if ( !this.debug && 0 < $( '.obs' ).length ) { |
$( window ).on( 'beforeunload', function( event ) { |
return this.msgTraduction( 'quitter-page' ); |
return 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mais non transmises seront perdues.'; |
}); |
} |
|
313,7 → 267,7 |
}; |
|
WidgetSaisie.prototype.surSuccesCompletionCourriel = function( infos, courriel ) { |
$( '#zone-courriel' ).before( '<p class="warning"><i class="fas fa-exclamation-triangle"></i> ' + this.msgTraduction( 'courriel-connu' ) + '</p>' ); |
$( '#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>' ); |
$( '#bouton-inscription, #zone-prenom-nom, #zone-courriel-confirmation' ).addClass( 'hidden' ); |
$( '#prenom, #nom, #courriel_confirmation' ).attr( 'disabled', 'disabled' ); |
$( '#bouton-connexion a' ).css( 'box-shadow', '0 0 1.5px 1px red' ); |
391,7 → 345,6 |
// @WARNING TEST |
$( '#dialogue-obs-transaction-ko' ).addClass( 'hidden' ); |
$( '#dialogue-obs-transaction-ok' ).addClass( 'hidden' ); |
console.log( this.validerFormulaire() ); |
|
if ( this.validerFormulaire() ) { |
this.masquerPanneau( '#dialogue-form-invalide' ); |
406,7 → 359,7 |
$( '#taxon' ).data( 'numNomSel', undefined ); |
} |
$( '#barre-progression-upload' ).attr( 'aria-valuemax', this.obsNbre ); |
$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' ' + this.msgTraduction( 'observations-transmises' ) ); |
$( '#barre-progression-upload .sr-only' ).text( '0/' + this.obsNbre + ' observations transmises' ); |
} else { |
this.afficherPanneau( '#dialogue-form-invalide' ); |
} |
417,92 → 370,56 |
*/ |
WidgetSaisie.prototype.afficherObs = function() { |
|
var obsHtmlDiff1 = '', |
obsHtmlDiff2 = '', |
obsHtmlDiff3 = '', |
obsHtmlDiff4 = '', |
obsHtmlDiff5 = '', |
obsHtmlDiff6 = '', |
taxon = '', |
commune = '', |
inseeLatitudeLongitude = '', |
lieudit = '', |
station = '', |
milieu = '', |
commentaires = ''; |
// var commune = $( '#commune-nom' ).text(); |
// commune = ( '' !== commune.trim() ) ? commune : $( '#carte-recherche' ).val(); |
|
if ( undefined != $('#taxon').data( 'numNomSel' ) ) { |
taxon = '<span class="referentiel-obs">' + '[' + this.nomSciReferentiel + ']' + '</span>'; |
} |
if ( 0 < $( '#commune-nom' ).val().length ) { |
commune = ' ' + this.msgTraduction( 'lieu-obs' ) + ' <span class="commune">' + commune + '</span> '; |
} |
if ( 0 < $( '#commune-insee' ).val().length && 0 < $( '#latitude' ).val().length && 0 < $( '#longitude' ).val().length ) { |
inseeLatitudeLongitude = $('#commune-insee').val() + ' [' + $( '#latitude' ).val() + ' / ' + $( '#longitude' ).val() + ']'; |
} |
if ( 0 < $( '#lieudit' ).val().length ) { |
lieudit = '<span>' + this.msgTraduction( 'lieu-dit' ) + ' :</span> ' + $( '#lieudit' ).val() + ' '; |
} |
if ( 0 < $( '#station' ).val().length ) { |
station = '<span>' + this.msgTraduction( 'station' ) + ' :</span> ' + $( '#station' ).val() + ' '; |
} |
if ( 0 < $( '#milieu' ).val().length ) { |
milieu = '<span>' + this.msgTraduction( 'milieu' ) + ' :</span> ' + $( '#milieu' ).val() + ' '; |
} |
if ( 0 < $( '#notes' ).val().length ) { |
commentaires = this.msgTraduction( 'commentaires' ) + ' : <span class="discretion">' + $( '#notes' ).val() + '</span>' + ' '; |
} |
// var code_insee = $('#commune-code-insee').text(); |
// code_insee = ( '' !== code_insee.trim() ) ? '(' + code_insee + ')' : ''; |
|
if ( window.matchMedia( '(min-width: 576px)' ).matches ) { |
/* La largeur minimum de l'affichage est 600 px inclus */ |
obsHtmlDiff1 = ' droite'; |
obsHtmlDiff2 = '<div></div>'; |
obsHtmlDiff3 = '<div class="row">'; |
obsHtmlDiff4 = ' col-md-2 col-sm-4'; |
obsHtmlDiff5 = ' class="col-md-9 col-sm-7"'; |
obsHtmlDiff6 = '</div>'; |
} |
// 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" '+ |
'title="' + this.msgTraduction( 'supprimer-observation-liste' ) + '"'+ |
'class="obs-action droite" '+ |
'title="Supprimer cette observation de la liste à transmettre"'+ |
'>'+ |
'<button class="btn btn-danger supprimer-obs' + obsHtmlDiff1 + '" value="'+ this.obsNbre + '" title="' + this.msgTraduction( 'obs-numero' ) + this.obsNbre + '">'+ |
'<button class="btn btn-danger supprimer-obs" value="'+ this.obsNbre + '" title="Observation n°' + this.obsNbre + '">'+ |
'<i class="far fa-trash-alt"></i>'+ |
'</button>'+ |
obsHtmlDiff2 + |
'</div> '+ |
|
obsHtmlDiff3 + |
'<div class="thumbnail' + obsHtmlDiff4 + '">'+ |
'<div class="row">'+ |
'<div class="thumbnail col-md-2">'+ |
this.ajouterImgMiniatureAuTransfert()+ |
'</div>'+ |
'<div' + obsHtmlDiff5 + '>'+ |
'<div class="col-md-9">'+ |
'<ul class="unstyled">'+ |
'<li>'+ |
'<span class="nom-sci">' + $( '#taxon' ).val() + '</span> '+ |
this.ajouterNumNomSel() + |
taxon + |
commune + |
inseeLatitudeLongitude + |
' ' + this.msgTraduction( 'obs-le' ) + ' ' + |
'<span class="date">' + $( '#date_releve' ).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>'+ |
lieudit + |
station + |
milieu + |
// '<span>Lieu-dit :</span> ' + $( '#lieudit' ).val() + ' '+ |
// '<span>Station :</span> ' + $( '#station' ).val() + ' '+ |
'<span>Milieu :</span> '+ $ ( '#milieu' ).val() + ' '+ |
'</li>'+ |
'<li>'+ |
commentaires + |
'Commentaires : <span class="discretion">' + $( '#notes' ).val() + '</span>'+ |
'</li>'+ |
'</ul>'+ |
'</div>'+ |
obsHtmlDiff6+ |
'</div>'+ |
|
'</div>' |
); |
|
509,24 → 426,14 |
$( '#zone-liste-obs' ).removeClass( 'hidden' ); |
}; |
|
WidgetSaisie.prototype.fournirDate = function( dateObs ) { |
|
if ( /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/.test( dateObs ) ) { |
return dateObs; |
} else if ( /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test( dateObs ) ) { |
var dateArray = dateObs.split( '-' ); |
return dateArray[2] + '/' + dateArray[1] + '/' + dateArray[0] |
} else { |
console.log( 'erreur date : ' + dateObs ) |
} |
|
} |
|
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' : lthis.fournirDate( $( '#date_releve' ).val() ), |
'date' : $( '#date' ).val(), |
'notes' : $( '#notes' ).val().trim(), |
'nom_sel' : $( '#taxon' ).val(), |
'num_nom_sel' : $( '#taxon' ).data( 'numNomSel' ), |
535,24 → 442,12 |
'num_taxon' : $( '#taxon' ).data( 'nt' ), |
'famille' : $( '#taxon' ).data( 'famille' ), |
'referentiel' : ( ( undefined === $( '#taxon' ).data( 'numNomSel' ) ) ? '' : lthis.nomSciReferentiel ), |
// 'pays' : $( 'pays' ).val(), |
// 'commune_nom' : $( '#commune-nom' ).val(), |
// 'commune_code_insee' : $( '#commune-code-insee' ).text(), |
// 'commune_code_insee' : $( '#commune-insee' ).val(), |
// 'latitude' : $( '#latitude' ).val(), |
// 'longitude' : $( '#longitude' ).val(), |
// 'commune_nom' : commune, |
// 'commune_code_insee' : $( '#commune-code-insee' ).text(), |
// 'lieudit' : $( '#lieudit' ).val(), |
// 'station' : $( '#station' ).val(), |
// 'altitude' : $( '#altitude' ).val(), |
|
// début valeurs pour test: |
'commune_nom' : 'Montpellier', |
'commune_code_insee' : '34172', |
'latitude' : '43.608320', |
'longitude' : '3.880196', |
'altitude' : '0', |
//fin valeurs pour test |
|
'milieu' : $( '#milieu' ).val(), |
|
//Ajout des champs images |
568,7 → 463,7 |
* Retourne un Array contenant les valeurs des champs étendus |
*/ |
WidgetSaisie.prototype.getObsChpEtendus = function() { |
var champs = new Array(), |
var champs = [], |
$thisForm = $( '#form-supp' ), |
elements = |
'input[type=text]:not(.collect-other),'+ |
579,29 → 474,24 |
'input[type=range]'+ |
'input[type=date],'+ |
'textarea,'+ |
'select:not(.list-checkbox)', |
retour = new Array(); |
'select'; |
|
$( elements, $thisForm ).each( function() { |
var valeur = $( this ).val(); |
cle = $( this ).attr( 'name' ); |
console.log(valeur); |
var valeur = $( this ).val(), |
cle = $( this ).attr( 'name' ), |
label = $( this ).data( 'label' ); |
if ( '' !== valeur ) { |
if ( cle in champs ) { |
champs[cle] += ';' + valeur; |
} else { |
champs[cle] = valeur; |
var chpEtendu = { |
cle: cle, |
label: label, |
valeur: valeur |
}; |
champs.push( chpEtendu ); |
} |
} |
}); |
|
for( var key in champs ) { |
retour.push({ 'cle' : key , 'valeur' : champs[key] }); |
return champs; |
}; |
|
return retour; |
}; |
|
WidgetSaisie.prototype.surChangementReferentiel = function() { |
this.nomSciReferentiel = $( '#referentiel' ).val(); |
$( '#taxon' ).val( '' ); |
764,7 → 654,7 |
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 + ' ' + this.msgTraduction( 'observations-transmises' ) ); |
$( '#barre-progression-upload .sr-only' ).text( this.nbObsTransmises + '/' + this.totalObsATransmettre + ' observations transmises' ); |
|
if( 0 === this.obsNbre ) { |
$( '.progress' ).removeClass( 'active' ); |
773,13 → 663,12 |
}; |
|
WidgetSaisie.prototype.validerFormulaire = function() { |
var observateur = $( '#form-observateur' ).valid(); |
var obs = $( '#form-observation' ).valid(); |
var geoloc = ( 'ok' === $( '#geoloc' ).val() ); |
( geoloc ) ? this.masquerPanneau( '#dialogue-geoloc-ko' ) : this.afficherPanneau( '#dialogue-geoloc-ko' ); |
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 && geoloc && obs ); |
return ( observateur /*&& station */&& obs ) ? true : false; |
}; |
|
WidgetSaisie.prototype.getNomsImgsOriginales = function() { |
822,7 → 711,7 |
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 ' + this.msgTraduction( 'observations-transmises' ) ); |
$( '#barre-progression-upload .sr-only' ).text( '0/0 observations transmises' ); |
$( '.progress' ).addClass( 'active' ); |
$( '.progress' ).addClass( 'progress-striped' ); |
}; |
917,7 → 806,7 |
WidgetSaisie.prototype.ajouterNumNomSel = function() { |
var nn = '<span class="nn">[nn' + $( '#taxon' ).data( 'numNomSel' ) + ']</span>'; |
if ( undefined == $( '#taxon' ).data( 'numNomSel' ) ) { |
nn = '<span class="alert-error">[' + this.msgTraduction( 'non-lie-au-ref' ) + ']</span>'; |
nn = '<span class="alert-error">[non lié au référentiel]</span>'; |
} |
return nn; |
}; |
993,7 → 882,7 |
|
// @TODO faire mieux que ça ! |
WidgetSaisie.prototype.surErreurChargementInfosObs = function() { |
alert( this.msgTraduction( 'erreur-chargement' ) ); |
alert( 'Erreur lors du chargement de l\'observation' ); |
}; |
|
WidgetSaisie.prototype.prechargerForm = function( data ) { |
1022,9 → 911,9 |
$.validator.addMethod( |
'dateCel', |
function ( value, element ) { |
return ( '' !== value || ( /^(?:[0-9]{4}-[0-9]{2}-[0-9]{2})|(?:[0-9]{2}\/[0-9]{2}\/[0-9]{4})$/.test( value ) ) ); |
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 ) ) ); |
}, |
this.msgTraduction( 'date-incomplete' ) |
'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.' |
); |
|
$.validator.addMethod( |
1066,7 → 955,7 |
|
unhighlight: function( element ) { |
if ( 'taxon' === $( element ).attr( 'id' ) ) { |
if ( 0 < $( '#taxon' ).val().length ) { |
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', '' ); |
1077,8 → 966,6 |
} |
$( '#taxon-input-groupe' ).removeClass( 'error' ); |
$( element ).next( 'span.help-inline' ).remove(); |
} else { |
$( '#taxon-input-groupe' ).addClass( 'error' ); |
} |
} else { |
$( element ).closest( '.control-group' ).removeClass( 'error' ); |
1091,13 → 978,21 |
|
WidgetSaisie.prototype.definirReglesFormValidator = function() { |
|
$( '#form-observation' ).validate({ |
$( '#form-observateur' ).validate({ |
rules : { |
date_releve : { |
courriel : { |
required : true, |
'dateCel' : true |
email : true, |
'userEmailOk' : true |
}, |
taxon : 'required' |
courriel_confirmation : { |
required : true, |
equalTo : '#courriel' |
} |
} |
}); |
// $( '#form-station' ).validate({ |
// rules: { |
// latitude : { |
// range: [-90, 90] |
// }, |
1104,36 → 999,32 |
// longitude : { |
// range: [-180, 180] |
// } |
} |
}); |
$( '#form-observateur' ).validate({ |
// } |
// }); |
$( '#form-observation' ).validate({ |
rules : { |
courriel : { |
date_releve : { |
required : true, |
email : true, |
'userEmailOk' : true |
'dateCel' : true |
}, |
courriel_confirmation : { |
required : true, |
equalTo : '#courriel' |
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' ); |
}; |
|
// /* calendrier */ |
// WidgetSaisie.prototype.configurerDatePicker = function( selector ) { |
// $.datepicker.setDefaults( $.datepicker.regional[ this.langue ] ); |
// $( selector ).datepicker({ |
// dateFormat: 'dd/mm/yyyy', |
// maxDate: new Date, |
// onSelect: function( date ) { |
// $( this ).valid(); |
// } |
// }); |
// $( selector + ' + img.ui-datepicker-trigger' ).appendTo( selector + '-icone.add-on' ); |
// }; |
|
WidgetSaisie.prototype.surAutocompletionTaxon = function( event, ui ) { |
$( '#taxon' ).data( ui.item ); |
if ( ui.item.retenu ) { |
1207,24 → 1098,6 |
$( selecteur ).addClass( 'hidden' ); |
}; |
|
/** |
* Si la langue est définie dans this.langue, et si des messages sont définis |
* dans this.msgs, tente de trouver le message dont la clé est [cle] dans la |
* langue en cours. S'il n'est pas trouvé, retourne la version française (par |
* défaut); si celle-ci n'exite pas, retourne "N/A". |
*/ |
WidgetSaisie.prototype.msgTraduction = function( cle ) { |
var msg = 'N/A'; |
if ( this.msgs ) { |
if ( this.langue in this.msgs && cle in this.msgs[this.langue] ) { |
msg = this.msgs[this.langue][cle]; |
} else if ( cle in this.msgs['fr'] ) { |
msg = this.msgs['fr'][cle]; |
} |
} |
return msg; |
}; |
|
// lib hors objet -- |
|
/** |