summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/data/demos/demo_WikipediaStore.html
blob: bc290b05570675c451dd040901634bde1a8e87ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Wikipedia Data Store</title>
<style type="text/css">
@import "../../../dojo/resources/dojo.css";
@import "../../../dijit/themes/tundra/tundra.css";
h1 { margin-bottom: 1em; }
</style>
<script type="text/javascript">
//<![CDATA[
djConfig = { isDebug: true };
//]]>
</script>
<script type="text/javascript" src="../../../dojo/dojo.js"></script>
<script type="text/javascript">
//<![CDATA[
dojo.require("dojox.data.WikipediaStore");
var store = new dojox.data.WikipediaStore();

function doSearch(){
	var outNode = dojo.byId("output");
	outNode.innerHTML = "Searching...";	

	function loadArticle(article){
		var request = {
			query: {
				title: article
			},
			onItem: function(item, req){
				var title = store.getValue(item, "title");
				var text = store.getValue(item, "text")["*"];
				outNode.innerHTML = "<h1>" + title + "</h1>" + text;
			}
		};
		console.log("Article request: ", request);
		store.fetch(request);
	}


	var request = {
		query: {
			action: "query",
			text: dojo.byId("searchText").value
		},
		count: dojo.byId("count").value,
		onBegin: function(count){
			outNode.innerHTML += " found " + count + " results.<br>Click one to load the article.";
		},
		onItem: function(item, req){
			console.debug(item);
			var node = document.createElement("a");
			node.href = "#";
			node.onclick = function(){
				console.log("clicked ", this.innerHTML);
				loadArticle(this.innerHTML);
			};
			node.style.padding = "6px";
			node.style.display = "block";
			node.innerHTML = store.getValue(item, "title");
			outNode.appendChild(node);
		}
	};
	console.log("Request: ", request);
	store.fetch(request);
}
//]]>
</script>
</head>
<body class="tundra" style="margin:20px;">
	<form action="#">
		<p>
			Text: <input id="searchText" type="text" value="dojo toolkit">
			Count: <input id="count" type="text" value="8" size="3">
			<input id="searchButton" type="button" value="store.fetch()" onclick="doSearch()">
		</p>

		<div id="output" style="padding:0 20px;">
		</div>
	</form>
</body>
</html>