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 |
|
1253 |
jpm |
455 |
$("[rel=tooltip]").tooltip('enable');
|
1249 |
jpm |
456 |
$("#btn-aide").on('click', basculerAffichageAide);
|
1218 |
jpm |
457 |
|
1249 |
jpm |
458 |
$("#prenom").on("change", formaterPrenom);
|
1218 |
jpm |
459 |
|
1249 |
jpm |
460 |
$("#nom").on("change", formaterNom);
|
1210 |
jpm |
461 |
|
1249 |
jpm |
462 |
configurerDatePicker();
|
1210 |
jpm |
463 |
|
|
|
464 |
ajouterAutocompletionNoms();
|
|
|
465 |
|
1249 |
jpm |
466 |
configurerFormValidator();
|
|
|
467 |
definirReglesFormValidator();
|
|
|
468 |
|
|
|
469 |
$("#courriel_confirmation").on('paste', bloquerCopierCollerCourriel);
|
|
|
470 |
|
|
|
471 |
$("a.afficher-coord").on('click', basculerAffichageCoord);
|
|
|
472 |
|
|
|
473 |
$("#ajouter-obs").on('click', ajouterObs);
|
|
|
474 |
|
|
|
475 |
$(".obs-nbre").on('changement', surChangementNbreObs);
|
|
|
476 |
|
|
|
477 |
$("body").on('click', ".supprimer-obs", supprimerObs);
|
|
|
478 |
|
|
|
479 |
$("#transmettre-obs").on('click', transmettreObs);
|
|
|
480 |
});
|
|
|
481 |
|
|
|
482 |
function configurerFormValidator() {
|
1210 |
jpm |
483 |
$.validator.addMethod(
|
|
|
484 |
"dateCel",
|
|
|
485 |
function (value, element) {
|
|
|
486 |
return /^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value);
|
1213 |
jpm |
487 |
},
|
|
|
488 |
"Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.");
|
1210 |
jpm |
489 |
$.extend($.validator.defaults, {
|
|
|
490 |
errorClass: "control-group error",
|
|
|
491 |
validClass: "control-group success",
|
|
|
492 |
errorElement: "span",
|
1213 |
jpm |
493 |
highlight: function(element, errorClass, validClass) {
|
1210 |
jpm |
494 |
if (element.type === 'radio') {
|
|
|
495 |
this.findByName(element.name).parent("div").parent("div").removeClass(validClass).addClass(errorClass);
|
|
|
496 |
} else {
|
|
|
497 |
$(element).parent("div").parent("div").removeClass(validClass).addClass(errorClass);
|
|
|
498 |
}
|
|
|
499 |
},
|
1213 |
jpm |
500 |
unhighlight: function(element, errorClass, validClass) {
|
1210 |
jpm |
501 |
if (element.type === 'radio') {
|
|
|
502 |
this.findByName(element.name).parent("div").parent("div").removeClass(errorClass).addClass(validClass);
|
|
|
503 |
} else {
|
1213 |
jpm |
504 |
if ($(element).attr('id') == 'taxon') {
|
|
|
505 |
var warningClass = "control-group warning";
|
1215 |
jpm |
506 |
if ($("#taxon").data("value") != $("#taxon").val()) {
|
|
|
507 |
$("#taxon").removeData();
|
|
|
508 |
$("#taxon").removeClass('ns-retenu');
|
1213 |
jpm |
509 |
if ($("#taxon").val() != '') {
|
|
|
510 |
$("#taxon-input-groupe").removeClass(validClass)
|
|
|
511 |
.removeClass(errorClass)
|
|
|
512 |
.addClass(warningClass);
|
1240 |
jpm |
513 |
this.showLabel(element, "Ce nom n'est pas lié au référentiel.");
|
1213 |
jpm |
514 |
}
|
|
|
515 |
} else {
|
|
|
516 |
if ($("#taxon").val() != '') {
|
|
|
517 |
$("#taxon-input-groupe").removeClass(warningClass)
|
|
|
518 |
.removeClass(errorClass)
|
|
|
519 |
.addClass(validClass);
|
|
|
520 |
$(element).next(" span.help-inline").remove();
|
|
|
521 |
}
|
|
|
522 |
}
|
|
|
523 |
} else {
|
|
|
524 |
$(element).parent("div").parent("div").removeClass(errorClass).addClass(validClass);
|
|
|
525 |
$(element).next(" span.help-inline").remove();
|
|
|
526 |
}
|
1210 |
jpm |
527 |
}
|
|
|
528 |
}
|
|
|
529 |
});
|
1249 |
jpm |
530 |
}
|
|
|
531 |
|
|
|
532 |
function definirReglesFormValidator() {
|
1210 |
jpm |
533 |
$("#form-observateur").validate({
|
|
|
534 |
rules: {
|
|
|
535 |
courriel : {
|
|
|
536 |
required : true,
|
|
|
537 |
email : true},
|
|
|
538 |
courriel_confirmation : {
|
|
|
539 |
required : true,
|
|
|
540 |
equalTo: "#courriel"}
|
|
|
541 |
}
|
|
|
542 |
});
|
|
|
543 |
$("#form-station").validate({
|
|
|
544 |
rules: {
|
|
|
545 |
latitude : {
|
|
|
546 |
required: true,
|
|
|
547 |
range: [-90, 90]},
|
|
|
548 |
longitude : {
|
|
|
549 |
required: true,
|
|
|
550 |
range: [-180, 180]}
|
|
|
551 |
}
|
|
|
552 |
});
|
|
|
553 |
$("#form-obs").validate({
|
|
|
554 |
rules: {
|
1213 |
jpm |
555 |
date : "dateCel",
|
1210 |
jpm |
556 |
taxon : "required"
|
|
|
557 |
}
|
|
|
558 |
});
|
1249 |
jpm |
559 |
}
|
|
|
560 |
|
|
|
561 |
function configurerDatePicker() {
|
|
|
562 |
$.datepicker.setDefaults($.datepicker.regional["fr"]);
|
|
|
563 |
$("#date").datepicker({
|
|
|
564 |
dateFormat: "dd/mm/yy",
|
|
|
565 |
showOn: "button",
|
|
|
566 |
buttonImageOnly: true,
|
|
|
567 |
buttonImage: CALENDRIER_ICONE_URL,
|
|
|
568 |
buttonText: "Afficher le calendrier pour saisir la date.",
|
|
|
569 |
showButtonPanel: true
|
1210 |
jpm |
570 |
});
|
1249 |
jpm |
571 |
$("img.ui-datepicker-trigger").appendTo("#date-icone");
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
function fermerPanneauAlert() {
|
|
|
575 |
$(this).parentsUntil(".zone-alerte", ".alert").hide();
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
function formaterNom() {
|
|
|
579 |
$(this).val($(this).val().toUpperCase());
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
function formaterPrenom() {
|
|
|
583 |
var prenom = new Array();
|
|
|
584 |
var mots = $(this).val().split(' ');
|
|
|
585 |
for (var i = 0; i < mots.length; i++) {
|
|
|
586 |
var mot = mots[i];
|
|
|
587 |
if (mot.indexOf('-') >= 0) {
|
|
|
588 |
var prenomCompose = new Array();
|
|
|
589 |
var motsComposes = mot.split('-');
|
|
|
590 |
for (var j = 0; j < motsComposes.length; j++) {
|
|
|
591 |
var motSimple = motsComposes[j];
|
|
|
592 |
var motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
|
|
|
593 |
prenomCompose.push(motMajuscule);
|
|
|
594 |
}
|
|
|
595 |
prenom.push(prenomCompose.join('-'));
|
|
|
596 |
} else {
|
|
|
597 |
var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
|
|
|
598 |
prenom.push(motMajuscule);
|
|
|
599 |
}
|
|
|
600 |
}
|
|
|
601 |
$(this).val(prenom.join(' '));
|
|
|
602 |
}
|
|
|
603 |
|
|
|
604 |
function basculerAffichageAide() {
|
|
|
605 |
if ($(this).hasClass('btn-warning')) {
|
|
|
606 |
$("[rel=tooltip]").tooltip('enable');
|
|
|
607 |
$(this).removeClass('btn-warning').addClass('btn-success');
|
|
|
608 |
$('#btn-aide-txt', this).text("Désactiver l'aide");
|
|
|
609 |
} else {
|
|
|
610 |
$("[rel=tooltip]").tooltip('disable');
|
|
|
611 |
$(this).removeClass('btn-success').addClass('btn-warning');
|
|
|
612 |
$('#btn-aide-txt', this).text("Activer l'aide");
|
|
|
613 |
}
|
|
|
614 |
}
|
|
|
615 |
|
|
|
616 |
function bloquerCopierCollerCourriel() {
|
1251 |
jpm |
617 |
afficherPanneau("#dialogue-bloquer-copier-coller");
|
1249 |
jpm |
618 |
return false;
|
|
|
619 |
}
|
|
|
620 |
|
|
|
621 |
function basculerAffichageCoord() {
|
|
|
622 |
$("a.afficher-coord").toggle();
|
|
|
623 |
$("#coordonnees-geo").toggle('slow');
|
|
|
624 |
//valeur false pour que le lien ne soit pas suivi
|
|
|
625 |
return false;
|
|
|
626 |
}
|
|
|
627 |
|
|
|
628 |
function ajouterObs() {
|
|
|
629 |
if (validerFormulaire() == true) {
|
|
|
630 |
obsNbre = obsNbre + 1;
|
|
|
631 |
$(".obs-nbre").text(obsNbre);
|
|
|
632 |
$(".obs-nbre").triggerHandler('changement');
|
|
|
633 |
afficherObs();
|
|
|
634 |
stockerObsData();
|
|
|
635 |
supprimerMiniature();
|
|
|
636 |
} else {
|
|
|
637 |
afficherPanneau('#dialogue-form-invalide');
|
|
|
638 |
}
|
|
|
639 |
}
|
|
|
640 |
|
|
|
641 |
function afficherObs() {
|
|
|
642 |
$("#liste-obs").prepend(
|
|
|
643 |
'<div id="obs'+obsNbre+'" class="row-fluid obs obs'+obsNbre+'">'+
|
|
|
644 |
'<div class="span12">'+
|
1253 |
jpm |
645 |
'<div class="well">'+
|
|
|
646 |
'<div class="obs-action pull-right" rel="tooltip" data-placement="bottom" '+
|
|
|
647 |
'title="Supprimer cette observation de la liste à transmettre">'+
|
1249 |
jpm |
648 |
'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
|
|
|
649 |
'<i class="icon-trash icon-white"></i>'+
|
|
|
650 |
'</button>'+
|
|
|
651 |
'</div> '+
|
|
|
652 |
'<div class="row-fluid">'+
|
|
|
653 |
'<div class="thumbnail span2">'+
|
|
|
654 |
ajouterImgMiniatureAuTransfert()+
|
1240 |
jpm |
655 |
'</div>'+
|
1249 |
jpm |
656 |
'<div class="span9">'+
|
|
|
657 |
'<ul class="unstyled">'+
|
|
|
658 |
'<li>'+
|
|
|
659 |
'<span class="nom-sci">'+$("#taxon").val()+'</span> '+
|
|
|
660 |
ajouterNumNomSel()+
|
|
|
661 |
' observé à '+
|
|
|
662 |
'<span class="commune">'+$('#commune-nom').text()+'</span> '+
|
|
|
663 |
'('+$('#commune-code-insee').text()+') ['+$("#latitude").val()+' / '+$("#longitude").val()+']'+
|
|
|
664 |
' le '+
|
|
|
665 |
'<span class="date">'+$("#date").val()+'</span>'+
|
|
|
666 |
'</li>'+
|
|
|
667 |
'<li>'+
|
|
|
668 |
'<span>Lieu-dit :</span> '+$('#lieudit').val()+' '+
|
|
|
669 |
'<span>Station :</span> '+$('#station').val()+' '+
|
|
|
670 |
'<span>Milieu :</span> '+$('#milieu').val()+' '+
|
|
|
671 |
'</li>'+
|
|
|
672 |
'<li>'+
|
|
|
673 |
'Commentaires : <span class="discretion">'+$("#notes").val()+'</span>'+
|
|
|
674 |
'</li>'+
|
|
|
675 |
'</ul>'+
|
|
|
676 |
'</div>'+
|
1237 |
jpm |
677 |
'</div>'+
|
1249 |
jpm |
678 |
'</div>'+
|
|
|
679 |
'</div>'+
|
|
|
680 |
'</div>');
|
|
|
681 |
}
|
|
|
682 |
|
|
|
683 |
function stockerObsData() {
|
|
|
684 |
$("#liste-obs").data('obsId'+obsNbre, {
|
|
|
685 |
'date' : $("#date").val(),
|
|
|
686 |
'notes' : $("#notes").val(),
|
|
|
687 |
|
|
|
688 |
'nom_sel' : $("#taxon").val(),
|
|
|
689 |
'num_nom_sel' : $("#taxon").data("numNomSel"),
|
|
|
690 |
'nom_ret' : $("#taxon").data("nomRet"),
|
|
|
691 |
'num_nom_ret' : $("#taxon").data("numNomRet"),
|
|
|
692 |
'num_taxon' : $("#taxon").data("nt"),
|
|
|
693 |
'famille' : $("#taxon").data("famille"),
|
|
|
694 |
'referentiel' : ($("#taxon").data("numNomSel") == undefined ? '' : NOM_SCI_REFERENTIEL),
|
|
|
695 |
|
|
|
696 |
'latitude' : $("#latitude").val(),
|
|
|
697 |
'longitude' : $("#longitude").val(),
|
|
|
698 |
'commune_nom' : $("#commune-nom").text(),
|
|
|
699 |
'commune_code_insee' : $("#commune-code-insee").text(),
|
1251 |
jpm |
700 |
'lieudit' : $("#lieudit").val(),
|
1249 |
jpm |
701 |
'station' : $("#station").val(),
|
|
|
702 |
'milieu' : $("#milieu").val(),
|
|
|
703 |
|
|
|
704 |
//Ajout des champs images
|
|
|
705 |
'image_nom' : $("#miniature-img").attr('alt'),
|
|
|
706 |
'image_b64' : getB64ImgOriginal()
|
1210 |
jpm |
707 |
});
|
1249 |
jpm |
708 |
}
|
|
|
709 |
|
|
|
710 |
function surChangementNbreObs() {
|
|
|
711 |
if (obsNbre == 0) {
|
|
|
712 |
$("#transmettre-obs").attr('disabled', 'disabled');
|
|
|
713 |
$("#ajouter-obs").removeAttr('disabled');
|
|
|
714 |
} else if (obsNbre > 0 && obsNbre < OBS_MAX_NBRE) {
|
|
|
715 |
$("#transmettre-obs").removeAttr('disabled');
|
|
|
716 |
$("#ajouter-obs").removeAttr('disabled');
|
|
|
717 |
} else if (obsNbre >= OBS_MAX_NBRE) {
|
|
|
718 |
$("#ajouter-obs").attr('disabled', 'disabled');
|
|
|
719 |
afficherPanneau("#dialogue-bloquer-creer-obs");
|
|
|
720 |
}
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
function transmettreObs() {
|
|
|
724 |
var observations = $("#liste-obs").data();
|
1210 |
jpm |
725 |
|
1249 |
jpm |
726 |
if (observations == undefined || jQuery.isEmptyObject(observations)) {
|
|
|
727 |
afficherPanneau("#dialogue-zero-obs");
|
|
|
728 |
} else {
|
|
|
729 |
observations['projet'] = TAG_PROJET;
|
|
|
730 |
observations['tag-obs'] = TAG_OBS;
|
|
|
731 |
observations['tag-img'] = TAG_IMG;
|
1210 |
jpm |
732 |
|
1249 |
jpm |
733 |
var utilisateur = new Object();
|
|
|
734 |
utilisateur.prenom = $("#prenom").val();
|
|
|
735 |
utilisateur.nom = $("#nom").val();
|
|
|
736 |
utilisateur.courriel = $("#courriel").val();
|
|
|
737 |
observations['utilisateur'] = utilisateur;
|
1251 |
jpm |
738 |
console.log(observations);
|
1249 |
jpm |
739 |
envoyerObsAuCel(observations);
|
|
|
740 |
}
|
|
|
741 |
return false;
|
|
|
742 |
}
|
|
|
743 |
|
|
|
744 |
function envoyerObsAuCel(observations) {
|
|
|
745 |
var erreurMsg = "";
|
|
|
746 |
$.ajax({
|
|
|
747 |
url : SERVICE_SAISIE_URL,
|
|
|
748 |
type : "POST",
|
|
|
749 |
data : observations,
|
|
|
750 |
dataType : "json",
|
|
|
751 |
beforeSend : function() {
|
1251 |
jpm |
752 |
$("#dialogue-obs-transaction-ko").hide();
|
|
|
753 |
$("#dialogue-obs-transaction-ok").hide();
|
1249 |
jpm |
754 |
$(".alert-txt .msg").remove();
|
|
|
755 |
$(".alert-txt .msg-erreur").remove();
|
|
|
756 |
$(".alert-txt .msg-debug").remove();
|
|
|
757 |
$("#chargement").show();
|
|
|
758 |
},
|
|
|
759 |
success : function(data, textStatus, jqXHR) {
|
|
|
760 |
$('#dialogue-obs-transaction-ok .alert-txt').append($("#tpl-transmission-ok").clone().html());
|
|
|
761 |
supprimerMiniature();
|
|
|
762 |
},
|
|
|
763 |
statusCode : {
|
|
|
764 |
500 : function(jqXHR, textStatus, errorThrown) {
|
|
|
765 |
erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n";
|
|
|
766 |
}
|
|
|
767 |
},
|
|
|
768 |
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
769 |
erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
|
|
|
770 |
try {
|
|
|
771 |
reponse = jQuery.parseJSON(jqXHR.responseText);
|
|
|
772 |
if (reponse != null) {
|
|
|
773 |
$.each(reponse, function (cle, valeur) {
|
|
|
774 |
erreurMsg += valeur + "\n";
|
|
|
775 |
});
|
|
|
776 |
}
|
|
|
777 |
} catch(e) {
|
|
|
778 |
erreurMsg += "L'erreur n'était pas en JSON.";
|
|
|
779 |
}
|
|
|
780 |
},
|
|
|
781 |
complete : function(jqXHR, textStatus) {
|
|
|
782 |
$("#chargement").hide();
|
|
|
783 |
var debugMsg = extraireEnteteDebug(jqXHR);
|
1210 |
jpm |
784 |
|
1249 |
jpm |
785 |
if (erreurMsg != '') {
|
|
|
786 |
if (DEBUG) {
|
|
|
787 |
$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-erreur">'+erreurMsg+'</pre>');
|
|
|
788 |
$("#dialogue-obs-transaction-ko .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
|
1210 |
jpm |
789 |
}
|
1249 |
jpm |
790 |
var hrefCourriel = "mailto:cel@tela-botanica.org?"+
|
|
|
791 |
"subject=Disfonctionnement du widget de saisie "+TAG_PROJET+
|
|
|
792 |
"&body="+erreurMsg+"\nDébogage :\n"+debugMsg;
|
|
|
793 |
|
|
|
794 |
$('#dialogue-obs-transaction-ko .alert-txt').append($("#tpl-transmission-ko").clone()
|
|
|
795 |
.find('.courriel-erreur')
|
|
|
796 |
.attr('href', hrefCourriel)
|
|
|
797 |
.end()
|
|
|
798 |
.html());
|
|
|
799 |
$("#dialogue-obs-transaction-ko").show();
|
|
|
800 |
} else {
|
|
|
801 |
if (DEBUG) {
|
|
|
802 |
$("#dialogue-obs-transaction-ok .alert-txt").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>');
|
|
|
803 |
}
|
|
|
804 |
$("#dialogue-obs-transaction-ok").show();
|
1251 |
jpm |
805 |
}
|
|
|
806 |
initialiserObs();
|
1210 |
jpm |
807 |
}
|
|
|
808 |
});
|
1249 |
jpm |
809 |
}
|
1210 |
jpm |
810 |
|
|
|
811 |
function validerFormulaire() {
|
|
|
812 |
$observateur = $("#form-observateur").valid();
|
|
|
813 |
$station = $("#form-station").valid();
|
|
|
814 |
$obs = $("#form-obs").valid();
|
|
|
815 |
return ($observateur == true && $station == true && $obs == true) ? true : false;
|
|
|
816 |
}
|
|
|
817 |
|
|
|
818 |
function getB64ImgOriginal() {
|
|
|
819 |
var b64 = '';
|
|
|
820 |
if ($("#miniature-img").hasClass('b64')) {
|
|
|
821 |
b64 = $("#miniature-img").attr('src');
|
|
|
822 |
} else if ($("#miniature-img").hasClass('b64-canvas')) {
|
|
|
823 |
b64 = $("#miniature-img").data('b64');
|
|
|
824 |
}
|
|
|
825 |
return b64;
|
|
|
826 |
}
|
|
|
827 |
|
|
|
828 |
function supprimerObs() {
|
|
|
829 |
var obsId = $(this).val();
|
|
|
830 |
// Problème avec IE 6 et 7
|
|
|
831 |
if (obsId == "Supprimer") {
|
|
|
832 |
obsId = $(this).attr("title");
|
|
|
833 |
}
|
1215 |
jpm |
834 |
obsNbre = obsNbre - 1;
|
|
|
835 |
$(".obs-nbre").text(obsNbre);
|
1237 |
jpm |
836 |
$(".obs-nbre").triggerHandler('changement');
|
1210 |
jpm |
837 |
|
1215 |
jpm |
838 |
$('.obs'+obsId).remove();
|
1210 |
jpm |
839 |
$("#liste-obs").removeData('obsId'+obsId);
|
|
|
840 |
}
|
|
|
841 |
|
1249 |
jpm |
842 |
function initialiserObs() {
|
1231 |
jpm |
843 |
obsNbre = 0;
|
|
|
844 |
$(".obs-nbre").text(obsNbre);
|
1249 |
jpm |
845 |
$(".obs-nbre").triggerHandler('changement');
|
|
|
846 |
$("#liste-obs").removeData();
|
|
|
847 |
$('.obs').remove();
|
|
|
848 |
$("#dialogue-bloquer-creer-obs").hide();
|
1231 |
jpm |
849 |
}
|
|
|
850 |
|
1210 |
jpm |
851 |
function ajouterImgMiniatureAuTransfert() {
|
|
|
852 |
var miniature = '';
|
|
|
853 |
if ($("#miniature img").length == 1) {
|
|
|
854 |
var css = $("#miniature-img").hasClass('b64') ? 'miniature b64' : 'miniature';
|
|
|
855 |
var src = $("#miniature-img").attr("src");
|
|
|
856 |
var alt = $("#miniature-img").attr("alt");
|
1240 |
jpm |
857 |
miniature = '<img class="'+css+' " alt="'+alt+'"src="'+src+'" />';
|
1237 |
jpm |
858 |
} else {
|
|
|
859 |
miniature = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
|
1210 |
jpm |
860 |
}
|
|
|
861 |
return miniature;
|
|
|
862 |
}
|
|
|
863 |
|
1240 |
jpm |
864 |
function ajouterNumNomSel() {
|
|
|
865 |
var nn = '';
|
|
|
866 |
if ($("#taxon").data("numNomSel") == undefined) {
|
|
|
867 |
nn = '<span class="alert-error">[non lié au référentiel]</span>';
|
|
|
868 |
} else {
|
|
|
869 |
nn = '<span class="nn">[nn'+$("#taxon").data("numNomSel")+']</span>';
|
|
|
870 |
}
|
|
|
871 |
return nn;
|
|
|
872 |
}
|
|
|
873 |
|
1210 |
jpm |
874 |
//+---------------------------------------------------------------------------------------------------------+
|
|
|
875 |
// AUTO-COMPLÉTION Noms Scientifiques
|
|
|
876 |
|
|
|
877 |
function ajouterAutocompletionNoms() {
|
|
|
878 |
$('#taxon').autocomplete({
|
|
|
879 |
source: function(requete, add){
|
|
|
880 |
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
|
|
|
881 |
requete = "";
|
1215 |
jpm |
882 |
var url = getUrlAutocompletionNomsSci();
|
|
|
883 |
$.getJSON(url, requete, function(data) {
|
1210 |
jpm |
884 |
var suggestions = traiterRetourNomsSci(data);
|
|
|
885 |
add(suggestions);
|
|
|
886 |
});
|
|
|
887 |
},
|
|
|
888 |
html: true
|
|
|
889 |
});
|
1215 |
jpm |
890 |
|
1213 |
jpm |
891 |
$( "#taxon" ).bind("autocompleteselect", function(event, ui) {
|
1215 |
jpm |
892 |
$("#taxon").data(ui.item);
|
|
|
893 |
if (ui.item.retenu == true) {
|
|
|
894 |
$("#taxon").addClass('ns-retenu');
|
|
|
895 |
} else {
|
|
|
896 |
$("#taxon").removeClass('ns-retenu');
|
|
|
897 |
}
|
1213 |
jpm |
898 |
});
|
1210 |
jpm |
899 |
}
|
|
|
900 |
|
1215 |
jpm |
901 |
function getUrlAutocompletionNomsSci() {
|
|
|
902 |
var mots = $('#taxon').val();
|
1210 |
jpm |
903 |
var url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL.replace('{masque}', mots);
|
|
|
904 |
return url;
|
|
|
905 |
}
|
|
|
906 |
|
|
|
907 |
function traiterRetourNomsSci(data) {
|
|
|
908 |
var suggestions = [];
|
|
|
909 |
if (data.resultat != undefined) {
|
|
|
910 |
$.each(data.resultat, function(i, val) {
|
|
|
911 |
val.nn = i;
|
1215 |
jpm |
912 |
var nom = {label : '', value : '', nt : '', nomSel : '', nomSelComplet : '', numNomSel : '',
|
|
|
913 |
nomRet : '', numNomRet : '', famille : '', retenu : false
|
|
|
914 |
};
|
|
|
915 |
if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
|
1213 |
jpm |
916 |
nom.label = "...";
|
|
|
917 |
nom.value = $('#taxon').val();
|
|
|
918 |
suggestions.push(nom);
|
|
|
919 |
return false;
|
|
|
920 |
} else {
|
1231 |
jpm |
921 |
nom.label = val.nom_sci_complet;
|
|
|
922 |
nom.value = val.nom_sci_complet;
|
1215 |
jpm |
923 |
nom.nt = val.num_taxonomique;
|
|
|
924 |
nom.nomSel = val.nom_sci;
|
|
|
925 |
nom.nomSelComplet = val.nom_sci_complet;
|
|
|
926 |
nom.numNomSel = val.nn;
|
1237 |
jpm |
927 |
nom.nomRet = val.nom_retenu_complet;
|
1220 |
jpm |
928 |
nom.numNomRet = val["nom_retenu.id"];
|
1231 |
jpm |
929 |
nom.famille = val.famille;
|
1215 |
jpm |
930 |
nom.retenu = (val.retenu == 'false') ? false : true;
|
|
|
931 |
|
1213 |
jpm |
932 |
suggestions.push(nom);
|
|
|
933 |
}
|
1210 |
jpm |
934 |
});
|
|
|
935 |
}
|
1213 |
jpm |
936 |
|
1210 |
jpm |
937 |
return suggestions;
|
|
|
938 |
}
|
|
|
939 |
|
|
|
940 |
/*
|
|
|
941 |
* jQuery UI Autocomplete HTML Extension
|
|
|
942 |
*
|
|
|
943 |
* Copyright 2010, Scott González (http://scottgonzalez.com)
|
|
|
944 |
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
945 |
*
|
|
|
946 |
* http://github.com/scottgonzalez/jquery-ui-extensions
|
|
|
947 |
*
|
|
|
948 |
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
|
|
|
949 |
*/
|
|
|
950 |
(function( $ ) {
|
1215 |
jpm |
951 |
var proto = $.ui.autocomplete.prototype,
|
|
|
952 |
initSource = proto._initSource;
|
|
|
953 |
|
|
|
954 |
function filter( array, term ) {
|
|
|
955 |
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
|
|
|
956 |
return $.grep( array, function(value) {
|
|
|
957 |
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
|
|
|
958 |
});
|
|
|
959 |
}
|
|
|
960 |
|
|
|
961 |
$.extend( proto, {
|
|
|
962 |
_initSource: function() {
|
|
|
963 |
if ( this.options.html && $.isArray(this.options.source) ) {
|
|
|
964 |
this.source = function( request, response ) {
|
|
|
965 |
response( filter( this.options.source, request.term ) );
|
|
|
966 |
};
|
|
|
967 |
} else {
|
|
|
968 |
initSource.call( this );
|
|
|
969 |
}
|
|
|
970 |
},
|
|
|
971 |
_renderItem: function( ul, item) {
|
|
|
972 |
if (item.retenu == true) {
|
|
|
973 |
item.label = "<strong>"+item.label+"</strong>";
|
|
|
974 |
}
|
|
|
975 |
|
|
|
976 |
return $( "<li></li>" )
|
|
|
977 |
.data( "item.autocomplete", item )
|
|
|
978 |
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
|
|
|
979 |
.appendTo( ul );
|
|
|
980 |
}
|
1210 |
jpm |
981 |
});
|
|
|
982 |
})( jQuery );
|