Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / dtl / contrib / data.js @ 12

History | View | Annotate | Download (2.83 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.dtl.contrib.data"]){
9
dojo._hasResource["dojox.dtl.contrib.data"]=true;
10
dojo.provide("dojox.dtl.contrib.data");
11
dojo.require("dojox.dtl._base");
12
(function(){
13
var dd=dojox.dtl;
14
var _1=dd.contrib.data;
15
var _2=true;
16
_1._BoundItem=dojo.extend(function(_3,_4){
17
this.item=_3;
18
this.store=_4;
19
},{get:function(_5){
20
var _6=this.store;
21
var _7=this.item;
22
if(_5=="getLabel"){
23
return _6.getLabel(_7);
24
}else{
25
if(_5=="getAttributes"){
26
return _6.getAttributes(_7);
27
}else{
28
if(_5=="getIdentity"){
29
if(_6.getIdentity){
30
return _6.getIdentity(_7);
31
}
32
return "Store has no identity API";
33
}else{
34
if(!_6.hasAttribute(_7,_5)){
35
if(_5.slice(-1)=="s"){
36
if(_2){
37
_2=false;
38
dojo.deprecated("You no longer need an extra s to call getValues, it can be figured out automatically");
39
}
40
_5=_5.slice(0,-1);
41
}
42
if(!_6.hasAttribute(_7,_5)){
43
return;
44
}
45
}
46
var _8=_6.getValues(_7,_5);
47
if(!_8){
48
return;
49
}
50
if(!dojo.isArray(_8)){
51
return new _1._BoundItem(_8,_6);
52
}
53
_8=dojo.map(_8,function(_9){
54
if(dojo.isObject(_9)&&_6.isItem(_9)){
55
return new _1._BoundItem(_9,_6);
56
}
57
return _9;
58
});
59
_8.get=_1._get;
60
return _8;
61
}
62
}
63
}
64
}});
65
_1._BoundItem.prototype.get.safe=true;
66
_1.BindDataNode=dojo.extend(function(_a,_b,_c,_d){
67
this.items=_a&&new dd._Filter(_a);
68
this.query=_b&&new dd._Filter(_b);
69
this.store=new dd._Filter(_c);
70
this.alias=_d;
71
},{render:function(_e,_f){
72
var _10=this.items&&this.items.resolve(_e);
73
var _11=this.query&&this.query.resolve(_e);
74
var _12=this.store.resolve(_e);
75
if(!_12||!_12.getFeatures){
76
throw new Error("data_bind didn't receive a store");
77
}
78
if(_11){
79
var _13=false;
80
_12.fetch({query:_11,sync:true,scope:this,onComplete:function(it){
81
_13=true;
82
_10=it;
83
}});
84
if(!_13){
85
throw new Error("The bind_data tag only works with a query if the store executed synchronously");
86
}
87
}
88
var _14=[];
89
if(_10){
90
for(var i=0,_15;_15=_10[i];i++){
91
_14.push(new _1._BoundItem(_15,_12));
92
}
93
}
94
_e[this.alias]=_14;
95
return _f;
96
},unrender:function(_16,_17){
97
return _17;
98
},clone:function(){
99
return this;
100
}});
101
dojo.mixin(_1,{_get:function(key){
102
if(this.length){
103
return (this[0] instanceof _1._BoundItem)?this[0].get(key):this[0][key];
104
}
105
},bind_data:function(_18,_19){
106
var _1a=_19.contents.split();
107
if(_1a[2]!="to"||_1a[4]!="as"||!_1a[5]){
108
throw new Error("data_bind expects the format: 'data_bind items to store as varName'");
109
}
110
return new _1.BindDataNode(_1a[1],null,_1a[3],_1a[5]);
111
},bind_query:function(_1b,_1c){
112
var _1d=_1c.contents.split();
113
if(_1d[2]!="to"||_1d[4]!="as"||!_1d[5]){
114
throw new Error("data_bind expects the format: 'bind_query query to store as varName'");
115
}
116
return new _1.BindDataNode(null,_1d[1],_1d[3],_1d[5]);
117
}});
118
_1._get.safe=true;
119
dd.register.tags("dojox.dtl.contrib",{"data":["bind_data","bind_query"]});
120
})();
121
}