Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 105 Rev 119
Line -... Line 1...
-
 
1
/**-------------------------- Objets globaux -----------------------------------*/
-
 
2
 
-
 
3
/*
-
 
4
 * Liste des noms scientifiques reçus pour la mise en gras des noms valide
-
 
5
 * et l'accès direct aux fiches 
-
 
6
 */
-
 
7
var listeNomsScientifiques = new Object();
-
 
8
/*
-
 
9
 * Les variables suivantes sont ajoutée automatiquement dans le squelette du moteur de
-
 
10
 * recherche par php, elles sont commentées ici pour qu'elles n'aient pas l'air 
-
 
11
 * de sortir de la cuisse de Jupiter
-
 
12
 * 
-
 
13
 * var urlServiceAutocompletionNomsSci : url de base du service de complétion de noms scientifiques
-
 
14
 * pour le projet en cours de consultation. 
-
 
15
 * Exemple : http://localhost/service:eflore:0.1/bdtfx/noms?recherche=etendue&retour.format=min&masque=Ace%mo
-
 
16
 * 
-
 
17
 * var urlServiceAutocompletionNomsVerna : url de base du service de complétion de noms vernaculaires
-
 
18
 * pour le projet en cours de consultation. 
-
 
19
 * Exemple : http://localhost/service:eflore:0.1/nvjfl/noms-vernaculaires?recherche=etendue&retour.format=oss&masque=aca&masque.lg=fra
-
 
20
 * 
-
 
21
 * var urlBaseFicheTaxon : url de base de fiches des taxons afin de rediriger l'utilisateur sans 
-
 
22
 * faire de recherche dans le cas d'une selection d'un nom sci dans la liste d'autocompletion
-
 
23
 * Exemple : http://localhost/eflore-consultation/index_botanique.php?referentiel=bdtfx&module=fiche&action=fiche&nn=127
-
 
24
 * 
-
 
25
 * 
-
 
26
 * var valeurDefautNomSci : Contient la valeur par défaut affichée dans le formulaire en mode sci
-
 
27
 * Exemple: Rechercher un nom scientifique
-
 
28
 * var valeurDefautNomVerna : Contient la valeur par défaut affichée dans le formulaire en mode verna
-
 
29
 * Exemple: Recherche un nom commun
-
 
30
 */
-
 
31
 
-
 
32
 
-
 
33
/**------------ Fonctions de détection de l'état du formulaire ------------------*/
1
function nomScientifiqueEstDemande()  {
34
function nomSciEstDemande()  {
2
	var boutonRadioNomSci = $('#type_nom_scientifique');
35
	var boutonRadioNomSci = $('#type_nom_scientifique');
3
	return (boutonRadioNomSci.attr("checked") != "undefined" && boutonRadioNomSci.attr("checked") == "checked");
36
	return (boutonRadioNomSci.attr("checked") != "undefined" && boutonRadioNomSci.attr("checked") == "checked");
4
}
37
}
Line 5... Line 38...
5
 
38
 
6
function nomVernaculaireEstDemande()  {
39
function nomVernaculaireEstDemande()  {
7
	var boutonRadioNomSci = $('#type_nom_vernaculaire');
40
	var boutonRadioNomSci = $('#type_nom_vernaculaire');
8
	return (boutonRadioNomSci.attr("checked") != "undefined" && boutonRadioNomSci.attr("checked") == "checked");
41
	return (boutonRadioNomSci.attr("checked") != "undefined" && boutonRadioNomSci.attr("checked") == "checked");
Line -... Line 42...
-
 
42
}
9
}
43
 
10
 
44
/**------------ Fonctions de gestion des urls d'autocompletion et des fiches ------------------*/
11
function getUrlAutocompletion(baseUrl, requete) {
45
function getUrlAutocompletion(baseUrl, requete, format) {
Line 12... Line 46...
12
	return baseUrl+"?recherche=etendue&retour.format=oss&navigation.limite=10&masque="+requete;
46
	return baseUrl+"?recherche=etendue&retour.format="+format+"&navigation.limite=10&masque="+requete;
13
}
47
}
14
 
48
 
Line 15... Line 49...
15
function getUrlAutocompletionNomsVerna(requete) {
49
function getUrlAutocompletionNomsVerna(requete) {
16
	return getUrlAutocompletion(urlServiceAutocompletionNomsVerna, requete)+"&masque.lg=fra";
50
	return getUrlAutocompletion(urlServiceAutocompletionNomsVerna, requete, 'oss')+"&masque.lg=fra";
17
}
51
}
Line 18... Line 52...
18
 
52
 
19
function getUrlAutocompletionNomsSci(requete) {
53
function getUrlAutocompletionNomsSci(requete) {
20
	return getUrlAutocompletion(urlServiceAutocompletionNomsSci, requete);
54
	return getUrlAutocompletion(urlServiceAutocompletionNomsSci, requete, 'min');
Line 29... Line 63...
29
	}
63
	}
Line 30... Line 64...
30
	
64
	
31
	return url;
65
	return url;
Line -... Line 66...
-
 
66
}
-
 
67
 
-
 
68
function getUrlFicheTaxon(num_nom) {
-
 
69
	return urlBaseFicheTaxon.replace('{num_taxon}',num_nom).replace('&','&');
-
 
70
}
-
 
71
 
-
 
72
/**------------------- Fonctions de gestion de l'autocompletion ---------------------------------*/
-
 
73
function traiterRetourNomsSci(data) {
-
 
74
	
32
}
75
    var suggestions = [];  
-
 
76
    if(data.resultat != undefined) {
-
 
77
	    $.each(data.resultat, function(i, val) {  
-
 
78
	    	val.num_tax = i;
-
 
79
	    	listeNomsScientifiques[val.nom_sci] = val;
-
 
80
	    	suggestions.push(val.nom_sci);  
-
 
81
	    });  
-
 
82
	}
-
 
83
	
-
 
84
	return suggestions;
-
 
85
}
-
 
86
 
-
 
87
function traiterRetourNomsVerna(data) {
-
 
88
	
-
 
89
    var suggestions = [];
-
 
90
    if(jQuery.type(data) == "array") {
-
 
91
	    $.each(data[1], function(i, val){  
-
 
92
	    	suggestions.push(val);  
-
 
93
	    });  
-
 
94
	}
-
 
95
	
-
 
96
	return suggestions;
-
 
97
}
33
 
98
 
34
$(document).ready(function() {
99
function ajouterAutocompletionNoms() {
35
	$('#nom').autocomplete({
100
	$('#nom').autocomplete({
36
        source: function(req, add){  
101
        source: function(req, add){  
37
            // la variable de requête doit être vidée car sinon le parametre "term" est ajouté
102
            // la variable de requête doit être vidée car sinon le parametre "term" est ajouté
Line 38... Line 103...
38
        	req = "";
103
        	req = "";
39
            $.getJSON(getUrlAppelCompletion($('#nom').val()), req, function(data) {  
104
            $.getJSON(getUrlAppelCompletion($('#nom').val()), req, function(data) {  
-
 
105
 
40
 
106
            	if(nomVernaculaireEstDemande()) {
41
                var suggestions = [];   
107
            		suggestions = traiterRetourNomsVerna(data);
Line 42... Line 108...
42
                $.each(data[1], function(i, val){  
108
            	} else {
43
                	suggestions.push(val);  
109
            		suggestions = traiterRetourNomsSci(data);
44
                });  
110
            	}
-
 
111
 
-
 
112
                add(suggestions);  
-
 
113
            });
-
 
114
        },
-
 
115
        select: function(ui, item) {
-
 
116
        	var nom = item.item.value;
-
 
117
        	if(listeNomsScientifiques[nom] != undefined) {
-
 
118
        		// En cas de selection d'un nom scientifique de la liste
-
 
119
        		var num_tax = listeNomsScientifiques[nom].num_tax;
-
 
120
        		// On redirige automatique l'utilisateur vers sa fiche
-
 
121
        		window.location = getUrlFicheTaxon(num_tax);
-
 
122
        	}
-
 
123
        },
-
 
124
        html: true
-
 
125
	});
-
 
126
}
-
 
127
 
-
 
128
/**------------ Fonctions de gestion de l'affichage des valeurs par defaut ----------------------*/
-
 
129
function ajouterActionClicSurTexteRecherche() {
-
 
130
	$('#nom').click(function() {
-
 
131
		if(formulaireAfficheValeurParDefaut()) {
-
 
132
			$('#nom').val('');
-
 
133
		}
45
 
134
		
-
 
135
		if($('#nom').hasClass('valeur-defaut-recherche')) {
-
 
136
			$('#nom').removeClass('valeur-defaut-recherche');
-
 
137
		}
-
 
138
	});
-
 
139
}
-
 
140
 
-
 
141
function formulaireAfficheValeurParDefaut() {
-
 
142
	valeur_form = $('#nom').val().trim();
-
 
143
	return valeur_form == '' || valeur_form == valeurDefautNomSci || valeur_form == valeurDefautNomVerna;
-
 
144
}
-
 
145
 
-
 
146
function gererAffichageValeursParDefaut() {
-
 
147
	$('input[name="type_nom"]').click(function() {
-
 
148
		afficherValeurParDefaut();
-
 
149
	});
-
 
150
	
-
 
151
	$('#nom').focus(function() {
-
 
152
		$('#nom').removeClass('valeur-defaut-recherche');
-
 
153
		if(formulaireAfficheValeurParDefaut()) {
-
 
154
			$('#nom').val('');
-
 
155
		} else {
-
 
156
			$('#nom').select();
-
 
157
		}
-
 
158
	});
-
 
159
}
-
 
160
 
-
 
161
function afficherValeurParDefaut() {
-
 
162
	if($('#nom') != undefined && $('#nom').val() != undefined) { 
-
 
163
		valeur_form = $('#nom').val().trim();
-
 
164
		if(formulaireAfficheValeurParDefaut()) {
-
 
165
			if(nomSciEstDemande()) {
-
 
166
	    		$('#nom').val(valeurDefautNomSci);
-
 
167
	    	} else {
-
 
168
	    		$('#nom').val(valeurDefautNomVerna);
-
 
169
	    	}
-
 
170
			$('#nom').addClass('valeur-defaut-recherche');
-
 
171
		}
-
 
172
	}
-
 
173
}
-
 
174
 
-
 
175
$(document).ready(function() {
-
 
176
	ajouterAutocompletionNoms();
-
 
177
	ajouterActionClicSurTexteRecherche();
-
 
178
	gererAffichageValeursParDefaut();
-
 
179
	afficherValeurParDefaut();
-
 
180
});
-
 
181
 
-
 
182
/*
-
 
183
 * jQuery UI Autocomplete HTML Extension
-
 
184
 *
-
 
185
 * Copyright 2010, Scott González (http://scottgonzalez.com)
-
 
186
 * Dual licensed under the MIT or GPL Version 2 licenses.
-
 
187
 *
-
 
188
 * http://github.com/scottgonzalez/jquery-ui-extensions
-
 
189
 * 
-
 
190
 * Adaptation par Aurélien Peronnet pour la mise en gras des noms de taxons valides
-
 
191
 */
-
 
192
(function( $ ) {
-
 
193
 
-
 
194
var proto = $.ui.autocomplete.prototype,
-
 
195
	initSource = proto._initSource;
-
 
196
 
-
 
197
function filter( array, term ) {
-
 
198
	var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
-
 
199
	return $.grep( array, function(value) {
-
 
200
		return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
-
 
201
	});
-
 
202
}
-
 
203
 
-
 
204
$.extend( proto, {
-
 
205
	_initSource: function() {
-
 
206
		if ( this.options.html && $.isArray(this.options.source) ) {
-
 
207
			this.source = function( request, response ) {
-
 
208
				response( filter( this.options.source, request.term ) );
-
 
209
			};
-
 
210
		} else {
-
 
211
			initSource.call( this );
-
 
212
		}
-
 
213
	},
-
 
214
	_renderItem: function( ul, item) {
-
 
215
		if(listeNomsScientifiques[item.label] != undefined && listeNomsScientifiques[item.label].retenu == "true") {
-
 
216
			item.label = "<b>"+item.label+"</b>";
-
 
217
		}
-
 
218
		
-
 
219
		return $( "<li></li>" )
46
                add(suggestions);  
220
			.data( "item.autocomplete", item )
Line -... Line 221...
-
 
221
			.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )