Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 2687 → Rev 2688

/trunk/widget/modules/saisie/squelettes/defaut/js/defaut.js
1,6 → 1,12
//+---------------------------------------------------------------------------------------------------------+
// GÉNÉRAL
/**
* Déclenchement des actions sur la page
*/
$(document).ready(function() {
// OMG un modèle objet !!
var widget = new WidgetSaisie();
widget.init();
 
// fermeture fenêtre
if (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.';
7,14 → 13,13
});
}
});
//+----------------------------------------------------------------------------------------------------------+
// FONCTIONS GÉNÉRIQUES
 
// lib
 
/**
* Stope l'évènement courrant quand on clique sur un lien.
* Utile pour Chrome, Safari...
* @param evenement
* @return
*/
* Stope l'évènement courant quand on clique sur un lien.
* Utile pour Chrome, Safari...
*/
function arreter(evenement) {
if (evenement.stopPropagation) {
evenement.stopPropagation();
25,6 → 30,11
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") != '') {
42,24 → 52,90
$(selecteur).fadeIn("slow").delay(DUREE_MESSAGE).fadeOut("slow");
}
 
//+----------------------------------------------------------------------------------------------------------+
//UPLOAD PHOTO : Traitement de l'image
$(document).ready(function() {
 
$(".effacer-miniature").click(function () {
supprimerMiniatures($(this));
 
 
/**
* Constructeur WidgetSaisie par défaut
*/
function WidgetSaisie() {
this.obsNbre = 0;
this.nbObsEnCours = 1;
this.totalObsATransmettre = 0;
this.nbObsTransmises = 0;
this.map = null;
this.marker = null;
this.latLng = null;
this.geocoder = null;
}
 
/**
* Initialisation du widget
*/
WidgetSaisie.prototype.init = function() {
this.initCarto();
this.initForm();
this.initEvts();
};
 
/**
* Initialise la cartographie
*/
WidgetSaisie.prototype.initCarto = function() {
this.initialiserGoogleMap();
this.initialiserAutocompleteCommune();
}
 
/**
* Initialise le formulaire, les validateurs, les listes de complétion...
*/
WidgetSaisie.prototype.initForm = function() {
if (OBS_ID != '') {
widget.chargerInfoObs();
}
 
this.configurerDatePicker();
this.ajouterAutocompletionNoms();
this.configurerFormValidator();
this.definirReglesFormValidator();
 
if(ESPECE_IMPOSEE) {
$("#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
};
$("#taxon").data(infosAssociee);
}
}
 
/**
* 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: afficherMiniature, // post-submit callback
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="'+CHARGEMENT_IMAGE_URL+'"/>');
$("#ajouter-obs").attr('disabled', 'disabled');
if(verifierFormat($("#fichier").val())) {
if(lthis.verifierFormat($("#fichier").val())) {
$("#form-upload").ajaxSubmit(options);
} else {
$('#form-upload')[0].reset();
67,36 → 143,51
}
return false;
});
// idéntité
$("#courriel").on('blur', this.requeterIdentite.bind(this));
$("#courriel").on('keypress', this.testerLancementRequeteIdentite.bind(this));
$(".alert .close").on('click', this.fermerPanneauAlert);
$("[rel=tooltip]").tooltip('enable');
$("#btn-aide").on('click', this.basculerAffichageAide);
$("#prenom").on("change", this.formaterPrenom.bind(this));
$("#nom").on("change", this.formaterNom.bind(this));
 
if(ESPECE_IMPOSEE) {
$("#taxon").attr("disabled", "disabled");
$("#taxon-input-groupe").attr("title","");
var infosAssociee = new Object();
infosAssociee.label = INFOS_ESPECE_IMPOSEE.nom_sci_complet;
infosAssociee.value = INFOS_ESPECE_IMPOSEE.nom_sci_complet;
infosAssociee.nt = INFOS_ESPECE_IMPOSEE.num_taxonomique;
infosAssociee.nomSel = INFOS_ESPECE_IMPOSEE.nom_sci;
infosAssociee.nomSelComplet = INFOS_ESPECE_IMPOSEE.nom_sci_complet;
infosAssociee.numNomSel = INFOS_ESPECE_IMPOSEE.id;
infosAssociee.nomRet = INFOS_ESPECE_IMPOSEE["nom_retenu.libelle"];
infosAssociee.numNomRet = INFOS_ESPECE_IMPOSEE["nom_retenu.id"];
infosAssociee.famille = INFOS_ESPECE_IMPOSEE.famille;
infosAssociee.retenu = (INFOS_ESPECE_IMPOSEE.retenu == 'false') ? false : true;
$("#taxon").data(infosAssociee);
}
$("#courriel_confirmation").on('paste', this.bloquerCopierCollerCourriel.bind(this));
$("a.afficher-coord").on('click', this.basculerAffichageCoord.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));
 
$('.effacer-miniature').live('click', function() {
$(this).parent().remove();
$("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));
});
}
 
function verifierFormat(nom) {
/**
* 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');
}
};
 
function afficherMiniature(reponse) {
/**
* Affiche la miniature d'une image temporaire (formulaire) qu'on a ajoutée à l'obs
*/
WidgetSaisie.prototype.afficherMiniature = function(reponse) {
if (DEBUG) {
var debogage = $("debogage", reponse).text();
//console.log("Débogage upload : "+debogage);
105,12 → 196,15
if (message != '') {
$("#miniature-msg").append(message);
} else {
$("#miniatures").append(creerWidgetMiniature(reponse));
$("#miniatures").append(this.creerWidgetMiniature(reponse));
}
$('#ajouter-obs').removeAttr('disabled');
}
};
 
function creerWidgetMiniature(reponse) {
/**
* 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 =
119,18 → 213,24
'<button class="effacer-miniature" type="button">Effacer</button>'+
'</div>'
return html;
}
};
 
function supprimerMiniatures() {
/**
* Efface toutes les miniatures (formulaire)
*/
WidgetSaisie.prototype.supprimerMiniatures = function() {
$("#miniatures").empty();
$("#miniature-msg").empty();
}
};
 
//Initialise l'autocomplétion de la commune, en fonction du référentiel
function initialiserAutocompleteCommune() {
/**
* Initialise l'autocomplétion de la commune, en fonction du référentiel
*/
WidgetSaisie.prototype.initialiserAutocompleteCommune = function() {
var geocoderOptions = {
};
var addressSuffix = '';
},
addressSuffix = '',
lthis = this;
 
switch(NOM_SCI_REFERENTIEL) {
case 'isfan':
158,7 → 258,7
source: function(request, response) {
geocoderOptions.address = request.term + addressSuffix;
console.log('Geocoder options', geocoderOptions);
geocoder.geocode( geocoderOptions, function(results, status) {
lthis.geocoder.geocode( geocoderOptions, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
response($.map(results, function(item) {
var retour = {
170,7 → 270,7
return retour;
}));
} else {
afficherErreurGoogleMap(status);
lthis.afficherErreurGoogleMap(status);
}
});
},
177,7 → 277,7
// Cette partie est executee a la selection d'une adresse
select: function(event, ui) {
var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
deplacerMarker(latLng);
lthis.deplacerMarker(latLng);
}
});
 
188,7 → 288,6
$("#carte-recherche").on('mouseup', function(event) {// Pour Safari...
event.preventDefault();
});
 
$("#carte-recherche").keypress(function(e) {
if (e.which == 13) {
e.preventDefault();
196,19 → 295,7
});
};
 
//+----------------------------------------------------------------------------------------------------------+
// GOOGLE MAP
var map;
var marker;
var latLng;
var geocoder;
 
$(document).ready(function() {
initialiserGoogleMap();
initialiserAutocompleteCommune();
});
 
function afficherErreurGoogleMap(status) {
WidgetSaisie.prototype.afficherErreurGoogleMap = function(status) {
if (DEBUG) {
$('#dialogue-google-map .contenu').empty().append(
'<pre class="msg-erreur">'+
216,44 → 303,49
'</pre>');
afficherPanneau('#dialogue-google-map');
}
}
};
 
function surDeplacementMarker() {
trouverCommune(marker.getPosition());
mettreAJourMarkerPosition(marker.getPosition());
}
WidgetSaisie.prototype.surDeplacementMarker = function() {
this.trouverCommune(this.marker.getPosition());
this.mettreAJourMarkerPosition(this.marker.getPosition());
};
 
function surClickDansCarte(event) {
deplacerMarker(event.latLng);
}
WidgetSaisie.prototype.surClickDansCarte = function(event) {
this.deplacerMarker(event.latLng);
};
 
function geolocaliser() {
/**
* Place le marqueur aux coordonnées indiquées dans les champs "latitude" et "longitude"
*/
WidgetSaisie.prototype.geolocaliser = function() {
var latitude = $('#latitude').val();
var longitude = $('#longitude').val();
latLng = new google.maps.LatLng(latitude, longitude);
deplacerMarker(latLng);
}
this.latLng = new google.maps.LatLng(latitude, longitude);
this.deplacerMarker(this.latLng);
};
 
function initialiserGoogleMap(){
WidgetSaisie.prototype.initialiserGoogleMap = function() {
var latLng,
zoomDefaut;
// Carte @TODO mettre ça dans la config
if(NOM_SCI_REFERENTIEL == 'bdtre') {
var latLng = new google.maps.LatLng(-21.10, 55.30);// Réunion
var zoomDefaut = 7;
latLng = new google.maps.LatLng(-21.10, 55.30);// Réunion
zoomDefaut = 7;
} else if(NOM_SCI_REFERENTIEL == 'lbf') {
var latLng = new google.maps.LatLng(33.72211, 35.8603);// Liban
var zoomDefaut = 7;
latLng = new google.maps.LatLng(33.72211, 35.8603);// Liban
zoomDefaut = 7;
} else if(NOM_SCI_REFERENTIEL == 'bdtxa') {
var latLng = new google.maps.LatLng(14.6, -61.08334);// Fort-De-France
var zoomDefaut = 8;
latLng = new google.maps.LatLng(14.6, -61.08334);// Fort-De-France
zoomDefaut = 8;
} else if(NOM_SCI_REFERENTIEL == 'isfan') {
var latLng = new google.maps.LatLng(29.28358, 10.21884);// Afrique du Nord
var zoomDefaut = 4;
latLng = new google.maps.LatLng(29.28358, 10.21884);// Afrique du Nord
zoomDefaut = 4;
} else if(NOM_SCI_REFERENTIEL == 'apd') {
var latLng = new google.maps.LatLng(8.75624, 1.80176);// Afrique de l'Ouest et du Centre
var zoomDefaut = 4;
latLng = new google.maps.LatLng(8.75624, 1.80176);// Afrique de l'Ouest et du Centre
zoomDefaut = 4;
} else {
var latLng = new google.maps.LatLng(46.30871, 2.54395);// Centre de la France
var zoomDefaut = 5;
latLng = new google.maps.LatLng(46.30871, 2.54395);// Centre de la France
zoomDefaut = 5;
}
 
var options = {
278,15 → 370,15
});
 
// Création de la carte Google
map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
map.mapTypes.set('OSM', osmMapType);
this.map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
this.map.mapTypes.set('OSM', osmMapType);
 
// Création du Geocoder
geocoder = new google.maps.Geocoder();
this.geocoder = new google.maps.Geocoder();
 
// Marqueur google draggable
marker = new google.maps.Marker({
map: map,
this.marker = new google.maps.Marker({
map: this.map,
draggable: true,
title: 'Ma station',
icon: GOOGLE_MAP_MARQUEUR_URL,
293,7 → 385,7
position: latLng
});
 
initialiserMarker(latLng);
this.initialiserMarker(latLng);
 
// Tentative de geocalisation
if (navigator.geolocation) {
300,51 → 392,51
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
latLng = new google.maps.LatLng(latitude, longitude);
deplacerMarker(latLng);
this.latLng = new google.maps.LatLng(latitude, longitude);
this.deplacerMarker(this.latLng);
});
}
 
// intéraction carte
$("#geolocaliser").on('click', geolocaliser);
google.maps.event.addListener(marker, 'dragend', surDeplacementMarker);
google.maps.event.addListener(map, 'click', surClickDansCarte);
}
$("#geolocaliser").on('click', this.geolocaliser.bind(this));
google.maps.event.addListener(this.marker, 'dragend', this.surDeplacementMarker.bind(this));
google.maps.event.addListener(this.map, 'click', this.surClickDansCarte.bind(this));
};
 
function initialiserMarker(latLng) {
if (marker != undefined) {
marker.setPosition(latLng);
map.setCenter(latLng);
WidgetSaisie.prototype.initialiserMarker = function(latLng) {
if (this.marker != undefined) {
this.marker.setPosition(latLng);
this.map.setCenter(latLng);
}
}
};
 
function deplacerMarker(latLng) {
if (marker != undefined) {
marker.setPosition(latLng);
map.setCenter(latLng);
mettreAJourMarkerPosition(latLng);
trouverCommune(latLng);
WidgetSaisie.prototype.deplacerMarker = function(latLng) {
if (this.marker != undefined) {
this.marker.setPosition(latLng);
this.map.setCenter(latLng);
this.mettreAJourMarkerPosition(latLng);
this.trouverCommune(latLng);
}
}
};
 
function mettreAJourMarkerPosition(latLng) {
WidgetSaisie.prototype.mettreAJourMarkerPosition = function(latLng) {
var lat = latLng.lat().toFixed(5);
var lng = latLng.lng().toFixed(5);
remplirChampLatitude(lat);
remplirChampLongitude(lng);
}
this.remplirChampLatitude(lat);
this.remplirChampLongitude(lng);
};
 
function remplirChampLatitude(latDecimale) {
WidgetSaisie.prototype.remplirChampLatitude = function(latDecimale) {
var lat = Math.round(latDecimale * 100000) / 100000;
$('#latitude').val(lat);
}
};
 
function remplirChampLongitude(lngDecimale) {
WidgetSaisie.prototype.remplirChampLongitude = function(lngDecimale) {
var lng = Math.round(lngDecimale * 100000) / 100000;
$('#longitude').val(lng);
}
};
 
function trouverCommune(pos) {
WidgetSaisie.prototype.trouverCommune = function(pos) {
$(function() {
 
var url_service = SERVICE_NOM_COMMUNE_URL;
407,23 → 499,20
}
});
});
}
};
//+---------------------------------------------------------------------------------------------------------+
// IDENTITÉ
$(document).ready(function() {
$("#courriel").on('blur', requeterIdentite);
$("#courriel").on('keypress', testerLancementRequeteIdentite);
});
 
function testerLancementRequeteIdentite(event) {
WidgetSaisie.prototype.testerLancementRequeteIdentite = function(event) {
if (event.which == 13) {
requeterIdentite();
event.preventDefault();
event.stopPropagation();
this.requeterIdentite();
this.event.preventDefault();
this.event.stopPropagation();
}
}
};
 
function requeterIdentite() {
WidgetSaisie.prototype.requeterIdentite = function() {
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/
441,12 → 530,12
$("#prenom, #nom, #courriel_confirmation").attr('disabled', 'disabled');
$("#date").focus();
} else {
surErreurCompletionCourriel();
lthis.surErreurCompletionCourriel();
}
},
error : function(jqXHR, textStatus, errorThrown) {
//console.log('ERREUR :'+textStatus);
surErreurCompletionCourriel();
lthis.surErreurCompletionCourriel();
},
complete : function(jqXHR, textStatus) {
//console.log('COMPLETE :'+textStatus);
454,22 → 543,17
$("#zone-courriel-confirmation").removeClass("hidden");
}
});
}
};
 
function surErreurCompletionCourriel() {
WidgetSaisie.prototype.surErreurCompletionCourriel = function() {
$("#prenom, #nom, #courriel_confirmation").val('');
$("#prenom, #nom, #courriel_confirmation").removeAttr('disabled');
afficherPanneau("#dialogue-courriel-introuvable");
}
};
//+---------------------------------------------------------------------------------------------------------+
//FORMULAIRE
$(document).ready(function() {
if (OBS_ID != '') {
chargerInfoObs();
}
});
 
function chargerInfoObs() {
WidgetSaisie.prototype.chargerInfoObs = function() {
var urlObs = SERVICE_OBS_URL + '/' + OBS_ID;
$.ajax({
url: urlObs,
476,7 → 560,7
type: 'GET',
success: function(data, textStatus, jqXHR) {
if (data != undefined && data != "") {
prechargerForm(data);
this.prechargerForm(data);
}
// TODO: voir s'il est pertinent d'indiquer quelque chose en cas d'erreur ou d'obs
// inexistante
485,9 → 569,9
// TODO: cf TODO ci-dessus
}
});
}
};
 
function prechargerForm(data) {
WidgetSaisie.prototype.prechargerForm = function(data) {
 
$("#milieu").val(data.milieu);
 
501,58 → 585,14
 
if(data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude")) {
var latLng = new google.maps.LatLng(data.latitude, data.longitude);
mettreAJourMarkerPosition(latLng);
marker.setPosition(latLng);
map.setCenter(latLng);
map.setZoom(16);
this.mettreAJourMarkerPosition(latLng);
this.marker.setPosition(latLng);
this.map.setCenter(latLng);
this.map.setZoom(16);
}
}
};
 
var obsNbre = 0;
 
$(document).ready(function() {
$(".alert .close").on('click', fermerPanneauAlert);
 
$("[rel=tooltip]").tooltip('enable');
$("#btn-aide").on('click', basculerAffichageAide);
 
$("#prenom").on("change", formaterPrenom);
 
$("#nom").on("change", formaterNom);
 
configurerDatePicker();
 
ajouterAutocompletionNoms();
 
configurerFormValidator();
definirReglesFormValidator();
 
$("#courriel_confirmation").on('paste', bloquerCopierCollerCourriel);
 
$("a.afficher-coord").on('click', basculerAffichageCoord);
 
$("#ajouter-obs").on('click', ajouterObs);
 
$(".obs-nbre").on('changement', surChangementNbreObs);
 
$("body").on('click', ".supprimer-obs", supprimerObs);
 
$("#transmettre-obs").on('click', transmettreObs);
 
$("#referentiel").on('change', surChangementReferentiel);
 
$("body").on('click', ".defilement-miniatures-gauche", function(event) {
event.preventDefault();
defilerMiniatures($(this));
});
 
$("body").on('click', ".defilement-miniatures-droite", function(event) {
event.preventDefault();
defilerMiniatures($(this));
});
});
 
function configurerFormValidator() {
WidgetSaisie.prototype.configurerFormValidator = function() {
$.validator.addMethod(
"dateCel",
function (value, element) {
577,7 → 617,7
if ($(element).attr('id') == 'taxon') {
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()) {
if ($("#taxon").data("value") != $("#taxon").val()) {
$("#taxon").data("numNomSel","");
$("#taxon").data("nomRet","");
$("#taxon").data("numNomRet","");
594,9 → 634,9
}
}
});
}
};
 
function definirReglesFormValidator() {
WidgetSaisie.prototype.definirReglesFormValidator = function() {
$("#form-observateur").validate({
rules: {
courriel : {
621,9 → 661,9
taxon : "required"
}
});
}
};
 
function configurerDatePicker() {
WidgetSaisie.prototype.configurerDatePicker = function() {
$.datepicker.setDefaults($.datepicker.regional["fr"]);
$("#date").datepicker({
dateFormat: "dd/mm/yy",
635,17 → 675,17
showButtonPanel: true
});
$("img.ui-datepicker-trigger").appendTo("#date-icone");
}
};
 
function fermerPanneauAlert() {
WidgetSaisie.prototype.fermerPanneauAlert = function() {
$(this).parentsUntil(".zone-alerte", ".alert").hide();
}
};
 
function formaterNom() {
WidgetSaisie.prototype.formaterNom = function() {
$(this).val($(this).val().toUpperCase());
}
};
 
function formaterPrenom() {
WidgetSaisie.prototype.formaterPrenom = function() {
var prenom = new Array();
var mots = $(this).val().split(' ');
for (var i = 0; i < mots.length; i++) {
665,9 → 705,9
}
}
$(this).val(prenom.join(' '));
}
};
 
function basculerAffichageAide() {
WidgetSaisie.prototype.basculerAffichageAide = function() {
if ($(this).hasClass('btn-warning')) {
$("[rel=tooltip]").tooltip('enable');
$(this).removeClass('btn-warning').addClass('btn-success');
677,59 → 717,65
$(this).removeClass('btn-success').addClass('btn-warning');
$('#btn-aide-txt', this).text("Activer l'aide");
}
}
};
 
function bloquerCopierCollerCourriel() {
WidgetSaisie.prototype.bloquerCopierCollerCourriel = function() {
afficherPanneau("#dialogue-bloquer-copier-coller");
return false;
}
};
 
function basculerAffichageCoord() {
WidgetSaisie.prototype.basculerAffichageCoord = function() {
$("a.afficher-coord").toggle();
$("#coordonnees-geo").toggle('slow');
//valeur false pour que le lien ne soit pas suivi
return false;
}
};
 
function ajouterObs() {
if (validerFormulaire() == true) {
obsNbre = obsNbre + 1;
$(".obs-nbre").text(obsNbre);
/**
* Ajoute une observation saisie dans le formulaire à la liste des observations à transmettre
*/
WidgetSaisie.prototype.ajouterObs = function() {
if (this.validerFormulaire() == true) {
this.obsNbre = this.obsNbre + 1;
$(".obs-nbre").text(this.obsNbre);
$(".obs-nbre").triggerHandler('changement');
afficherObs();
stockerObsData();
supprimerMiniatures();
this.afficherObs();
this.stockerObsData();
this.supprimerMiniatures();
if(!ESPECE_IMPOSEE) {
$("#taxon").val("");
$("#taxon").data("numNomSel",undefined);
}
$('#barre-progression-upload').attr('aria-valuemax', obsNbre);
$('#barre-progression-upload .sr-only').text('0/'+obsNbre+" observations transmises");
$('#barre-progression-upload').attr('aria-valuemax', this.obsNbre);
$('#barre-progression-upload .sr-only').text('0/'+this.obsNbre+" observations transmises");
} else {
afficherPanneau('#dialogue-form-invalide');
}
}
};
 
function afficherObs() {
/**
* Affiche une observation dans la liste des observations à transmettre
*/
WidgetSaisie.prototype.afficherObs = function() {
$("#liste-obs").prepend(
'<div id="obs'+obsNbre+'" class="row-fluid obs obs'+obsNbre+'">'+
'<div id="obs'+this.obsNbre+'" class="row-fluid obs obs'+this.obsNbre+'">'+
'<div class="span12">'+
'<div class="well">'+
'<div class="obs-action pull-right" rel="tooltip" data-placement="bottom" '+
'title="Supprimer cette observation de la liste à transmettre">'+
'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
'<button class="btn btn-danger supprimer-obs" value="'+this.obsNbre+'" title="'+this.obsNbre+'">'+
'<i class="icon-trash icon-white"></i>'+
'</button>'+
'</div> '+
'<div class="row-fluid">'+
'<div class="thumbnail span2">'+
ajouterImgMiniatureAuTransfert()+
this.ajouterImgMiniatureAuTransfert()+
'</div>'+
'<div class="span9">'+
'<ul class="unstyled">'+
'<li>'+
'<span class="nom-sci">'+$("#taxon").val()+'</span> '+
ajouterNumNomSel()+'<span class="referentiel-obs">'+
this.ajouterNumNomSel()+'<span class="referentiel-obs">'+
($("#taxon").data("numNomSel") == undefined ? '' : '['+NOM_SCI_REFERENTIEL+']')+'</span>'+
' observé à '+
'<span class="commune">'+$('#commune-nom').text()+'</span> '+
751,10 → 797,11
'</div>'+
'</div>'+
'</div>');
}
};
 
function stockerObsData() {
$("#liste-obs").data('obsId'+obsNbre, {
WidgetSaisie.prototype.stockerObsData = function() {
var lthis = this;
$("#liste-obs").data('obsId'+this.obsNbre, {
'date' : $("#date").val(),
'notes' : $("#notes").val(),
 
775,47 → 822,45
'milieu' : $("#milieu").val(),
 
//Ajout des champs images
'image_nom' : getNomsImgsOriginales(),
'image_b64' : getB64ImgsOriginales()
'image_nom' : lthis.getNomsImgsOriginales(),
'image_b64' : lthis.getB64ImgsOriginales()
});
}
};
 
function surChangementReferentiel() {
WidgetSaisie.prototype.surChangementReferentiel = function() {
NOM_SCI_REFERENTIEL = $('#referentiel').val();
$('#taxon').val('');
initialiserAutocompleteCommune();
initialiserGoogleMap();
}
this.initialiserAutocompleteCommune();
this.initialiserGoogleMap();
};
 
function surChangementNbreObs() {
if (obsNbre == 0) {
WidgetSaisie.prototype.surChangementNbreObs = function() {
if (this.obsNbre == 0) {
$("#transmettre-obs").attr('disabled', 'disabled');
$("#ajouter-obs").removeAttr('disabled');
} else if (obsNbre > 0 && obsNbre < OBS_MAX_NBRE) {
} else if (this.obsNbre > 0 && this.obsNbre < OBS_MAX_NBRE) {
$("#transmettre-obs").removeAttr('disabled');
$("#ajouter-obs").removeAttr('disabled');
} else if (obsNbre >= OBS_MAX_NBRE) {
} else if (this.obsNbre >= OBS_MAX_NBRE) {
$("#ajouter-obs").attr('disabled', 'disabled');
afficherPanneau("#dialogue-bloquer-creer-obs");
}
}
};
 
var nbObsEnCours = 1;
var totalObsATransmettre = 0;
function transmettreObs() {
WidgetSaisie.prototype.transmettreObs = function() {
var observations = $("#liste-obs").data();
if (observations == undefined || jQuery.isEmptyObject(observations)) {
afficherPanneau("#dialogue-zero-obs");
} else {
nbObsEnCours = 1;
nbObsTransmises = 0;
totalObsATransmettre = $.map(observations, function(n, i) { return i; }).length;
depilerObsPourEnvoi();
this.nbObsEnCours = 1;
this.nbObsTransmises = 0;
this.totalObsATransmettre = $.map(observations, function(n, i) { return i; }).length;
this.depilerObsPourEnvoi();
}
return false;
}
};
 
function depilerObsPourEnvoi() {
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
823,12 → 868,12
// 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) {
obsATransmettre = new Object();
obsATransmettre = {
'projet' : TAG_PROJET,
'tag-obs' : TAG_OBS,
'tag-img' : TAG_IMG
};
 
obsATransmettre['projet'] = TAG_PROJET;
obsATransmettre['tag-obs'] = TAG_OBS;
obsATransmettre['tag-img'] = TAG_IMG;
 
var utilisateur = new Object();
utilisateur.id_utilisateur = $("#id_utilisateur").val();
utilisateur.prenom = $("#prenom").val();
838,28 → 883,28
obsATransmettre[obsNum] = observations[obsNum];
var idObsNumerique = obsNum.replace('obsId', '');
if(idObsNumerique != "") {
envoyerObsAuCel(idObsNumerique, obsATransmettre);
this.envoyerObsAuCel(idObsNumerique, obsATransmettre);
}
 
break;
}
}
};
 
var nbObsTransmises = 0;
function mettreAJourProgression() {
nbObsTransmises++;
var pct = (nbObsTransmises/totalObsATransmettre)*100;
$('#barre-progression-upload').attr('aria-valuenow', nbObsTransmises);
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(nbObsTransmises+"/"+totalObsATransmettre+" observations transmises");
$('#barre-progression-upload .sr-only').text(this.nbObsTransmises+"/"+this.totalObsATransmettre+" observations transmises");
 
if(obsNbre == 0) {
if(this.obsNbre == 0) {
$('.progress').removeClass('active');
$('.progress').removeClass('progress-striped');
}
}
};
 
function envoyerObsAuCel(idObs, observation) {
WidgetSaisie.prototype.envoyerObsAuCel = function(idObs, observation) {
var lthis = this;
var erreurMsg = "";
$.ajax({
url : SERVICE_SAISIE_URL,
877,13 → 922,13
success : function(data, textStatus, jqXHR) {
// mise à jour du nombre d'obs à transmettre
// et suppression de l'obs
supprimerObsParId(idObs);
nbObsEnCours++;
lthis.supprimerObsParId(idObs);
this.nbObsEnCours++;
// mise à jour du statut
mettreAJourProgression();
if(obsNbre > 0) {
lthis.mettreAJourProgression();
if(this.obsNbre > 0) {
// dépilement de la suivante
depilerObsPourEnvoi();
lthis.depilerObsPourEnvoi();
}
},
statusCode : {
927,18 → 972,18
.html());
$("#dialogue-obs-transaction-ko").show();
$("#chargement").hide();
initialiserBarreProgression();
lthis.initialiserBarreProgression();
} else {
if (DEBUG) {
$("#dialogue-obs-transaction-ok .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
}
if(obsNbre == 0) {
if(this.obsNbre == 0) {
setTimeout(function() {
$("#chargement").hide();
$('#dialogue-obs-transaction-ok .alert-txt').append($('#tpl-transmission-ok').clone().html());
$("#dialogue-obs-transaction-ok").show();
window.location.hash = "dialogue-obs-transaction-ok";
initialiserObs();
lthis.initialiserObs();
}, 1500);
 
}
945,24 → 990,24
}
}
});
}
};
 
function validerFormulaire() {
WidgetSaisie.prototype.validerFormulaire = function() {
$observateur = $("#form-observateur").valid();
$station = $("#form-station").valid();
$obs = $("#form-obs").valid();
return ($observateur == true && $station == true && $obs == true) ? true : false;
}
};
 
function getNomsImgsOriginales() {
WidgetSaisie.prototype.getNomsImgsOriginales = function() {
var noms = new Array();
$(".miniature-img").each(function() {
noms.push($(this).attr('alt'));
});
return noms;
}
};
 
function getB64ImgsOriginales() {
WidgetSaisie.prototype.getB64ImgsOriginales = function() {
var b64 = new Array();
$(".miniature-img").each(function() {
if ($(this).hasClass('b64')) {
973,58 → 1018,63
});
 
return b64;
}
};
 
function supprimerObs() {
var obsId = $(this).val();
WidgetSaisie.prototype.supprimerObs = function(selector) {
var obsId = $(selector).val();
// Problème avec IE 6 et 7
if (obsId == "Supprimer") {
obsId = $(this).attr("title");
obsId = $(selector).attr("title");
}
supprimerObsParId(obsId);
}
this.supprimerObsParId(obsId);
};
 
function supprimerObsParId(obsId) {
obsNbre = obsNbre - 1;
$(".obs-nbre").text(obsNbre);
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);
}
};
 
function initialiserBarreProgression() {
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');
}
};
 
function initialiserObs() {
obsNbre = 0;
nbObsTransmises = 0;
nbObsEnCours = 0;
totalObsATransmettre = 0;
initialiserBarreProgression();
$(".obs-nbre").text(obsNbre);
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").hide();
}
};
 
function ajouterImgMiniatureAuTransfert() {
var html = '';
var miniatures = '';
var premiere = true;
/**
* 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 = '',
miniatures = '',
premiere = true;
if ($("#miniatures img").length >= 1) {
$("#miniatures img").each(function() {
var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee';
premiere = false;
var css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature';
var src = $(this).attr("src");
var alt = $(this).attr("alt");
miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
var css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature',
src = $(this).attr("src"),
alt = $(this).attr("alt"),
//miniature = '<img class="'+css+' '+visible+'" alt="'+alt+'"src="'+src+'" />';
miniature = '<div class="'+css+' '+visible+'" alt="'+alt+'" style="background-image: url('+src+')" ></div>';
miniatures += miniature;
});
visible = ($("#miniatures img").length > 1) ? '' : 'defilement-miniatures-cache';
1038,11 → 1088,11
html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
}
return html;
}
};
 
function defilerMiniatures(element) {
WidgetSaisie.prototype.defilerMiniatures = function(element) {
 
var miniatureSelectionne = element.siblings("img.miniature-selectionnee");
var miniatureSelectionne = element.siblings("div.miniature-selectionnee");
miniatureSelectionne.removeClass('miniature-selectionnee');
miniatureSelectionne.addClass('miniature-cachee');
var miniatureAffichee = miniatureSelectionne;
1063,9 → 1113,9
//console.log(miniatureAffichee);
miniatureAffichee.addClass('miniature-selectionnee');
miniatureAffichee.removeClass('miniature-cachee');
}
};
 
function ajouterNumNomSel() {
WidgetSaisie.prototype.ajouterNumNomSel = function() {
var nn = '';
if ($("#taxon").data("numNomSel") == undefined) {
nn = '<span class="alert-error">[non lié au référentiel]</span>';
1073,20 → 1123,21
nn = '<span class="nn">[nn'+$("#taxon").data("numNomSel")+']</span>';
}
return nn;
}
};
 
//+---------------------------------------------------------------------------------------------------------+
// AUTO-COMPLÉTION Noms Scientifiques
 
function ajouterAutocompletionNoms() {
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 = getUrlAutocompletionNomsSci();
var url = lthis.getUrlAutocompletionNomsSci();
$.getJSON(url, requete, function(data) {
var suggestions = traiterRetourNomsSci(data);
var suggestions = lthis.traiterRetourNomsSci(data);
add(suggestions);
});
}
1102,16 → 1153,16
$("#taxon").removeClass('ns-retenu');
}
});
}
};
 
function getUrlAutocompletionNomsSci() {
WidgetSaisie.prototype.getUrlAutocompletionNomsSci = function() {
var mots = $('#taxon').val();
var url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_REFERENTIEL);
url = url.replace('{masque}', mots);
return url;
}
};
 
function traiterRetourNomsSci(data) {
WidgetSaisie.prototype.traiterRetourNomsSci = function(data) {
var suggestions = [];
if (data.resultat != undefined) {
$.each(data.resultat, function(i, val) {
1144,7 → 1195,7
}
 
return suggestions;
}
};
 
/*
* jQuery UI Autocomplete HTML Extension
1160,7 → 1211,7
var proto = $.ui.autocomplete.prototype,
initSource = proto._initSource;
 
function filter( array, term ) {
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() );