Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1345 → Rev 1346

/trunk/widget/modules/saisie/squelettes/sauvages/js/sauvages.js
12,6 → 12,7
}
return false;
}
 
// TODO : voir si cette fonction est bien utile. Résoud le pb d'un warning sous chrome.
(function(){
// remove layerX and layerY
28,147 → 29,437
//+----------------------------------------------------------------------------------------------------------+
//UPLOAD PHOTO : Traitement de l'image
$(document).ready(function() {
//prepare the form when the DOM is ready
//create service object(proxy) using SMD (generated by the json result)
var options = {
success: afficherMiniature, // post-submit callback
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
resetForm: true // reset the form after successful submit
};
$("#effacer-miniature").click(function () {
supprimerMiniature();
});
if (HTML5 && window.File && window.FileReader && isCanvasSupported()) {
if (DEBUG) {
console.log("Support OK pour : API File et Canvas.");
}
$('#fichier').bind('change', function(e) {
afficherMiniatureHtml5(e);
});
} else {
$("#fichier").bind('change', function (e) {
arreter(e);
var options = {
success: afficherMiniature, // post-submit callback
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
resetForm: true // reset the form after successful submit
};
$("#form-upload").ajaxSubmit(options);
return false;
});
}
});
function isCanvasSupported(){
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
}
 
// post-submit callback
function afficherMiniature(reponse) {
// 'responseXML' is the XML document returned by the server; we use
// jQuery to extract the content of the message node from the XML doc
function afficherMiniatureHtml5(evt) {
supprimerMiniature();
var selectedfiles = evt.target.files;
var f = selectedfiles[0];// Nous récupérons seulement le premier fichier.
if (f.type != 'image/jpeg') {
var message = "Seule les images JPEG sont supportées.";
$("#miniature-msg").append(message);
} else if (f.size > 5242880) {
var message = "Votre image à un poids supérieur à 5Mo.";
$("#miniature-msg").append(message);
} else {
var reader = new FileReader();
// Lit le fichier image commune url de données
reader.readAsDataURL(f);
var imgNom = f.name;
// Closure pour capturer les infos du fichier
reader.onload = (function(theFile) {
return function(e) {
// Rendre la miniature
var imageBase64 = e.target.result;
//$("#miniature").append('<img id="miniature-img" class="miniature b64" src="'+imageBase64+'" alt="'+imgNom+'"/>');
// HTML5 Canvas
var img = new Image();
img.src = imageBase64;
img.alt = imgNom;
img.onload = function() {
transformerImgEnCanvas(this, 100, 100, false, 'white');
};
};
})(f);
}
$("#effacer-miniature").show();
}
function transformerImgEnCanvas(img, thumbwidth, thumbheight, crop, background) {
var canvas = document.createElement('canvas');
canvas.width = thumbwidth;
canvas.height = thumbheight;
var dimensions = calculerDimenssions(img.width, img.height, thumbwidth, thumbheight);
if (crop) {
canvas.width = dimensions.w;
canvas.height = dimensions.h;
dimensions.x = 0;
dimensions.y = 0;
}
cx = canvas.getContext('2d');
if (background !== 'transparent') {
cx.fillStyle = background;
cx.fillRect(0, 0, thumbwidth, thumbheight);
}
cx.drawImage(img, dimensions.x, dimensions.y, dimensions.w, dimensions.h);
afficherMiniatureCanvas(img, canvas);
}
 
function calculerDimensions(imagewidth, imageheight, thumbwidth, thumbheight) {
var w = 0, h = 0, x = 0, y = 0,
widthratio = imagewidth / thumbwidth,
heightratio = imageheight / thumbheight,
maxratio = Math.max(widthratio, heightratio);
if (maxratio > 1) {
w = imagewidth / maxratio;
h = imageheight / maxratio;
} else {
w = imagewidth;
h = imageheight;
}
x = (thumbwidth - w) / 2;
y = (thumbheight - h) / 2;
return {w:w, h:h, x:x, y:y};
}
 
function afficherMiniatureCanvas(imgB64, canvas) {
var url = canvas.toDataURL('image/jpeg' , 0.8);
var alt = imgB64.alt;
var title = Math.round(url.length / 1000 * 100) / 100 + ' KB';
var miniature = '<img id="miniature-img" class="miniature b64-canvas" src="'+url+'" alt="'+alt+'" title="'+title+'" />';
$("#miniature").append(miniature);
$("#miniature-img").data('b64', imgB64.src);
}
 
function afficherMiniature(reponse) {
supprimerMiniature();
if (DEBUG) {
var debogage = $("debogage", reponse).text();
console.log("Débogage upload : "+debogage);
}
var message = $("message", reponse).text();
if (message != '') {
$("#miniature-msg").append(message);
} else {
var miniatureUrl = $("miniature-url", reponse).text();
var imgNom = $("image-nom", reponse).text();
$("#miniature").empty();
$("#miniature").append('<img id="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>');
console.log(imgNom);
console.log(miniatureUrl);
};
$("#form-upload").submit(function() {
// inside event callbacks 'this' is the DOM element so we first
// wrap it in a jQuery object and then invoke ajaxSubmit
$(this).ajaxSubmit(options);
// !!! Important !!!
// always return false to prevent standard browser submit and page navigation
return false;
});
});
}
$("#effacer-miniature").show();
}
 
function supprimerMiniature() {
$("#miniature").empty();
$("#miniature-msg").empty();
$("#effacer-miniature").hide();
}
 
//+----------------------------------------------------------------------------------------------------------+
// GOOGLE MAP
var geocoder;
var map;
// marqueurs de début et fin de rue
var marker;
var markerFin;
// coordonnées de début et fin de rue
var latLng;
var latLngFin;
// ligne reliant les deux points de début et fin
var ligneRue;
// Booléen de test afin de ne pas faire apparaitre la fin de rue à la premiere localisation
var premierDeplacement = true;
 
function initialize(){
function initialiserGoogleMap(){
// Carte
var latLng = new google.maps.LatLng(43.29545, 5.37458);
$('#adresse').val('1 rue de la canebiere, 13001');
$('#latitude').val('43.29545');
$('#longitude').val('5.37458');
latLng = new google.maps.LatLng(48.8543, 2.3483);// Paris
if (VILLE == 'Marseille') {
latLng = new google.maps.LatLng(43.29545, 5.37458);
} else if (VILLE == 'Montpellier') {
latLng = new google.maps.LatLng(43.61077, 3.87672);
}
latLngFin = latLng;
var options = {
zoom: 16,
center: latLng,
mapTypeId: google.maps.MapTypeId.SATELLITE
mapTypeId: google.maps.MapTypeId.HYBRID,
mapTypeControlOptions: {
mapTypeIds: ['OSM', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN]}
};
 
// Ajout de la couche OSM à la carte
osmMapType = new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
return "http://tile.openstreetmap.org/" +
zoom + "/" + coord.x + "/" + coord.y + ".png";
},
tileSize: new google.maps.Size(256, 256),
isPng: true,
alt: 'OpenStreetMap',
name: 'OSM',
maxZoom: 19
});
map = new google.maps.Map(document.getElementById("map_canvas"), options); //affiche la google map dans la div map_canvas
// 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);
// Geocodeur
geocoder = new google.maps.Geocoder();
console.log(GOOGLE_MAP_MARQUEUR_URL);
 
// Marqueur google draggable
marker = new google.maps.Marker({
map: map,
draggable: true,
title: 'Ma station',
icon: GOOGLE_MAP_MARQUEUR_URL,
title: 'Début de la portion de rue étudiée',
icon: MARQUEUR_ICONE_DEBUT_URL,
position: latLng
});
deplacerMarker(latLng);
// Tentative de geocalisation
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
latLng = new google.maps.LatLng(latitude, longitude);
latLngFin = latLng;
// si l'utilisateur géolocalise sa ville alors le premier déplacement doit être réinitialisé
premierDeplacement = true;
deplacerMarker(latLng);
});
}
}
 
 
var valeurDefautRechercheLieu = "";
 
$(document).ready(function() {
initialize();
$(function() {
// Tentative de geocalisation
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var altitude = position.coords.altitude;
var geocalisation = new google.maps.LatLng(latitude, longitude);
marker.setPosition(geocalisation);
map.setCenter(geocalisation);
$('#latitude').val(marker.getPosition().lat());
$('#longitude').val(marker.getPosition().lng());
$('#adresse').val(codeLatLng(marker.getPosition()));
});
}
// Autocompletion du champ adresse
$("#adresse").autocomplete({
//Cette partie utilise geocoder pour extraire des valeurs d'adresse
source: function(request, response) {
geocoder.geocode( {'address': request.term }, function(results, status) {
initialiserGoogleMap();
gererAffichageValeursParDefaut();
 
// Autocompletion du champ adresse
$("#rue").autocomplete({
//Cette partie utilise geocoder pour extraire des valeurs d'adresse
source: function(request, response) {
geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
response($.map(results, function(item) {
return {
label: item.formatted_address,
value: item.formatted_address,
var rue = "";
$.each(item.address_components, function(){
if (this.types[0] == "route" || this.types[0] == "street_address" ) {
rue = this.short_name;
}
});
var retour = {
label: item.formatted_address,
value: rue,
latitude: item.geometry.location.lat(),
longitude: item.geometry.location.lng()
}
};
return retour;
}));
})
},
// Cette partie est executee a la selection d'une adresse
select: function(event, ui) {
$("#latitude").val(ui.item.latitude);
$("#longitude").val(ui.item.longitude);
var location = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
marker.setPosition(location);
map.setCenter(location);
map.setZoom(20);
}
});
 
// Ajoute un ecouteur sur le marker pour le reverse geocoding
google.maps.event.addListener(marker, 'drag', function() {
geocoder.geocode({'latLng': marker.getPosition()}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
$('#adresse').val(results[0].formatted_address);
$('#latitude').val(Math.round(marker.getPosition().lat()*100000)/100000);
$('#longitude').val(Math.round(marker.getPosition().lng()*100000)/100000);
}
} else {
afficherErreurGoogleMap(status);
}
});
});
},
// Cette partie est executee a la selection d'une adresse
select: function(event, ui) {
latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
deplacerMarker(latLng);
afficherEtapeGeolocalisation(2);
}
});
$("#geolocaliser").click(function() {
var latitude = $('#latitude').val();
var longitude = $('#longitude').val();
latLng = new google.maps.LatLng(latitude, longitude);
deplacerMarker(latLng);
});
google.maps.event.addListener(marker, 'dragend', function() {
trouverCommune(marker.getPosition());
mettreAJourMarkerPosition(marker.getPosition());
deplacerMarker(marker.getPosition());
});
google.maps.event.addListener(map, 'click', function(event) {
deplacerMarker(event.latLng);
});
});
 
// Transforme les coordonnés en adresse (reverse geocoder)
function codeLatLng() {
var lat = parseFloat(document.getElementById("latitude").value);
var lng = parseFloat(document.getElementById("longitude").value);
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
marker.setPosition(latlng);
map.setCenter(latlng);
$('#adresse').val(results[0].formatted_address);
function gererAffichageValeursParDefaut() {
afficherEtapeGeolocalisation(1);
}
 
function afficherEtapeGeolocalisation(numEtape) {
$(".liste_indication_geolocalisation").children().hide();
$(".liste_indication_geolocalisation :nth-child("+numEtape+")").show();
}
 
function afficherErreurGoogleMap(status) {
if (DEBUG) {
$("#dialogue-google-map").empty();
$("#dialogue-google-map").append('<pre class="msg-erreur">'+
"Le service de Géocodage de Google Map a échoué à cause de l'erreur : "+status+
'</pre>');
$("#dialogue-google-map").dialog();
}
}
 
function deplacerMarker(latLng) {
if (marker != undefined) {
marker.setPosition(latLng);
map.setCenter(latLng);
//map.setZoom(18);
trouverCommune(latLng);
if(!premierDeplacement) {
if(markerFin != undefined) {
markerFin.setMap(null);
}
latLngFin = new google.maps.LatLng(latLng.lat(), latLng.lng() + 0.0010);
// Marqueur google draggable
markerFin = new google.maps.Marker({
map: map,
draggable: true,
title: 'Fin de la portion de rue étudiée',
icon: MARQUEUR_ICONE_FIN_URL,
position: latLngFin
});
google.maps.event.addListener(markerFin, 'dragend', function() {
dessinerLigneRue(marker.getPosition(), markerFin.getPosition());
latLngFin = markerFin.getPosition();
latLngCentre = new google.maps.LatLng((latLngFin.lat() + latLng.lat())/2, (latLngFin.lng() + latLng.lng())/2);
mettreAJourMarkerPosition(latLngCentre);
afficherEtapeGeolocalisation(4);
});
dessinerLigneRue(latLng, latLngFin);
latLngCentre = new google.maps.LatLng((latLngFin.lat() + latLng.lat())/2, (latLngFin.lng() + latLng.lng())/2);
mettreAJourMarkerPosition(latLng);
afficherEtapeGeolocalisation(3);
} else {
alert("Geocoder failed due to: " + status);
mettreAJourMarkerPosition(latLng);
}
premierDeplacement = false;
}
}
 
function dessinerLigneRue(pointDebut, pointFin) {
if(ligneRue != undefined) {
ligneRue.setMap(null);
}
ligneRue = new google.maps.Polyline({
path: [pointDebut, pointFin],
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
 
ligneRue.setMap(map);
}
 
function mettreAJourMarkerPosition(latLng) {
var lat = latLng.lat().toFixed(5);
var lng = latLng.lng().toFixed(5);
remplirChampLatitude(lat);
remplirChampLongitude(lng);
}
 
function remplirChampLatitude(latDecimale) {
var lat = Math.round(latDecimale*100000)/100000;
$('#latitude').val(lat);
}
 
function remplirChampLongitude(lngDecimale) {
var lng = Math.round(lngDecimale*100000)/100000;
$('#longitude').val(lng);
}
 
function trouverCommune(pos) {
$(function() {
var urlNomCommuneFormatee = SERVICE_NOM_COMMUNE_URL.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
$.ajax({
url : urlNomCommuneFormatee,
type : "GET",
dataType : "jsonp",
beforeSend : function() {
$(".commune-info").empty();
$("#dialogue-erreur").empty();
},
success : function(data, textStatus, jqXHR) {
$(".commune-info").empty();
if(data != null) {
$("#commune-nom").append(data.nom);
$("#commune-code-insee").append(data.codeINSEE);
$("#marqueur-commune").data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
}
},
statusCode : {
500 : function(jqXHR, textStatus, errorThrown) {
if (DEBUG) {
$("#dialogue-erreur").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 = "";
if (reponse != null) {
$.each(reponse, function (cle, valeur) {
erreurMsg += valeur + "<br />";
});
}
$("#dialogue-erreur").append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
}
}
},
error : function(jqXHR, textStatus, errorThrown) {
if (DEBUG) {
$("#dialogue-erreur").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
reponse = jQuery.parseJSON(jqXHR.responseText);
var erreurMsg = "";
if (reponse != null) {
$.each(reponse, function (cle, valeur) {
erreurMsg += valeur + "<br />";
});
}
$("#dialogue-erreur").append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
}
},
complete : function(jqXHR, textStatus) {
if (DEBUG && jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
var debugMsg = "";
debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
if (debugInfos != null) {
$.each(debugInfos, function (cle, valeur) {
debugMsg += valeur + "<br />";
});
$("#dialogue-erreur").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
}
}
if ($("#dialogue-erreur .msg").length > 0) {
$("#dialogue-erreur").dialog();
}
}
});
});
}
 
175,6 → 466,8
//+---------------------------------------------------------------------------------------------------------+
// FORMULAIRE
$(document).ready(function() {
$("#date").datepicker($.datepicker.regional['fr']);
$("form#saisie-obs").validate({
rules: {
courriel : {
184,8 → 477,11
required : true,
equalTo: "#courriel"
},
milieu : "required",
adresse : "required",
rue_cote : "required",
"milieu[]" : {
required: true,
minlength: 1
},
latitude : {
required: true,
range: [-90, 90]},
196,40 → 492,24
required: true,
date: true},
taxon : "required"
},
messages: {
"milieu[]": "Vous devez sélectionner au moins un milieu"
}
});
$("#date").datepicker($.datepicker.regional['fr']);
$("#courriel_confirmation").bind('paste', function(e) {
$("#dialogue-bloquer-copier-coller").dialog();
return false;
});
/*---Afficher/cacher les coordonnees geographiques----*/
var showText=" -Afficher-";
var hideText=" -Masquer- ";
//créer le lien afficher/masquer
$("#coordonnees-geo").before("<a href='#' id='toogle_link'>"+showText+"</a>")
//masquer le contenu
$("#masque").hide();
//bascule le texte d'afficher à masquer
$("a#toogle_link").click(function() {
//changer le texte du lien
if($('a#toogle_link').text()==showText){
$('a#toogle_link').text(hideText);
} else{
$('a#toogle_link').text(showText);
}
//basuler l'affichage
$('#masque').toggle('slow');
//valeur false pour que le lien ne soit pas suivi
return false
$("a.afficher-coord").click(function() {
$("a.afficher-coord").toggle();
$("#coordonnees-geo").toggle('slow');
//valeur false pour que le lien ne soit pas suivi
return false;
});
 
/*------obs-----------*/
var obsNumero = 0;
$("#ajouter-obs").bind('click', function(e) {
236,6 → 516,14
if ($("#saisie-obs").valid() == false) {
$("#dialogue-form-invalide").dialog();
} else {
var milieux = [];
$('input:checked["name=milieux[]"]').each(function() {
milieux.push($(this).val());
});
var rue = ($("#rue").val() == valeurDefautRechercheLieu) ? 'non renseigné(e)' : $("#rue").val();
//rassemble les obs dans un tableau html
obsNumero = obsNumero + 1;
$("#liste-obs tbody").append(
242,13 → 530,12
'<tr id="obs'+obsNumero+'" class="obs">'+
'<td>'+obsNumero+'</td>'+
'<td>'+$("#date").val()+'</td>'+
'<td>'+$("#adresse").val()+'</td>'+
'<td>'+rue+'</td>'+
'<td>'+$("#taxon option:selected").text()+'</td>'+
'<td>'+$('input[name=milieu]:checked').val()+'</td>'+
'<td>'+$("#latitude").val()+'</td>'+
'<td>'+$("#longitude").val()+'</td>'+
'<td>'+milieux.join(',<br />')+'</td>'+
'<td>'+$("#latitude").val()+' / '+$("#longitude").val()+'</td>'+
//Ajout du champ photo
'<td><img class="miniature" alt="'+$("#miniature-img").attr("alt")+'"src="'+$("#miniature-img").attr("src")+'" /></td>'+
'<td class="obs-miniature">'+ajouterImgMiniatureAuTransfert()+'</td>'+
'<td>'+$("#notes").val()+'</td>'+
'<td><button class="supprimer-obs" value="'+obsNumero+'" title="Supprimer l\'observation '+obsNumero+'">'+
'<img src="'+SUPPRIMER_ICONE_URL+'"/></button></td>'+
264,131 → 551,155
'num_taxon' : taxons[numNomSel]['num_taxon'],
'famille' : taxons[numNomSel]['famille'],
'nom_fr' : taxons[numNomSel]['nom_fr'],
'station' : $("#adresse").val(),
'milieu' : $('input[name=milieu]:checked').val(),
'milieu' : milieux.join(','),
'latitude' : $("#latitude").val(),
'longitude' : $("#longitude").val(),
'tag' : 'Sauvages',
//Ajout du champ photo
'commune_nom' : $("#commune-nom").text(),
'commune_code_insee' : $("#commune-code-insee").text(),
'lieudit' : rue,
'station' : latLng.lat().toFixed(5)+','+latLng.lng().toFixed(5)+';'+latLngFin.lat().toFixed(5)+','+latLngFin.lng().toFixed(5)+';'+$("#rue_cote").val(),
'notes' : $("#notes").val(),
//Ajout des champs images
'image_nom' : $("#miniature-img").attr('alt'),
//'image_b64' : $("#miniature-img").attr('alt'),
'notes' : $("#notes").val()});
'image_b64' : getB64ImgOriginal()
});
}
});
$(".supprimer-obs").live('click', function() {
var obsId = $(this).val();
// Problème avec IE 6 et 7
if (obsId == "Supprimer") {
obsId = $(this).attr("title");
}
$('#obs'+obsId).remove();
$("#liste-obs").removeData('obsId'+obsId)
});
 
$("#effacer-miniature").click(function () {
$("#miniature").empty();
});
$(".supprimer-obs").live('click', supprimerObs);
// TODO : remplacer par du jquery
//document.getElementById('image_file').addEventListener('change', handleFileSelect, false);
$("#transmettre-obs").click(function(e) {
var observations = $("#liste-obs").data();
if (observations == undefined || jQuery.isEmptyObject(observations)) {
$("#dialogue-zero-obs").dialog();
} else if ($("#saisie-obs").valid() == false) {
$("#dialogue-form-invalide").dialog();
} else {
observations['projet'] = 'Sauvages';
var utilisateur = new Object();
utilisateur.prenom = $("#prenom").val();
utilisateur.nom = $("#nom").val();
utilisateur.courriel = $("#courriel").val();
observations['utilisateur'] = utilisateur;
$.ajax({
url : SERVICE_SAISIE_URL,
type : "POST",
data : observations,
context : document.body,
beforeSend : function() {
$("#msg").remove();
$("#msg-erreur").remove();
$("#msg-debug").remove();
},
statusCode : {
500 : function(jqXHR, textStatus, errorThrown) {
$("#dialogue-obs-transaction").append('<p id="msg">Un problème est survenu lors de la transmission de vos observations.</p>');
reponse = jQuery.parseJSON(jqXHR.responseText);
var erreurMsg = "";
if (reponse != null) {
$.each(reponse, function (cle, valeur) {
erreurMsg += valeur + "<br />";
});
}
$("#dialogue-obs-transaction").append('<p id="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
}
},
success : function(data, textStatus, jqXHR) {
$("#dialogue-obs-transaction").append('<p id="msg">Vos observations ont bien été transmises.</p>');
},
complete : function(jqXHR, textStatus) {
var debugMsg = "";
if (DEBUG && jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
if (debugInfos != null) {
$.each(debugInfos, function (cle, valeur) {
debugMsg += valeur + "<br />";
});
$("#dialogue-obs-transaction").append('<pre id="msg-debug">Débogage : '+debugMsg+'</pre>');
}
}
$("#dialogue-obs-transaction").dialog();
$("#liste-obs").removeData();
$('.obs').remove();
obsNumero = 0;
},
});
var erreurMsg = "";
$.ajax({
url : SERVICE_SAISIE_URL,
type : "POST",
data : observations,
dataType : "json",
beforeSend : function() {
$(".msg").remove();
$(".msg-erreur").remove();
$(".msg-debug").remove();
$("#chargement").show();
},
success : function(data, textStatus, jqXHR) {
var message = 'Merci Beaucoup! Vos observations ont bien été transmises aux chercheurs.<br />'+
'Elles sont désormais affichées sur la carte Sauvages de ma rue, <br />'+
'et s\'ajoutent aux données du Carnet en ligne (<a href="http://www.tela-botanica.org/widget:cel:carto">voir la carte</a>) de Tela Botanica <br />'+
'<br /> '+
'Bonne continuation! <br />'+
'<br /> '+
'Si vous souhaitez modifier ou supprimer vos données, vous pouvez les retrouver en vous connectant au <a href="http://www.tela-botanica.org/page:cel">Carnet en ligne</a>. <br /> '+
'(Attention, il est nécessaire de s\'inscrire gratuitement à Tela Botanica au préalable, si ce n\'est pas déjà fait). <br /> '+
'<br /> '+
'Pour toute question, n\'hésitez pas: notre contact: sauvages@tela-botanica.org ';
$("#dialogue-obs-transaction").append('<p class="msg">'+message+'</p>');
supprimerMiniature();
},
statusCode : {
500 : function(jqXHR, textStatus, errorThrown) {
$("#chargement").hide();
erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
if (DEBUG) {
$("#dialogue-obs-transaction").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
}
}
},
error : function(jqXHR, textStatus, errorThrown) {
erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
try {
reponse = jQuery.parseJSON(jqXHR.responseText);
if (reponse != null) {
$.each(reponse, function (cle, valeur) {
erreurMsg += valeur + "\n";
});
}
} catch(e) {
erreurMsg += "L'erreur n'était pas en JSON.";
}
if (DEBUG) {
$("#dialogue-obs-transaction").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
}
},
complete : function(jqXHR, textStatus) {
$("#chargement").hide();
var debugMsg = '';
if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
if (debugInfos != null) {
$.each(debugInfos, function (cle, valeur) {
debugMsg += valeur + "\n";
});
}
}
if (erreurMsg != '') {
$("#dialogue-obs-transaction").append('<p class="msg">'+
'Une erreur est survenue lors de la transmission de vos observations.'+'<br />'+
'Vous pouvez signaler le disfonctionnement à <a href="'+
'mailto:cel@tela-botanica.org'+'?'+
'subject=Disfonctionnement du widget de saisie Biodiversite34'+
"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
'">cel@tela-botanica.org</a>.'+
'</p>');
}
if (DEBUG) {
$("#dialogue-obs-transaction").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
}
$("#dialogue-obs-transaction").dialog();
$("#liste-obs").removeData();
$('.obs').remove();
obsNumero = 0;
}
});
}
return false;
});
});
 
function getB64ImgOriginal() {
var b64 = '';
if ($("#miniature-img").hasClass('b64')) {
b64 = $("#miniature-img").attr('src');
} else if ($("#miniature-img").hasClass('b64-canvas')) {
b64 = $("#miniature-img").data('b64');
}
return b64;
}
 
function handleFileSelect(evt) {
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
var selectedfiles = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = selectedfiles[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Read in the image file as a data URL.
reader.readAsDataURL(f);
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
document.getElementById('image').src = e.target.result;
//document.getElementById('list').insertBefore(img, null);
};
})(f);
}
function supprimerObs() {
var obsId = $(this).val();
// Problème avec IE 6 et 7
if (obsId == "Supprimer") {
obsId = $(this).attr("title");
}
$('#obs'+obsId).remove();
$("#liste-obs").removeData('obsId'+obsId);
}
 
}
else {
alert('The File APIs are not fully supported in this browser.');
function ajouterImgMiniatureAuTransfert() {
var miniature = '';
if ($("#miniature img").length == 1) {
var css = $("#miniature-img").hasClass('b64') ? 'miniature b64' : 'miniature';
var src = $("#miniature-img").attr("src");
var alt = $("#miniature-img").attr("alt");
miniature = '<img class="'+css+'" alt="'+alt+'"src="'+src+'" />';
}
return miniature;
}