root / trunk / web / dojo / dojox / grid / _Selector.js
History | View | Annotate | Download (6.3 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.grid._Selector"]){ |
9 |
dojo._hasResource["dojox.grid._Selector"]=true; |
10 |
dojo.provide("dojox.grid._Selector");
|
11 |
dojo.require("dojox.grid.Selection");
|
12 |
dojo.require("dojox.grid._View");
|
13 |
dojo.require("dojox.grid._Builder");
|
14 |
(function(){
|
15 |
dojox.grid._InputSelectorHeaderBuilder=dojo.extend(function(_1){
|
16 |
dojox.grid._HeaderBuilder.call(this,_1);
|
17 |
},dojox.grid._HeaderBuilder.prototype,{generateHtml:function(){ |
18 |
var w=this.view.contentWidth||0; |
19 |
var _2=this.view.grid.selection.getSelectedCount(); |
20 |
var _3=(_2&&_2==this.view.grid.rowCount)?" dijitCheckBoxChecked dijitChecked":""; |
21 |
return "<table style=\"width:"+w+"px;\" "+"border=\"0\" cellspacing=\"0\" cellpadding=\"0\" "+"role=\"presentation\"><tr><th style=\"text-align: center;\">"+"<div class=\"dojoxGridCheckSelector dijitReset dijitInline dijitCheckBox"+_3+"\"></div></th></tr></table>"; |
22 |
},doclick:function(e){ |
23 |
var _4=this.view.grid.selection.getSelectedCount(); |
24 |
this.view._selectionChanging=true; |
25 |
if(_4==this.view.grid.rowCount){ |
26 |
this.view.grid.selection.deselectAll();
|
27 |
}else{
|
28 |
this.view.grid.selection.selectRange(0,this.view.grid.rowCount-1); |
29 |
} |
30 |
this.view._selectionChanging=false; |
31 |
this.view.onSelectionChanged();
|
32 |
return true; |
33 |
}}); |
34 |
dojox.grid._SelectorContentBuilder=dojo.extend(function(_5){
|
35 |
dojox.grid._ContentBuilder.call(this,_5);
|
36 |
},dojox.grid._ContentBuilder.prototype,{generateHtml:function(_6,_7){ |
37 |
var w=this.view.contentWidth||0; |
38 |
return "<table class=\"dojoxGridRowbarTable\" style=\"width:"+w+"px;\" border=\"0\" "+"cellspacing=\"0\" cellpadding=\"0\" role=\"presentation\"><tr>"+"<td style=\"text-align: center;\" class=\"dojoxGridRowbarInner\">"+this.getCellContent(_7)+"</td></tr></table>"; |
39 |
},getCellContent:function(_8){ |
40 |
return " "; |
41 |
},findTarget:function(){ |
42 |
var t=dojox.grid._ContentBuilder.prototype.findTarget.apply(this,arguments); |
43 |
return t;
|
44 |
},domouseover:function(e){ |
45 |
this.view.grid.onMouseOverRow(e);
|
46 |
},domouseout:function(e){ |
47 |
if(!this.isIntraRowEvent(e)){ |
48 |
this.view.grid.onMouseOutRow(e);
|
49 |
} |
50 |
},doclick:function(e){ |
51 |
var _9=e.rowIndex;
|
52 |
var _a=this.view.grid.selection.isSelected(_9); |
53 |
var _b=this.view.grid.selection.mode; |
54 |
if(!_a){
|
55 |
if(_b=="single"){ |
56 |
this.view.grid.selection.select(_9);
|
57 |
}else{
|
58 |
if(_b!="none"){ |
59 |
this.view.grid.selection.addToSelection(_9);
|
60 |
} |
61 |
} |
62 |
}else{
|
63 |
this.view.grid.selection.deselect(_9);
|
64 |
} |
65 |
return true; |
66 |
}}); |
67 |
dojox.grid._InputSelectorContentBuilder=dojo.extend(function(_c){
|
68 |
dojox.grid._SelectorContentBuilder.call(this,_c);
|
69 |
},dojox.grid._SelectorContentBuilder.prototype,{getCellContent:function(_d){ |
70 |
var v=this.view; |
71 |
var _e=v.inputType=="checkbox"?"CheckBox":"Radio"; |
72 |
var _f=!!v.grid.selection.isSelected(_d)?" dijit"+_e+"Checked dijitChecked":""; |
73 |
return "<div class=\"dojoxGridCheckSelector dijitReset dijitInline dijit"+_e+_f+"\"></div>"; |
74 |
}}); |
75 |
dojo.declare("dojox.grid._Selector",dojox.grid._View,{inputType:"",selectionMode:"",defaultWidth:"2em",noscroll:true,padBorderWidth:2,_contentBuilderClass:dojox.grid._SelectorContentBuilder,postCreate:function(){ |
76 |
this.inherited(arguments); |
77 |
if(this.selectionMode){ |
78 |
this.grid.selection.mode=this.selectionMode; |
79 |
} |
80 |
this.connect(this.grid.selection,"onSelected","onSelected"); |
81 |
this.connect(this.grid.selection,"onDeselected","onDeselected"); |
82 |
},buildRendering:function(){ |
83 |
this.inherited(arguments); |
84 |
this.scrollboxNode.style.overflow="hidden"; |
85 |
},getWidth:function(){ |
86 |
return this.viewWidth||this.defaultWidth; |
87 |
},resize:function(){ |
88 |
this.adaptHeight();
|
89 |
},setStructure:function(s){ |
90 |
this.inherited(arguments); |
91 |
if(s.defaultWidth){
|
92 |
this.defaultWidth=s.defaultWidth;
|
93 |
} |
94 |
},adaptWidth:function(){ |
95 |
if(!("contentWidth" in this)&&this.contentNode){ |
96 |
this.contentWidth=this.contentNode.offsetWidth-this.padBorderWidth; |
97 |
} |
98 |
},doStyleRowNode:function(_10,_11){ |
99 |
var n=["dojoxGridRowbar dojoxGridNonNormalizedCell"]; |
100 |
if(this.grid.rows.isOver(_10)){ |
101 |
n.push("dojoxGridRowbarOver");
|
102 |
} |
103 |
if(this.grid.selection.isSelected(_10)){ |
104 |
n.push("dojoxGridRowbarSelected");
|
105 |
} |
106 |
_11.className=n.join(" ");
|
107 |
},onSelected:function(_12){ |
108 |
this.grid.updateRow(_12);
|
109 |
},onDeselected:function(_13){ |
110 |
this.grid.updateRow(_13);
|
111 |
}}); |
112 |
if(!dojox.grid._View.prototype._headerBuilderClass&&!dojox.grid._View.prototype._contentBuilderClass){
|
113 |
dojox.grid._Selector.prototype.postCreate=function(){ |
114 |
this.connect(this.scrollboxNode,"onscroll","doscroll"); |
115 |
dojox.grid.util.funnelEvents(this.contentNode,this,"doContentEvent",["mouseover","mouseout","click","dblclick","contextmenu","mousedown"]); |
116 |
dojox.grid.util.funnelEvents(this.headerNode,this,"doHeaderEvent",["dblclick","mouseover","mouseout","mousemove","mousedown","click","contextmenu"]); |
117 |
if(this._contentBuilderClass){ |
118 |
this.content=new this._contentBuilderClass(this); |
119 |
}else{
|
120 |
this.content=new dojox.grid._ContentBuilder(this); |
121 |
} |
122 |
if(this._headerBuilderClass){ |
123 |
this.header=new this._headerBuilderClass(this); |
124 |
}else{
|
125 |
this.header=new dojox.grid._HeaderBuilder(this); |
126 |
} |
127 |
if(!dojo._isBodyLtr()){
|
128 |
this.headerNodeContainer.style.width=""; |
129 |
} |
130 |
this.connect(this.grid.selection,"onSelected","onSelected"); |
131 |
this.connect(this.grid.selection,"onDeselected","onDeselected"); |
132 |
}; |
133 |
} |
134 |
dojo.declare("dojox.grid._RadioSelector",dojox.grid._Selector,{inputType:"radio",selectionMode:"single",_contentBuilderClass:dojox.grid._InputSelectorContentBuilder,buildRendering:function(){ |
135 |
this.inherited(arguments); |
136 |
this.headerNode.style.visibility="hidden"; |
137 |
},renderHeader:function(){ |
138 |
}}); |
139 |
dojo.declare("dojox.grid._CheckBoxSelector",dojox.grid._Selector,{inputType:"checkbox",_headerBuilderClass:dojox.grid._InputSelectorHeaderBuilder,_contentBuilderClass:dojox.grid._InputSelectorContentBuilder,postCreate:function(){ |
140 |
this.inherited(arguments); |
141 |
this.connect(this.grid,"onSelectionChanged","onSelectionChanged"); |
142 |
this.connect(this.grid,"updateRowCount","_updateVisibility"); |
143 |
},renderHeader:function(){ |
144 |
this.inherited(arguments); |
145 |
this._updateVisibility(this.grid.rowCount); |
146 |
},_updateVisibility:function(_14){ |
147 |
this.headerNode.style.visibility=_14?"":"hidden"; |
148 |
},onSelectionChanged:function(){ |
149 |
if(this._selectionChanging){ |
150 |
return;
|
151 |
} |
152 |
var _15=dojo.query(".dojoxGridCheckSelector",this.headerNode)[0]; |
153 |
var g=this.grid; |
154 |
var s=(g.rowCount&&g.rowCount==g.selection.getSelectedCount());
|
155 |
g.allItemsSelected=s||false;
|
156 |
dojo.toggleClass(_15,"dijitChecked",g.allItemsSelected);
|
157 |
dojo.toggleClass(_15,"dijitCheckBoxChecked",g.allItemsSelected);
|
158 |
}}); |
159 |
})(); |
160 |
} |