Subversion Repositories eFlore/Applications.cel

Rev

Rev 1560 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1560 Rev 1562
Line 41... Line 41...
41
function afficherPanneau(selecteur) {
41
function afficherPanneau(selecteur) {
42
	$(selecteur).fadeIn('slow').delay(DUREE_MESSAGE).fadeOut('slow');
42
	$(selecteur).fadeIn('slow').delay(DUREE_MESSAGE).fadeOut('slow');
43
}
43
}
Line 44... Line 44...
44
 
44
 
45
//+----------------------------------------------------------------------------------------------------------+
45
//+----------------------------------------------------------------------------------------------------------+
-
 
46
//FORM IDENTITE : gestion de l'observateur
46
//UPLOAD PHOTO : Traitement de l'image 
47
 
47
$(document).ready(function() {
-
 
48
	$('.effacer-miniature').click(function () {
-
 
49
		supprimerMiniatures($(this));
-
 
50
	});
-
 
51
	
-
 
52
	$('#photo-placeholder').click(function(event) {
-
 
53
		$('#fichier').click();
-
 
54
	});
-
 
55
	
48
$(document).ready(function() {
56
	$('#fichier').bind('change', function (e) {
-
 
57
		arreter(e);
-
 
58
		var options = { 
-
 
59
			success: afficherMiniature, // post-submit callback 
-
 
60
			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type) 
-
 
61
			resetForm: true // reset the form after successful submit 
-
 
62
		};
-
 
63
		$('#miniature').append(
-
 
64
			'<img id="miniature-chargement" class="miniature" alt="chargement" src="'+CHARGEMENT_IMAGE_URL+'"/>');
49
	$('#courriel').on('blur', requeterIdentite);
65
		$('#ajouter-obs').attr('disabled', 'disabled');
-
 
66
		if(verifierFormat($('#fichier').val())) {
-
 
67
			$('#form-upload').ajaxSubmit(options);
-
 
68
		} else {
-
 
69
			window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+	$('#fichier').attr('accept'));
-
 
70
		}
-
 
71
		return false;
-
 
72
	});
-
 
73
	
-
 
74
	$('.effacer-miniature').on('click', function() {
-
 
75
		$(this).parent().remove();
-
 
76
	});
50
	$('#courriel').on('keypress', testerLancementRequeteIdentite);
Line 77... Line 51...
77
});
51
});
-
 
52
 
78
 
53
function testerLancementRequeteIdentite(event) {
79
function verifierFormat(nom) {
54
	if (event.which == 13) {
80
	var parts = nom.split('.');
55
		requeterIdentite();
-
 
56
		event.preventDefault();
81
	extension = parts[parts.length - 1];
57
		event.stopPropagation();
Line 82... Line 58...
82
	return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
58
	}
-
 
59
}
-
 
60
 
-
 
61
function requeterIdentite() {
-
 
62
	var courriel = $('#courriel').val();
-
 
63
	//TODO: mettre ceci en paramètre de config
83
}
64
	var urlAnnuaire = SERVICE_ANNUAIRE_ID_URL + courriel;
84
 
65
	$.ajax({
85
function afficherMiniature(reponse) { 
66
		url: urlAnnuaire,
86
	if (DEBUG) {
-
 
87
		var debogage = $('debogage', reponse).text();
67
		type: 'GET',
88
		console.log('Débogage upload : ' + debogage);
68
		success: function(data, textStatus, jqXHR) {
89
	}
69
			console.log('SUCCESS:'+textStatus);
-
 
70
			if (data != undefined && data[courriel] != undefined) {
-
 
71
				var infos = data[courriel];
-
 
72
				$('#id_utilisateur').val(infos.id);
-
 
73
				$('#prenom').val(infos.prenom);
-
 
74
				$('#nom').val(infos.nom);
90
	var message = $('message', reponse).text();
75
				$('#courriel_confirmation').val(courriel);
-
 
76
				$('#prenom, #nom, #courriel_confirmation').attr('disabled', 'disabled');
-
 
77
				$('#date').focus();
-
 
78
			} else {
91
	if (message != '') {
79
				surErreurCompletionCourriel();
-
 
80
			}
-
 
81
		},
92
		$('#miniature-msg').append(message);
82
		error: function(jqXHR, textStatus, errorThrown) {
-
 
83
			console.log('ERREUR :'+textStatus);
-
 
84
			surErreurCompletionCourriel();
93
	} else {
85
		},
-
 
86
		complete: function(jqXHR, textStatus) {
-
 
87
			console.log('COMPLETE :'+textStatus);
-
 
88
			$('#zone-prenom-nom').removeClass('hidden');
94
		$('#miniatures').append(creerWidgetMiniature(reponse));
89
			$('#zone-courriel-confirmation').removeClass('hidden');
Line 95... Line 90...
95
	}
90
		}
96
	$('#ajouter-obs').removeAttr('disabled');	
91
	});
97
}
-
 
98
 
-
 
99
function creerWidgetMiniature(reponse) {
-
 
100
	var miniatureUrl = $('miniature-url', reponse).text(),
92
}
101
		imgNom = $('image-nom', reponse).text(),
93
 
102
		html = 
-
 
103
			'<div class="miniature">'+
-
 
104
				'<img class="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
94
function surErreurCompletionCourriel() {
Line 105... Line 95...
105
				'<button class="effacer-miniature" type="button">Effacer</button>'+
95
	$('#prenom, #nom, #courriel_confirmation').val('');
-
 
96
	$('#prenom, #nom, #courriel_confirmation').removeAttr('disabled');
-
 
97
	afficherPanneau('#dialogue-courriel-introuvable');
-
 
98
}
-
 
99
 
106
			'</div>'
100
function formaterNom() {
-
 
101
	$(this).val($(this).val().toUpperCase());
-
 
102
}
-
 
103
 
-
 
104
function formaterPrenom() {
-
 
105
	var prenom = new Array(),
-
 
106
		mots = $(this).val().split(' ');
-
 
107
	for (var i = 0; i < mots.length; i++) {
-
 
108
		var mot = mots[i];
-
 
109
		if (mot.indexOf('-') >= 0) {
-
 
110
			var prenomCompose = new Array(),
-
 
111
				motsComposes = mot.split('-');
-
 
112
			for (var j = 0; j < motsComposes.length; j++) {
-
 
113
				var motSimple = motsComposes[j],
-
 
114
					motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
-
 
115
				prenomCompose.push(motMajuscule);
-
 
116
			}
-
 
117
			prenom.push(prenomCompose.join('-'));
107
	return html;
118
		} else {
108
}
119
			var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
Line 109... Line 120...
109
 
120
			prenom.push(motMajuscule);
110
function supprimerMiniatures() {
121
		}
-
 
122
	}
111
	$('#miniatures').empty();
123
	$(this).val(prenom.join(' '));
112
	$('#miniature-msg').empty();
124
}
113
}
125
 
114
 
126
//+----------------------------------------------------------------------------------------------------------+
Line 163... Line 175...
163
		}
175
		}
164
	});
176
	});
Line 165... Line 177...
165
	
177
	
Line 166... Line 178...
166
	$('#geolocaliser').on('click', geolocaliser);
178
	$('#geolocaliser').on('click', geolocaliser);
Line 167... Line 179...
167
	
179
	
168
	google.maps.event.addListener(marker, 'dragend', surDeplacementMarker);
180
	//google.maps.event.addListener(marker, 'dragend', surDeplacementMarker);
Line 169... Line 181...
169
	
181
	
170
	google.maps.event.addListener(map, 'click', surClickDansCarte);
182
	//google.maps.event.addListener(map, 'click', surClickDansCarte);
171
});
183
});
Line 183... Line 195...
183
					google.maps.MapTypeId.ROADMAP, 
195
					google.maps.MapTypeId.ROADMAP, 
184
					google.maps.MapTypeId.HYBRID, 
196
					google.maps.MapTypeId.HYBRID, 
185
					google.maps.MapTypeId.SATELLITE, 
197
					google.maps.MapTypeId.SATELLITE, 
186
					google.maps.MapTypeId.TERRAIN]}
198
					google.maps.MapTypeId.TERRAIN]}
187
		};
199
		};
188
 
200
	
189
	// Ajout de la couche OSM à la carte
201
	// Ajout de la couche OSM à la carte
190
	osmMapType = new google.maps.ImageMapType({
202
	osmMapType = new google.maps.ImageMapType({
191
		getTileUrl: function(coord, zoom) {
203
		getTileUrl: function(coord, zoom) {
192
			return 'http://tile.openstreetmap.org/' + zoom + '/' + coord.x + '/' + coord.y + '.png';
204
			return 'http://tile.openstreetmap.org/' + zoom + '/' + coord.x + '/' + coord.y + '.png';
193
		},
205
		},
Line 344... Line 356...
344
				}
356
				}
345
			}
357
			}
346
		});
358
		});
347
	});
359
	});
348
}
360
}
-
 
361
 
-
 
362
 
349
//+---------------------------------------------------------------------------------------------------------+
363
//+---------------------------------------------------------------------------------------------------------+
350
// IDENTITÉ
-
 
351
$(document).ready(function() {
364
//AUTO-COMPLÉTION Noms Scientifiques
352
	$('#courriel').on('blur', requeterIdentite);
-
 
353
	$('#courriel').on('keypress', testerLancementRequeteIdentite);
-
 
354
});
-
 
Line 355... Line 365...
355
 
365
 
-
 
366
function ajouterAutocompletionNoms() {
-
 
367
	$('#taxon').autocomplete({
-
 
368
		source: function(requete, add){  
-
 
369
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
-
 
370
			
-
 
371
			var url = getUrlAutocompletionNomsSci();
-
 
372
			$.getJSON(url, function(data) {
-
 
373
				console.log(data);
-
 
374
				var suggestions = traiterRetourNomsSci(data);
-
 
375
				add(suggestions);  
-
 
376
			});
-
 
377
		},
-
 
378
		html: true
-
 
379
	});
-
 
380
	
-
 
381
	$('#taxon').bind('autocompleteselect', function(event, ui) {
356
function testerLancementRequeteIdentite(event) {
382
		$('#taxon').data(ui.item);
-
 
383
		if (ui.item.retenu == true) {
-
 
384
			$('#taxon').addClass('ns-retenu');
-
 
385
		} else {
-
 
386
			$('#taxon').removeClass('ns-retenu');
-
 
387
		}
-
 
388
	});
-
 
389
}
-
 
390
 
-
 
391
function getUrlAutocompletionNomsSci() {
-
 
392
	var mots = $('#taxon').val(),
-
 
393
		url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_PROJET);
-
 
394
	url = url.replace('{masque}', mots);
-
 
395
	return url;
-
 
396
}
-
 
397
 
357
	if (event.which == 13) {
398
function traiterRetourNomsSci(data) {
-
 
399
	var suggestions = [];
-
 
400
	if (data.resultat != undefined) {
-
 
401
		$.each(data.resultat, function(i, val) {
-
 
402
			val.nn = i;
-
 
403
			var nom = {label: '', value: '', nt: '', nomSel: '', nomSelComplet: '', numNomSel: '',
-
 
404
				nomRet: '', numNomRet: '', famille: '', retenu: false
-
 
405
			};
-
 
406
			if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
-
 
407
				nom.label = '...';
-
 
408
				nom.value = $('#taxon').val();
358
		requeterIdentite();
409
				suggestions.push(nom);
-
 
410
				return false;
-
 
411
			} else {
-
 
412
				nom.label = val.nom_sci_complet;
-
 
413
				nom.value = val.nom_sci_complet;
-
 
414
				nom.nt = val.num_taxonomique;
-
 
415
				nom.nomSel = val.nom_sci;
-
 
416
				nom.nomSelComplet = val.nom_sci_complet;
-
 
417
				nom.numNomSel = val.nn;
-
 
418
				nom.nomRet = val.nom_retenu_complet;
-
 
419
				nom.numNomRet = val['nom_retenu.id'];
-
 
420
				nom.famille = val.famille;
-
 
421
				nom.retenu = (val.retenu == 'false') ? false : true;
359
		event.preventDefault();
422
				
-
 
423
				suggestions.push(nom);
-
 
424
			}
360
		event.stopPropagation();
425
		});
-
 
426
	}
361
	}
427
	return suggestions;
Line -... Line 428...
-
 
428
}
362
}
429
 
-
 
430
/*
-
 
431
* jQuery UI Autocomplete HTML Extension
363
 
432
*
-
 
433
* Copyright 2010, Scott González (http://scottgonzalez.com)
364
function requeterIdentite() {
434
* Dual licensed under the MIT or GPL Version 2 licenses.
-
 
435
*
365
	var courriel = $('#courriel').val();
436
* http://github.com/scottgonzalez/jquery-ui-extensions
366
	//TODO: mettre ceci en paramètre de config
437
* 
367
	var urlAnnuaire = SERVICE_ANNUAIRE_ID_URL + courriel;
438
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
368
	$.ajax({
439
*/
369
		url: urlAnnuaire,
440
(function($) {
-
 
441
	var proto = $.ui.autocomplete.prototype,
370
		type: 'GET',
442
		initSource = proto._initSource;
371
		success: function(data, textStatus, jqXHR) {
443
	
372
			console.log('SUCCESS:'+textStatus);
444
	function filter(array, term) {
373
			if (data != undefined && data[courriel] != undefined) {
445
		var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), 'i');
-
 
446
		return $.grep(array, function(value) {
-
 
447
			return matcher.test($('<div>').html(value.label || value.value || value).text());
-
 
448
		});
374
				var infos = data[courriel];
449
	}
375
				$('#id_utilisateur').val(infos.id);
450
	
-
 
451
	$.extend(proto, {
376
				$('#prenom').val(infos.prenom);
452
		_initSource: function() {
377
				$('#nom').val(infos.nom);
453
			if (this.options.html && $.isArray(this.options.source)) {
378
				$('#courriel_confirmation').val(courriel);
454
				this.source = function( request, response ) {
379
				$('#prenom, #nom, #courriel_confirmation').attr('disabled', 'disabled');
455
					response(filter(this.options.source, request.term));
380
				$('#date').focus();
456
				};
381
			} else {
457
			} else {
382
				surErreurCompletionCourriel();
458
				initSource.call(this);
383
			}
459
			}
-
 
460
		},
384
		},
461
		_renderItem: function(ul, item) {
-
 
462
			if (item.retenu == true) {
-
 
463
				item.label = '<strong>'+item.label+'</strong>';
-
 
464
			}
385
		error: function(jqXHR, textStatus, errorThrown) {
465
			
-
 
466
			return $('<li></li>')
-
 
467
				.data('item.autocomplete', item)
386
			console.log('ERREUR :'+textStatus);
468
				.append($('<a></a>')[this.options.html ? 'html' : 'text'](item.label))
-
 
469
				.appendTo(ul);
-
 
470
		}
-
 
471
	});
-
 
472
})(jQuery);
-
 
473
 
387
			surErreurCompletionCourriel();
474
//+----------------------------------------------------------------------------------------------------------+
-
 
475
//UPLOAD PHOTO : Traitement de l'image 
388
		},
476
$(document).ready(function() {
-
 
477
	$('body').on('click', '.effacer-miniature', function(event) {
-
 
478
		supprimerMiniature($(this));
389
		complete: function(jqXHR, textStatus) {
479
	});
-
 
480
	
-
 
481
	$('#photo-placeholder').click(function(event) {
-
 
482
		$('#fichier').click();
-
 
483
	});
-
 
484
	
-
 
485
	$('#fichier').bind('change', function (e) {
-
 
486
		arreter(e);
-
 
487
		var options = { 
-
 
488
			success: afficherMiniature, // post-submit callback 
-
 
489
			dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type) 
-
 
490
			resetForm: true // reset the form after successful submit 
-
 
491
		};
390
			console.log('COMPLETE :'+textStatus);
492
		$('#miniature').append(
-
 
493
			'<img id="miniature-chargement" class="miniature" alt="chargement" src="'+CHARGEMENT_IMAGE_URL+'"/>');
-
 
494
		$('#ajouter-obs').attr('disabled', 'disabled');
-
 
495
		if (verifierFormat($('#fichier').val())) {
-
 
496
			$('#form-upload').ajaxSubmit(options);
391
			$('#zone-prenom-nom').removeClass('hidden');
497
		} else {
-
 
498
			window.alert("Le format de fichier n'est pas supporté, les formats acceptés sont "+	$('#fichier').attr('accept'));
392
			$('#zone-courriel-confirmation').removeClass('hidden');
499
		}
-
 
500
		return false;
-
 
501
	});
-
 
502
	
-
 
503
	$('.effacer-miniature').on('click', function() {
-
 
504
		$(this).parent().remove();
-
 
505
	});
-
 
506
});
-
 
507
 
-
 
508
function verifierFormat(nom) {
-
 
509
	var parts = nom.split('.');
393
		}
510
	extension = parts[parts.length - 1];
Line 394... Line 511...
394
	});
511
	return (extension.toLowerCase() == 'jpeg' || extension.toLowerCase() == 'jpg');
-
 
512
}
-
 
513
 
-
 
514
function afficherMiniature(reponse) { 
-
 
515
	if (DEBUG) {
-
 
516
		var debogage = $('debogage', reponse).text();
-
 
517
		console.log('Débogage upload : ' + debogage);
-
 
518
	}
-
 
519
	var message = $('message', reponse).text();
395
}
520
	if (message != '') {
-
 
521
		$('#miniature-msg').append(message);
396
 
522
	} else {
-
 
523
		$('#miniatures').append(creerWidgetMiniature(reponse));
-
 
524
	}
-
 
525
	$('#ajouter-obs').removeAttr('disabled');	
-
 
526
}
-
 
527
 
-
 
528
function creerWidgetMiniature(reponse) {
-
 
529
	var miniatureUrl = $('miniature-url', reponse).text(),
-
 
530
		imgNom = $('image-nom', reponse).text(),
-
 
531
		html = 
-
 
532
			'<div class="miniature">'+
-
 
533
				'<img class="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'+
-
 
534
				'<button class="btn effacer-miniature" type="button">Effacer</button>'+
-
 
535
			'</div>'
-
 
536
	return html;
397
function surErreurCompletionCourriel() {
537
}
-
 
538
 
-
 
539
function supprimerMiniature(miniature) {
-
 
540
	miniature.parents('.miniature').remove();
-
 
541
}
-
 
542
 
398
	$('#prenom, #nom, #courriel_confirmation').val('');
543
function supprimerMiniatures() {
-
 
544
	$('#miniatures').empty();
-
 
545
	$('#miniature-msg').empty();
399
	$('#prenom, #nom, #courriel_confirmation').removeAttr('disabled');
546
}
400
	afficherPanneau('#dialogue-courriel-introuvable');
547
 
401
}
-
 
Line 402... Line 548...
402
//+---------------------------------------------------------------------------------------------------------+
548
 
403
// FORMULAIRE
549
//+---------------------------------------------------------------------------------------------------------+
404
var obsNbre = 0;
550
// FORMULAIRE : traitements génériques
405
 
551
 
Line 440... Line 586...
440
	
586
	
Line 441... Line 587...
441
	ajouterAutocompletionNoms();
587
	ajouterAutocompletionNoms();
442
	
588
	
443
	configurerFormValidator();
589
	configurerFormValidator();
-
 
590
	definirReglesFormValidator();
-
 
591
	
-
 
592
	$('.dropdown-menu input, .dropdown-menu label').on('click', function(event) {
-
 
593
		event.stopPropagation();
-
 
594
	});
-
 
595
	$('.cb-milieux').on('click', function(event) {
-
 
596
		$(this).valid();
-
 
597
		event.stopPropagation();
-
 
598
	});
-
 
599
	
-
 
600
	$('input#hauteur-plante').on('blur', function() {
-
 
601
		// if there's a bad value
-
 
602
		var valeur = $(this).val();
-
 
603
		console.log(valeur);
-
 
604
		if (! valeur.match(/^[0-9]+$/)) {
-
 
605
			// replace it with nothing
-
 
606
			var nouvelleValeur = valeur.replace(/[^0-9]/g, '');
-
 
607
			$(this).val(nouvelleValeur);
-
 
608
		}
444
	definirReglesFormValidator();
609
	});
Line 445... Line 610...
445
		
610
	
Line 446... Line 611...
446
	$('#courriel_confirmation').on('paste', bloquerCopierCollerCourriel);
611
	$('#courriel_confirmation').on('paste', bloquerCopierCollerCourriel);
Line 453... Line 618...
453
	
618
	
Line 454... Line 619...
454
	$('body').on('click', '.supprimer-obs', supprimerObs);
619
	$('body').on('click', '.supprimer-obs', supprimerObs);
Line 455... Line 620...
455
	
620
	
456
	$('#transmettre-obs').on('click', transmettreObs);
-
 
457
	
621
	$('#transmettre-obs').on('click', transmettreObs);
458
	$('body').on('click', '.defilement-miniatures-gauche', function(event) {
622
	
459
		event.preventDefault();
-
 
460
		defilerMiniatures($(this));
623
	$('body').on('click', '.defilement-control-zone', function(event) {
461
	});
-
 
462
	
624
		defilerMiniatures($(this));
463
	$('body').on('click', '.defilement-miniatures-droite', function(event) {
625
	});
464
		event.preventDefault();
-
 
465
		defilerMiniatures($(this));
626
	$('body').on('mouseover', '.defilement-control-zone', function(event) {
466
	});
627
		$('.defilement-control', this).removeClass('hidden');
467
	
628
	});
Line 468... Line -...
468
	$('.dropdown-menu input, .dropdown-menu label').on('click', function(event) {
-
 
469
		event.stopPropagation();
-
 
470
	});
-
 
471
	
-
 
472
	$('input#hauteur-plante').on('blur', function() {
-
 
473
		// if there's a bad value
-
 
474
		var valeur = $(this).val();
-
 
475
		console.log(valeur);
-
 
476
		if (! valeur.match(/^[0-9]+$/)) {
-
 
477
			// replace it with nothing
-
 
478
			var nouvelleValeur = valeur.replace(/[^0-9]/g, '');
629
	$('body').on('mouseout', '.defilement-control-zone', function(event) {
Line 479... Line 630...
479
			$(this).val(nouvelleValeur);
630
		$('.defilement-control', this).addClass('hidden');
480
		}
631
	});
481
	});
632
	
Line 491... Line 642...
491
			insertBefore( el ).find('.horizontal-slider').slider({
642
			insertBefore( el ).find('.horizontal-slider').slider({
492
				min: 1,
643
				min: 1,
493
				max: el.options.length,
644
				max: el.options.length,
494
				range: 'min',
645
				range: 'min',
495
				value: el.selectedIndex + 1,
646
				value: el.selectedIndex + 1,
496
				slide: function( event, ui ) {
647
				slide: function(event, ui) {
497
					el.selectedIndex = ui.value - 1;
648
					el.selectedIndex = ui.value - 1;
498
					slider.find('a').text(el.options[el.selectedIndex].text);
649
					slider.find('a').text(el.options[el.selectedIndex].text);
-
 
650
					
-
 
651
					$(selector + ' option[selected="selected"]').removeAttr('selected');
-
 
652
					$(selector + ' :nth-child('+ui.value+')').attr('selected', 'selected')
-
 
653
					$(selector).valid();
499
				},
654
				},
500
				stop: function() {
655
				stop: function() {
501
					$(el).change();
656
					$(el).change();
502
				}
657
				}
503
			});
658
			});
Line 526... Line 681...
526
			slider.parent().find('.slider-legend p');//.css('text-indent', '200%');
681
			slider.parent().find('.slider-legend p');//.css('text-indent', '200%');
527
		}
682
		}
528
	});
683
	});
529
}
684
}
Line -... Line 685...
-
 
685
 
-
 
686
function configurerDatePicker(selector) {
-
 
687
	$.datepicker.setDefaults($.datepicker.regional['fr']);
-
 
688
	$(selector).datepicker({
-
 
689
		dateFormat: 'dd/mm/yy',
-
 
690
		showOn: 'button',
-
 
691
		buttonImageOnly: true,
-
 
692
		buttonImage: CALENDRIER_ICONE_URL,
-
 
693
		buttonText: 'Afficher le calendrier pour saisir la date.',
-
 
694
		showButtonPanel: true,
-
 
695
		onSelect: function(date) {
-
 
696
			$(this).valid();
-
 
697
        }
-
 
698
	});
-
 
699
	$(selector + ' + img.ui-datepicker-trigger').appendTo(selector + '-icone.add-on');
-
 
700
}
530
 
701
 
531
function configurerFormValidator() {
702
function configurerFormValidator() {
532
	$.validator.addMethod(
703
	$.validator.addMethod(
533
		'dateCel', 
704
		'dateCel', 
534
		function (value, element) { 
705
		function (value, element) { 
535
			return value == '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value)); 
706
			return value == '' || (/^[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}$/.test(value)); 
536
		}, 
707
		}, 
537
		'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.');
-
 
538
	$.validator.addMethod(
-
 
539
		'chckMilieux', 
-
 
540
		function(value, element) { 
-
 
541
			var ok = $('input[name="milieux"]:checked').length > 0 ? true : false;
-
 
542
			console.log('Check Milieux : ' + ok);
-
 
543
			return ok; 
-
 
544
		}, 
-
 
Line 545... Line 708...
545
		'Veuillez sélectionner au moins une case à cocher.');
708
		'Format : jj/mm/aaaa. Date incomplète, utiliser 0, exemple : 00/12/2011.');
-
 
709
	
546
	
710
	$.extend($.validator.defaults, {
547
	$.extend($.validator.defaults, {
711
		ignore: [],// Forcer Jquery Validate à examiner les éléments avec en display:none;
548
		highlight: function(element) {
-
 
549
			$(element).closest('.control-group').removeClass('success').addClass('error');
-
 
550
			
-
 
551
			console.log('KO:'+$(element).attr('name')+' / nbre: '+$(element).length);
712
		highlight: function(element) {
552
			
713
			$(element).closest('.control-group').removeClass('success').addClass('error');
553
		},
-
 
554
		success: function(element) {
-
 
555
			console.log('OK:'+element.before+' / nbre: '+$(element).length);
-
 
556
			console.log(element);
714
		},
557
			
715
		success: function(element) {
Line 558... Line 716...
558
			element.text('OK!').addClass('valid');
716
			element.text('OK!').addClass('valid');
559
			element.closest('.control-group').removeClass('error').addClass('success');
717
			element.closest('.control-group').removeClass('error').addClass('success');
Line 618... Line 776...
618
			date: {
776
			date: {
619
				required: true,
777
				required: true,
620
				'dateCel' : true},
778
				'dateCel' : true},
621
			dateDerniereIntervention: {
779
			dateDerniereIntervention: {
622
				required: true}
780
				required: true}
623
		}
781
		},
-
 
782
		errorPlacement: function(error, element) {
-
 
783
	        if (element.attr('name') == 'date') {
-
 
784
		        element.parent('.input-prepend').after(error);
-
 
785
	        } else {
-
 
786
	        	error.insertAfter(element);
-
 
787
	        }
-
 
788
	    }
624
	});
789
	});
625
	$('#form-obs').validate({
790
	$('#form-obs').validate({
626
		rules: {
791
		rules: {
627
			'taxon-liste': {
792
			'taxon-liste': {
628
				required: true},
793
				required: true},
629
			milieux: {
794
			'milieux[]': {
630
				chckMilieux:true},
795
				required: true,
-
 
796
				minlength: 1},
631
			hauteurPlante: {
797
			hauteurPlante: {
632
				required: true,
798
				required: true,
633
				digits: true},
799
				digits: true},
634
			resistanceTraitementPhyto: {
800
			resistanceTraitementPhyto: {
635
				required: true}
801
				required: true}
636
		}
802
		},
637
	});
-
 
638
}
-
 
639
 
-
 
640
function configurerDatePicker(selector) {
803
		errorPlacement: function(error, element) {
641
	$.datepicker.setDefaults($.datepicker.regional['fr']);
804
	        if (element.attr('name') == 'milieux[]') {
642
	$(selector).datepicker({
805
		        error.insertAfter('#milieux-controls');
643
		dateFormat: 'dd/mm/yy',
-
 
644
		showOn: 'button',
806
	        } else {
645
		buttonImageOnly: true,
-
 
646
		buttonImage: CALENDRIER_ICONE_URL,
807
	        	error.insertAfter(element);
647
		buttonText: 'Afficher le calendrier pour saisir la date.',
808
	        }
648
		showButtonPanel: true
809
	    }
649
	});
810
	});
650
	$(selector + ' + img.ui-datepicker-trigger').appendTo(selector + '-icone.add-on');
-
 
651
}
-
 
652
 
-
 
653
function fermerPanneauAlert() {
-
 
654
	$(this).parentsUntil('.zone-alerte', '.alert').hide();
-
 
655
}
811
}
Line 656... Line 812...
656
 
812
 
657
function formaterNom() {
813
function validerFormulaire() {
658
	$(this).val($(this).val().toUpperCase());
-
 
659
}
-
 
660
 
814
	var observateur = $('#form-observateur').valid(),
661
function formaterPrenom() {
815
		station = $('#form-site').valid(),
662
	var prenom = new Array(),
816
		date = $('#form-date').valid(),
663
		mots = $(this).val().split(' ');
-
 
664
	for (var i = 0; i < mots.length; i++) {
-
 
665
		var mot = mots[i];
-
 
666
		if (mot.indexOf('-') >= 0) {
-
 
667
			var prenomCompose = new Array(),
-
 
668
				motsComposes = mot.split('-');
-
 
669
			for (var j = 0; j < motsComposes.length; j++) {
-
 
670
				var motSimple = motsComposes[j],
817
		obs = $('#form-obs').valid();
671
					motMajuscule = motSimple.charAt(0).toUpperCase() + motSimple.slice(1);
-
 
672
				prenomCompose.push(motMajuscule);
818
	return (observateur == true && station == true && obs == true && date == true) ? true : false;
673
			}
-
 
674
			prenom.push(prenomCompose.join('-'));
-
 
675
		} else {
-
 
676
			var motMajuscule = mot.charAt(0).toUpperCase() + mot.slice(1);
-
 
677
			prenom.push(motMajuscule);
819
}
678
		}
820
 
-
 
821
 
679
	}
822
function fermerPanneauAlert() {
680
	$(this).val(prenom.join(' '));
823
	$(this).parentsUntil('.zone-alerte', '.alert').hide();
Line 681... Line 824...
681
}
824
}
682
 
825
 
683
function basculerAffichageAide() {
826
function basculerAffichageAide() {
Line 702... Line 845...
702
	$('#coordonnees-geo').toggle('slow');
845
	$('#coordonnees-geo').toggle('slow');
703
	//valeur false pour que le lien ne soit pas suivi
846
	//valeur false pour que le lien ne soit pas suivi
704
	return false;
847
	return false;
705
}
848
}
Line -... Line 849...
-
 
849
 
-
 
850
 
-
 
851
//+----------------------------------------------------------------------------------------------------------+
-
 
852
// CRÉER OBS : Gestion des obs
-
 
853
 
-
 
854
var obsNbre = 0;
706
 
855
 
707
function ajouterObs() {
856
function ajouterObs() {
708
	if (validerFormulaire() == true) {
857
	if (validerFormulaire() == true) {
709
		obsNbre = obsNbre + 1;
858
		obsNbre = obsNbre + 1;
710
		$('.obs-nbre').text(obsNbre);
859
		$('.obs-nbre').text(obsNbre);
Line 740... Line 889...
740
						'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
889
						'<button class="btn btn-danger supprimer-obs" value="'+obsNbre+'" title="'+obsNbre+'">'+
741
							'<i class="icon-trash icon-white"></i>'+
890
							'<i class="icon-trash icon-white"></i>'+
742
						'</button>'+
891
						'</button>'+
743
					'</div> '+		
892
					'</div> '+		
744
					'<div class="row-fluid">'+	
893
					'<div class="row-fluid">'+	
745
						'<div class="thumbnail span2">'+
894
						'<div class="span2 obs-miniatures">'+
746
							ajouterImgMiniatureAuTransfert()+
895
							ajouterImgMiniatureAuTransfert()+
747
						'</div>'+
896
						'</div>'+
748
						'<div class="span9">'+
897
						'<div class="span8">'+
749
							'<ul class="unstyled">'+
898
							'<ul class="unstyled">'+
750
								'<li>'+
899
								'<li>'+
751
									'<span class="nom-sci">' + taxon + '</span> ' +
900
									'<span class="nom-sci">' + taxon + '</span> ' +
752
									formaterNumNomSel(numNomSel)+
901
									formaterNumNomSel(numNomSel)+
753
									'<span class="referentiel-obs">' + referentiel + '</span>' +
902
									'<span class="referentiel-obs">' + referentiel + '</span>' +
Line 756... Line 905...
756
									'(' + codeInsee + ') [' + lat +' / ' + lng + ']' +
905
									'(' + codeInsee + ') [' + lat +' / ' + lng + ']' +
757
									' le ' +
906
									' le ' +
758
									'<span class="date">' + date + '</span>' +
907
									'<span class="date">' + date + '</span>' +
759
								'</li>' +
908
								'</li>' +
760
								'<li>' +
909
								'<li>' +
761
									'<span>Site :</span> ' + site + ' ' +
910
									'<span>Site :</span> ' + site + ' ' +  ' ; ' +
762
									'<span>Milieu :</span> ' + milieux + ' ' +
911
									'<span>Milieu :</span> ' + milieux + ' ' +
763
								'</li>' +
912
								'</li>' +
764
								'<li>' +
913
								'<li>' +
765
									'Commentaires : <span class="discretion">' + notes + '</span>'+
914
									'Commentaires : <span class="discretion">' + notes + '</span>'+
766
								'</li>'+
915
								'</li>'+
Line 773... Line 922...
773
}
922
}
Line 774... Line 923...
774
 
923
 
775
function getMilieux() {
924
function getMilieux() {
776
	var milieuxStr = '',
925
	var milieuxStr = '',
777
		milieux = [];
926
		milieux = [];
778
	$('input:checkbox[name="milieux"]:checked').each(function() {
927
	$('input:checkbox[name="milieux[]"]:checked').each(function() {
779
		milieux.push($(this).val());
928
		milieux.push($(this).val());
Line 780... Line 929...
780
	});
929
	});
781
	
930
	
782
	milieuxStr = Array.prototype.slice.call(milieux).join(', ');
931
	milieuxStr = Array.prototype.slice.call(milieux).join(', ');
Line 783... Line 932...
783
	return milieuxStr;
932
	return milieuxStr;
784
}
933
}
785
 
934
 
-
 
935
function ajouterImgMiniatureAuTransfert() {
786
function ajouterImgMiniatureAuTransfert() {
936
	var html = '',
-
 
937
		miniatures = '',
787
	var html = '',
938
		indicateurs = '',
-
 
939
		premiere = true,
-
 
940
		numero = 1;
788
		miniatures = '',
941
	if ($('#miniatures img').length == 0) {
789
		premiere = true;
942
		html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
790
	if ($('#miniatures img').length >= 1) {
943
	} else if ($('#miniatures img').length >= 1) {
791
		$('#miniatures img').each(function() {
944
		$('#miniatures img').each(function() {
792
			var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee',
945
			var visible = premiere ? 'miniature-selectionnee' : 'miniature-cachee',
793
				css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature',
-
 
-
 
946
				css = $(this).hasClass('b64') ? 'miniature b64' : 'miniature',
794
				src = $(this).attr('src'),
947
				src = $(this).attr('src'),
795
				alt = $(this).attr('alt');
948
				alt = $(this).attr('alt');
-
 
949
			
-
 
950
			var miniature = '<img class="'+css+' '+visible+'"  alt="'+alt+'"src="'+src+'" />';
-
 
951
			miniatures += miniature;
-
 
952
			
-
 
953
			var indicateurActif = premiere ? 'active' : '';
-
 
954
			var indicateur = '<li class="' + indicateurActif + '" data-numero="' + numero++ + '"></li>';
796
			premiere = false;
955
			indicateurs += indicateur;
-
 
956
		
797
			miniature = '<img class="'+css+' '+visible+'"  alt="'+alt+'"src="'+src+'" />';
957
			premiere = false;
-
 
958
		});
-
 
959
		
798
			miniatures += miniature;
960
		if ($('#miniatures img').length == 1) {
799
		});
961
			html = miniatures;
-
 
962
		} else {
-
 
963
			html = 
800
		visible = ($('#miniatures img').length > 1) ? '' : 'defilement-miniatures-cache';
964
				'<div class="defilement">' +
801
		var html = 
965
					miniatures +
-
 
966
					'<a class="defilement-control-zone gauche">' +
802
			'<div class="defilement-miniatures">'+
967
					'	<span class="defilement-control gauche hidden">&#60;</span>' +
-
 
968
					'</a>' +
-
 
969
					'<a class="defilement-control-zone droite">' +
803
				'<a href="#" class="defilement-miniatures-gauche '+visible+'">&#60;</a>'+
970
					'	<span class="defilement-control droite hidden">&#62;</span>' +
804
				miniatures+
971
					'</a>' +
805
				'<a href="#" class="defilement-miniatures-droite '+visible+'">&#62;</a>'+
-
 
806
			'</div>';
972
					'<ol class="defilement-indicateurs">' + indicateurs + '</ol>' +
807
	} else {
973
				'</div>';
808
		html = '<img class="miniature" alt="Aucune photo"src="'+PAS_DE_PHOTO_ICONE_URL+'" />';
974
		}
Line -... Line 975...
-
 
975
	}
-
 
976
	return html;
-
 
977
}
-
 
978
 
-
 
979
function defilerMiniatures(element) {
-
 
980
	var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
-
 
981
	miniatureSelectionne.removeClass('miniature-selectionnee').addClass('miniature-cachee');
-
 
982
	var miniatureAffichee = miniatureSelectionne;
-
 
983
	
-
 
984
	var indicateurActif = element.parent().find('.defilement-indicateurs .active');
-
 
985
	console.log(indicateurActif)
-
 
986
	indicateurActif.removeClass('active');
-
 
987
	
-
 
988
	if (element.hasClass('defilement-control-zone') && element.hasClass('gauche')) {
-
 
989
		if (miniatureSelectionne.prev('.miniature').length != 0) {
-
 
990
			miniatureAffichee = miniatureSelectionne.prev('.miniature');
-
 
991
			indicateurActif.prev().addClass('active');
-
 
992
		} else {
-
 
993
			miniatureAffichee = miniatureSelectionne.siblings('.miniature').last();
-
 
994
			indicateurActif.siblings().last().addClass('active');
-
 
995
		}
-
 
996
	} else {
-
 
997
		if (miniatureSelectionne.next('.miniature').length != 0) {
-
 
998
			miniatureAffichee = miniatureSelectionne.next('.miniature');
-
 
999
			indicateurActif.next().addClass('active');
-
 
1000
		} else {
-
 
1001
			miniatureAffichee = miniatureSelectionne.siblings('.miniature').first();
-
 
1002
			indicateurActif.siblings().first().addClass('active');
-
 
1003
		}
809
	}
1004
	}
810
	return html;
1005
	miniatureAffichee.addClass('miniature-selectionnee').removeClass('miniature-cachee');
811
}
-
 
812
 
1006
}
813
function formaterNumNomSel(numNomSel) {
1007
 
814
	var nn = '';
1008
function formaterNumNomSel(numNomSel) {
815
	
1009
	var nn = '';
816
	if (numNomSel == undefined) {
1010
	if (numNomSel == undefined) {
Line 866... Line 1060...
866
		$('#ajouter-obs').attr('disabled', 'disabled');
1060
		$('#ajouter-obs').attr('disabled', 'disabled');
867
		afficherPanneau('#dialogue-bloquer-creer-obs');
1061
		afficherPanneau('#dialogue-bloquer-creer-obs');
868
	}
1062
	}
869
}
1063
}
Line -... Line 1064...
-
 
1064
 
-
 
1065
function supprimerObs() {
-
 
1066
	var obsId = $(this).val();
-
 
1067
	// Problème avec IE 6 et 7
-
 
1068
	if (obsId == 'Supprimer') {
-
 
1069
		obsId = $(this).attr('title');
-
 
1070
	}
-
 
1071
	obsNbre = obsNbre - 1;
-
 
1072
	$('.obs-nbre').text(obsNbre);
-
 
1073
	$('.obs-nbre').triggerHandler('changement');
-
 
1074
	
-
 
1075
	$('.obs'+obsId).remove();
-
 
1076
	$('#liste-obs').removeData('obsId' + obsId);
-
 
1077
}
-
 
1078
 
-
 
1079
function initialiserObs() {
-
 
1080
	obsNbre = 0;
-
 
1081
	$('.obs-nbre').text(obsNbre);
-
 
1082
	$('.obs-nbre').triggerHandler('changement');
-
 
1083
	$('#liste-obs').removeData();
-
 
1084
	$('.obs').remove();
-
 
1085
	$('#dialogue-bloquer-creer-obs').hide();
-
 
1086
}
-
 
1087
 
-
 
1088
function getNomsImgsOriginales() {
-
 
1089
	var noms = new Array();
-
 
1090
	$('.miniature-img').each(function() {
-
 
1091
		noms.push($(this).attr('alt'));
-
 
1092
	});
-
 
1093
	return noms;
-
 
1094
}
-
 
1095
 
-
 
1096
function getB64ImgsOriginales() {
-
 
1097
	var b64 = new Array();
-
 
1098
	$('.miniature-img').each(function() {
-
 
1099
		if ($(this).hasClass('b64')) {
-
 
1100
			b64.push($(this).attr('src'));
-
 
1101
		} else if ($(this).hasClass('b64-canvas')) {
-
 
1102
			b64.push($(this).data('b64'));
-
 
1103
		}
-
 
1104
	});
-
 
1105
	return b64;
-
 
1106
}
-
 
1107
 
-
 
1108
//+----------------------------------------------------------------------------------------------------------+
-
 
1109
// TRANSFERER OBS : envoie des obs au CEL
870
 
1110
 
871
function transmettreObs() {
1111
function transmettreObs() {
872
	var observations = $('#liste-obs').data();
1112
	var observations = $('#liste-obs').data();
Line 873... Line 1113...
873
	console.log(observations);
1113
	console.log(observations);
Line 953... Line 1193...
953
				$('#dialogue-obs-transaction-ok').show();
1193
				$('#dialogue-obs-transaction-ok').show();
954
			}
1194
			}
955
			initialiserObs();
1195
			initialiserObs();
956
		}
1196
		}
957
	});
1197
	});
958
}
-
 
959
 
-
 
960
function validerFormulaire() {
-
 
961
	var observateur = $('#form-observateur').valid(),
-
 
962
		station = $('#form-site').valid(),
-
 
963
		date = $('#form-date').valid(),
-
 
964
		obs = $('#form-obs').valid();
-
 
965
	return (observateur == true && station == true && obs == true && date == true) ? true : false;
-
 
966
}
-
 
967
 
-
 
968
function getNomsImgsOriginales() {
-
 
969
	var noms = new Array();
-
 
970
	$('.miniature-img').each(function() {
-
 
971
		noms.push($(this).attr('alt'));
-
 
972
	});
-
 
973
	return noms;
-
 
974
}
-
 
975
 
-
 
976
function getB64ImgsOriginales() {
-
 
977
	var b64 = new Array();
-
 
978
	$('.miniature-img').each(function() {
-
 
979
		if ($(this).hasClass('b64')) {
-
 
980
			b64.push($(this).attr('src'));
-
 
981
		} else if ($(this).hasClass('b64-canvas')) {
-
 
982
			b64.push($(this).data('b64'));
-
 
983
		}
-
 
984
	});
-
 
985
	return b64;
-
 
986
}
-
 
987
 
-
 
988
function supprimerObs() {
-
 
989
	var obsId = $(this).val();
-
 
990
	// Problème avec IE 6 et 7
-
 
991
	if (obsId == 'Supprimer') {
-
 
992
		obsId = $(this).attr('title');
-
 
993
	}
-
 
994
	obsNbre = obsNbre - 1;
-
 
995
	$('.obs-nbre').text(obsNbre);
-
 
996
	$('.obs-nbre').triggerHandler('changement');
-
 
997
	
-
 
998
	$('.obs'+obsId).remove();
-
 
999
	$('#liste-obs').removeData('obsId' + obsId);
-
 
1000
}
-
 
1001
 
-
 
1002
function initialiserObs() {
-
 
1003
	obsNbre = 0;
-
 
1004
	$('.obs-nbre').text(obsNbre);
-
 
1005
	$('.obs-nbre').triggerHandler('changement');
-
 
1006
	$('#liste-obs').removeData();
-
 
1007
	$('.obs').remove();
-
 
1008
	$('#dialogue-bloquer-creer-obs').hide();
-
 
1009
}
-
 
1010
 
-
 
1011
 
-
 
1012
function defilerMiniatures(element) {
-
 
1013
	var miniatureSelectionne = element.siblings('img.miniature-selectionnee');
-
 
1014
	miniatureSelectionne.removeClass('miniature-selectionnee');
-
 
1015
	miniatureSelectionne.addClass('miniature-cachee');
-
 
1016
	var miniatureAffichee = miniatureSelectionne;
-
 
1017
	
-
 
1018
	if(element.hasClass('defilement-miniatures-gauche')) {
-
 
1019
		if(miniatureSelectionne.prev('.miniature').length != 0) {
-
 
1020
			miniatureAffichee = miniatureSelectionne.prev('.miniature');
-
 
1021
		} else {
-
 
1022
			miniatureAffichee = miniatureSelectionne.siblings('.miniature').last();
-
 
1023
		}
-
 
1024
	} else {
-
 
1025
		if(miniatureSelectionne.next('.miniature').length != 0) {
-
 
1026
			miniatureAffichee = miniatureSelectionne.next('.miniature');
-
 
1027
		} else {
-
 
1028
			miniatureAffichee = miniatureSelectionne.siblings('.miniature').first();
-
 
1029
		}
-
 
1030
	}
-
 
1031
	miniatureAffichee.addClass('miniature-selectionnee');
-
 
1032
	miniatureAffichee.removeClass('miniature-cachee');
-
 
1033
}
-
 
1034
 
-
 
1035
//+---------------------------------------------------------------------------------------------------------+
-
 
1036
// AUTO-COMPLÉTION Noms Scientifiques
-
 
1037
 
-
 
1038
function ajouterAutocompletionNoms() {
-
 
1039
	$('#taxon').autocomplete({
-
 
1040
		source: function(requete, add){  
-
 
1041
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
-
 
1042
			
-
 
1043
			var url = getUrlAutocompletionNomsSci();
-
 
1044
			$.getJSON(url, function(data) {
-
 
1045
				console.log(data);
-
 
1046
				var suggestions = traiterRetourNomsSci(data);
-
 
1047
				add(suggestions);  
-
 
1048
			});
-
 
1049
		},
-
 
1050
		html: true
-
 
1051
	});
-
 
1052
	
-
 
1053
	$('#taxon').bind('autocompleteselect', function(event, ui) {
-
 
1054
		$('#taxon').data(ui.item);
-
 
1055
		if (ui.item.retenu == true) {
-
 
1056
			$('#taxon').addClass('ns-retenu');
-
 
1057
		} else {
-
 
1058
			$('#taxon').removeClass('ns-retenu');
-
 
1059
		}
-
 
1060
	});
-
 
1061
}
-
 
1062
 
-
 
1063
function getUrlAutocompletionNomsSci() {
-
 
1064
	var mots = $('#taxon').val(),
-
 
1065
		url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL_TPL.replace('{referentiel}',NOM_SCI_PROJET);
-
 
1066
	url = url.replace('{masque}', mots);
-
 
1067
	return url;
-
 
1068
}
-
 
1069
 
-
 
1070
function traiterRetourNomsSci(data) {
-
 
1071
	var suggestions = [];
-
 
1072
	if (data.resultat != undefined) {
-
 
1073
		$.each(data.resultat, function(i, val) {
-
 
1074
			val.nn = i;
-
 
1075
			var nom = {label: '', value: '', nt: '', nomSel: '', nomSelComplet: '', numNomSel: '',
-
 
1076
				nomRet: '', numNomRet: '', famille: '', retenu: false
-
 
1077
			};
-
 
1078
			if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
-
 
1079
				nom.label = '...';
-
 
1080
				nom.value = $('#taxon').val();
-
 
1081
				suggestions.push(nom);
-
 
1082
				return false;
-
 
1083
			} else {
-
 
1084
				nom.label = val.nom_sci_complet;
-
 
1085
				nom.value = val.nom_sci_complet;
-
 
1086
				nom.nt = val.num_taxonomique;
-
 
1087
				nom.nomSel = val.nom_sci;
-
 
1088
				nom.nomSelComplet = val.nom_sci_complet;
-
 
1089
				nom.numNomSel = val.nn;
-
 
1090
				nom.nomRet = val.nom_retenu_complet;
-
 
1091
				nom.numNomRet = val['nom_retenu.id'];
-
 
1092
				nom.famille = val.famille;
-
 
1093
				nom.retenu = (val.retenu == 'false') ? false : true;
-
 
1094
				
-
 
1095
				suggestions.push(nom);
-
 
1096
			}
-
 
1097
		});
-
 
1098
	}
-
 
1099
	return suggestions;
-
 
1100
}
-
 
1101
 
-
 
1102
/*
-
 
1103
 * jQuery UI Autocomplete HTML Extension
-
 
1104
 *
-
 
1105
 * Copyright 2010, Scott González (http://scottgonzalez.com)
-
 
1106
 * Dual licensed under the MIT or GPL Version 2 licenses.
-
 
1107
 *
-
 
1108
 * http://github.com/scottgonzalez/jquery-ui-extensions
-
 
1109
 * 
-
 
1110
 * Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
-
 
1111
 */
-
 
1112
(function($) {
-
 
1113
	var proto = $.ui.autocomplete.prototype,
-
 
1114
		initSource = proto._initSource;
-
 
1115
	
-
 
1116
	function filter(array, term) {
-
 
1117
		var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), 'i');
-
 
1118
		return $.grep(array, function(value) {
-
 
1119
			return matcher.test($('<div>').html(value.label || value.value || value).text());
-
 
1120
		});
-
 
1121
	}
-
 
1122
	
-
 
1123
	$.extend(proto, {
-
 
1124
		_initSource: function() {
-
 
1125
			if (this.options.html && $.isArray(this.options.source)) {
-
 
1126
				this.source = function( request, response ) {
-
 
1127
					response(filter(this.options.source, request.term));
-
 
1128
				};
-
 
1129
			} else {
-
 
1130
				initSource.call(this);
-
 
1131
			}
-
 
1132
		},
-
 
1133
		_renderItem: function(ul, item) {
-
 
1134
			if (item.retenu == true) {
-
 
1135
				item.label = '<strong>'+item.label+'</strong>';
-
 
1136
			}
-
 
1137
			
-
 
1138
			return $('<li></li>')
-
 
1139
				.data('item.autocomplete', item)
-
 
1140
				.append($('<a></a>')[this.options.html ? 'html' : 'text'](item.label))
-
 
1141
				.appendTo(ul);
-
 
1142
		}
-
 
1143
	});
-
 
1144
})(jQuery);
-
 
1145
1198
}
-
 
1199
1146
1200