| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/connect", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/_base/array" |
| 6 |
], function(declare, connect, lang, array){ |
| 7 |
|
| 8 |
return declare("dojox.grid._SelectionPreserver", null, { |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
constructor: function(selection){ |
| 25 |
this.selection = selection; |
| 26 |
var grid = this.grid = selection.grid; |
| 27 |
this.reset(); |
| 28 |
this._connects = [ |
| 29 |
connect.connect(grid, '_setStore', this, 'reset'), |
| 30 |
connect.connect(grid, '_addItem', this, '_reSelectById'), |
| 31 |
connect.connect(selection, 'onSelected', lang.hitch(this, '_selectById', true)), |
| 32 |
connect.connect(selection, 'onDeselected', lang.hitch(this, '_selectById', false)), |
| 33 |
connect.connect(selection, 'deselectAll', this, 'reset') |
| 34 |
]; |
| 35 |
}, |
| 36 |
destroy: function(){ |
| 37 |
this.reset(); |
| 38 |
array.forEach(this._connects, connect.disconnect); |
| 39 |
delete this._connects; |
| 40 |
}, |
| 41 |
reset: function(){ |
| 42 |
this._selectedById = {}; |
| 43 |
}, |
| 44 |
_reSelectById: function(item, index){ |
| 45 |
|
| 46 |
|
| 47 |
if(item && this.grid._hasIdentity){ |
| 48 |
this.selection.selected[index] = this._selectedById[this.grid.store.getIdentity(item)]; |
| 49 |
} |
| 50 |
}, |
| 51 |
_selectById: function(toSelect, inItemOrIndex){ |
| 52 |
|
| 53 |
|
| 54 |
if(this.selection.mode == 'none' || !this.grid._hasIdentity){ return; } |
| 55 |
var item = inItemOrIndex, g = this.grid; |
| 56 |
if(typeof inItemOrIndex == "number" || typeof inItemOrIndex == "string"){ |
| 57 |
var entry = g._by_idx[inItemOrIndex]; |
| 58 |
item = entry && entry.item; |
| 59 |
} |
| 60 |
if(item){ |
| 61 |
this._selectedById[g.store.getIdentity(item)] = !!toSelect; |
| 62 |
} |
| 63 |
return item; |
| 64 |
} |
| 65 |
}); |
| 66 |
}); |