root / trunk / web / dojo / dojox / data / PicasaStore.js @ 12
History | View | Annotate | Download (4.21 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dojox.data.PicasaStore"]){ |
9 |
dojo._hasResource["dojox.data.PicasaStore"]=true; |
10 |
dojo.provide("dojox.data.PicasaStore");
|
11 |
dojo.require("dojo.data.util.simpleFetch");
|
12 |
dojo.require("dojo.io.script");
|
13 |
dojo.require("dojo.date.stamp");
|
14 |
dojo.declare("dojox.data.PicasaStore",null,{constructor:function(_1){ |
15 |
if(_1&&_1.label){
|
16 |
this.label=_1.label;
|
17 |
} |
18 |
if(_1&&"urlPreventCache" in _1){ |
19 |
this.urlPreventCache=_1.urlPreventCache?true:false; |
20 |
} |
21 |
if(_1&&"maxResults" in _1){ |
22 |
this.maxResults=parseInt(_1.maxResults);
|
23 |
if(!this.maxResults){ |
24 |
this.maxResults=20; |
25 |
} |
26 |
} |
27 |
},_picasaUrl:"http://picasaweb.google.com/data/feed/api/all",_storeRef:"_S",label:"title",urlPreventCache:false,maxResults:20,_assertIsItem:function(_2){ |
28 |
if(!this.isItem(_2)){ |
29 |
throw new Error("dojox.data.PicasaStore: a function was passed an item argument that was not an item"); |
30 |
} |
31 |
},_assertIsAttribute:function(_3){ |
32 |
if(typeof _3!=="string"){ |
33 |
throw new Error("dojox.data.PicasaStore: a function was passed an attribute argument that was not an attribute name string"); |
34 |
} |
35 |
},getFeatures:function(){ |
36 |
return {"dojo.data.api.Read":true}; |
37 |
},getValue:function(_4,_5,_6){ |
38 |
var _7=this.getValues(_4,_5); |
39 |
if(_7&&_7.length>0){ |
40 |
return _7[0]; |
41 |
} |
42 |
return _6;
|
43 |
},getAttributes:function(_8){ |
44 |
return ["id","published","updated","category","title$type","title","summary$type","summary","rights$type","rights","link","author","gphoto$id","gphoto$name","location","imageUrlSmall","imageUrlMedium","imageUrl","datePublished","dateTaken","description"]; |
45 |
},hasAttribute:function(_9,_a){ |
46 |
if(this.getValue(_9,_a)){ |
47 |
return true; |
48 |
} |
49 |
return false; |
50 |
},isItemLoaded:function(_b){ |
51 |
return this.isItem(_b); |
52 |
},loadItem:function(_c){ |
53 |
},getLabel:function(_d){ |
54 |
return this.getValue(_d,this.label); |
55 |
},getLabelAttributes:function(_e){ |
56 |
return [this.label]; |
57 |
},containsValue:function(_f,_10,_11){ |
58 |
var _12=this.getValues(_f,_10); |
59 |
for(var i=0;i<_12.length;i++){ |
60 |
if(_12[i]===_11){
|
61 |
return true; |
62 |
} |
63 |
} |
64 |
return false; |
65 |
},getValues:function(_13,_14){ |
66 |
this._assertIsItem(_13);
|
67 |
this._assertIsAttribute(_14);
|
68 |
if(_14==="title"){ |
69 |
return [this._unescapeHtml(_13.title)]; |
70 |
}else{
|
71 |
if(_14==="author"){ |
72 |
return [this._unescapeHtml(_13.author[0].name)]; |
73 |
}else{
|
74 |
if(_14==="datePublished"){ |
75 |
return [dojo.date.stamp.fromISOString(_13.published)];
|
76 |
}else{
|
77 |
if(_14==="dateTaken"){ |
78 |
return [dojo.date.stamp.fromISOString(_13.published)];
|
79 |
}else{
|
80 |
if(_14==="updated"){ |
81 |
return [dojo.date.stamp.fromISOString(_13.updated)];
|
82 |
}else{
|
83 |
if(_14==="imageUrlSmall"){ |
84 |
return [_13.media.thumbnail[1].url]; |
85 |
}else{
|
86 |
if(_14==="imageUrl"){ |
87 |
return [_13.content$src]; |
88 |
}else{
|
89 |
if(_14==="imageUrlMedium"){ |
90 |
return [_13.media.thumbnail[2].url]; |
91 |
}else{
|
92 |
if(_14==="link"){ |
93 |
return [_13.link[1]]; |
94 |
}else{
|
95 |
if(_14==="tags"){ |
96 |
return _13.tags.split(" "); |
97 |
}else{
|
98 |
if(_14==="description"){ |
99 |
return [this._unescapeHtml(_13.summary)]; |
100 |
} |
101 |
} |
102 |
} |
103 |
} |
104 |
} |
105 |
} |
106 |
} |
107 |
} |
108 |
} |
109 |
} |
110 |
} |
111 |
return [];
|
112 |
},isItem:function(_15){ |
113 |
if(_15&&_15[this._storeRef]===this){ |
114 |
return true; |
115 |
} |
116 |
return false; |
117 |
},close:function(_16){ |
118 |
},_fetchItems:function(_17,_18,_19){ |
119 |
if(!_17.query){
|
120 |
_17.query={}; |
121 |
} |
122 |
var _1a={alt:"jsonm",pp:"1",psc:"G"}; |
123 |
_1a["start-index"]="1"; |
124 |
if(_17.query.start){
|
125 |
_1a["start-index"]=_17.query.start;
|
126 |
} |
127 |
if(_17.query.tags){
|
128 |
_1a.q=_17.query.tags; |
129 |
} |
130 |
if(_17.query.userid){
|
131 |
_1a.uname=_17.query.userid; |
132 |
} |
133 |
if(_17.query.userids){
|
134 |
_1a.ids=_17.query.userids; |
135 |
} |
136 |
if(_17.query.lang){
|
137 |
_1a.hl=_17.query.lang; |
138 |
} |
139 |
_1a["max-results"]=this.maxResults; |
140 |
var _1b=this; |
141 |
var _1c=null; |
142 |
var _1d=function(_1e){ |
143 |
if(_1c!==null){ |
144 |
dojo.disconnect(_1c); |
145 |
} |
146 |
_18(_1b._processPicasaData(_1e),_17); |
147 |
}; |
148 |
var _1f={url:this._picasaUrl,preventCache:this.urlPreventCache,content:_1a,callbackParamName:"callback",handle:_1d}; |
149 |
var _20=dojo.io.script.get(_1f);
|
150 |
_20.addErrback(function(_21){
|
151 |
dojo.disconnect(_1c); |
152 |
_19(_21,_17); |
153 |
}); |
154 |
},_processPicasaData:function(_22){ |
155 |
var _23=[];
|
156 |
if(_22.feed){
|
157 |
_23=_22.feed.entry; |
158 |
for(var i=0;i<_23.length;i++){ |
159 |
var _24=_23[i];
|
160 |
_24[this._storeRef]=this; |
161 |
} |
162 |
} |
163 |
return _23;
|
164 |
},_unescapeHtml:function(str){ |
165 |
if(str){
|
166 |
str=str.replace(/&/gm,"&").replace(/</gm,"<").replace(/>/gm,">").replace(/"/gm,"\""); |
167 |
str=str.replace(/'/gm,"'"); |
168 |
} |
169 |
return str;
|
170 |
}}); |
171 |
dojo.extend(dojox.data.PicasaStore,dojo.data.util.simpleFetch); |
172 |
} |