1 | define([ |
---|
2 | "dojo/_base/declare", |
---|
3 | "./_SelectionPreserver", |
---|
4 | "./Selection" |
---|
5 | ], function(declare, _SelectionPreserver, Selection){ |
---|
6 | |
---|
7 | return declare("dojox.grid.DataSelection", Selection, { |
---|
8 | constructor: function(grid){ |
---|
9 | if(grid.keepSelection){ |
---|
10 | this.preserver = new _SelectionPreserver(this); |
---|
11 | } |
---|
12 | }, |
---|
13 | |
---|
14 | destroy: function(){ |
---|
15 | if(this.preserver){ |
---|
16 | this.preserver.destroy(); |
---|
17 | } |
---|
18 | }, |
---|
19 | |
---|
20 | getFirstSelected: function(){ |
---|
21 | var idx = Selection.prototype.getFirstSelected.call(this); |
---|
22 | |
---|
23 | if(idx == -1){ return null; } |
---|
24 | return this.grid.getItem(idx); |
---|
25 | }, |
---|
26 | |
---|
27 | getNextSelected: function(inPrev){ |
---|
28 | var old_idx = this.grid.getItemIndex(inPrev); |
---|
29 | var idx = Selection.prototype.getNextSelected.call(this, old_idx); |
---|
30 | |
---|
31 | if(idx == -1){ return null; } |
---|
32 | return this.grid.getItem(idx); |
---|
33 | }, |
---|
34 | |
---|
35 | getSelected: function(){ |
---|
36 | var result = []; |
---|
37 | for(var i=0, l=this.selected.length; i<l; i++){ |
---|
38 | if(this.selected[i]){ |
---|
39 | result.push(this.grid.getItem(i)); |
---|
40 | } |
---|
41 | } |
---|
42 | return result; |
---|
43 | }, |
---|
44 | |
---|
45 | addToSelection: function(inItemOrIndex){ |
---|
46 | if(this.mode == 'none'){ return; } |
---|
47 | var idx = null; |
---|
48 | if(typeof inItemOrIndex == "number" || typeof inItemOrIndex == "string"){ |
---|
49 | idx = inItemOrIndex; |
---|
50 | }else{ |
---|
51 | idx = this.grid.getItemIndex(inItemOrIndex); |
---|
52 | } |
---|
53 | Selection.prototype.addToSelection.call(this, idx); |
---|
54 | }, |
---|
55 | |
---|
56 | deselect: function(inItemOrIndex){ |
---|
57 | if(this.mode == 'none'){ return; } |
---|
58 | var idx = null; |
---|
59 | if(typeof inItemOrIndex == "number" || typeof inItemOrIndex == "string"){ |
---|
60 | idx = inItemOrIndex; |
---|
61 | }else{ |
---|
62 | idx = this.grid.getItemIndex(inItemOrIndex); |
---|
63 | } |
---|
64 | Selection.prototype.deselect.call(this, idx); |
---|
65 | }, |
---|
66 | |
---|
67 | deselectAll: function(inItemOrIndex){ |
---|
68 | var idx = null; |
---|
69 | if(inItemOrIndex || typeof inItemOrIndex == "number"){ |
---|
70 | if(typeof inItemOrIndex == "number" || typeof inItemOrIndex == "string"){ |
---|
71 | idx = inItemOrIndex; |
---|
72 | }else{ |
---|
73 | idx = this.grid.getItemIndex(inItemOrIndex); |
---|
74 | } |
---|
75 | Selection.prototype.deselectAll.call(this, idx); |
---|
76 | }else{ |
---|
77 | this.inherited(arguments); |
---|
78 | } |
---|
79 | } |
---|
80 | }); |
---|
81 | }); |
---|