source: Dev/branches/rest-dojo-ui/client/dojox/grid/tests/yahooSearch.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.9 KB
Line 
1dojo.declare("YahooStore", dojox.data.ServiceStore, {
2        _processResults: function(results, def){
3                var totalCount = 0;
4                if(results.ResultSet){
5                        totalCount = results.ResultSet.totalResultsAvailable;
6                        results = results.ResultSet.Result;
7                }
8                var resultSet = this.inherited(arguments);
9                resultSet.totalCount = totalCount > 1000 ? 1000 : totalCount;
10                return resultSet;
11        },
12        fetch: function(request){
13                if(request.query){
14                        if(request.count){
15                                request.query['results'] = request.count;
16                        }
17                        if(typeof request.start != "undefined"){
18                                request.query['start'] = request.start + 1;
19                        }
20                }
21
22                return this.inherited(arguments);
23        }
24});
25
26var getCellData = function(item, field){
27        return grid.store.getValue(item, field);
28};
29
30var getLink = function(inRowIndex, inItem){
31        if(!inItem){ return ' '; }
32        return {
33                text: getCellData(inItem, 'Title'),
34                href: getCellData(inItem, 'ClickUrl')
35        };
36};
37
38var formatLink = function(result){
39        return typeof result == 'object' ? dojo.string.substitute(
40                '<a target="_blank" href="${href}">${text}</a>',
41                result
42        ) : result;
43}
44
45var formatDate = function(inDatum, inRowIndex){
46        if(!inDatum){ return '&nbsp;'; }
47        var d = new Date(inDatum * 1000);
48        return dojo.string.substitute(
49                "${0}/${1}/${2}",
50                [ d.getMonth()+1, d.getDate(), d.getFullYear() ]
51        );
52};
53
54var getImage = function(inRowIndex, inItem){
55        if(!inItem){ return '&nbsp;'; }
56        var thumb = getCellData(inItem, "Thumbnail");
57        return {
58                href: getCellData(inItem, "ClickUrl"),
59                src: thumb.Url,
60                width: thumb.Width,
61                height: thumb.Height
62        };
63};
64
65var formatImage = function(result){
66        return typeof result == "object" ? dojo.string.substitute(
67                '<a href="${href}" target="_blank"><img border=0 src="${src}" width="${width}" height="${height}"></a>', result) :
68                result;
69}
70
71var getDimensions = function(inRowIndex, inItem){
72        if(!inItem){ return '&nbsp;'; }
73        var w = getCellData(inItem, "Width");
74        var h = getCellData(inItem, "Height");
75        return w + ' x ' + h;
76};
Note: See TracBrowser for help on using the repository browser.