Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource['dojox.grid._grid.selection']){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource['dojox.grid._grid.selection'] = true;
3
dojo.provide('dojox.grid._grid.selection');
4
 
5
dojo.declare("dojox.grid.selection", null, {
6
	// summary:
7
	//	Manages row selection for grid. Owned by grid and used internally
8
	//	for selection. Override to implement custom selection.
9
	constructor: function(inGrid){
10
		this.grid = inGrid;
11
		this.selected = [];
12
	},
13
	multiSelect: true,
14
	selected: null,
15
	updating: 0,
16
	selectedIndex: -1,
17
	onCanSelect: function(inIndex){
18
		return this.grid.onCanSelect(inIndex);
19
	},
20
	onCanDeselect: function(inIndex){
21
		return this.grid.onCanDeselect(inIndex);
22
	},
23
	onSelected: function(inIndex){
24
		return this.grid.onSelected(inIndex);
25
	},
26
	onDeselected: function(inIndex){
27
		return this.grid.onDeselected(inIndex);
28
	},
29
	//onSetSelected: function(inIndex, inSelect) { };
30
	onChanging: function(){
31
	},
32
	onChanged: function(){
33
		return this.grid.onSelectionChanged();
34
	},
35
	isSelected: function(inIndex){
36
		return this.selected[inIndex];
37
	},
38
	getFirstSelected: function(){
39
		for(var i=0, l=this.selected.length; i<l; i++){
40
			if(this.selected[i]){
41
				return i;
42
			}
43
		}
44
		return -1;
45
	},
46
	getNextSelected: function(inPrev){
47
		for(var i=inPrev+1, l=this.selected.length; i<l; i++){
48
			if(this.selected[i]){
49
				return i;
50
			}
51
		}
52
		return -1;
53
	},
54
	getSelected: function(){
55
		var result = [];
56
		for(var i=0, l=this.selected.length; i<l; i++){
57
			if(this.selected[i]){
58
				result.push(i);
59
			}
60
		}
61
		return result;
62
	},
63
	getSelectedCount: function(){
64
		var c = 0;
65
		for(var i=0; i<this.selected.length; i++){
66
			if(this.selected[i]){
67
				c++;
68
			}
69
		}
70
		return c;
71
	},
72
	beginUpdate: function(){
73
		if(this.updating == 0){
74
			this.onChanging();
75
		}
76
		this.updating++;
77
	},
78
	endUpdate: function(){
79
		this.updating--;
80
		if(this.updating == 0){
81
			this.onChanged();
82
		}
83
	},
84
	select: function(inIndex){
85
		this.unselectAll(inIndex);
86
		this.addToSelection(inIndex);
87
	},
88
	addToSelection: function(inIndex){
89
		inIndex = Number(inIndex);
90
		if(this.selected[inIndex]){
91
			this.selectedIndex = inIndex;
92
		}else{
93
			if(this.onCanSelect(inIndex) !== false){
94
				this.selectedIndex = inIndex;
95
				this.beginUpdate();
96
				this.selected[inIndex] = true;
97
				this.grid.onSelected(inIndex);
98
				//this.onSelected(inIndex);
99
				//this.onSetSelected(inIndex, true);
100
				this.endUpdate();
101
			}
102
		}
103
	},
104
	deselect: function(inIndex){
105
		inIndex = Number(inIndex);
106
		if(this.selectedIndex == inIndex){
107
			this.selectedIndex = -1;
108
		}
109
		if(this.selected[inIndex]){
110
			if(this.onCanDeselect(inIndex) === false){
111
				return;
112
			}
113
			this.beginUpdate();
114
			delete this.selected[inIndex];
115
			this.grid.onDeselected(inIndex);
116
			//this.onDeselected(inIndex);
117
			//this.onSetSelected(inIndex, false);
118
			this.endUpdate();
119
		}
120
	},
121
	setSelected: function(inIndex, inSelect){
122
		this[(inSelect ? 'addToSelection' : 'deselect')](inIndex);
123
	},
124
	toggleSelect: function(inIndex){
125
		this.setSelected(inIndex, !this.selected[inIndex])
126
	},
127
	insert: function(inIndex){
128
		this.selected.splice(inIndex, 0, false);
129
		if(this.selectedIndex >= inIndex){
130
			this.selectedIndex++;
131
		}
132
	},
133
	remove: function(inIndex){
134
		this.selected.splice(inIndex, 1);
135
		if(this.selectedIndex >= inIndex){
136
			this.selectedIndex--;
137
		}
138
	},
139
	unselectAll: function(inExcept){
140
		for(var i in this.selected){
141
			if((i!=inExcept)&&(this.selected[i]===true)){
142
				this.deselect(i);
143
			}
144
		}
145
	},
146
	shiftSelect: function(inFrom, inTo){
147
		var s = (inFrom >= 0 ? inFrom : inTo), e = inTo;
148
		if(s > e){
149
			e = s;
150
			s = inTo;
151
		}
152
		for(var i=s; i<=e; i++){
153
			this.addToSelection(i);
154
		}
155
	},
156
	clickSelect: function(inIndex, inCtrlKey, inShiftKey){
157
		this.beginUpdate();
158
		if(!this.multiSelect){
159
			this.select(inIndex);
160
		}else{
161
			var lastSelected = this.selectedIndex;
162
			if(!inCtrlKey){
163
				this.unselectAll(inIndex);
164
			}
165
			if(inShiftKey){
166
				this.shiftSelect(lastSelected, inIndex);
167
			}else if(inCtrlKey){
168
				this.toggleSelect(inIndex);
169
			}else{
170
				this.addToSelection(inIndex)
171
			}
172
		}
173
		this.endUpdate();
174
	},
175
	clickSelectEvent: function(e){
176
		this.clickSelect(e.rowIndex, e.ctrlKey, e.shiftKey);
177
	},
178
	clear: function(){
179
		this.beginUpdate();
180
		this.unselectAll();
181
		this.endUpdate();
182
	}
183
});
184
 
185
}