root / trunk / web / dojo / dojox / widget / Iterator.js
History | View | Annotate | Download (2.35 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.widget.Iterator"]){ |
||
9 | dojo._hasResource["dojox.widget.Iterator"]=true; |
||
10 | dojo.provide("dojox.widget.Iterator");
|
||
11 | dojo.require("dijit.Declaration");
|
||
12 | dojo.experimental("dojox.widget.Iterator");
|
||
13 | dojo.declare("dojox.widget.Iterator",[dijit.Declaration],{constructor:(function(){ |
||
14 | var _1=0; |
||
15 | return function(){ |
||
16 | this.attrs=[];
|
||
17 | this.children=[];
|
||
18 | this.widgetClass="dojox.widget.Iterator._classes._"+(_1++); |
||
19 | }; |
||
20 | })(),start:0,fetchMax:1000,query:{name:"*"},attrs:[],defaultValue:"",widgetCtor:null,dataValues:[],data:null,store:null,_srcIndex:0,_srcParent:null,_setSrcIndex:function(s){ |
||
21 | this._srcIndex=0; |
||
22 | this._srcParent=s.parentNode;
|
||
23 | var ts=s;
|
||
24 | while(ts.previousSibling){
|
||
25 | this._srcIndex++;
|
||
26 | ts=ts.previousSibling; |
||
27 | } |
||
28 | },postscript:function(p,s){ |
||
29 | this._setSrcIndex(s);
|
||
30 | this.inherited("postscript",arguments); |
||
31 | var wc=this.widgetCtor=dojo.getObject(this.widgetClass); |
||
32 | this.attrs=dojo.map(wc.prototype.templateString.match(/\$\{([^\s\:\}]+)(?:\:([^\s\:\}]+))?\}/g),function(s){ |
||
33 | return s.slice(2,-1); |
||
34 | }); |
||
35 | dojo.forEach(this.attrs,function(m){ |
||
36 | wc.prototype[m]="";
|
||
37 | }); |
||
38 | this.update();
|
||
39 | },clear:function(){ |
||
40 | if(this.children.length){ |
||
41 | this._setSrcIndex(this.children[0].domNode); |
||
42 | } |
||
43 | dojo.forEach(this.children,"item.destroy();"); |
||
44 | this.children=[];
|
||
45 | },update:function(){ |
||
46 | if(this.store){ |
||
47 | this.fetch();
|
||
48 | }else{
|
||
49 | this.onDataAvailable(this.data||this.dataValues); |
||
50 | } |
||
51 | },_addItem:function(_2,_3){ |
||
52 | if(dojo.isString(_2)){
|
||
53 | _2={value:_2};
|
||
54 | } |
||
55 | var _4=new this.widgetCtor(_2); |
||
56 | this.children.push(_4);
|
||
57 | dojo.place(_4.domNode,this._srcParent,this._srcIndex+_3); |
||
58 | },getAttrValuesObj:function(_5){ |
||
59 | var _6={};
|
||
60 | if(dojo.isString(_5)){
|
||
61 | dojo.forEach(this.attrs,function(_7){ |
||
62 | _6[_7]=(_7=="value")?_5:this.defaultValue; |
||
63 | },this);
|
||
64 | }else{
|
||
65 | dojo.forEach(this.attrs,function(_8){ |
||
66 | if(this.store){ |
||
67 | _6[_8]=this.store.getValue(_5,_8)||this.defaultValue; |
||
68 | }else{
|
||
69 | _6[_8]=_5[_8]||this.defaultValue;
|
||
70 | } |
||
71 | },this);
|
||
72 | } |
||
73 | return _6;
|
||
74 | },onDataAvailable:function(_9){ |
||
75 | this.clear();
|
||
76 | dojo.forEach(_9,function(_a,_b){
|
||
77 | this._addItem(this.getAttrValuesObj(_a),_b); |
||
78 | },this);
|
||
79 | },fetch:function(_c,_d,_e){ |
||
80 | this.store.fetch({query:_c||this.query,start:_d||this.start,count:_e||this.fetchMax,onComplete:dojo.hitch(this,"onDataAvailable")}); |
||
81 | }}); |
||
82 | dojox.widget.Iterator._classes={}; |
||
83 | } |