source: Dev/trunk/src/client/dojox/grid/_Selector.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 7.3 KB
Line 
1define([
2        "../main",
3        "dojo/_base/declare",
4        "dojo/_base/lang",
5        "dojo/query",
6        "dojo/dom-class",
7        "./Selection",
8        "./_View",
9        "./_Builder",
10        "./util"
11], function(dojox, declare, lang, query, domClass, Selection, _View, _Builder, util){
12       
13        var _InputSelectorHeaderBuilder = dojox.grid._InputSelectorHeaderBuilder = lang.extend(function(view){
14                _Builder._HeaderBuilder.call(this, view);
15        },_Builder._HeaderBuilder.prototype,{
16                generateHtml: function(){
17                        var w = this.view.contentWidth || 0;
18                        var selectedCount = this.view.grid.selection.getSelectedCount();
19                        var checked = (selectedCount && selectedCount == this.view.grid.rowCount) ? ' dijitCheckBoxChecked dijitChecked' : '';
20                        return '<table style="width:' + w + 'px;" ' +
21                                'border="0" cellspacing="0" cellpadding="0" ' +
22                                'role="presentation"><tr><th style="text-align: center;">' +
23                                '<div class="dojoxGridCheckSelector dijitReset dijitInline dijitCheckBox' + checked + '"></div></th></tr></table>';
24                },
25                doclick: function(e){
26                        var selectedCount = this.view.grid.selection.getSelectedCount();
27
28                        this.view._selectionChanging = true;
29                        if(selectedCount==this.view.grid.rowCount){
30                                this.view.grid.selection.deselectAll();
31                        }else{
32                                this.view.grid.selection.selectRange(0, this.view.grid.rowCount-1);
33                        }
34                        this.view._selectionChanging = false;
35                        this.view.onSelectionChanged();
36                        return true;
37                }
38        });
39
40        var _SelectorContentBuilder = dojox.grid._SelectorContentBuilder = lang.extend(function(view){
41                _Builder._ContentBuilder.call(this, view);
42        },_Builder._ContentBuilder.prototype,{
43                generateHtml: function(inDataIndex, inRowIndex){
44                        var w = this.view.contentWidth || 0;
45                        return '<table class="dojoxGridRowbarTable" style="width:' + w + 'px;" border="0" ' +
46                                'cellspacing="0" cellpadding="0" role="presentation"><tr>' +
47                                '<td  style="text-align: center;" class="dojoxGridRowbarInner">' + this.getCellContent(inRowIndex) + '</td></tr></table>';
48                },
49                getCellContent: function(inRowIndex){
50                        return '&nbsp;';
51                },
52                findTarget: function(){
53                        var t = _Builder._ContentBuilder.prototype.findTarget.apply(this, arguments);
54                        return t;
55                },
56                domouseover: function(e){
57                        this.view.grid.onMouseOverRow(e);
58                },
59                domouseout: function(e){
60                        if(!this.isIntraRowEvent(e)){
61                                this.view.grid.onMouseOutRow(e);
62                        }
63                },
64                doclick: function(e){
65                        var idx = e.rowIndex;
66                        var selected = this.view.grid.selection.isSelected(idx);
67                        var mode = this.view.grid.selection.mode;
68
69                        if(!selected){
70                                if(mode == 'single'){
71                                        this.view.grid.selection.select(idx);
72                                }else if(mode != 'none'){
73                                        this.view.grid.selection.addToSelection(idx);
74                                }
75                        }else{
76                                this.view.grid.selection.deselect(idx);
77                        }
78
79                        return true;
80                }
81        });
82
83        var _InputSelectorContentBuilder = dojox.grid._InputSelectorContentBuilder = lang.extend(function(view){
84                _SelectorContentBuilder.call(this, view);
85        },_SelectorContentBuilder.prototype,{
86                getCellContent: function(rowIndex){
87                        var v = this.view;
88                        var type = v.inputType == "checkbox" ? "CheckBox" : "Radio";
89                        var checked = !!v.grid.selection.isSelected(rowIndex) ? ' dijit' + type + 'Checked dijitChecked' : '';
90                        return '<div class="dojoxGridCheckSelector dijitReset dijitInline dijit' + type + checked + '"></div>';
91                }
92        });
93
94        var _Selector = declare("dojox.grid._Selector", _View, {
95                inputType: '',
96                selectionMode: '',
97
98                // summary:
99                //      Custom grid view. If used in a grid structure, provides a small selectable region for grid rows.
100                defaultWidth: "2em",
101                noscroll: true,
102                padBorderWidth: 2,
103
104                _contentBuilderClass: _SelectorContentBuilder,
105
106                postCreate: function(){
107                        this.inherited(arguments);
108
109                        if(this.selectionMode){
110                                this.grid.selection.mode = this.selectionMode;
111                        }
112                        this.connect(this.grid.selection, 'onSelected', 'onSelected');
113                        this.connect(this.grid.selection, 'onDeselected', 'onDeselected');
114                },
115                buildRendering: function(){
116                        this.inherited(arguments);
117                        this.scrollboxNode.style.overflow = "hidden";
118                },
119                getWidth: function(){
120                        return this.viewWidth || this.defaultWidth;
121                },
122                resize: function(){
123                        this.adaptHeight();
124                },
125                setStructure: function(s){
126                        this.inherited(arguments);
127                        if(s.defaultWidth){
128                                this.defaultWidth = s.defaultWidth;
129                        }
130                },
131                adaptWidth: function(){
132                        // Only calculate this here - rather than every call to buildRowContent
133                        if(!("contentWidth" in this) && this.contentNode){
134                                this.contentWidth = this.contentNode.offsetWidth - this.padBorderWidth;
135                        }
136                },
137                // styling
138                doStyleRowNode: function(inRowIndex, inRowNode){
139                        var n = [ "dojoxGridRowbar dojoxGridNonNormalizedCell" ];
140                        if(this.grid.rows.isOver(inRowIndex)){
141                                n.push("dojoxGridRowbarOver");
142                        }
143                        if(this.grid.selection.isSelected(inRowIndex)){
144                                n.push("dojoxGridRowbarSelected");
145                        }
146                        inRowNode.className = n.join(" ");
147                },
148                // event handlers
149                onSelected: function(inIndex){
150                        this.grid.updateRow(inIndex);
151                },
152                onDeselected: function(inIndex){
153                        this.grid.updateRow(inIndex);
154                }
155        });
156        if(!_View.prototype._headerBuilderClass &&
157                !_View.prototype._contentBuilderClass){
158                _Selector.prototype.postCreate = function(){
159                        this.connect(this.scrollboxNode,"onscroll","doscroll");
160                        util.funnelEvents(this.contentNode, this, "doContentEvent", [ 'mouseover', 'mouseout', 'click', 'dblclick', 'contextmenu', 'mousedown' ]);
161                        util.funnelEvents(this.headerNode, this, "doHeaderEvent", [ 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mousedown', 'click', 'contextmenu' ]);
162                        if(this._contentBuilderClass){
163                                this.content = new this._contentBuilderClass(this);
164                        }else{
165                                this.content = new _Builder._ContentBuilder(this);
166                        }
167                        if(this._headerBuilderClass){
168                                this.header = new this._headerBuilderClass(this);
169                        }else{
170                                this.header = new _Builder._HeaderBuilder(this);
171                        }
172                        //BiDi: in RTL case, style width='9000em' causes scrolling problem in head node
173                        if(!this.grid.isLeftToRight()){
174                                this.headerNodeContainer.style.width = "";
175                        }
176                        this.connect(this.grid.selection, 'onSelected', 'onSelected');
177                        this.connect(this.grid.selection, 'onDeselected', 'onDeselected');
178                };
179        }
180
181        declare("dojox.grid._RadioSelector", _Selector, {
182                inputType: 'radio',
183                selectionMode: 'single',
184
185                _contentBuilderClass: _InputSelectorContentBuilder,
186
187                buildRendering: function(){
188                        this.inherited(arguments);
189                        this.headerNode.style.visibility = "hidden";
190                },
191               
192                renderHeader: function(){}
193        });
194
195        declare("dojox.grid._CheckBoxSelector", _Selector, {
196                inputType: 'checkbox',
197                _headerBuilderClass: _InputSelectorHeaderBuilder,
198                _contentBuilderClass: _InputSelectorContentBuilder,
199                postCreate: function(){
200                        this.inherited(arguments);
201                        this.connect(this.grid, 'onSelectionChanged', 'onSelectionChanged');
202                        this.connect(this.grid, 'updateRowCount', '_updateVisibility');
203                },
204                renderHeader: function(){
205                        this.inherited(arguments);
206                        this._updateVisibility(this.grid.rowCount);
207                },
208                _updateVisibility: function(rowCount){
209                        this.headerNode.style.visibility = rowCount ? "" : "hidden";
210                },
211                onSelectionChanged: function(){
212                        if(this._selectionChanging){ return; }
213                        var inputDiv = query('.dojoxGridCheckSelector', this.headerNode)[0];
214                        var g = this.grid;
215                        var s = (g.rowCount && g.rowCount == g.selection.getSelectedCount());
216                        g.allItemsSelected = s||false;
217                        domClass.toggle(inputDiv, "dijitChecked", g.allItemsSelected);
218                        domClass.toggle(inputDiv, "dijitCheckBoxChecked", g.allItemsSelected);
219                }
220        });
221       
222        return _Selector;
223
224});
Note: See TracBrowser for help on using the repository browser.