1210 |
jpm |
1 |
//+---------------------------------------------------------------------------------------------------------+
|
|
|
2 |
// GÉNÉRAL
|
1249 |
jpm |
3 |
$(document).ready(function() {
|
|
|
4 |
$(window).on('beforeunload', function(event) {
|
|
|
5 |
return 'Êtes vous sûr de vouloir quiter la page?\nLes observations saisies mains non transmises seront perdues.';
|
|
|
6 |
});
|
|
|
7 |
});
|
|
|
8 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
9 |
// FONCTIONS GÉNÉRIQUES
|
1210 |
jpm |
10 |
/**
|
|
|
11 |
* Stope l'évènement courrant quand on clique sur un lien.
|
|
|
12 |
* Utile pour Chrome, Safari...
|
|
|
13 |
* @param evenement
|
|
|
14 |
* @return
|
|
|
15 |
*/
|
|
|
16 |
function arreter(evenement) {
|
|
|
17 |
if (evenement.stopPropagation) {
|
|
|
18 |
evenement.stopPropagation();
|
|
|
19 |
}
|
1249 |
jpm |
20 |
if (evenement.preventDefault) {
|
|
|
21 |
evenement.preventDefault();
|
|
|
22 |
}
|
1210 |
jpm |
23 |
return false;
|
|
|
24 |
}
|
|
|
25 |
|
1249 |
jpm |
26 |
function extraireEnteteDebug(jqXHR) {
|
|
|
27 |
var msgDebug = '';
|
|
|
28 |
if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
|
|
|
29 |
var debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
|
|
|
30 |
if (debugInfos != null) {
|
|
|
31 |
$.each(debugInfos, function (cle, valeur) {
|
|
|
32 |
msgDebug += valeur + "\n";
|
|
|
33 |
});
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
return msgDebug;
|
|
|
37 |
}
|
1210 |
jpm |
38 |
|
1249 |
jpm |
39 |
function afficherPanneau(selecteur) {
|
|
|
40 |
$(selecteur).fadeIn("slow").delay(DUREE_MESSAGE).fadeOut("slow");
|
|
|
41 |
}
|
|
|
42 |
|
1210 |
jpm |
43 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
44 |
//UPLOAD PHOTO : Traitement de l'image
|
1249 |
jpm |
45 |
$(document).ready(function() {
|
1210 |
jpm |
46 |
|
|
|
47 |
$("#effacer-miniature").click(function () {
|
|
|
48 |
supprimerMiniature();
|
|
|
49 |
});
|
|
|
50 |
|
|
|
51 |
if (HTML5 && window.File && window.FileReader && isCanvasSupported()) {
|
|
|
52 |
if (DEBUG) {
|
|
|
53 |
console.log("Support OK pour : API File et Canvas.");
|
|
|
54 |
}
|
|
|
55 |
$('#fichier').bind('change', function(e) {
|
|
|
56 |
afficherMiniatureHtml5(e);
|
|
|
57 |
});
|
|
|
58 |
} else {
|
|
|
59 |
$("#fichier").bind('change', function (e) {
|
|
|
60 |
arreter(e);
|
|
|
61 |
var options = {
|
|
|
62 |
success: afficherMiniature, // post-submit callback
|
|
|
63 |
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type)
|
|
|
64 |
resetForm: true // reset the form after successful submit
|
|
|
65 |
};
|
|
|
66 |
$("#form-upload").ajaxSubmit(options);
|
|
|
67 |
return false;
|
|
|
68 |
});
|
|
|
69 |
}
|
|
|
70 |
});
|
1249 |
jpm |
71 |
|
1210 |
jpm |
72 |
function isCanvasSupported(){
|
|
|
73 |
var elem = document.createElement('canvas');
|
|
|
74 |
return !!(elem.getContext && elem.getContext('2d'));
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
function afficherMiniatureHtml5(evt) {
|
|
|
78 |
supprimerMiniature();
|
|
|
79 |
|
|
|
80 |
var selectedfiles = evt.target.files;
|
|
|
81 |
var f = selectedfiles[0];// Nous récupérons seulement le premier fichier.
|
|
|
82 |
if (f.type != 'image/jpeg') {
|
|
|
83 |
var message = "Seule les images JPEG sont supportées.";
|
|
|
84 |
$("#miniature-msg").append(message);
|
|
|
85 |
} else if (f.size > 5242880) {
|
|
|
86 |
var message = "Votre image à un poids supérieur à 5Mo.";
|
|
|
87 |
$("#miniature-msg").append(message);
|
|
|
88 |
} else {
|
|
|
89 |
var reader = new FileReader();
|
|
|
90 |
// Lit le fichier image commune url de données
|
|
|
91 |
reader.readAsDataURL(f);
|
|
|
92 |
var imgNom = f.name;
|
|
|
93 |
|
|
|
94 |
// Closure pour capturer les infos du fichier
|
|
|
95 |
reader.onload = (function(theFile) {
|
|
|
96 |
return function(e) {
|
|
|
97 |
// Rendre la miniature
|
|
|
98 |
var imageBase64 = e.target.result;
|
|
|
99 |
//$("#miniature").append('<img id="miniature-img" class="miniature b64" src="'+imageBase64+'" alt="'+imgNom+'"/>');
|
|
|
100 |
|
|
|
101 |
// HTML5 Canvas
|
|
|
102 |
var img = new Image();
|
|
|
103 |
img.src = imageBase64;
|
|
|
104 |
img.alt = imgNom;
|
|
|
105 |
img.onload = function() {
|
|
|
106 |
transformerImgEnCanvas(this, 100, 100, false, 'white');
|
|
|
107 |
};
|
|
|
108 |
};
|
|
|
109 |
})(f);
|
|
|
110 |
}
|
|
|
111 |
$("#effacer-miniature").show();
|
|
|
112 |
}
|
1249 |
jpm |
113 |
|
1210 |
jpm |
114 |
function transformerImgEnCanvas(img, thumbwidth, thumbheight, crop, background) {
|
|
|
115 |
var canvas = document.createElement('canvas');
|
|
|
116 |
canvas.width = thumbwidth;
|
|
|
117 |
canvas.height = thumbheight;
|
|
|
118 |
var dimensions = calculerDimenssions(img.width, img.height, thumbwidth, thumbheight);
|
|
|
119 |
if (crop) {
|
|
|
120 |
canvas.width = dimensions.w;
|
|
|
121 |
canvas.height = dimensions.h;
|
|
|
122 |
dimensions.x = 0;
|
|
|
123 |
dimensions.y = 0;
|
|
|
124 |
}
|
|
|
125 |
cx = canvas.getContext('2d');
|
|
|
126 |
if (background !== 'transparent') {
|
|
|
127 |
cx.fillStyle = background;
|
|
|
128 |
cx.fillRect(0, 0, thumbwidth, thumbheight);
|
|
|
129 |
}
|
|
|
130 |
cx.drawImage(img, dimensions.x, dimensions.y, dimensions.w, dimensions.h);
|
|
|
131 |
afficherMiniatureCanvas(img, canvas);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
function calculerDimenssions(imagewidth, imageheight, thumbwidth, thumbheight) {
|
|
|
135 |
var w = 0, h = 0, x = 0, y = 0,
|
|
|
136 |
widthratio = imagewidth / thumbwidth,
|
|
|
137 |
heightratio = imageheight / thumbheight,
|
|
|
138 |
maxratio = Math.max(widthratio, heightratio);
|
|
|
139 |
if (maxratio > 1) {
|
|
|
140 |
w = imagewidth / maxratio;
|
|
|
141 |
h = imageheight / maxratio;
|
|
|
142 |
} else {
|
|
|
143 |
w = imagewidth;
|
|
|
144 |
h = imageheight;
|
|
|
145 |
}
|
|
|
146 |
x = (thumbwidth - w) / 2;
|
|
|
147 |
y = (thumbheight - h) / 2;
|
|
|
148 |
return {w:w, h:h, x:x, y:y};
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
function afficherMiniatureCanvas(imgB64, canvas) {
|
|
|
152 |
var url = canvas.toDataURL('image/jpeg' , 0.8);
|
|
|
153 |
var alt = imgB64.alt;
|
|
|
154 |
var title = Math.round(url.length / 1000 * 100) / 100 + ' KB';
|
|
|
155 |
var miniature = '<img id="miniature-img" class="miniature b64-canvas" src="'+url+'" alt="'+alt+'" title="'+title+'" />';
|
|
|
156 |
$("#miniature").append(miniature);
|
|
|
157 |
$("#miniature-img").data('b64', imgB64.src);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
function afficherMiniature(reponse) {
|
|
|
161 |
supprimerMiniature();
|
|
|
162 |
if (DEBUG) {
|
|
|
163 |
var debogage = $("debogage", reponse).text();
|
|
|
164 |
console.log("Débogage upload : "+debogage);
|
|
|
165 |
}
|
|
|
166 |
var message = $("message", reponse).text();
|
|
|
167 |
if (message != '') {
|
|
|
168 |
$("#miniature-msg").append(message);
|
|
|
169 |
} else {
|
|
|
170 |
var miniatureUrl = $("miniature-url", reponse).text();
|
|
|
171 |
var imgNom = $("image-nom", reponse).text();
|
|
|
172 |
$("#miniature").append('<img id="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>');
|
|
|
173 |
}
|
|
|
174 |
$("#effacer-miniature").show();
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
function supprimerMiniature() {
|
|
|
178 |
$("#miniature").empty();
|
|
|
179 |
$("#miniature-msg").empty();
|
|
|
180 |
$("#effacer-miniature").hide();
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
//+----------------------------------------------------------------------------------------------------------+
|
|
|
184 |
// GOOGLE MAP
|
|
|
185 |
var map;
|
|
|
186 |
var marker;
|
|
|
187 |
var latLng;
|
1216 |
jpm |
188 |
var geocoder;
|
1210 |
jpm |
189 |
|
1216 |
jpm |
190 |
$(document).ready(function() {
|
|
|
191 |
initialiserGoogleMap();
|
|
|
192 |
|
|
|
193 |
// Autocompletion du champ adresse
|
1221 |
jpm |
194 |
$("#carte-recherche").on('focus', function() {
|
|
|
195 |
$(this).select();
|
|
|
196 |
});
|
|
|
197 |
$("#carte-recherche").on('mouseup', function(event) {// Pour Safari...
|
|
|
198 |
event.preventDefault();
|
|
|
199 |
});
|
1216 |
jpm |
200 |
$("#carte-recherche").autocomplete({
|
|
|
201 |
//Cette partie utilise geocoder pour extraire des valeurs d'adresse
|
|
|
202 |
source: function(request, response) {
|
|
|
203 |
|
|
|
204 |
geocoder.geocode( {'address': request.term+', France', 'region' : 'fr' }, function(results, status) {
|
|
|
205 |
if (status == google.maps.GeocoderStatus.OK) {
|
|
|
206 |
response($.map(results, function(item) {
|
|
|
207 |
var retour = {
|
|
|
208 |
label: item.formatted_address,
|
|
|
209 |
value: item.formatted_address,
|
|
|
210 |
latitude: item.geometry.location.lat(),
|
|
|
211 |
longitude: item.geometry.location.lng()
|
|
|
212 |
};
|
|
|
213 |
return retour;
|
|
|
214 |
}));
|
|
|
215 |
} else {
|
|
|
216 |
afficherErreurGoogleMap(status);
|
|
|
217 |
}
|
|
|
218 |
});
|
|
|
219 |
},
|
|
|
220 |
// Cette partie est executee a la selection d'une adresse
|
|
|
221 |
select: function(event, ui) {
|
|
|
222 |
var latLng = new google.maps.LatLng(ui.item.latitude, ui.item.longitude);
|
|
|
223 |
deplacerMarker(latLng);
|
|
|
224 |
}
|
|
|
225 |
});
|
|
|
226 |
|
1249 |
jpm |
227 |
$("#geolocaliser").on('click', geolocaliser);
|
1216 |
jpm |
228 |
|
1249 |
jpm |
229 |
google.maps.event.addListener(marker, 'dragend', surDeplacementMarker);
|
1216 |
jpm |
230 |
|
1249 |
jpm |
231 |
google.maps.event.addListener(map, 'click', surClickDansCarte);
|
1216 |
jpm |
232 |
});
|
|
|
233 |
|
1249 |
jpm |
234 |
function surDeplacementMarker() {
|
|
|
235 |
trouverCommune(marker.getPosition());
|
|
|
236 |
mettreAJourMarkerPosition(marker.getPosition());
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
function surClickDansCarte(event) {
|
|
|
240 |
deplacerMarker(event.latLng);
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
function geolocaliser() {
|
|
|
244 |
var latitude = $('#latitude').val();
|
|
|
245 |
var longitude = $('#longitude').val();
|
|
|
246 |
latLng = new google.maps.LatLng(latitude, longitude);
|
|
|
247 |
deplacerMarker(latLng);
|
|
|
248 |
}
|
|
|
249 |
|
1210 |
jpm |
250 |
function initialiserGoogleMap(){
|
|
|
251 |
// Carte
|
|
|
252 |
var latLng = new google.maps.LatLng(48.8543, 2.3483);// Paris
|
|
|
253 |
|
|
|
254 |
var options = {
|
|
|
255 |
zoom: 16,
|
|
|
256 |
center: latLng,
|
|
|
257 |
mapTypeId: google.maps.MapTypeId.HYBRID,
|
|
|
258 |
mapTypeControlOptions: {
|
|
|
259 |
mapTypeIds: ['OSM', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN]}
|
|
|
260 |
};
|
|
|
261 |
|
|
|
262 |
// Ajout de la couche OSM à la carte
|
|
|
263 |
osmMapType = new google.maps.ImageMapType({
|
|
|
264 |
getTileUrl: function(coord, zoom) {
|
|
|
265 |
return "http://tile.openstreetmap.org/" +
|
|
|
266 |
zoom + "/" + coord.x + "/" + coord.y + ".png";
|
|
|
267 |
},
|
|
|
268 |
tileSize: new google.maps.Size(256, 256),
|
|
|
269 |
isPng: true,
|
|
|
270 |
alt: 'OpenStreetMap',
|
|
|
271 |
name: 'OSM',
|
|
|
272 |
maxZoom: 19
|
|
|
273 |
});
|
|
|
274 |
|
|
|
275 |
// Création de la carte Google
|
|
|
276 |
map = new google.maps.Map(document.getElementById('map-canvas'), options); //affiche la google map dans la div map_canvas
|
|
|
277 |
map.mapTypes.set('OSM', osmMapType);
|
|
|
278 |
|
1216 |
jpm |
279 |
// Création du Geocoder
|
|
|
280 |
geocoder = new google.maps.Geocoder();
|
|
|
281 |
|
1210 |
jpm |
282 |
// Marqueur google draggable
|
|
|
283 |
marker = new google.maps.Marker({
|
|
|
284 |
map: map,
|
|
|
285 |
draggable: true,
|
|
|
286 |
title: 'Ma station',
|
|
|
287 |
icon: GOOGLE_MAP_MARQUEUR_URL,
|
|
|
288 |
position: latLng
|
|
|
289 |
});
|
|
|
290 |
|
|
|
291 |
deplacerMarker(latLng);
|
|
|
292 |
|
|
|
293 |
// Tentative de geocalisation
|
|
|
294 |
if (navigator.geolocation) {
|
|
|
295 |
navigator.geolocation.getCurrentPosition(function(position) {
|
|
|
296 |
var latitude = position.coords.latitude;
|
|
|
297 |
var longitude = position.coords.longitude;
|
|
|
298 |
latLng = new google.maps.LatLng(latitude, longitude);
|
|
|
299 |
deplacerMarker(latLng);
|
|
|
300 |
});
|
|
|
301 |
}
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
function deplacerMarker(latLng) {
|
|
|
305 |
if (marker != undefined) {
|
|
|
306 |
marker.setPosition(latLng);
|
|
|
307 |
map.setCenter(latLng);
|
|
|
308 |
mettreAJourMarkerPosition(latLng);
|
|
|
309 |
trouverCommune(latLng);
|
|
|
310 |
}
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
function mettreAJourMarkerPosition(latLng) {
|
|
|
314 |
var lat = latLng.lat().toFixed(5);
|
|
|
315 |
var lng = latLng.lng().toFixed(5);
|
|
|
316 |
remplirChampLatitude(lat);
|
|
|
317 |
remplirChampLongitude(lng);
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
function remplirChampLatitude(latDecimale) {
|
|
|
321 |
var lat = Math.round(latDecimale * 100000) / 100000;
|
|
|
322 |
$('#latitude').val(lat);
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
function remplirChampLongitude(lngDecimale) {
|
|
|
326 |
var lng = Math.round(lngDecimale * 100000) / 100000;
|
|
|
327 |
$('#longitude').val(lng);
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
function trouverCommune(pos) {
|
|
|
331 |
$(function() {
|
|
|
332 |
var urlNomCommuneFormatee = SERVICE_NOM_COMMUNE_URL.replace('{lat}', pos.lat()).replace('{lon}', pos.lng());
|
|
|
333 |
$.ajax({
|
|
|
334 |
url : urlNomCommuneFormatee,
|
|
|
335 |
type : "GET",
|
|
|
336 |
dataType : "jsonp",
|
|
|
337 |
beforeSend : function() {
|
|
|
338 |
$(".commune-info").empty();
|
1220 |
jpm |
339 |
$("#dialogue-erreur .alert-txt").empty();
|
1210 |
jpm |
340 |
},
|
|
|
341 |
success : function(data, textStatus, jqXHR) {
|
|
|
342 |
$(".commune-info").empty();
|
|
|
343 |
$("#commune-nom").append(data.nom);
|
|
|
344 |
$("#commune-code-insee").append(data.codeINSEE);
|
|
|
345 |
$("#marqueur-commune").data('commune', {'nom' : data.nom, 'codeInsee' : data.codeINSEE});
|
|
|
346 |
},
|
|
|
347 |
statusCode : {
|
|
|
348 |
500 : function(jqXHR, textStatus, errorThrown) {
|
|
|
349 |
if (DEBUG) {
|
1220 |
jpm |
350 |
$("#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>');
|
1210 |
jpm |
351 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
352 |
var erreurMsg = "";
|
|
|
353 |
if (reponse != null) {
|
|
|
354 |
$.each(reponse, function (cle, valeur) {
|
|
|
355 |
erreurMsg += valeur + "<br />";
|
|
|
356 |
});
|
|
|
357 |
}
|
|
|
358 |
|
1220 |
jpm |
359 |
$("#dialogue-erreur .alert-txt").append('<p class="msg-erreur">Erreur 500 : '+errorThrown+"<br />"+erreurMsg+'</p>');
|
1210 |
jpm |
360 |
}
|
|
|
361 |
}
|
|
|
362 |
},
|
|
|
363 |
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
364 |
if (DEBUG) {
|
1220 |
jpm |
365 |
$("#dialogue-erreur .alert-txt").append('<p class="msg">Une erreur Ajax est survenue lors de la transmission de vos observations.</p>');
|
1210 |
jpm |
366 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
367 |
var erreurMsg = "";
|
|
|
368 |
if (reponse != null) {
|
|
|
369 |
$.each(reponse, function (cle, valeur) {
|
|
|
370 |
erreurMsg += valeur + "<br />";
|
|
|
371 |
});
|
|
|
372 |
}
|
|
|
373 |
|
1220 |
jpm |
374 |
$("#dialogue-erreur .alert-txt").append('<p class="msg-erreur">Erreur Ajax : '+errorThrown+' (type : '+textStatus+') <br />'+erreurMsg+'</p>');
|
1210 |
jpm |
375 |
}
|
|
|
376 |
},
|
|
|
377 |
complete : function(jqXHR, textStatus) {
|
1249 |
jpm |
378 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
|
|
379 |
if (debugMsg != '') {
|
|
|
380 |
if (DEBUG) {
|
1220 |
jpm |
381 |
$("#dialogue-erreur .alert-txt").append('<pre class="msg-debug msg">Débogage : '+debugMsg+'</pre>');
|
1210 |
jpm |
382 |
}
|
|
|
383 |
}
|
|
|
384 |
if ($("#dialogue-erreur .msg").length > 0) {
|
1220 |
jpm |
385 |
$("#dialogue-erreur").show();
|
1210 |
jpm |
386 |
}
|
|
|
387 |
}
|
|
|
388 |
});
|
|
|
389 |
});
|
|
|
390 |
}
|
1241 |
jpm |
391 |
//+---------------------------------------------------------------------------------------------------------+
|
|
|
392 |
// IDENTITÉ
|
|
|
393 |
$(document).ready(function() {
|
1249 |
jpm |
394 |
$("#courriel").on('blur', requeterIdentite);
|
|
|
395 |
$("#courriel").on('keypress', testerLancementRequeteIdentite);
|
|
|
396 |
});
|
|
|
397 |
|
|
|
398 |
function testerLancementRequeteIdentite(event) {
|
|
|
399 |
if (event.which == 13) {
|
|
|
400 |
requeterIdentite();
|
|
|
401 |
event.preventDefault();
|
|
|
402 |
event.stopPropagation();
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
function requeterIdentite() {
|
|
|
407 |
var courriel = $("#courriel").val();
|
|
|
408 |
var urlAnnuaire = "http://www.tela-botanica.org/client/annuaire_nouveau/actuelle/jrest/utilisateur/identite-par-courriel/"+courriel;//http://localhost/applications/annuaire/jrest/
|
|
|
409 |
$.ajax({
|
|
|
410 |
url : urlAnnuaire,
|
|
|
411 |
type : "GET",
|
|
|
412 |
success : function(data, textStatus, jqXHR) {
|
|
|
413 |
console.log('SUCCESS:'+textStatus);
|
|
|
414 |
if (data != undefined && data[courriel] != undefined) {
|
|
|
415 |
var infos = data[courriel];
|
|
|
416 |
$("#prenom").val(infos.prenom);
|
|
|
417 |
$("#nom").val(infos.nom);
|
|
|
418 |
$("#courriel_confirmation").val(courriel);
|
|
|
419 |
$("#prenom, #nom, #courriel_confirmation").attr('disabled', 'disabled');
|
|
|
420 |
$("#date").focus();
|
|
|
421 |
} else {
|
|
|
422 |
surErreurCompletionCourriel();
|
1241 |
jpm |
423 |
}
|
1249 |
jpm |
424 |
},
|
|
|
425 |
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
426 |
console.log('ERREUR :'+textStatus);
|
|
|
427 |
surErreurCompletionCourriel();
|
|
|
428 |
},
|
|
|
429 |
complete : function(jqXHR, textStatus) {
|
|
|
430 |
console.log('COMPLETE :'+textStatus);
|
|
|
431 |
$("#zone-prenom-nom").removeClass("hidden");
|
|
|
432 |
$("#zone-courriel-confirmation").removeClass("hidden");
|
|
|
433 |
}
|
1241 |
jpm |
434 |
});
|
1249 |
jpm |
435 |
}
|
1210 |
jpm |
436 |
|
1249 |
jpm |
437 |
function surErreurCompletionCourriel() {
|
|
|
438 |
$("#prenom, #nom, #courriel_confirmation").val('');
|
|
|
439 |
$("#prenom, #nom, #courriel_confirmation").removeAttr('disabled');
|
|
|
440 |
afficherPanneau("#dialogue-courriel-introuvable");
|
|
|
441 |
}
|
1210 |
jpm |
442 |
//+---------------------------------------------------------------------------------------------------------+
|
1249 |
jpm |
443 |
//FORMULAIRE VALIDATION
|
|
|
444 |
$(document).ready(function() {
|
|
|
445 |
|
|
|
446 |
|
|
|
447 |
});
|
|
|
448 |
//+---------------------------------------------------------------------------------------------------------+
|
1210 |
jpm |
449 |
// FORMULAIRE
|
1215 |
jpm |
450 |
var obsNbre = 0;
|
|
|
451 |
|
1210 |
jpm |
452 |
$(document).ready(function() {
|
1249 |
jpm |
453 |
$(".alert .close").on('click', fermerPanneauAlert);
|
1220 |
jpm |
454 |
|
1249 |
jpm |
455 |
$("#btn-aide").on('click', basculerAffichageAide);
|
1218 |
jpm |
456 |
|
1249 |
jpm |
457 |
$("#prenom").on("change", formaterPrenom);
|
1218 |
jpm |
458 |
|
1249 |
jpm |
459 |
$("#nom").on("change", formaterNom);
|
1210 |
jpm |
460 |
|
1249 |
jpm |
461 |
configurerDatePicker();
|
1210 |
jpm |
462 |
|
|
|
463 |
ajouterAutocompletionNoms();
|
|
|
464 |
|
1249 |
jpm |
465 |
configurerFormValidator();
|
|
|
466 |
definirReglesFormValidator();
|
|
|
467 |
|
|
|
468 |
$("#courriel_confirmation").on('paste', bloquerCopierCollerCourriel);
|
|
|
469 |
|
|
|
470 |
$("a.afficher-coord").on('click', basculerAffichageCoord);
|
|
|
471 |
|
|
|
472 |
$("#ajouter-obs").on('click', ajouterObs);
|
|
|
473 |
|
|
|
474 |
$(".obs-nbre").on('changement', surChangementNbreObs);
|
|
|
475 |
|
|
|
476 |
$("body").on('click', ".supprimer-obs", supprimerObs);
|
|
|
477 |
|
|
|
478 |
$("#transmettre-obs").on('click', transmettreObs);
|
|
|
479 |
});
|
|
|
480 |
|
|
|
481 |
function configurerFormValidator() {
|
1210 |
jpm |
482 |
$.validator.addMethod(
|
|
|
483 |
"dateCel",
|
|
|
484 |
function (value, element) {
|
|
|
485 |
return /^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value);
|
1213 |
jpm |
486 |
},
|
|
|
487 |
"Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.");
|
1210 |
jpm |
488 |
$.extend($.validator.defaults, {
|
|
|
489 |
errorClass: "control-group error",
|
|
|
490 |
validClass: "control-group success",
|
|
|
491 |
errorElement: "span",
|
1213 |
jpm |
492 |
highlight: function(element, errorClass, validClass) {
|
1210 |
jpm |
493 |
if (element.type === 'radio') {
|
|
|
494 |
this.findByName(element.name).parent("div").parent("div").removeClass(validClass).addClass(errorClass);
|
|
|
495 |
} else {
|
|
|
496 |
$(element).parent("div").parent("div").removeClass(validClass).addClass(errorClass);
|
|
|
497 |
}
|
|
|
498 |
},
|
1213 |
jpm |
499 |
unhighlight: function(element, errorClass, validClass) {
|
1210 |
jpm |
500 |
if (element.type === 'radio') {
|
|
|
501 |
this.findByName(element.name).parent("div").parent("div").removeClass(errorClass).addClass(validClass);
|
|
|
502 |
} else {
|
1213 |
jpm |
503 |
if ($(element).attr('id') == 'taxon') {
|
|
|
504 |
var warningClass = "control-group warning";
|
1215 |
jpm |
505 |
if ($("#taxon").data("value") != $("#taxon").val()) {
|
|
|
506 |
$("#taxon").removeData();
|
|
|
507 |
$("#taxon").removeClass('ns-retenu');
|
1213 |
jpm |
508 |
if ($("#taxon").val() != '') {
|
|
|
509 |
$("#taxon-input-groupe").removeClass(validClass)
|
|
|
510 |
.removeClass(errorClass)
|
|
|
511 |
.addClass(warningClass);
|
1240 |
jpm |
512 |
this.showLabel(element, "Ce nom n'est pas lié au référentiel.");
|
1213 |
jpm |
513 |
}
|
|
|
514 |
} else {
|
|
|
515 |
if ($("#taxon").val() != '') {
|
|
|
516 |
$("#taxon-input-groupe").removeClass(warningClass)
|
|
|
517 |
.removeClass(errorClass)
|
|
|
518 |
.addClass(validClass);
|
|
|
519 |
$(element).next(" span.help-inline").remove();
|
|
|
520 |
}
|
|
|
521 |
}
|
|
|
522 |
} else {
|
|
|
523 |
$(element).parent("div").parent("div").removeClass(errorClass).addClass(validClass);
|
|
|
524 |
$(element).next(" span.help-inline").remove();
|
|
|
525 |
}
|
1210 |
jpm |
526 |
}
|
|
|
527 |
}
|
|
|
528 |
});
|
1249 |
jpm |
529 |
}
|
|
|
530 |
|
|
|
531 |
function definirReglesFormValidator() {
|
1210 |
jpm |
532 |
$("#form-observateur").validate({
|
|
|
533 |
rules: {
|
|
|
534 |
courriel : {
|
|
|
535 |
required : true,
|
|
|
536 |
email : true},
|
|
|
537 |
courriel_confirmation : {
|
|
|
538 |
required : true,
|
|
|
539 |
equalTo: "#courriel"}
|
|
|
540 |
}
|
|
|
541 |
});
|
|
|
542 |
$("#form-station").validate({
|
|
|
543 |
rules: {
|
|
|
544 |
latitude : {
|
|
|
545 |
required: true,
|
|
|
546 |
range: [-90, 90]},
|
|
|
547 |
longitude : {
|
|
|
548 |
required: true,
|
|
|
549 |
range: [-180, 180]}
|
|
|
550 |
}
|
|
|
551 |
});
|
|
|
552 |
$("#form-obs").validate({
|
|
|
553 |
rules: {
|
1213 |
jpm |
554 |
date : "dateCel",
|
1210 |
jpm |
555 |
taxon : "required"
|
|
|
556 |
}
|
|
|
557 |
});
|
1249 |
jpm |
558 |
}
|
|
|
559 |
|
|
|
560 |
function configurerDatePicker() {
|
|
|
561 |
$.datepicker.setDefaults($.datepicker.regional["fr"]);
|
|
|
562 |
$("#date").datepicker({
|
|
|
563 |
dateFormat: "dd/mm/yy",
|
|
|
564 |
showOn: "button",
|
|
|
565 |
buttonImageOnly: true,
|
|
|
566 |
buttonImage: CALENDRIER_ICONE_URL,
|
|
|
567 |
buttonText: "Afficher le calendrier pour saisir la date.",
|
|
|
568 |
showButtonPanel: true
|
1210 |
jpm |
569 |
});
|
1249 |
jpm |
570 |
$("img.ui-datepicker-trigger").appendTo("#date-icone");
|
|
|
571 |
}
|
|
|
572 |
|
|
|
573 |
function fermerPanneauAlert() {
|
|
|
574 |
$(this).parentsUntil(".zone-alerte", ".alert").hide();
|
|
|
575 |
}
|
|
|
576 |
|
|
|
577 |
function formaterNom() {
|
|
|
578 |
$(this).val($(this).val().toUpperCase());
|
|
|
579 |
}
|
|
|
580 |
|
|
|
581 |
function formaterPrenom() {
|
|
|
582 |
var prenom = new Array();
|
|
|
583 |
var mots = $(this).val().split(' ');
|
|
|
584 |
for (var i = 0; i < mots.length; i++) {
|
|
|
585 |
var mot = mots[i];
|
|
|
586 |
if (mot.indexOf('-') >= 0) {
|
|
|
587 |
var prenomCompose = new Array();
|
|
|
588 |
var motsComposes = mot.split('-');
|
|
|
589 |
for (var j = 0; j < motsComposes.length; j++) {
|
|
|
590 |
var motSimple = motsComposes[j];
|
|
|
591 |
var motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
|
|
|
592 |
prenomCompose.push(motMajuscule);
|
|
|
593 |
}
|
|
|
594 |
prenom.push(prenomCompose.join('-'));
|
|
|
595 |
} else {
|
|
|
596 |
var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
|
|
|
597 |
prenom.push(motMajuscule);
|
|
|
598 |
}
|
|
|
599 |
}
|
|
|
600 |
$(this).val(prenom.join(' '));
|
|
|
601 |
}
|
|
|
602 |
|
|
|
603 |
function basculerAffichageAide() {
|
|
|
604 |
if ($(this).hasClass('btn-warning')) {
|
|
|
605 |
$("[rel=tooltip]").tooltip('enable');
|
|
|
606 |
$(this).removeClass('btn-warning').addClass('btn-success');
|
|
|
607 |
$('#btn-aide-txt', this).text("Désactiver l'aide");
|
|
|
608 |
} else {
|
|
|
609 |
$("[rel=tooltip]").tooltip('disable');
|
|
|
610 |
$(this).removeClass('btn-success').addClass('btn-warning');
|
|
|
611 |
$('#btn-aide-txt', this).text("Activer l'aide");
|
|
|
612 |
}
|
|
|
613 |
}
|
|
|
614 |
|
|
|
615 |
function bloquerCopierCollerCourriel() {
|
1251 |
jpm |
616 |
afficherPanneau("#dialogue-bloquer-copier-coller");
|
1249 |
jpm |
617 |
return false;
|
|
|
618 |
}
|
|
|
619 |
|
|
|
620 |
function basculerAffichageCoord() {
|
|
|
621 |
$("a.afficher-coord").toggle();
|
|
|
622 |
$("#coordonnees-geo").toggle('slow');
|
|
|
623 |
//valeur false pour que le lien ne soit pas suivi
|
|
|
624 |
return false;
|
|
|
625 |
}
|
|
|
626 |
|
|
|
627 |
function ajouterObs() {
|
|
|
628 |
if (validerFormulaire() == true) {
|
|
|
629 |
obsNbre = obsNbre + 1;
|
|
|
630 |
$(".obs-nbre").text(obsNbre);
|
|
|
631 |
$(".obs-nbre").triggerHandler('changement');
|
|
|
632 |
afficherObs();
|
|
|
633 |
stockerObsData();
|
|
|
634 |
supprimerMiniature();
|
|
|
635 |
} else {
|
|
|
636 |
afficherPanneau('#dialogue-form-invalide');
|
|
|
637 |
}
|
|
|
638 |
}
|
|
|
639 |
|
|
|
640 |
function afficherObs() {
|
|
|
641 |
$("#liste-obs").prepend(
|
|
|
642 |
'<div id="obs'+obsNbre+'" class="row-fluid obs obs'+obsNbre+'">'+
|
|
|
643 |
'<div class="span12">'+
|
|
|
644 |
'<div class="well" >'+
|
|
|
645 |
'<div class="obs-action pull-right" rel="tooltip" title="Supprimer cette observation">'+
|
|
|
646 |
'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
|
|
|
647 |
'<i class="icon-trash icon-white"></i>'+
|
|
|
648 |
'</button>'+
|
|
|
649 |
'</div> '+
|
|
|
650 |
'<div class="row-fluid">'+
|
|
|
651 |
'<div class="thumbnail span2">'+
|
|
|
652 |
ajouterImgMiniatureAuTransfert()+
|
1240 |
jpm |
653 |
'</div>'+
|
1249 |
jpm |
654 |
'<div class="span9">'+
|
|
|
655 |
'<ul class="unstyled">'+
|
|
|
656 |
'<li>'+
|
|
|
657 |
'<span class="nom-sci">'+$("#taxon").val()+'</span> '+
|
|
|
658 |
ajouterNumNomSel()+
|
|
|
659 |
' observé à '+
|
|
|
660 |
'<span class="commune">'+$('#commune-nom').text()+'</span> '+
|
|
|
661 |
'('+$('#commune-code-insee').text()+') ['+$("#latitude").val()+' / '+$("#longitude").val()+']'+
|
|
|
662 |
' le '+
|
|
|
663 |
'<span class="date">'+$("#date").val()+'</span>'+
|
|
|
664 |
'</li>'+
|
|
|
665 |
'<li>'+
|
|
|
666 |
'<span>Lieu-dit :</span> '+$('#lieudit').val()+' '+
|
|
|
667 |
'<span>Station :</span> '+$('#station').val()+' '+
|
|
|
668 |
'<span>Milieu :</span> '+$('#milieu').val()+' '+
|
|
|
669 |
'</li>'+
|
|
|
670 |
'<li>'+
|
|
|
671 |
'Commentaires : <span class="discretion">'+$("#notes").val()+'</span>'+
|
|
|
672 |
'</li>'+
|
|
|
673 |
'</ul>'+
|
|
|
674 |
'</div>'+
|
1237 |
jpm |
675 |
'</div>'+
|
1249 |
jpm |
676 |
'</div>'+
|
|
|
677 |
'</div>'+
|
|
|
678 |
'</div>');
|
|
|
679 |
}
|
|
|
680 |
|
|
|
681 |
function stockerObsData() {
|
|
|
682 |
$("#liste-obs").data('obsId'+obsNbre, {
|
|
|
683 |
'date' : $("#date").val(),
|
|
|
684 |
'notes' : $("#notes").val(),
|
|
|
685 |
|
|
|
686 |
'nom_sel' : $("#taxon").val(),
|
|
|
687 |
'num_nom_sel' : $("#taxon").data("numNomSel"),
|
|
|
688 |
'nom_ret' : $("#taxon").data("nomRet"),
|
|
|
689 |
'num_nom_ret' : $("#taxon").data("numNomRet"),
|
|
|
690 |
'num_taxon' : $("#taxon").data("nt"),
|
|
|
691 |
'famille' : $("#taxon").data("famille"),
|
|
|
692 |
'referentiel' : ($("#taxon").data("numNomSel") == undefined ? '' : NOM_SCI_REFERENTIEL),
|
|
|
693 |
|
|
|
694 |
'latitude' : $("#latitude").val(),
|
|
|
695 |
'longitude' : $("#longitude").val(),
|
|
|
696 |
'commune_nom' : $("#commune-nom").text(),
|
|
|
697 |
'commune_code_insee' : $("#commune-code-insee").text(),
|
1251 |
jpm |
698 |
'lieudit' : $("#lieudit").val(),
|
1249 |
jpm |
699 |
'station' : $("#station").val(),
|
|
|
700 |
'milieu' : $("#milieu").val(),
|
|
|
701 |
|
|
|
702 |
//Ajout des champs images
|
|
|
703 |
'image_nom' : $("#miniature-img").attr('alt'),
|
|
|
704 |
'image_b64' : getB64ImgOriginal()
|
1210 |
jpm |
705 |
});
|
1249 |
jpm |
706 |
}
|
|
|
707 |
|
|
|
708 |
function surChangementNbreObs() {
|
|
|
709 |
if (obsNbre == 0) {
|
|
|
710 |
$("#transmettre-obs").attr('disabled', 'disabled');
|
|
|
711 |
$("#ajouter-obs").removeAttr('disabled');
|
|
|
712 |
} else if (obsNbre > 0 && obsNbre < OBS_MAX_NBRE) {
|
|
|
713 |
$("#transmettre-obs").removeAttr('disabled');
|
|
|
714 |
$("#ajouter-obs").removeAttr('disabled');
|
|
|
715 |
} else if (obsNbre >= OBS_MAX_NBRE) {
|
|
|
716 |
$("#ajouter-obs").attr('disabled', 'disabled');
|
|
|
717 |
afficherPanneau("#dialogue-bloquer-creer-obs");
|
|
|
718 |
}
|
|
|
719 |
}
|
|
|
720 |
|
|
|
721 |
function transmettreObs() {
|
|
|
722 |
var observations = $("#liste-obs").data();
|
1210 |
jpm |
723 |
|
1249 |
jpm |
724 |
if (observations == undefined || jQuery.isEmptyObject(observations)) {
|
|
|
725 |
afficherPanneau("#dialogue-zero-obs");
|
|
|
726 |
} else {
|
|
|
727 |
observations['projet'] = TAG_PROJET;
|
|
|
728 |
observations['tag-obs'] = TAG_OBS;
|
|
|
729 |
observations['tag-img'] = TAG_IMG;
|
1210 |
jpm |
730 |
|
1249 |
jpm |
731 |
var utilisateur = new Object();
|
|
|
732 |
utilisateur.prenom = $("#prenom").val();
|
|
|
733 |
utilisateur.nom = $("#nom").val();
|
|
|
734 |
utilisateur.courriel = $("#courriel").val();
|
|
|
735 |
observations['utilisateur'] = utilisateur;
|
1251 |
jpm |
736 |
console.log(observations);
|
1249 |
jpm |
737 |
envoyerObsAuCel(observations);
|
|
|
738 |
}
|
|
|
739 |
return false;
|
|
|
740 |
}
|
|
|
741 |
|
|
|
742 |
function envoyerObsAuCel(observations) {
|
|
|
743 |
var erreurMsg = "";
|
|
|
744 |
$.ajax({
|
|
|
745 |
url : SERVICE_SAISIE_URL,
|
|
|
746 |
type : "POST",
|
|
|
747 |
data : observations,
|
|
|
748 |
dataType : "json",
|
|
|
749 |
beforeSend : function() {
|
1251 |
jpm |
750 |
$("#dialogue-obs-transaction-ko").hide();
|
|
|
751 |
$("#dialogue-obs-transaction-ok").hide();
|
1249 |
jpm |
752 |
$(".alert-txt .msg").remove();
|
|
|
753 |
$(".alert-txt .msg-erreur").remove();
|
|
|
754 |
$(".alert-txt .msg-debug").remove();
|
|
|
755 |
$("#chargement").show();
|
|
|
756 |
},
|
|
|
757 |
success : function(data, textStatus, jqXHR) {
|
|
|
758 |
$('#dialogue-obs-transaction-ok .alert-txt').append($("#tpl-transmission-ok").clone().html());
|
|
|
759 |
supprimerMiniature();
|
|
|
760 |
},
|
|
|
761 |
statusCode : {
|
|
|
762 |
500 : function(jqXHR, textStatus, errorThrown) {
|
|
|
763 |
erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
|
|
|
764 |
}
|
|
|
765 |
},
|
|
|
766 |
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
767 |
erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
|
|
|
768 |
try {
|
|
|
769 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
770 |
if (reponse != null) {
|
|
|
771 |
$.each(reponse, function (cle, valeur) {
|
|
|
772 |
erreurMsg += valeur + "\n";
|
|
|
773 |
});
|
|
|
774 |
}
|
|
|
775 |
} catch(e) {
|
|
|
776 |
erreurMsg += "L'erreur n'était pas en JSON.";
|
|
|
777 |
}
|
|
|
778 |
},
|
|
|
779 |
complete : function(jqXHR, textStatus) {
|
|
|
780 |
$("#chargement").hide();
|
|
|
781 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
1210 |
jpm |
782 |
|
1249 |
jpm |
783 |
if (erreurMsg != '') {
|
|
|
784 |
if (DEBUG) {
|
|
|
785 |
$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
|
|
|
786 |
$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
|
1210 |
jpm |
787 |
}
|
1249 |
jpm |
788 |
var hrefCourriel = "mailto:cel@tela-botanica.org?"+
|
|
|
789 |
"subject=Disfonctionnement du widget de saisie "+TAG_PROJET+
|
|
|
790 |
"&body="+erreurMsg+"\nDébogage :\n"+debugMsg;
|
|
|
791 |
|
|
|
792 |
$('#dialogue-obs-transaction-ko .alert-txt').append($("#tpl-transmission-ko").clone()
|
|
|
793 |
.find('.courriel-erreur')
|
|
|
794 |
.attr('href', hrefCourriel)
|
|
|
795 |
.end()
|
|
|
796 |
.html());
|
|
|
797 |
$("#dialogue-obs-transaction-ko").show();
|
|
|
798 |
} else {
|
|
|
799 |
if (DEBUG) {
|
|
|
800 |
$("#dialogue-obs-transaction-ok .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
|
|
|
801 |
}
|
|
|
802 |
$("#dialogue-obs-transaction-ok").show();
|
1251 |
jpm |
803 |
}
|
|
|
804 |
initialiserObs();
|
1210 |
jpm |
805 |
}
|
|
|
806 |
});
|
1249 |
jpm |
807 |
}
|
1210 |
jpm |
808 |
|
|
|
809 |
function validerFormulaire() {
|
|
|
810 |
$observateur = $("#form-observateur").valid();
|
|
|
811 |
$station = $("#form-station").valid();
|
|
|
812 |
$obs = $("#form-obs").valid();
|
|
|
813 |
return ($observateur == true && $station == true && $obs == true) ? true : false;
|
|
|
814 |
}
|
|
|
815 |
|
|
|
816 |
function getB64ImgOriginal() {
|
|
|
817 |
var b64 = '';
|
|
|
818 |
if ($("#miniature-img").hasClass('b64')) {
|
|
|
819 |
b64 = $("#miniature-img").attr('src');
|
|
|
820 |
} else if ($("#miniature-img").hasClass('b64-canvas')) {
|
|
|
821 |
b64 = $("#miniature-img").data('b64');
|
|
|
822 |
}
|
|
|
823 |
return b64;
|
|
|
824 |
}
|
|
|
825 |
|
|
|
826 |
function supprimerObs() {
|
|
|
827 |
var obsId = $(this).val();
|
|
|
828 |
// Problème avec IE 6 et 7
|
|
|
829 |
if (obsId == "Supprimer") {
|
|
|
830 |
obsId = $(this).attr("title");
|
|
|
831 |
}
|
1215 |
jpm |
832 |
obsNbre = obsNbre - 1;
|
|
|
833 |
$(".obs-nbre").text(obsNbre);
|
1237 |
jpm |
834 |
$(".obs-nbre").triggerHandler('changement');
|
1210 |
jpm |
835 |
|
1215 |
jpm |
836 |
$('.obs'+obsId).remove();
|
1210 |
jpm |
837 |
$("#liste-obs").removeData('obsId'+obsId);
|
|
|
838 |
}
|
|
|
839 |
|
1249 |
jpm |
840 |
function initialiserObs() {
|
1231 |
jpm |
841 |
obsNbre = 0;
|
|
|
842 |
$(".obs-nbre").text(obsNbre);
|
1249 |
jpm |
843 |
$(".obs-nbre").triggerHandler('changement');
|
|
|
844 |
$("#liste-obs").removeData();
|
|
|
845 |
$('.obs').remove();
|
|
|
846 |
$("#dialogue-bloquer-creer-obs").hide();
|
1231 |
jpm |
847 |
}
|
|
|
848 |
|
1210 |
jpm |
849 |
function ajouterImgMiniatureAuTransfert() {
|
|
|
850 |
var miniature = '';
|
|
|
851 |
if ($("#miniature img").length == 1) {
|
|
|
852 |
var css = $("#miniature-img").hasClass('b64') ? 'miniature b64' : 'miniature';
|
|
|
853 |
var src = $("#miniature-img").attr("src");
|
|
|
854 |
var alt = $("#miniature-img").attr("alt");
|
1240 |
jpm |
855 |
miniature = '<img class="'+css+' " alt="'+alt+'"src="'+src+'" />';
|
1237 |
jpm |
856 |
} else {
|
|
|
857 |
miniature = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
|
1210 |
jpm |
858 |
}
|
|
|
859 |
return miniature;
|
|
|
860 |
}
|
|
|
861 |
|
1240 |
jpm |
862 |
function ajouterNumNomSel() {
|
|
|
863 |
var nn = '';
|
|
|
864 |
if ($("#taxon").data("numNomSel") == undefined) {
|
|
|
865 |
nn = '<span class="alert-error">[non lié au référentiel]</span>';
|
|
|
866 |
} else {
|
|
|
867 |
nn = '<span class="nn">[nn'+$("#taxon").data("numNomSel")+']</span>';
|
|
|
868 |
}
|
|
|
869 |
return nn;
|
|
|
870 |
}
|
|
|
871 |
|
1210 |
jpm |
872 |
//+---------------------------------------------------------------------------------------------------------+
|
|
|
873 |
// AUTO-COMPLÉTION Noms Scientifiques
|
|
|
874 |
|
|
|
875 |
function ajouterAutocompletionNoms() {
|
|
|
876 |
$('#taxon').autocomplete({
|
|
|
877 |
source: function(requete, add){
|
|
|
878 |
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
|
|
|
879 |
requete = "";
|
1215 |
jpm |
880 |
var url = getUrlAutocompletionNomsSci();
|
|
|
881 |
$.getJSON(url, requete, function(data) {
|
1210 |
jpm |
882 |
var suggestions = traiterRetourNomsSci(data);
|
|
|
883 |
add(suggestions);
|
|
|
884 |
});
|
|
|
885 |
},
|
|
|
886 |
html: true
|
|
|
887 |
});
|
1215 |
jpm |
888 |
|
1213 |
jpm |
889 |
$( "#taxon" ).bind("autocompleteselect", function(event, ui) {
|
1215 |
jpm |
890 |
$("#taxon").data(ui.item);
|
|
|
891 |
if (ui.item.retenu == true) {
|
|
|
892 |
$("#taxon").addClass('ns-retenu');
|
|
|
893 |
} else {
|
|
|
894 |
$("#taxon").removeClass('ns-retenu');
|
|
|
895 |
}
|
1213 |
jpm |
896 |
});
|
1210 |
jpm |
897 |
}
|
|
|
898 |
|
1215 |
jpm |
899 |
function getUrlAutocompletionNomsSci() {
|
|
|
900 |
var mots = $('#taxon').val();
|
1210 |
jpm |
901 |
var url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL.replace('{masque}', mots);
|
|
|
902 |
return url;
|
|
|
903 |
}
|
|
|
904 |
|
|
|
905 |
function traiterRetourNomsSci(data) {
|
|
|
906 |
var suggestions = [];
|
|
|
907 |
if (data.resultat != undefined) {
|
|
|
908 |
$.each(data.resultat, function(i, val) {
|
|
|
909 |
val.nn = i;
|
1215 |
jpm |
910 |
var nom = {label : '', value : '', nt : '', nomSel : '', nomSelComplet : '', numNomSel : '',
|
|
|
911 |
nomRet : '', numNomRet : '', famille : '', retenu : false
|
|
|
912 |
};
|
|
|
913 |
if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
|
1213 |
jpm |
914 |
nom.label = "...";
|
|
|
915 |
nom.value = $('#taxon').val();
|
|
|
916 |
suggestions.push(nom);
|
|
|
917 |
return false;
|
|
|
918 |
} else {
|
1231 |
jpm |
919 |
nom.label = val.nom_sci_complet;
|
|
|
920 |
nom.value = val.nom_sci_complet;
|
1215 |
jpm |
921 |
nom.nt = val.num_taxonomique;
|
|
|
922 |
nom.nomSel = val.nom_sci;
|
|
|
923 |
nom.nomSelComplet = val.nom_sci_complet;
|
|
|
924 |
nom.numNomSel = val.nn;
|
1237 |
jpm |
925 |
nom.nomRet = val.nom_retenu_complet;
|
1220 |
jpm |
926 |
nom.numNomRet = val["nom_retenu.id"];
|
1231 |
jpm |
927 |
nom.famille = val.famille;
|
1215 |
jpm |
928 |
nom.retenu = (val.retenu == 'false') ? false : true;
|
|
|
929 |
|
1213 |
jpm |
930 |
suggestions.push(nom);
|
|
|
931 |
}
|
1210 |
jpm |
932 |
});
|
|
|
933 |
}
|
1213 |
jpm |
934 |
|
1210 |
jpm |
935 |
return suggestions;
|
|
|
936 |
}
|
|
|
937 |
|
|
|
938 |
/*
|
|
|
939 |
* jQuery UI Autocomplete HTML Extension
|
|
|
940 |
*
|
|
|
941 |
* Copyright 2010, Scott González (http://scottgonzalez.com)
|
|
|
942 |
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
943 |
*
|
|
|
944 |
* http://github.com/scottgonzalez/jquery-ui-extensions
|
|
|
945 |
*
|
|
|
946 |
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
|
|
|
947 |
*/
|
|
|
948 |
(function( $ ) {
|
1215 |
jpm |
949 |
var proto = $.ui.autocomplete.prototype,
|
|
|
950 |
initSource = proto._initSource;
|
|
|
951 |
|
|
|
952 |
function filter( array, term ) {
|
|
|
953 |
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
|
|
|
954 |
return $.grep( array, function(value) {
|
|
|
955 |
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
|
|
|
956 |
});
|
|
|
957 |
}
|
|
|
958 |
|
|
|
959 |
$.extend( proto, {
|
|
|
960 |
_initSource: function() {
|
|
|
961 |
if ( this.options.html && $.isArray(this.options.source) ) {
|
|
|
962 |
this.source = function( request, response ) {
|
|
|
963 |
response( filter( this.options.source, request.term ) );
|
|
|
964 |
};
|
|
|
965 |
} else {
|
|
|
966 |
initSource.call( this );
|
|
|
967 |
}
|
|
|
968 |
},
|
|
|
969 |
_renderItem: function( ul, item) {
|
|
|
970 |
if (item.retenu == true) {
|
|
|
971 |
item.label = "<strong>"+item.label+"</strong>";
|
|
|
972 |
}
|
|
|
973 |
|
|
|
974 |
return $( "<li></li>" )
|
|
|
975 |
.data( "item.autocomplete", item )
|
|
|
976 |
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
|
|
|
977 |
.appendTo( ul );
|
|
|
978 |
}
|
1210 |
jpm |
979 |
});
|
|
|
980 |
})( jQuery );
|