PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/kharm/public/js/forms.js

http://kharm-xml.googlecode.com/
JavaScript | 89 lines | 84 code | 5 blank | 0 comment | 22 complexity | 84146b336d509f9a4e6607b20e093564 MD5 | raw file
 1function lookup(inputString, form) {
 2	if(inputString.length <= 2) {
 3		$("#" + form + " .suggestions").hide();
 4	} else {
 5		var params = setParameters(form);
 6		$.post("forms.php",
 7				params, 
 8				function(data){
 9					if(data != null && data != "") {
10						$("#" + form + " .autoSuggestionsList ul").html("");
11						$("#" + form + " .suggestions").show();
12						switch (form) {
13							case "countries": suggestCountries(data["pays"]);break;
14							case "cities": suggestCities(data["ville"]);break;
15							case "meetings": suggestMeetings(data["meeting"]);break;
16							default: break;
17						}
18					}
19				}, "json");
20	}
21}
22
23function setParameters(form) {
24	switch (form) {
25		case 'countries': return {year: $("#filter_year").attr("value"),
26									type: ""+form+""};
27		case 'cities': return {year: $("#filter_year").attr("value"),
28								country: $("#countries .inputString").val(),
29								type: ""+form+""};
30		case 'meetings': return {year: $("#filter_year").attr("value"),
31							country: $("#countries .inputString").val(),
32							city: $("#cities .inputString").val(),
33							type: ""+form+""};
34		default : break;
35	}
36}
37
38function fill(thisValue, form) {
39	$("#" + form + " .inputString").val(thisValue);
40	setTimeout("$('#" + form + " .suggestions').hide();", 200);
41}
42
43function suggestCountries(data) {
44	if (typeof(data) == typeof({})) {
45		for (var z=0; (z<data.length && z<=20); z++) {
46			$('#countries .autoSuggestionsList ul').append("<li onClick=\"fill('"
47					+data[z]+"', 'countries');\">" + data[z] + "</li>");
48		}
49	} else {
50		$('#countries .autoSuggestionsList ul').append("<li onClick=\"fill('"
51				+data+"', 'countries');\">" + data + "</li>");
52	}
53}
54function suggestCities(data) {
55	if (typeof(data) == typeof({})) {
56		for (var z=0; (z<data.length && z<=20); z++) {
57			$('#cities .autoSuggestionsList ul').append("<li onClick=\"fill('"
58					+data[z]+"', 'cities');\">" + data[z] + "</li>");
59		}
60	} else {
61		$('#cities .autoSuggestionsList ul').append("<li onClick=\"fill('"
62				+data+"', 'cities');\">" + data + "</li>");
63	}
64}
65function suggestMeetings(data) {
66	meetings_tmp = new Array();
67	if (data.length > 0) {
68		for (var z=0; (z<data.length && z<=20); z++) {
69			meetings_tmp.push(data[z]);
70			$('#meetings .autoSuggestionsList ul').append("<li onClick=\"selectMeeting('"
71					+(meetings_tmp.length-1)+"');\">" + data[z]["name"] + "</li>");
72		}
73	} else {
74		meetings_tmp.push(data);
75		$('#meetings .autoSuggestionsList ul').append("<li onClick=\"selectMeeting('"
76				+(meetings_tmp.length-1)+"');\">" + data["name"] + "</li>");
77	}
78}
79
80function selectMeeting(meeting) {
81	fill(meetings_tmp[meeting]["name"], 'meetings');
82	meetings.push(meetings_tmp[meeting]);
83	geocodeAndSave(meeting);
84	draw_chart_themes(meetings_tmp[meeting]["themes"]["theme"], meetings_tmp[meeting]["name"]);
85}
86
87function selectCountryOrCity(thisValue, form) {
88	fill(thisValue, form);
89}