336,6 → 336,8 |
|
//+---------------------------------------------------------------------------------------------------------+ |
// FORMULAIRE |
var obsNbre = 0; |
|
$(document).ready(function() { |
$("#prenom").bind("change", function(event) { |
var prenom = new Array(); |
387,14 → 389,14 |
} else { |
if ($(element).attr('id') == 'taxon') { |
var warningClass = "control-group warning"; |
if ($("#taxon").data("selection") != $("#taxon").val()) { |
$("#taxon").data("selection", ""); |
$("#taxon").data("nn", ""); |
if ($("#taxon").data("value") != $("#taxon").val()) { |
$("#taxon").removeData(); |
$("#taxon").removeClass('ns-retenu'); |
if ($("#taxon").val() != '') { |
$("#taxon-input-groupe").removeClass(validClass) |
.removeClass(errorClass) |
.addClass(warningClass); |
this.showLabel(element, "Nom abscent du référentiel."); |
this.showLabel(element, "Nom absent du référentiel."); |
} |
} else { |
if ($("#taxon").val() != '') { |
456,40 → 458,48 |
if (validerFormulaire() == true) { |
//rassemble les obs dans un tableau html |
obsNumero = obsNumero + 1; |
obsNbre = obsNbre + 1; |
$(".obs-nbre").text(obsNbre); |
$("#liste-obs tbody").append( |
'<tr id="obs'+obsNumero+'" class="obs">'+ |
'<td>'+obsNumero+'</td>'+ |
'<td>'+$("#date").val()+'</td>'+ |
'<tr id="obs'+obsNumero+'" class="obs obs'+obsNumero+'">'+ |
'<td rowspan="3" class="obs-miniature">'+ajouterImgMiniatureAuTransfert()+'</td>'+ |
'<td>'+$("#taxon").val()+'</td>'+ |
'<td>'+$("#latitude").val()+' / '+$("#longitude").val()+'</td>'+ |
'<td>'+$('#commune-nom').text()+' ('+$('#commune-code-insee').text()+')</td>'+ |
'<td colspan="2">'+$('#commune-nom').text()+' ('+$('#commune-code-insee').text()+') ['+$("#latitude").val()+' / '+$("#longitude").val()+']</td>'+ |
'<td rowspan="3">'+$("#notes").val()+'</td>'+ |
'<td rowspan="3" class="obs-action">'+ |
'<button class="supprimer-obs" value="'+obsNumero+'" title="Supprimer l\'observation '+obsNumero+'">'+ |
'<img src="'+SUPPRIMER_ICONE_URL+'"/></button>'+ |
'</td>'+ |
'</tr>'+ |
'<tr class="obs obs'+obsNumero+'">'+ |
'<td rowspan="2">'+$("#date").val()+'</td>'+ |
'<td>'+$('#lieudit').val()+'</td>'+ |
'<td>'+$('#station').val()+'</td>'+ |
'<td>'+$('#milieu').val()+'</td>'+ |
'<td class="obs-miniature">'+ajouterImgMiniatureAuTransfert()+'</td>'+ |
'<td>'+$("#notes").val()+'</td>'+ |
'<td><button class="supprimer-obs" value="'+obsNumero+'" title="Supprimer l\'observation '+obsNumero+'">'+ |
'<img src="'+SUPPRIMER_ICONE_URL+'"/></button></td>'+ |
'</tr>'+ |
'<tr class="obs obs'+obsNumero+'">'+ |
'<td colspan="2">'+$('#milieu').val()+'</td>'+ |
'</tr>'); |
//rassemble les obs dans #liste-obs |
var numNomSel = $("#taxon").val(); |
$("#liste-obs").data('obsId'+obsNumero, { |
'date' : $("#date").val(), |
'num_nom_sel' : numNomSel, |
'nom_sel' : taxons[numNomSel]['nom_sel'], |
'nom_ret' : taxons[numNomSel]['nom_ret'], |
'num_nom_ret' : taxons[numNomSel]['num_nom_ret'], |
'num_taxon' : taxons[numNomSel]['num_taxon'], |
'famille' : taxons[numNomSel]['famille'], |
'nom_fr' : taxons[numNomSel]['nom_fr'], |
'milieu' : $('input[name=milieu]:checked').val(), |
'notes' : $("#notes").val(), |
|
'nom_sel' : $("#taxon").val(), |
'num_nom_sel' : $("#taxon").data("numNomSel"), |
'nom_ret' : $("#taxon").data("nomRet"), |
'num_nom_ret' : $("#taxon").data("numNomRet"), |
'num_taxon' : $("#taxon").data("nt"), |
'famille' : $("#taxon").data("famille"), |
'referentiel' : NOM_SCI_REFERENTIEL, |
|
'latitude' : $("#latitude").val(), |
'longitude' : $("#longitude").val(), |
'commune_nom' : $("#commune-nom").text(), |
'commune_code_insee' : $("#commune-code-insee").text(), |
'lieu_dit' : $("#rue").val(), |
'station' : $("#rue_num_debut").val()+'-'+$("#rue_num_fin").val()+'-'+$("#rue_cote").val(), |
'notes' : $("#notes").val(), |
'lieu_dit' : $("#lieu_dit").val(), |
'station' : $("#station").val(), |
'milieu' : $("#milieu").val(), |
|
//Ajout des champs images |
'image_nom' : $("#miniature-img").attr('alt'), |
'image_b64' : getB64ImgOriginal() |
507,7 → 517,7 |
} else if ($("#saisie-obs").valid() == false) { |
$("#dialogue-form-invalide").dialog(); |
} else { |
observations['projet'] = 'Sauvages'; |
observations['projet'] = PROJET_TAG; |
|
var utilisateur = new Object(); |
utilisateur.prenom = $("#prenom").val(); |
616,8 → 626,10 |
if (obsId == "Supprimer") { |
obsId = $(this).attr("title"); |
} |
obsNbre = obsNbre - 1; |
$(".obs-nbre").text(obsNbre); |
|
$('#obs'+obsId).remove(); |
$('.obs'+obsId).remove(); |
$("#liste-obs").removeData('obsId'+obsId); |
} |
|
634,7 → 646,6 |
|
//+---------------------------------------------------------------------------------------------------------+ |
// AUTO-COMPLÉTION Noms Scientifiques |
var listeNomsScientifiques = new Object(); |
|
function ajouterAutocompletionNoms() { |
$('#taxon').autocomplete({ |
641,7 → 652,8 |
source: function(requete, add){ |
// la variable de requête doit être vidée car sinon le parametre "term" est ajouté |
requete = ""; |
$.getJSON(getUrlAutocompletionNomsSci($('#taxon').val()), requete, function(data) { |
var url = getUrlAutocompletionNomsSci(); |
$.getJSON(url, requete, function(data) { |
var suggestions = traiterRetourNomsSci(data); |
add(suggestions); |
}); |
648,13 → 660,19 |
}, |
html: true |
}); |
|
$( "#taxon" ).bind("autocompleteselect", function(event, ui) { |
$("#taxon").data("selection", ui.item.value); |
$("#taxon").data("nn", ui.item.nn); |
$("#taxon").data(ui.item); |
if (ui.item.retenu == true) { |
$("#taxon").addClass('ns-retenu'); |
} else { |
$("#taxon").removeClass('ns-retenu'); |
} |
}); |
} |
|
function getUrlAutocompletionNomsSci(mots) { |
function getUrlAutocompletionNomsSci() { |
var mots = $('#taxon').val(); |
var url = SERVICE_AUTOCOMPLETION_NOM_SCI_URL.replace('{masque}', mots); |
return url; |
} |
664,18 → 682,27 |
if (data.resultat != undefined) { |
$.each(data.resultat, function(i, val) { |
val.nn = i; |
var nom = {}; |
if (suggestions.length >= 20) { |
var nom = {label : '', value : '', nt : '', nomSel : '', nomSelComplet : '', numNomSel : '', |
nomRet : '', numNomRet : '', famille : '', retenu : false |
}; |
if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) { |
nom.label = "..."; |
nom.value = $('#taxon').val(); |
nom.nn = ""; |
suggestions.push(nom); |
return false; |
} else { |
nom.label = val.nom_sci; |
nom.value = val.nom_sci; |
nom.nn = val.nn; |
listeNomsScientifiques[val.nom_sci] = val; |
nom.nt = val.num_taxonomique; |
nom.nomSel = val.nom_sci; |
nom.nomSelComplet = val.nom_sci_complet; |
nom.numNomSel = val.nn; |
nom.nomRet = val.nom_retenu; |
// TODO : remplacer val.nom_retenu par val.nom_retenu.libelle et réactiver nom_retenu.id |
//nom.numNomRet = val.nom_retenu.id; |
nom.famille = val.famille; |
nom.retenu = (val.retenu == 'false') ? false : true; |
|
suggestions.push(nom); |
} |
}); |
695,41 → 722,35 |
* Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides |
*/ |
(function( $ ) { |
|
var proto = $.ui.autocomplete.prototype, |
initSource = proto._initSource; |
|
function filter( array, term ) { |
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" ); |
return $.grep( array, function(value) { |
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() ); |
var proto = $.ui.autocomplete.prototype, |
initSource = proto._initSource; |
|
function filter( array, term ) { |
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" ); |
return $.grep( array, function(value) { |
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() ); |
}); |
} |
|
$.extend( proto, { |
_initSource: function() { |
if ( this.options.html && $.isArray(this.options.source) ) { |
this.source = function( request, response ) { |
response( filter( this.options.source, request.term ) ); |
}; |
} else { |
initSource.call( this ); |
} |
}, |
_renderItem: function( ul, item) { |
if (item.retenu == true) { |
item.label = "<strong>"+item.label+"</strong>"; |
} |
|
return $( "<li></li>" ) |
.data( "item.autocomplete", item ) |
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) ) |
.appendTo( ul ); |
} |
}); |
} |
|
$.extend( proto, { |
_initSource: function() { |
if ( this.options.html && $.isArray(this.options.source) ) { |
this.source = function( request, response ) { |
response( filter( this.options.source, request.term ) ); |
}; |
} else { |
initSource.call( this ); |
} |
}, |
_renderItem: function( ul, item) { |
if (listeNomsScientifiques[item.label] != undefined && listeNomsScientifiques[item.label].retenu == "true") { |
item.label = "<b>"+item.label+"</b>"; |
} |
|
if (item.label == '...') { |
item.label = "<b>"+item.label+"</b>"; |
} |
|
return $( "<li></li>" ) |
.data( "item.autocomplete", item ) |
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) ) |
.appendTo( ul ); |
} |
}); |
|
})( jQuery ); |