Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 720 Rev 724
Line 19... Line 19...
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
 */
Line -... Line 23...
-
 
23
 
-
 
24
var champs_ts = ["#au","#and","#anf","#nom","#bib"];
23
 
25
 
24
$(document).ready(function() {
26
$(document).ready(function() {
25
	ajouterAutocompletionNoms();
27
	ajouterAutocompletion();
26
	ajouterActionClicSurTexteRecherche();
28
	ajouterActionClicSurTexteRecherche(champs_ts);
27
	gererAffichageValeursParDefaut();
29
	gererAffichageValeursParDefaut(champs_ts);
28
	afficherValeurParDefaut();
30
	afficherValeurParDefaut(champs_ts);
Line 29... Line 31...
29
});
31
});
-
 
32
 
-
 
33
/**------------------- Fonctions de gestion de l'autocompletion ---------------------------------*/
-
 
34
function ajouterAutocompletion(){
-
 
35
		ajouterAutocompletionNoms();
-
 
36
		$('.champ_autocomplete').each(function(index) {
-
 
37
			ajouterAutocompletionAvancee($(this));
-
 
38
		});
-
 
39
}
-
 
40
 
-
 
41
function ajouterAutocompletionAvancee(champs){
-
 
42
			champs.autocomplete({			
-
 
43
				source: function(requete, add){  
-
 
44
				// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
-
 
45
					requete = "";
-
 
46
					var id = champs.attr('id');
-
 
47
					var url = getUrlAutocompletionAvancee(id);
-
 
48
						$.getJSON(url, requete, function(data) { 
-
 
49
					var suggestions = [];
-
 
50
					suggestions = traiterRetourAvance(data,champs);
-
 
51
					add(suggestions);  
-
 
52
					});
-
 
53
				},
-
 
54
	        	html: true
-
 
55
			});
30
 
56
 
31
/**------------------- Fonctions de gestion de l'autocompletion ---------------------------------*/
57
}
32
function ajouterAutocompletionNoms() {
58
function ajouterAutocompletionNoms() {
33
	$('#nom').autocomplete({
59
	$('#nom').autocomplete({
34
		source: function(requete, add){  
60
		source: function(requete, add){  
35
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
61
			// la variable de requête doit être vidée car sinon le parametre "term" est ajouté
36
			requete = "";
62
			requete = "";
37
			var url = getUrlAppelCompletion();
63
			var url = getUrlAppelCompletion();
38
			$.getJSON(url, requete, function(data) {  
64
			$.getJSON(url, requete, function(data) {
39
				var suggestions = [];
65
				var suggestions = [];
40
				if (nomVernaculaireEstDemande()) {
66
				if (nomVernaculaireEstDemande()) {
41
					suggestions = traiterRetourNomsVerna(data);
67
					suggestions = traiterRetourNomsVerna(data);
Line 78... Line 104...
78
		});
104
		});
79
	}
105
	}
80
	return suggestions;
106
	return suggestions;
81
}
107
}
Line -... Line 108...
-
 
108
 
-
 
109
 
-
 
110
 
-
 
111
function traiterRetourAvance(data, champs) {
-
 
112
	var suggestions = [];  
-
 
113
	if (jQuery.type(data) == "array") { 
-
 
114
		$.each(data[1], function(i, val) {
-
 
115
			var ch = {label : '', value : ''};
-
 
116
			if (suggestions.length >= AUTOCOMPLETION_ELEMENTS_NBRE) {
-
 
117
				ch.label = "...";
-
 
118
				ch.value = champs.val();
-
 
119
				suggestions.push(ch);
-
 
120
				return false;
-
 
121
			} else {
-
 
122
				ch.label = val;
-
 
123
				ch.value = val;
-
 
124
				suggestions.push(ch);
-
 
125
			}
-
 
126
		});
-
 
127
	}
-
 
128
	return suggestions;
-
 
129
}
82
 
130
 
83
function traiterRetourNomsVerna(data) {
131
function traiterRetourNomsVerna(data) {
84
	var suggestions = [];
132
	var suggestions = [];
85
	if (jQuery.type(data) == "array") {
133
	if (jQuery.type(data) == "array") {
86
		$.each(data[1], function(i, val){
134
		$.each(data[1], function(i, val){
Line 100... Line 148...
100
	return suggestions;
148
	return suggestions;
101
}
149
}
Line 102... Line 150...
102
 
150
 
-
 
151
 
-
 
152
/**------------ Fonctions de gestion des urls d'autocompletion et des fiches ------------------*/
-
 
153
 
-
 
154
function getUrlAutocompletionAvancee(parametre) {
-
 
155
	var valeur = getValeurMasque(parametre);
-
 
156
	var ns_str = getValeurNsStructure(parametre);
-
 
157
	var url = URL_SERVICE_AUTOCOMPLETION_NOM_SCI+"?recherche=etendue&"+
-
 
158
	"navigation.limite="+AUTOCOMPLETION_ELEMENTS_NBRE +'&masque.'+parametre+'='+valeur+
-
 
159
	'&retour.format=oss&distinct=1&ns.structure='+ns_str;
-
 
160
	return url;
-
 
161
}
-
 
162
 
-
 
163
function getValeurMasque(parametre) {
-
 
164
	var valeur = $('#'+parametre).val();
-
 
165
	if (parametre == 'au' ){
-
 
166
		valeur = valeur +',(' + valeur + ')';
-
 
167
	} else if (parametre == 'bib' ){
-
 
168
		valeur = valeur +', %; ' + valeur ;
-
 
169
	}
-
 
170
	return valeur;
-
 
171
}
-
 
172
 
-
 
173
function getValeurNsStructure(parametre) {
-
 
174
	var ns = '';
-
 
175
	if (parametre == 'au' || parametre == 'bib'){
-
 
176
		ns = parametre +'_ss';
-
 
177
	} else {
-
 
178
		ns = parametre;
-
 
179
	}
-
 
180
	return ns;
-
 
181
}
103
 
182
 
104
/**------------ Fonctions de gestion des urls d'autocompletion et des fiches ------------------*/
183
 
105
function getUrlAppelCompletion() {
184
function getUrlAppelCompletion() {
106
	var url = '';
185
	var url = '';
107
	var mots = $('#nom').val();
186
	var mots = $('#nom').val();
Line 146... Line 225...
146
	var boutonRadioNomSci = $('#type_nom_vernaculaire');
225
	var boutonRadioNomSci = $('#type_nom_vernaculaire');
147
	return (boutonRadioNomSci.attr("checked") != "undefined" && boutonRadioNomSci.attr("checked") == "checked");
226
	return (boutonRadioNomSci.attr("checked") != "undefined" && boutonRadioNomSci.attr("checked") == "checked");
148
}
227
}
Line 149... Line 228...
149
 
228
 
150
/**------------ Fonctions de gestion de l'affichage des valeurs par defaut ----------------------*/
229
/**------------ Fonctions de gestion de l'affichage des valeurs par defaut ----------------------*/
-
 
230
function ajouterActionClicSurTexteRecherche(champs) {
151
function ajouterActionClicSurTexteRecherche() {
231
	$.each(champs, function(index, value) {
152
	$('#nom').click(function() {
232
		$(value).click(function() {
153
		if (formulaireAfficheValeurParDefaut()) {
233
			if (formulaireAfficheValeurParDefaut(value)) {
154
			$('#nom').val('');
234
				$(value).val('');
155
		}
235
			}
156
		if ($('#nom').hasClass('valeur-defaut-recherche')) {
236
			if ($(value).hasClass('valeur-defaut-recherche')) {
157
			$('#nom').removeClass('valeur-defaut-recherche');
237
				$(value).removeClass('valeur-defaut-recherche');
-
 
238
			}
158
		}
239
		});
159
	});
240
	});
Line 160... Line 241...
160
}
241
}
161
 
242
 
162
function formulaireAfficheValeurParDefaut() {
243
function formulaireAfficheValeurParDefaut(champ) {
163
	valeur_form = $('#nom').val();
244
	valeur_form = $(champ).val();
-
 
245
	valeur_form = $.trim(valeur_form);
164
	valeur_form = $.trim(valeur_form);
246
	return ( valeur_form == '' || valeur_form == VALEUR_DEFAUT_NOM_SCI || valeur_form == VALEUR_DEFAUT_NOM_VERNA 
Line 165... Line 247...
165
	return valeur_form == '' || valeur_form == VALEUR_DEFAUT_NOM_SCI || valeur_form == VALEUR_DEFAUT_NOM_VERNA;
247
			|| valeur_form == VALEUR_DEFAUT_AU || valeur_form == VALEUR_DEFAUT_BIB || valeur_form == VALEUR_DEFAUT_DATE );
166
}
248
}
167
 
249
 
168
function gererAffichageValeursParDefaut() {
250
function gererAffichageValeursParDefaut(champs) {
169
	$('input[name="type_nom"]').click(function() {
-
 
-
 
251
		$('input[name="type_nom"]').click(function() {
170
		afficherValeurParDefaut();
252
			afficherValeurParDefautNom();
171
	});
253
		});
172
	
254
		$.each(champs, function(index, value) {
173
	$('#nom').focus(function() {
255
			$(value).focus(function() {
174
		$('#nom').removeClass('valeur-defaut-recherche');
256
				$(value).removeClass('valeur-defaut-recherche');
175
		if (formulaireAfficheValeurParDefaut()) {
257
				if (formulaireAfficheValeurParDefaut(value)) {
-
 
258
					$(value).val('');
-
 
259
				} else {
-
 
260
					$(value).select();
-
 
261
				}
-
 
262
			});
-
 
263
		});
-
 
264
}
-
 
265
 
-
 
266
function afficherValeurParDefaut(champs){
-
 
267
	$.each(champs, function(index, value) {
-
 
268
		if (value == '#nom') {
176
			$('#nom').val('');
269
			afficherValeurParDefautNom();
177
		} else {
270
		}else{
178
			$('#nom').select();
271
			afficherValeurParDefautAvance(value);
Line 179... Line 272...
179
		}
272
		}
180
	});
273
	});
181
}
274
}
182
 
275
 
183
function afficherValeurParDefaut() {
276
function afficherValeurParDefautNom() {
184
	if($('#nom') != undefined && $('#nom').val() != undefined) { 
277
	if($('#nom') != undefined && $('#nom').val() != undefined) { 
185
		valeur_form = $('#nom').val();
278
		valeur_form = $('#nom').val();
186
		valeur_form = $.trim(valeur_form);
279
		valeur_form = $.trim(valeur_form);
187
		if (formulaireAfficheValeurParDefaut()) {
280
		if (formulaireAfficheValeurParDefaut('#nom')) {
188
			if (nomSciEstDemande()) {
281
			if (nomSciEstDemande()) {
Line 199... Line 292...
199
			$('#eflore_nomenclature_fiche').hide();
292
			$('#eflore_nomenclature_fiche').hide();
200
		}
293
		}
201
	}
294
	}
202
}
295
}
Line -... Line 296...
-
 
296
 
-
 
297
 
-
 
298
function afficherValeurParDefautAvance(champs) {
-
 
299
		if($(champs) != undefined && $(champs).val() != undefined) { 
-
 
300
			valeur_form = $(champs).val();
-
 
301
			valeur_form = $.trim(valeur_form);
-
 
302
			if (formulaireAfficheValeurParDefaut(champs)) {
-
 
303
				if (champs == "#au") {
-
 
304
					$(champs).val(VALEUR_DEFAUT_AU);
-
 
305
			
-
 
306
				}else if (champs == "#bib" ) {
-
 
307
					$(champs).val(VALEUR_DEFAUT_BIB);
-
 
308
				} else {
-
 
309
					$(champs).val(VALEUR_DEFAUT_DATE);
-
 
310
				}
-
 
311
				$(champs).addClass('valeur-defaut-recherche');
-
 
312
			}
-
 
313
 
-
 
314
		}
-
 
315
 
-
 
316
	
-
 
317
}
-
 
318
 
-
 
319
 
-
 
320
 
-
 
321
 
203
 
322
 
204
/*
323
/*
205
 * jQuery UI Autocomplete HTML Extension
324
 * jQuery UI Autocomplete HTML Extension
206
 *
325
 *
207
 * Copyright 2010, Scott González (http://scottgonzalez.com)
326
 * Copyright 2010, Scott González (http://scottgonzalez.com)