root / trunk / web / dojo / dojox / grid / cells / _base.js
History | View | Annotate | Download (7.43 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.grid.cells._base"]){ |
||
9 | dojo._hasResource["dojox.grid.cells._base"]=true; |
||
10 | dojo.provide("dojox.grid.cells._base");
|
||
11 | dojo.require("dojox.grid.util");
|
||
12 | dojo.require("dijit._Widget");
|
||
13 | dojo.declare("dojox.grid._DeferredTextWidget",dijit._Widget,{deferred:null,_destroyOnRemove:true,postCreate:function(){ |
||
14 | if(this.deferred){ |
||
15 | this.deferred.addBoth(dojo.hitch(this,function(_1){ |
||
16 | if(this.domNode){ |
||
17 | this.domNode.innerHTML=_1;
|
||
18 | } |
||
19 | })); |
||
20 | } |
||
21 | }}); |
||
22 | (function(){
|
||
23 | var _2=function(_3){ |
||
24 | try{
|
||
25 | dojox.grid.util.fire(_3,"focus");
|
||
26 | dojox.grid.util.fire(_3,"select");
|
||
27 | } |
||
28 | catch(e){
|
||
29 | } |
||
30 | }; |
||
31 | var _4=function(){ |
||
32 | setTimeout(dojo.hitch.apply(dojo,arguments),0); |
||
33 | }; |
||
34 | var _5=dojox.grid.cells;
|
||
35 | dojo.declare("dojox.grid.cells._Base",null,{styles:"",classes:"",editable:false,alwaysEditing:false,formatter:null,defaultValue:"...",value:null,hidden:false,noresize:false,draggable:true,_valueProp:"value",_formatPending:false,constructor:function(_6){ |
||
36 | this._props=_6||{};
|
||
37 | dojo.mixin(this,_6);
|
||
38 | if(this.draggable===undefined){ |
||
39 | this.draggable=true; |
||
40 | } |
||
41 | },_defaultFormat:function(_7,_8){ |
||
42 | var s=this.grid.formatterScope||this; |
||
43 | var f=this.formatter; |
||
44 | if(f&&s&&typeof f=="string"){ |
||
45 | f=this.formatter=s[f];
|
||
46 | } |
||
47 | var v=(_7!=this.defaultValue&&f)?f.apply(s,_8):_7; |
||
48 | if(typeof v=="undefined"){ |
||
49 | return this.defaultValue; |
||
50 | } |
||
51 | if(v&&v.addBoth){
|
||
52 | v=new dojox.grid._DeferredTextWidget({deferred:v},dojo.create("span",{innerHTML:this.defaultValue})); |
||
53 | } |
||
54 | if(v&&v.declaredClass&&v.startup){
|
||
55 | return "<div class='dojoxGridStubNode' linkWidget='"+v.id+"' cellIdx='"+this.index+"'>"+this.defaultValue+"</div>"; |
||
56 | } |
||
57 | return v;
|
||
58 | },format:function(_9,_a){ |
||
59 | var f,i=this.grid.edit.info,d=this.get?this.get(_9,_a):(this.value||this.defaultValue); |
||
60 | d=(d&&d.replace&&this.grid.escapeHTMLInData)?d.replace(/&/g,"&").replace(/</g,"<"):d; |
||
61 | if(this.editable&&(this.alwaysEditing||(i.rowIndex==_9&&i.cell==this))){ |
||
62 | return this.formatEditing(d,_9); |
||
63 | }else{
|
||
64 | return this._defaultFormat(d,[d,_9,this]); |
||
65 | } |
||
66 | },formatEditing:function(_b,_c){ |
||
67 | },getNode:function(_d){ |
||
68 | return this.view.getCellNode(_d,this.index); |
||
69 | },getHeaderNode:function(){ |
||
70 | return this.view.getHeaderCellNode(this.index); |
||
71 | },getEditNode:function(_e){ |
||
72 | return (this.getNode(_e)||0).firstChild||0; |
||
73 | },canResize:function(){ |
||
74 | var uw=this.unitWidth; |
||
75 | return uw&&(uw!=="auto"); |
||
76 | },isFlex:function(){ |
||
77 | var uw=this.unitWidth; |
||
78 | return uw&&dojo.isString(uw)&&(uw=="auto"||uw.slice(-1)=="%"); |
||
79 | },applyEdit:function(_f,_10){ |
||
80 | this.grid.edit.applyCellEdit(_f,this,_10); |
||
81 | },cancelEdit:function(_11){ |
||
82 | this.grid.doCancelEdit(_11);
|
||
83 | },_onEditBlur:function(_12){ |
||
84 | if(this.grid.edit.isEditCell(_12,this.index)){ |
||
85 | this.grid.edit.apply();
|
||
86 | } |
||
87 | },registerOnBlur:function(_13,_14){ |
||
88 | if(this.commitOnBlur){ |
||
89 | dojo.connect(_13,"onblur",function(e){ |
||
90 | setTimeout(dojo.hitch(this,"_onEditBlur",_14),250); |
||
91 | }); |
||
92 | } |
||
93 | },needFormatNode:function(_15,_16){ |
||
94 | this._formatPending=true; |
||
95 | _4(this,"_formatNode",_15,_16); |
||
96 | },cancelFormatNode:function(){ |
||
97 | this._formatPending=false; |
||
98 | },_formatNode:function(_17,_18){ |
||
99 | if(this._formatPending){ |
||
100 | this._formatPending=false; |
||
101 | dojo.setSelectable(this.grid.domNode,true); |
||
102 | this.formatNode(this.getEditNode(_18),_17,_18); |
||
103 | } |
||
104 | },formatNode:function(_19,_1a,_1b){ |
||
105 | if(dojo.isIE){
|
||
106 | _4(this,"focus",_1b,_19); |
||
107 | }else{
|
||
108 | this.focus(_1b,_19);
|
||
109 | } |
||
110 | },dispatchEvent:function(m,e){ |
||
111 | if(m in this){ |
||
112 | return this[m](e); |
||
113 | } |
||
114 | },getValue:function(_1c){ |
||
115 | return this.getEditNode(_1c)[this._valueProp]; |
||
116 | },setValue:function(_1d,_1e){ |
||
117 | var n=this.getEditNode(_1d); |
||
118 | if(n){
|
||
119 | n[this._valueProp]=_1e;
|
||
120 | } |
||
121 | },focus:function(_1f,_20){ |
||
122 | _2(_20||this.getEditNode(_1f));
|
||
123 | },save:function(_21){ |
||
124 | this.value=this.value||this.getValue(_21); |
||
125 | },restore:function(_22){ |
||
126 | this.setValue(_22,this.value); |
||
127 | },_finish:function(_23){ |
||
128 | dojo.setSelectable(this.grid.domNode,false); |
||
129 | this.cancelFormatNode();
|
||
130 | },apply:function(_24){ |
||
131 | this.applyEdit(this.getValue(_24),_24); |
||
132 | this._finish(_24);
|
||
133 | },cancel:function(_25){ |
||
134 | this.cancelEdit(_25);
|
||
135 | this._finish(_25);
|
||
136 | }}); |
||
137 | _5._Base.markupFactory=function(_26,_27){ |
||
138 | var d=dojo;
|
||
139 | var _28=d.trim(d.attr(_26,"formatter")||""); |
||
140 | if(_28){
|
||
141 | _27.formatter=dojo.getObject(_28)||_28; |
||
142 | } |
||
143 | var get=d.trim(d.attr(_26,"get")||""); |
||
144 | if(get){
|
||
145 | _27.get=dojo.getObject(get); |
||
146 | } |
||
147 | var _29=function(_2a,_2b,_2c){ |
||
148 | var _2d=d.trim(d.attr(_26,_2a)||""); |
||
149 | if(_2d){
|
||
150 | _2b[_2c||_2a]=!(_2d.toLowerCase()=="false");
|
||
151 | } |
||
152 | }; |
||
153 | _29("sortDesc",_27);
|
||
154 | _29("editable",_27);
|
||
155 | _29("alwaysEditing",_27);
|
||
156 | _29("noresize",_27);
|
||
157 | _29("draggable",_27);
|
||
158 | var _2e=d.trim(d.attr(_26,"loadingText")||d.attr(_26,"defaultValue")||""); |
||
159 | if(_2e){
|
||
160 | _27.defaultValue=_2e; |
||
161 | } |
||
162 | var _2f=function(_30,_31,_32){ |
||
163 | var _33=d.trim(d.attr(_26,_30)||"")||undefined; |
||
164 | if(_33){
|
||
165 | _31[_32||_30]=_33; |
||
166 | } |
||
167 | }; |
||
168 | _2f("styles",_27);
|
||
169 | _2f("headerStyles",_27);
|
||
170 | _2f("cellStyles",_27);
|
||
171 | _2f("classes",_27);
|
||
172 | _2f("headerClasses",_27);
|
||
173 | _2f("cellClasses",_27);
|
||
174 | }; |
||
175 | dojo.declare("dojox.grid.cells.Cell",_5._Base,{constructor:function(){ |
||
176 | this.keyFilter=this.keyFilter; |
||
177 | },keyFilter:null,formatEditing:function(_34,_35){ |
||
178 | this.needFormatNode(_34,_35);
|
||
179 | return "<input class=\"dojoxGridInput\" type=\"text\" value=\""+_34+"\">"; |
||
180 | },formatNode:function(_36,_37,_38){ |
||
181 | this.inherited(arguments); |
||
182 | this.registerOnBlur(_36,_38);
|
||
183 | },doKey:function(e){ |
||
184 | if(this.keyFilter){ |
||
185 | var key=String.fromCharCode(e.charCode);
|
||
186 | if(key.search(this.keyFilter)==-1){ |
||
187 | dojo.stopEvent(e); |
||
188 | } |
||
189 | } |
||
190 | },_finish:function(_39){ |
||
191 | this.inherited(arguments); |
||
192 | var n=this.getEditNode(_39); |
||
193 | try{
|
||
194 | dojox.grid.util.fire(n,"blur");
|
||
195 | } |
||
196 | catch(e){
|
||
197 | } |
||
198 | }}); |
||
199 | _5.Cell.markupFactory=function(_3a,_3b){ |
||
200 | _5._Base.markupFactory(_3a,_3b); |
||
201 | var d=dojo;
|
||
202 | var _3c=d.trim(d.attr(_3a,"keyFilter")||""); |
||
203 | if(_3c){
|
||
204 | _3b.keyFilter=new RegExp(_3c);
|
||
205 | } |
||
206 | }; |
||
207 | dojo.declare("dojox.grid.cells.RowIndex",_5.Cell,{name:"Row",postscript:function(){ |
||
208 | this.editable=false; |
||
209 | },get:function(_3d){ |
||
210 | return _3d+1; |
||
211 | }}); |
||
212 | _5.RowIndex.markupFactory=function(_3e,_3f){ |
||
213 | _5.Cell.markupFactory(_3e,_3f); |
||
214 | }; |
||
215 | dojo.declare("dojox.grid.cells.Select",_5.Cell,{options:null,values:null,returnIndex:-1,constructor:function(_40){ |
||
216 | this.values=this.values||this.options; |
||
217 | },formatEditing:function(_41,_42){ |
||
218 | this.needFormatNode(_41,_42);
|
||
219 | var h=["<select class=\"dojoxGridSelect\">"]; |
||
220 | for(var i=0,o,v;((o=this.options[i])!==undefined)&&((v=this.values[i])!==undefined);i++){ |
||
221 | h.push("<option",(_41==v?" selected":"")," value=\""+v+"\"",">",o,"</option>"); |
||
222 | } |
||
223 | h.push("</select>");
|
||
224 | return h.join(""); |
||
225 | },getValue:function(_43){ |
||
226 | var n=this.getEditNode(_43); |
||
227 | if(n){
|
||
228 | var i=n.selectedIndex,o=n.options[i];
|
||
229 | return this.returnIndex>-1?i:o.value||o.innerHTML; |
||
230 | } |
||
231 | }}); |
||
232 | _5.Select.markupFactory=function(_44,_45){ |
||
233 | _5.Cell.markupFactory(_44,_45); |
||
234 | var d=dojo;
|
||
235 | var _46=d.trim(d.attr(_44,"options")||""); |
||
236 | if(_46){
|
||
237 | var o=_46.split(","); |
||
238 | if(o[0]!=_46){ |
||
239 | _45.options=o; |
||
240 | } |
||
241 | } |
||
242 | var _47=d.trim(d.attr(_44,"values")||""); |
||
243 | if(_47){
|
||
244 | var v=_47.split(","); |
||
245 | if(v[0]!=_47){ |
||
246 | _45.values=v; |
||
247 | } |
||
248 | } |
||
249 | }; |
||
250 | dojo.declare("dojox.grid.cells.AlwaysEdit",_5.Cell,{alwaysEditing:true,_formatNode:function(_48,_49){ |
||
251 | this.formatNode(this.getEditNode(_49),_48,_49); |
||
252 | },applyStaticValue:function(_4a){ |
||
253 | var e=this.grid.edit; |
||
254 | e.applyCellEdit(this.getValue(_4a),this,_4a); |
||
255 | e.start(this,_4a,true); |
||
256 | }}); |
||
257 | _5.AlwaysEdit.markupFactory=function(_4b,_4c){ |
||
258 | _5.Cell.markupFactory(_4b,_4c); |
||
259 | }; |
||
260 | dojo.declare("dojox.grid.cells.Bool",_5.AlwaysEdit,{_valueProp:"checked",formatEditing:function(_4d,_4e){ |
||
261 | return "<input class=\"dojoxGridInput\" type=\"checkbox\""+(_4d?" checked=\"checked\"":"")+" style=\"width: auto\" />"; |
||
262 | },doclick:function(e){ |
||
263 | if(e.target.tagName=="INPUT"){ |
||
264 | this.applyStaticValue(e.rowIndex);
|
||
265 | } |
||
266 | }}); |
||
267 | _5.Bool.markupFactory=function(_4f,_50){ |
||
268 | _5.AlwaysEdit.markupFactory(_4f,_50); |
||
269 | }; |
||
270 | })(); |
||
271 | } |