Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 2699 → Rev 2700

/trunk/widget/modules/saisie/squelettes/defaut/js/WidgetSaisie.js
10,6 → 10,33
this.marker = null;
this.latLng = null;
this.geocoder = null;
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 = null;
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.googleMapMarqueurUrl = null;
this.chargementIconeUrl = null;
this.chargementImageIconeUrl = null;
this.calendrierIconeUrl = null;
this.pasDePhotoIconeUrl = null;
}
 
/**
33,7 → 60,7
* Initialise le formulaire, les validateurs, les listes de complétion...
*/
WidgetSaisie.prototype.initForm = function() {
if (OBS_ID != '') {
if (this.obsId != '') {
this.chargerInfoObs();
}
 
42,20 → 69,20
this.configurerFormValidator();
this.definirReglesFormValidator();
 
if(ESPECE_IMPOSEE) {
if(this.especeImposee) {
$("#taxon").attr("disabled", "disabled");
$("#taxon-input-groupe").attr("title","");
var infosAssociee = {
label : INFOS_ESPECE_IMPOSEE.nom_sci_complet,
value : INFOS_ESPECE_IMPOSEE.nom_sci_complet,
nt : INFOS_ESPECE_IMPOSEE.num_taxonomique,
nomSel : INFOS_ESPECE_IMPOSEE.nom_sci,
nomSelComplet : INFOS_ESPECE_IMPOSEE.nom_sci_complet,
numNomSel : INFOS_ESPECE_IMPOSEE.id,
nomRet : INFOS_ESPECE_IMPOSEE["nom_retenu.libelle"],
numNomRet : INFOS_ESPECE_IMPOSEE["nom_retenu.id"],
famille : INFOS_ESPECE_IMPOSEE.famille,
retenu : (INFOS_ESPECE_IMPOSEE.retenu == 'false') ? false : true
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 : this.infosEspeceImposee["nom_retenu.libelle"],
numNomRet : this.infosEspeceImposee["nom_retenu.id"],
famille : this.infosEspeceImposee.famille,
retenu : (this.infosEspeceImposee.retenu == 'false') ? false : true
};
$("#taxon").data(infosAssociee);
}
76,7 → 103,7
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="'+CHARGEMENT_IMAGE_URL+'"/>');
$("#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);
116,6 → 143,13
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.';
});
}
}
 
/**
131,7 → 165,7
* Affiche la miniature d'une image temporaire (formulaire) qu'on a ajoutée à l'obs
*/
WidgetSaisie.prototype.afficherMiniature = function(reponse) {
if (DEBUG) {
if (this.debug) {
var debogage = $("debogage", reponse).text();
//console.log("Débogage upload : "+debogage);
}
175,7 → 209,7
addressSuffix = '',
lthis = this;
 
switch(NOM_SCI_REFERENTIEL) {
switch(this.nomSciReferentiel) {
case 'isfan':
// Si des résultats se trouvent dans ce rectangle, ils apparaîtront en premier.
// Ça marche moyen...
239,12 → 273,12
};
 
WidgetSaisie.prototype.afficherErreurGoogleMap = function(status) {
if (DEBUG) {
if (this.debug) {
$('#dialogue-google-map .contenu').empty().append(
'<pre class="msg-erreur">'+
"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
'</pre>');
afficherPanneau('#dialogue-google-map');
this.afficherPanneau('#dialogue-google-map');
}
};
 
271,19 → 305,19
var latLng,
zoomDefaut;
// Carte @TODO mettre ça dans la config
if(NOM_SCI_REFERENTIEL == 'bdtre') {
if(this.nomSciReferentiel == 'bdtre') {
latLng = new google.maps.LatLng(-21.10, 55.30);// Réunion
zoomDefaut = 7;
} else if(NOM_SCI_REFERENTIEL == 'lbf') {
} else if(this.nomSciReferentiel == 'lbf') {
latLng = new google.maps.LatLng(33.72211, 35.8603);// Liban
zoomDefaut = 7;
} else if(NOM_SCI_REFERENTIEL == 'bdtxa') {
} else if(this.nomSciReferentiel == 'bdtxa') {
latLng = new google.maps.LatLng(14.6, -61.08334);// Fort-De-France
zoomDefaut = 8;
} else if(NOM_SCI_REFERENTIEL == 'isfan') {
} else if(this.nomSciReferentiel == 'isfan') {
latLng = new google.maps.LatLng(29.28358, 10.21884);// Afrique du Nord
zoomDefaut = 4;
} else if(NOM_SCI_REFERENTIEL == 'apd') {
} else if(this.nomSciReferentiel == 'apd') {
latLng = new google.maps.LatLng(8.75624, 1.80176);// Afrique de l'Ouest et du Centre
zoomDefaut = 4;
} else {
324,7 → 358,7
map: this.map,
draggable: true,
title: 'Ma station',
icon: GOOGLE_MAP_MARQUEUR_URL,
icon: this.googleMapMarqueurUrl,
position: latLng
});
 
380,9 → 414,10
};
 
WidgetSaisie.prototype.trouverCommune = function(pos) {
var lthis = this;
$(function() {
 
var url_service = SERVICE_NOM_COMMUNE_URL;
var url_service = lthis.serviceNomCommuneUrl;
 
var urlNomCommuneFormatee = url_service.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
$.ajax({
401,7 → 436,7
},
statusCode : {
500 : function(jqXHR, textStatus, errorThrown) {
if (DEBUG) {
if (this.debug) {
$("#dialogue-erreur .alert-txt").append('<p id="msg">Un problème est survenu lors de l\'appel au service fournissante le nom des communes.</p>');
reponse = jQuery.parseJSON(jqXHR.responseText);
var erreurMsg = "";
416,7 → 451,7
}
},
error : function(jqXHR, textStatus, errorThrown) {
if (DEBUG) {
if (this.debug) {
$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
reponse = jQuery.parseJSON(jqXHR.responseText);
var erreurMsg = "";
432,7 → 467,7
complete : function(jqXHR, textStatus) {
var debugMsg = extraireEnteteDebug(jqXHR);
if (debugMsg != '') {
if (DEBUG) {
if (this.debug) {
$("#dialogue-erreur .alert-txt").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
}
}
456,7 → 491,7
var lthis = this;
var courriel = $("#courriel").val();
//TODO: mettre ceci en paramètre de config
var urlAnnuaire = SERVICE_ANNUAIRE_ID_URL+courriel;//http://localhost/applications/annuaire/jrest/
var urlAnnuaire = this.serviceAnnuaireIdUrl + courriel;//http://localhost/applications/annuaire/jrest/
$.ajax({
url : urlAnnuaire,
type : "GET",
490,13 → 525,13
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
$("#prenom, #nom, #courriel_confirmation").val('');
$("#prenom, #nom, #courriel_confirmation").removeAttr('disabled');
afficherPanneau("#dialogue-courriel-introuvable");
this.afficherPanneau("#dialogue-courriel-introuvable");
};
//+---------------------------------------------------------------------------------------------------------+
//FORMULAIRE
 
WidgetSaisie.prototype.chargerInfoObs = function() {
var urlObs = SERVICE_OBS_URL + '/' + OBS_ID;
var urlObs = this.serviceObsUrl + '/' + this.obsId;
$.ajax({
url: urlObs,
type: 'GET',
612,7 → 647,7
maxDate: new Date,
showOn: "button",
buttonImageOnly: true,
buttonImage: CALENDRIER_ICONE_URL,
buttonImage: this.calendrierIconeUrl,
buttonText: "Afficher le calendrier pour saisir la date.",
showButtonPanel: true
});
662,7 → 697,7
};
 
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() {
afficherPanneau("#dialogue-bloquer-copier-coller");
this.afficherPanneau("#dialogue-bloquer-copier-coller");
return false;
};
 
684,7 → 719,7
this.afficherObs();
this.stockerObsData();
this.supprimerMiniatures();
if(!ESPECE_IMPOSEE) {
if(! this.especeImposee) {
$("#taxon").val("");
$("#taxon").data("numNomSel",undefined);
}
691,7 → 726,7
$('#barre-progression-upload').attr('aria-valuemax', this.obsNbre);
$('#barre-progression-upload .sr-only').text('0/'+this.obsNbre+" observations transmises");
} else {
afficherPanneau('#dialogue-form-invalide');
this.afficherPanneau('#dialogue-form-invalide');
}
};
 
718,7 → 753,7
'<li>'+
'<span class="nom-sci">'+$("#taxon").val()+'</span> '+
this.ajouterNumNomSel()+'<span class="referentiel-obs">'+
($("#taxon").data("numNomSel") == undefined ? '' : '['+NOM_SCI_REFERENTIEL+']')+'</span>'+
($("#taxon").data("numNomSel") == undefined ? '' : '['+ this.nomSciReferentiel +']')+'</span>'+
' observé à '+
'<span class="commune">'+$('#commune-nom').text()+'</span> '+
'('+$('#commune-code-insee').text()+') ['+$("#latitude").val()+' / '+$("#longitude").val()+']'+
753,7 → 788,7
'num_nom_ret' : $("#taxon").data("numNomRet"),
'num_taxon' : $("#taxon").data("nt"),
'famille' : $("#taxon").data("famille"),
'referentiel' : ($("#taxon").data("numNomSel") == undefined ? '' : NOM_SCI_REFERENTIEL),
'referentiel' : ($("#taxon").data("numNomSel") == undefined ? '' : lthis.nomSciReferentiel),
 
'latitude' : $("#latitude").val(),
'longitude' : $("#longitude").val(),
770,7 → 805,7
};
 
WidgetSaisie.prototype.surChangementReferentiel = function() {
NOM_SCI_REFERENTIEL = $('#referentiel').val();
this.nomSciReferentiel = $('#referentiel').val();
$('#taxon').val('');
this.initialiserAutocompleteCommune();
this.initialiserGoogleMap();
780,12 → 815,12
if (this.obsNbre == 0) {
$("#transmettre-obs").attr('disabled', 'disabled');
$("#ajouter-obs").removeAttr('disabled');
} else if (this.obsNbre > 0 && this.obsNbre < OBS_MAX_NBRE) {
} else if (this.obsNbre > 0 && this.obsNbre < this.obsMaxNbre) {
$("#transmettre-obs").removeAttr('disabled');
$("#ajouter-obs").removeAttr('disabled');
} else if (this.obsNbre >= OBS_MAX_NBRE) {
} else if (this.obsNbre >= this.obsMaxNbre) {
$("#ajouter-obs").attr('disabled', 'disabled');
afficherPanneau("#dialogue-bloquer-creer-obs");
this.afficherPanneau("#dialogue-bloquer-creer-obs");
}
};
 
792,7 → 827,7
WidgetSaisie.prototype.transmettreObs = function() {
var observations = $("#liste-obs").data();
if (observations == undefined || jQuery.isEmptyObject(observations)) {
afficherPanneau("#dialogue-zero-obs");
this.afficherPanneau("#dialogue-zero-obs");
} else {
this.nbObsEnCours = 1;
this.nbObsTransmises = 0;
811,9 → 846,9
// ou bien utiliser un vrai tableau et pas un objet
for (var obsNum in observations) {
var obsATransmettre = {
'projet' : TAG_PROJET,
'tag-obs' : TAG_OBS,
'tag-img' : TAG_IMG
'projet' : this.tagProjet,
'tag-obs' : this.tagObs,
'tag-img' : this.tagImg
};
var utilisateur = {
id_utilisateur : $("#id_utilisateur").val(),
830,6 → 865,7
 
break;
}
$('#zone-liste-obs').addClass("hidden");
};
 
WidgetSaisie.prototype.mettreAJourProgression = function() {
849,7 → 885,7
var lthis = this;
var erreurMsg = "";
$.ajax({
url : SERVICE_SAISIE_URL,
url : lthis.serviceSaisieUrl,
type : "POST",
data : observation,
dataType : "json",
863,10 → 899,10
// mise à jour du nombre d'obs à transmettre
// et suppression de l'obs
lthis.supprimerObsParId(idObs);
this.nbObsEnCours++;
lthis.nbObsEnCours++;
// mise à jour du statut
lthis.mettreAJourProgression();
if(this.obsNbre > 0) {
if(lthis.obsNbre > 0) {
// dépilement de la suivante
lthis.depilerObsPourEnvoi();
}
886,7 → 922,7
});
}
} catch(e) {
erreurMsg += "L'erreur n'était pas en JSON.";
erreurMsg += "Erreur inconnue: " + jqXHR.responseText;
}
},
complete : function(jqXHR, textStatus) {
893,12 → 929,12
var debugMsg = extraireEnteteDebug(jqXHR);
 
if (erreurMsg != '') {
if (DEBUG) {
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 "+TAG_PROJET+
"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
914,10 → 950,10
$("#chargement").hide();
lthis.initialiserBarreProgression();
} else {
if (DEBUG) {
if (lthis.debug) {
$("#dialogue-obs-transaction-ok .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
}
if(this.obsNbre == 0) {
if(lthis.obsNbre == 0) {
setTimeout(function() {
$("#chargement").hide();
$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
1025,7 → 1061,7
'<a href="#" class="defilement-miniatures-droite '+visible+'">&#62;</a>'+
'</div>';
} else {
html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
html = '<img class="miniature" alt="Aucune photo"src="'+ this.pasDePhotoIconeUrl +'" />';
}
return html;
};
1094,7 → 1130,7
 
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
var mots = $('#taxon').val();
var url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_REFERENTIEL);
var url = this.serviceAutocompletionNomSciUrlTpl.replace('{referentiel}', this.nomSciReferentiel);
url = url.replace('{masque}', mots);
return url;
};
1107,7 → 1143,7
var nom = {label : '', value : '', nt : '', nomSel : '', nomSelComplet : '', numNomSel : '',
nomRet : '', numNomRet : '', famille : '', retenu : false
};
if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
if (suggestions.length >= this.autocompletionElementsNbre) {
nom.label = "...";
nom.value = $('#taxon').val();
suggestions.push(nom);
1134,6 → 1170,10
return suggestions;
};
 
WidgetSaisie.prototype.afficherPanneau = function(selecteur) {
$(selecteur).fadeIn("slow").delay(this.dureeMessage).fadeOut("slow");
}
 
// lib hors objet --
 
/**
1168,10 → 1208,6
return msgDebug;
}
 
function afficherPanneau(selecteur) {
$(selecteur).fadeIn("slow").delay(DUREE_MESSAGE).fadeOut("slow");
}
 
/*
* jQuery UI Autocomplete HTML Extension
*