Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 597 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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