Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / data / StoreExplorer.js

History | View | Annotate | Download (4.22 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.data.StoreExplorer"]){
9
dojo._hasResource["dojox.data.StoreExplorer"]=true;
10
dojo.provide("dojox.data.StoreExplorer");
11
dojo.require("dojox.grid.DataGrid");
12
dojo.require("dojox.data.ItemExplorer");
13
dojo.require("dijit.layout.BorderContainer");
14
dojo.require("dijit.layout.ContentPane");
15
dojo.declare("dojox.data.StoreExplorer",dijit.layout.BorderContainer,{constructor:function(_1){
16
dojo.mixin(this,_1);
17
},store:null,stringQueries:false,postCreate:function(){
18
var _2=this;
19
this.inherited(arguments);
20
var _3=new dijit.layout.ContentPane({region:"top"}).placeAt(this);
21
function _4(_5,_6){
22
var _7=new dijit.form.Button({label:_5});
23
_3.containerNode.appendChild(_7.domNode);
24
_7.onClick=_6;
25
return _7;
26
};
27
var _8=_3.containerNode.appendChild(document.createElement("span"));
28
_8.innerHTML="Enter query:  ";
29
_8.id="queryText";
30
var _9=_3.containerNode.appendChild(document.createElement("input"));
31
_9.type="text";
32
_9.id="queryTextBox";
33
_4("Query",function(){
34
var _a=_9.value;
35
_2.setQuery(_2.stringQueries?_a:dojo.fromJson(_a));
36
});
37
_3.containerNode.appendChild(document.createElement("span")).innerHTML="   ";
38
var _b=_4("Create New",dojo.hitch(this,"createNew"));
39
var _c=_4("Delete",function(){
40
var _d=_e.selection.getSelected();
41
for(var i=0;i<_d.length;i++){
42
_2.store.deleteItem(_d[i]);
43
}
44
});
45
this.setItemName=function(_f){
46
_b.attr("label","<img style='width:12px; height:12px' src='"+dojo.moduleUrl("dijit.themes.tundra.images","dndCopy.png")+"' /> Create New "+_f);
47
_c.attr("label","Delete "+_f);
48
};
49
_4("Save",function(){
50
_2.store.save({onError:function(_10){
51
alert(_10);
52
}});
53
_2.tree.refreshItem();
54
});
55
_4("Revert",function(){
56
_2.store.revert();
57
});
58
_4("Add Column",function(){
59
var _11=prompt("Enter column name:","property");
60
if(_11){
61
_2.gridLayout.push({field:_11,name:_11,formatter:dojo.hitch(_2,"_formatCell"),editable:true});
62
_2.grid.attr("structure",_2.gridLayout);
63
}
64
});
65
var _12=new dijit.layout.ContentPane({region:"center"}).placeAt(this);
66
var _e=this.grid=new dojox.grid.DataGrid({store:this.store});
67
_12.attr("content",_e);
68
_e.canEdit=function(_13,_14){
69
var _15=this._copyAttr(_14,_13.field);
70
return !(_15&&typeof _15=="object")||_15 instanceof Date;
71
};
72
var _16=new dijit.layout.ContentPane({region:"trailing",splitter:true,style:"width: 300px"}).placeAt(this);
73
var _17=this.tree=new dojox.data.ItemExplorer({store:this.store});
74
_16.attr("content",_17);
75
dojo.connect(_e,"onCellClick",function(){
76
var _18=_e.selection.getSelected()[0];
77
_17.setItem(_18);
78
});
79
this.gridOnFetchComplete=_e._onFetchComplete;
80
this.setStore(this.store);
81
},setQuery:function(_19,_1a){
82
this.grid.setQuery(_19,_1a);
83
},_formatCell:function(_1b){
84
if(this.store.isItem(_1b)){
85
return this.store.getLabel(_1b)||this.store.getIdentity(_1b);
86
}
87
return _1b;
88
},setStore:function(_1c){
89
this.store=_1c;
90
var _1d=this;
91
var _1e=this.grid;
92
_1e._pending_requests[0]=false;
93
function _1f(_20){
94
return _1d._formatCell(_20);
95
};
96
var _21=this.gridOnFetchComplete;
97
_1e._onFetchComplete=function(_22,req){
98
var _23=_1d.gridLayout=[];
99
var _24,key,_25,i,j,k,_26=_1c.getIdentityAttributes();
100
for(i=0;i<_26.length;i++){
101
key=_26[i];
102
_23.push({field:key,name:key,_score:100,formatter:_1f,editable:false});
103
}
104
for(i=0;_25=_22[i++];){
105
var _27=_1c.getAttributes(_25);
106
for(k=0;key=_27[k++];){
107
var _28=false;
108
for(j=0;_24=_23[j++];){
109
if(_24.field==key){
110
_24._score++;
111
_28=true;
112
break;
113
}
114
}
115
if(!_28){
116
_23.push({field:key,name:key,_score:1,formatter:_1f,styles:"white-space:nowrap; ",editable:true});
117
}
118
}
119
}
120
_23=_23.sort(function(a,b){
121
return a._score>b._score?-1:1;
122
});
123
for(j=0;_24=_23[j];j++){
124
if(_24._score<_22.length/40*j){
125
_23.splice(j,_23.length-j);
126
break;
127
}
128
}
129
for(j=0;_24=_23[j++];){
130
_24.width=Math.round(100/_23.length)+"%";
131
}
132
_1e._onFetchComplete=_21;
133
_1e.attr("structure",_23);
134
var _29=_21.apply(this,arguments);
135
};
136
_1e.setStore(_1c);
137
this.queryOptions={cache:true};
138
this.tree.setStore(_1c);
139
},createNew:function(){
140
var _2a=prompt("Enter any properties (in JSON literal form) to put in the new item (passed to the newItem constructor):","{ }");
141
if(_2a){
142
try{
143
this.store.newItem(dojo.fromJson(_2a));
144
}
145
catch(e){
146
alert(e);
147
}
148
}
149
}});
150
}