summaryrefslogtreecommitdiff
path: root/includes/js/dojox/grid/tests/test_yahoo_search.html
blob: 063c289bae9f014f66b0b80dbb60eeb5465b57ce (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>dojox.Grid - Yahoo Search Test</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
	<style>
		@import "../_grid/Grid.css";
		body {
			font-size: 0.9em;
			font-family: Geneva, Arial, Helvetica, sans-serif;
		}
		.grid {
			height: 30em;
		}
		
		#info {
			width: 700px;
		}
	</style>
	<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:false, parseOnLoad: true"></script>
	<script type="text/javascript">
		dojo.require("dojox.grid.Grid");
		dojo.require("dojo.parser");
	</script>
	<script type="text/javascript" src="yahooSearch.js"></script>
	<script type="text/javascript">
		webFields = [
			{ name: 'Title', na: '' }, 
			{ name: 'ModificationDate', na: ''},
			{ name: 'Summary', na: '&nbsp;' },
			{ name: 'Url', na: '' },
			{ name: 'MimeType', na: '&nbsp;'},
			{ name: 'DisplayUrl', na: '&nbsp;'}
		];
		
		imageFields = [		
			{ name: 'Title', na: '' }, 
			{ name: 'Thumbnail', na: ''},
			{ name: 'Summary', na: '' },
			{ name: 'Url', na: '' },
			{ name: 'FileSize', na: ''},
			{ name: 'Height', na: ''},
			{ name: 'Width', na: ''}
		];

		var model = new dojox.grid.data.yahooSearch(imageFields, null, "searchInput");
		model.observer(this);
		// report some model send/receive status
		model.onSend = function(inParams) {
			dojo.byId('sendInfo').innerHTML = dojo.string.substitute('Request rows ${0} to ${1}.&nbsp&nbsp;', [inParams.start, inParams.start + inParams.results -1] );
		}
		model.onReceive = function(inData) {
			dojo.byId('receiveInfo').innerHTML = dojo.string.substitute('Receive rows ${0} to ${1}.&nbsp&nbsp;', [inData.firstResultPosition, inData.firstResultPosition + inData.totalResultsReturned-1]);
		}

		
		var webLayout = [ 
			{ type: 'dojox.GridRowView', width: '20px' },
			{ noscroll: true,
				cells: [
					[ { name: 'Row', width: 3, styles: 'text-align: center;', get: function(inRowIndex) { return inRowIndex + 1 } }]
				]
			},
			{ cells: [
					[	{ name: 'Site', width: 30, field: 3, extraField: 0, formatter: formatLink }, { name: 'Date', width: 10, field: 1, formatter: formatDate} ],
					[	{ name: 'Display Url', width: 30, field: 5, styles: 'color: green; size: small;' }, { name: 'Type', width: 10, field: 4, styles: ' font-style: italic; color: gray; size: small;'} ],
					[ { name: 'Summary',  width: 40, colSpan: 2, field: 2 } ]
			]}
		];
		
		// remove the height from the header image cell / row cells have a default height so there's less adjustment when thumb comes in.
		beforeImageRow = function(inRowIndex, inSubRow) {
			inSubRow[0][0].cellStyles = (inRowIndex == -1 ? '' : 'height: 100px;');
			inSubRow[1][0].cellStyles = (inRowIndex == -1 ? '' : 'vertical-align: top; height: 75px;');
		}
		
		var imageLayout = [ 
			{ type: 'dojox.GridRowView', width: '20px' },
			{ noscroll: true,
				cells: [
					[ { name: 'Row', width: 3, styles: 'text-align: center;', get: function(inRowIndex) { return inRowIndex + 1 } }]
				]
			},
			{ onBeforeRow: beforeImageRow,
				cells: [
					[	{ name: 'Image', cellStyles: "height: 100px;", styles: "text-align: center;", width: 13, rowSpan: 2, field: 3, extraField: 1, formatter: formatImage },
						{ name: 'Title', cellStyles: "height: 10px;", width: 14, field: 3, extraField: 0, formatter: formatLink }, 
						{ name: 'Size', width: 8, field: 4, styles: "font-style: italic; text-align: center;" },
						{ name: 'Dimensions', width: 8, field: 6, extraField: 5, styles: "text-align: center;", formatter: formatDimensions }
					],
					[ { name: 'Summary',  cellStyles: "vertical-align: top; height: 75px;", colSpan: 3, field: 2 } ]
			]}
		];
		
		// execute search
		doSearch = function() {
			var web = dojo.byId('webRb').checked;
			model.setRowCount(0);
			model.clear();
			model.fields.set(web ? webFields : imageFields);
			model.url = 'http://search.yahooapis.com/' + (web ? 'WebSearchService/V1/webSearch' : 'ImageSearchService/V1/imageSearch');
			grid.scrollToRow(0);
			grid.setStructure(web ? webLayout : imageLayout);
			model.requestRows();
		}
		
		// do search on enter...
		keypress = function(e) {
			if (e.keyCode == dojo.keys.ENTER)
				doSearch();
		}

		dojo.addOnLoad(function() {
			dojo.byId('webRb').checked = "checked";
			dojo.connect(dojo.byId("searchInput"), "keypress", keypress);
			doSearch();
		});

	</script>
</head>
<body>
<div style="font-weight: bold; padding-bottom: 0.25em;">dojox.Grid - Yahoo Search Test</div>
<div style="padding-bottom: 3px;">
	<label><input id="webRb" type="radio" name="searchType" checked>Web</label>&nbsp;&nbsp;
	<label><input id="imageRb" type="radio" name="searchType">Images</label>
</div>	
<input id="searchInput" type="text" value="apple">&nbsp;&nbsp;
<button onclick="doSearch()">Search</button><br><br>
<div jsId="grid" class="grid" autoWidth="true" structure="webLayout" dojoType="dojox.Grid" model="model" elasticView="1"></div>
<br>
<div id="info">
	<div id="rowCount" style="float: left"></div>
	<div style="float: right">
		<div id="sendInfo" style="text-align: right"></div>
		<div id="receiveInfo" style="text-align: right"></div>
	</div>
</div>
<br /><br />
<p>Note: requires PHP for proxy.</p>
</body>
</html>