root / trunk / web / dojo / dojox / atom / widget / FeedViewer.js @ 10
History | View | Annotate | Download (11.6 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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.atom.widget.FeedViewer"]){ |
||
9 | dojo._hasResource["dojox.atom.widget.FeedViewer"]=true; |
||
10 | dojo.provide("dojox.atom.widget.FeedViewer");
|
||
11 | dojo.require("dijit._Widget");
|
||
12 | dojo.require("dijit._Templated");
|
||
13 | dojo.require("dijit._Container");
|
||
14 | dojo.require("dojox.atom.io.Connection");
|
||
15 | dojo.requireLocalization("dojox.atom.widget","FeedViewerEntry",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw"); |
||
16 | dojo.experimental("dojox.atom.widget.FeedViewer");
|
||
17 | dojo.declare("dojox.atom.widget.FeedViewer",[dijit._Widget,dijit._Templated,dijit._Container],{feedViewerTableBody:null,feedViewerTable:null,entrySelectionTopic:"",url:"",xmethod:false,localSaveOnly:false,templateString:dojo.cache("dojox.atom","widget/templates/FeedViewer.html","<div class=\"feedViewerContainer\" dojoAttachPoint=\"feedViewerContainerNode\">\n\t<table cellspacing=\"0\" cellpadding=\"0\" class=\"feedViewerTable\">\n\t\t<tbody dojoAttachPoint=\"feedViewerTableBody\" class=\"feedViewerTableBody\">\n\t\t</tbody>\n\t</table>\n</div>\n"),_feed:null,_currentSelection:null,_includeFilters:null,alertsEnabled:false,postCreate:function(){ |
||
18 | this._includeFilters=[];
|
||
19 | if(this.entrySelectionTopic!==""){ |
||
20 | this._subscriptions=[dojo.subscribe(this.entrySelectionTopic,this,"_handleEvent")]; |
||
21 | } |
||
22 | this.atomIO=new dojox.atom.io.Connection(); |
||
23 | this.childWidgets=[];
|
||
24 | },startup:function(){ |
||
25 | this.containerNode=this.feedViewerTableBody; |
||
26 | var _1=this.getDescendants(); |
||
27 | for(var i in _1){ |
||
28 | var _2=_1[i];
|
||
29 | if(_2&&_2.isFilter){
|
||
30 | this._includeFilters.push(new dojox.atom.widget.FeedViewer.CategoryIncludeFilter(_2.scheme,_2.term,_2.label)); |
||
31 | _2.destroy(); |
||
32 | } |
||
33 | } |
||
34 | if(this.url!==""){ |
||
35 | this.setFeedFromUrl(this.url); |
||
36 | } |
||
37 | },clear:function(){ |
||
38 | this.destroyDescendants();
|
||
39 | },setFeedFromUrl:function(_3){ |
||
40 | if(_3!==""){ |
||
41 | if(this._isRelativeURL(_3)){ |
||
42 | var _4=""; |
||
43 | if(_3.charAt(0)!=="/"){ |
||
44 | _4=this._calculateBaseURL(window.location.href,true); |
||
45 | }else{
|
||
46 | _4=this._calculateBaseURL(window.location.href,false); |
||
47 | } |
||
48 | this.url=_4+_3;
|
||
49 | } |
||
50 | this.atomIO.getFeed(_3,dojo.hitch(this,this.setFeed)); |
||
51 | } |
||
52 | },setFeed:function(_5){ |
||
53 | this._feed=_5;
|
||
54 | this.clear();
|
||
55 | var _6=function(a,b){ |
||
56 | var _7=this._displayDateForEntry(a); |
||
57 | var _8=this._displayDateForEntry(b); |
||
58 | if(_7>_8){
|
||
59 | return -1; |
||
60 | } |
||
61 | if(_7<_8){
|
||
62 | return 1; |
||
63 | } |
||
64 | return 0; |
||
65 | }; |
||
66 | var _9=function(_a){ |
||
67 | var _b=_a.split(","); |
||
68 | _b.pop(); |
||
69 | return _b.join(","); |
||
70 | }; |
||
71 | var _c=_5.entries.sort(dojo.hitch(this,_6)); |
||
72 | if(_5){
|
||
73 | var _d=null; |
||
74 | for(var i=0;i<_c.length;i++){ |
||
75 | var _e=_c[i];
|
||
76 | if(this._isFilterAccepted(_e)){ |
||
77 | var _f=this._displayDateForEntry(_e); |
||
78 | var _10=""; |
||
79 | if(_f!==null){ |
||
80 | _10=_9(_f.toLocaleString()); |
||
81 | if(_10===""){ |
||
82 | _10=""+(_f.getMonth()+1)+"/"+_f.getDate()+"/"+_f.getFullYear(); |
||
83 | } |
||
84 | } |
||
85 | if((_d===null)||(_d!=_10)){ |
||
86 | this.appendGrouping(_10);
|
||
87 | _d=_10; |
||
88 | } |
||
89 | this.appendEntry(_e);
|
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | },_displayDateForEntry:function(_11){ |
||
94 | if(_11.updated){
|
||
95 | return _11.updated;
|
||
96 | } |
||
97 | if(_11.modified){
|
||
98 | return _11.modified;
|
||
99 | } |
||
100 | if(_11.issued){
|
||
101 | return _11.issued;
|
||
102 | } |
||
103 | return new Date(); |
||
104 | },appendGrouping:function(_12){ |
||
105 | var _13=new dojox.atom.widget.FeedViewerGrouping({}); |
||
106 | _13.setText(_12); |
||
107 | this.addChild(_13);
|
||
108 | this.childWidgets.push(_13);
|
||
109 | },appendEntry:function(_14){ |
||
110 | var _15=new dojox.atom.widget.FeedViewerEntry({"xmethod":this.xmethod}); |
||
111 | _15.setTitle(_14.title.value); |
||
112 | _15.setTime(this._displayDateForEntry(_14).toLocaleTimeString());
|
||
113 | _15.entrySelectionTopic=this.entrySelectionTopic;
|
||
114 | _15.feed=this;
|
||
115 | this.addChild(_15);
|
||
116 | this.childWidgets.push(_15);
|
||
117 | this.connect(_15,"onClick","_rowSelected"); |
||
118 | _14.domNode=_15.entryNode; |
||
119 | _14._entryWidget=_15; |
||
120 | _15.entry=_14; |
||
121 | },deleteEntry:function(_16){ |
||
122 | if(!this.localSaveOnly){ |
||
123 | this.atomIO.deleteEntry(_16.entry,dojo.hitch(this,this._removeEntry,_16),null,this.xmethod); |
||
124 | }else{
|
||
125 | this._removeEntry(_16,true); |
||
126 | } |
||
127 | dojo.publish(this.entrySelectionTopic,[{action:"delete",source:this,entry:_16.entry}]); |
||
128 | },_removeEntry:function(_17,_18){ |
||
129 | if(_18){
|
||
130 | var idx=dojo.indexOf(this.childWidgets,_17); |
||
131 | var _19=this.childWidgets[idx-1]; |
||
132 | var _1a=this.childWidgets[idx+1]; |
||
133 | if(_19.declaredClass==="dojox.atom.widget.FeedViewerGrouping"&&(_1a===undefined||_1a.declaredClass==="dojox.atom.widget.FeedViewerGrouping")){ |
||
134 | _19.destroy(); |
||
135 | } |
||
136 | _17.destroy(); |
||
137 | }else{
|
||
138 | } |
||
139 | },_rowSelected:function(evt){ |
||
140 | var _1b=evt.target;
|
||
141 | while(_1b){
|
||
142 | if(_1b.attributes){
|
||
143 | var _1c=_1b.attributes.getNamedItem("widgetid"); |
||
144 | if(_1c&&_1c.value.indexOf("FeedViewerEntry")!=-1){ |
||
145 | break;
|
||
146 | } |
||
147 | } |
||
148 | _1b=_1b.parentNode; |
||
149 | } |
||
150 | for(var i=0;i<this._feed.entries.length;i++){ |
||
151 | var _1d=this._feed.entries[i]; |
||
152 | if((_1b===_1d.domNode)&&(this._currentSelection!==_1d)){ |
||
153 | dojo.addClass(_1d.domNode,"feedViewerEntrySelected");
|
||
154 | dojo.removeClass(_1d._entryWidget.timeNode,"feedViewerEntryUpdated");
|
||
155 | dojo.addClass(_1d._entryWidget.timeNode,"feedViewerEntryUpdatedSelected");
|
||
156 | this.onEntrySelected(_1d);
|
||
157 | if(this.entrySelectionTopic!==""){ |
||
158 | dojo.publish(this.entrySelectionTopic,[{action:"set",source:this,feed:this._feed,entry:_1d}]); |
||
159 | } |
||
160 | if(this._isEditable(_1d)){ |
||
161 | _1d._entryWidget.enableDelete(); |
||
162 | } |
||
163 | this._deselectCurrentSelection();
|
||
164 | this._currentSelection=_1d;
|
||
165 | break;
|
||
166 | }else{
|
||
167 | if((_1b===_1d.domNode)&&(this._currentSelection===_1d)){ |
||
168 | dojo.publish(this.entrySelectionTopic,[{action:"delete",source:this,entry:_1d}]); |
||
169 | this._deselectCurrentSelection();
|
||
170 | break;
|
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | },_deselectCurrentSelection:function(){ |
||
175 | if(this._currentSelection){ |
||
176 | dojo.addClass(this._currentSelection._entryWidget.timeNode,"feedViewerEntryUpdated"); |
||
177 | dojo.removeClass(this._currentSelection.domNode,"feedViewerEntrySelected"); |
||
178 | dojo.removeClass(this._currentSelection._entryWidget.timeNode,"feedViewerEntryUpdatedSelected"); |
||
179 | this._currentSelection._entryWidget.disableDelete();
|
||
180 | this._currentSelection=null; |
||
181 | } |
||
182 | },_isEditable:function(_1e){ |
||
183 | var _1f=false; |
||
184 | if(_1e&&_1e!==null&&_1e.links&&_1e.links!==null){ |
||
185 | for(var x in _1e.links){ |
||
186 | if(_1e.links[x].rel&&_1e.links[x].rel=="edit"){ |
||
187 | _1f=true;
|
||
188 | break;
|
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | return _1f;
|
||
193 | },onEntrySelected:function(_20){ |
||
194 | },_isRelativeURL:function(url){ |
||
195 | var _21=function(url){ |
||
196 | var _22=false; |
||
197 | if(url.indexOf("file://")===0){ |
||
198 | _22=true;
|
||
199 | } |
||
200 | return _22;
|
||
201 | }; |
||
202 | var _23=function(url){ |
||
203 | var _24=false; |
||
204 | if(url.indexOf("http://")===0){ |
||
205 | _24=true;
|
||
206 | } |
||
207 | return _24;
|
||
208 | }; |
||
209 | var _25=false; |
||
210 | if(url!==null){ |
||
211 | if(!_21(url)&&!_23(url)){
|
||
212 | _25=true;
|
||
213 | } |
||
214 | } |
||
215 | return _25;
|
||
216 | },_calculateBaseURL:function(_26,_27){ |
||
217 | var _28=null; |
||
218 | if(_26!==null){ |
||
219 | var _29=_26.indexOf("?"); |
||
220 | if(_29!=-1){ |
||
221 | _26=_26.substring(0,_29);
|
||
222 | } |
||
223 | if(_27){
|
||
224 | _29=_26.lastIndexOf("/");
|
||
225 | if((_29>0)&&(_29<_26.length)&&(_29!==(_26.length-1))){ |
||
226 | _28=_26.substring(0,(_29+1)); |
||
227 | }else{
|
||
228 | _28=_26; |
||
229 | } |
||
230 | }else{
|
||
231 | _29=_26.indexOf("://");
|
||
232 | if(_29>0){ |
||
233 | _29=_29+3;
|
||
234 | var _2a=_26.substring(0,_29); |
||
235 | var _2b=_26.substring(_29,_26.length);
|
||
236 | _29=_2b.indexOf("/");
|
||
237 | if((_29<_2b.length)&&(_29>0)){ |
||
238 | _28=_2a+_2b.substring(0,_29);
|
||
239 | }else{
|
||
240 | _28=_2a+_2b; |
||
241 | } |
||
242 | } |
||
243 | } |
||
244 | } |
||
245 | return _28;
|
||
246 | },_isFilterAccepted:function(_2c){ |
||
247 | var _2d=false; |
||
248 | if(this._includeFilters&&(this._includeFilters.length>0)){ |
||
249 | for(var i=0;i<this._includeFilters.length;i++){ |
||
250 | var _2e=this._includeFilters[i]; |
||
251 | if(_2e.match(_2c)){
|
||
252 | _2d=true;
|
||
253 | break;
|
||
254 | } |
||
255 | } |
||
256 | }else{
|
||
257 | _2d=true;
|
||
258 | } |
||
259 | return _2d;
|
||
260 | },addCategoryIncludeFilter:function(_2f){ |
||
261 | if(_2f){
|
||
262 | var _30=_2f.scheme;
|
||
263 | var _31=_2f.term;
|
||
264 | var _32=_2f.label;
|
||
265 | var _33=true; |
||
266 | if(!_30){
|
||
267 | _30=null;
|
||
268 | } |
||
269 | if(!_31){
|
||
270 | _30=null;
|
||
271 | } |
||
272 | if(!_32){
|
||
273 | _30=null;
|
||
274 | } |
||
275 | if(this._includeFilters&&this._includeFilters.length>0){ |
||
276 | for(var i=0;i<this._includeFilters.length;i++){ |
||
277 | var _34=this._includeFilters[i]; |
||
278 | if((_34.term===_31)&&(_34.scheme===_30)&&(_34.label===_32)){
|
||
279 | _33=false;
|
||
280 | break;
|
||
281 | } |
||
282 | } |
||
283 | } |
||
284 | if(_33){
|
||
285 | this._includeFilters.push(dojox.atom.widget.FeedViewer.CategoryIncludeFilter(_30,_31,_32));
|
||
286 | } |
||
287 | } |
||
288 | },removeCategoryIncludeFilter:function(_35){ |
||
289 | if(_35){
|
||
290 | var _36=_35.scheme;
|
||
291 | var _37=_35.term;
|
||
292 | var _38=_35.label;
|
||
293 | if(!_36){
|
||
294 | _36=null;
|
||
295 | } |
||
296 | if(!_37){
|
||
297 | _36=null;
|
||
298 | } |
||
299 | if(!_38){
|
||
300 | _36=null;
|
||
301 | } |
||
302 | var _39=[];
|
||
303 | if(this._includeFilters&&this._includeFilters.length>0){ |
||
304 | for(var i=0;i<this._includeFilters.length;i++){ |
||
305 | var _3a=this._includeFilters[i]; |
||
306 | if(!((_3a.term===_37)&&(_3a.scheme===_36)&&(_3a.label===_38))){
|
||
307 | _39.push(_3a); |
||
308 | } |
||
309 | } |
||
310 | this._includeFilters=_39;
|
||
311 | } |
||
312 | } |
||
313 | },_handleEvent:function(_3b){ |
||
314 | if(_3b.source!=this){ |
||
315 | if(_3b.action=="update"&&_3b.entry){ |
||
316 | var evt=_3b;
|
||
317 | if(!this.localSaveOnly){ |
||
318 | this.atomIO.updateEntry(evt.entry,dojo.hitch(evt.source,evt.callback),null,true); |
||
319 | } |
||
320 | this._currentSelection._entryWidget.setTime(this._displayDateForEntry(evt.entry).toLocaleTimeString()); |
||
321 | this._currentSelection._entryWidget.setTitle(evt.entry.title.value);
|
||
322 | }else{
|
||
323 | if(_3b.action=="post"&&_3b.entry){ |
||
324 | if(!this.localSaveOnly){ |
||
325 | this.atomIO.addEntry(_3b.entry,this.url,dojo.hitch(this,this._addEntry)); |
||
326 | }else{
|
||
327 | this._addEntry(_3b.entry);
|
||
328 | } |
||
329 | } |
||
330 | } |
||
331 | } |
||
332 | },_addEntry:function(_3c){ |
||
333 | this._feed.addEntry(_3c);
|
||
334 | this.setFeed(this._feed); |
||
335 | dojo.publish(this.entrySelectionTopic,[{action:"set",source:this,feed:this._feed,entry:_3c}]); |
||
336 | },destroy:function(){ |
||
337 | this.clear();
|
||
338 | dojo.forEach(this._subscriptions,dojo.unsubscribe);
|
||
339 | }}); |
||
340 | dojo.declare("dojox.atom.widget.FeedViewerEntry",[dijit._Widget,dijit._Templated],{templateString:dojo.cache("dojox.atom","widget/templates/FeedViewerEntry.html","<tr class=\"feedViewerEntry\" dojoAttachPoint=\"entryNode\" dojoAttachEvent=\"onclick:onClick\">\n <td class=\"feedViewerEntryUpdated\" dojoAttachPoint=\"timeNode\">\n </td>\n <td>\n <table border=\"0\" width=\"100%\" dojoAttachPoint=\"titleRow\">\n <tr padding=\"0\" border=\"0\">\n <td class=\"feedViewerEntryTitle\" dojoAttachPoint=\"titleNode\">\n </td>\n <td class=\"feedViewerEntryDelete\" align=\"right\">\n <span dojoAttachPoint=\"deleteButton\" dojoAttachEvent=\"onclick:deleteEntry\" class=\"feedViewerDeleteButton\" style=\"display:none;\">[delete]</span>\n </td>\n <tr>\n </table>\n </td>\n</tr>\n"),entryNode:null,timeNode:null,deleteButton:null,entry:null,feed:null,postCreate:function(){ |
||
341 | var _3d=dojo.i18n.getLocalization("dojox.atom.widget","FeedViewerEntry"); |
||
342 | this.deleteButton.innerHTML=_3d.deleteButton;
|
||
343 | },setTitle:function(_3e){ |
||
344 | if(this.titleNode.lastChild){ |
||
345 | this.titleNode.removeChild(this.titleNode.lastChild); |
||
346 | } |
||
347 | var _3f=document.createElement("div"); |
||
348 | _3f.innerHTML=_3e; |
||
349 | this.titleNode.appendChild(_3f);
|
||
350 | },setTime:function(_40){ |
||
351 | if(this.timeNode.lastChild){ |
||
352 | this.timeNode.removeChild(this.timeNode.lastChild); |
||
353 | } |
||
354 | var _41=document.createTextNode(_40);
|
||
355 | this.timeNode.appendChild(_41);
|
||
356 | },enableDelete:function(){ |
||
357 | if(this.deleteButton!==null){ |
||
358 | this.deleteButton.style.display="inline"; |
||
359 | } |
||
360 | },disableDelete:function(){ |
||
361 | if(this.deleteButton!==null){ |
||
362 | this.deleteButton.style.display="none"; |
||
363 | } |
||
364 | },deleteEntry:function(_42){ |
||
365 | _42.preventDefault(); |
||
366 | _42.stopPropagation(); |
||
367 | this.feed.deleteEntry(this); |
||
368 | },onClick:function(e){ |
||
369 | }}); |
||
370 | dojo.declare("dojox.atom.widget.FeedViewerGrouping",[dijit._Widget,dijit._Templated],{templateString:dojo.cache("dojox.atom","widget/templates/FeedViewerGrouping.html","<tr dojoAttachPoint=\"groupingNode\" class=\"feedViewerGrouping\">\n\t<td colspan=\"2\" dojoAttachPoint=\"titleNode\" class=\"feedViewerGroupingTitle\">\n\t</td>\n</tr>\n"),groupingNode:null,titleNode:null,setText:function(_43){ |
||
371 | if(this.titleNode.lastChild){ |
||
372 | this.titleNode.removeChild(this.titleNode.lastChild); |
||
373 | } |
||
374 | var _44=document.createTextNode(_43);
|
||
375 | this.titleNode.appendChild(_44);
|
||
376 | }}); |
||
377 | dojo.declare("dojox.atom.widget.AtomEntryCategoryFilter",[dijit._Widget,dijit._Templated],{scheme:"",term:"",label:"",isFilter:true}); |
||
378 | dojo.declare("dojox.atom.widget.FeedViewer.CategoryIncludeFilter",null,{constructor:function(_45,_46,_47){ |
||
379 | this.scheme=_45;
|
||
380 | this.term=_46;
|
||
381 | this.label=_47;
|
||
382 | },match:function(_48){ |
||
383 | var _49=false; |
||
384 | if(_48!==null){ |
||
385 | var _4a=_48.categories;
|
||
386 | if(_4a!==null){ |
||
387 | for(var i=0;i<_4a.length;i++){ |
||
388 | var _4b=_4a[i];
|
||
389 | if(this.scheme!==""){ |
||
390 | if(this.scheme!==_4b.scheme){ |
||
391 | break;
|
||
392 | } |
||
393 | } |
||
394 | if(this.term!==""){ |
||
395 | if(this.term!==_4b.term){ |
||
396 | break;
|
||
397 | } |
||
398 | } |
||
399 | if(this.label!==""){ |
||
400 | if(this.label!==_4b.label){ |
||
401 | break;
|
||
402 | } |
||
403 | } |
||
404 | _49=true;
|
||
405 | } |
||
406 | } |
||
407 | } |
||
408 | return _49;
|
||
409 | }}); |
||
410 | } |