source: [view]
dojo.provide("dojox.grid.enhanced.dnd._DndSelectingManager");
dojo.require("dojox.grid.util");
dojo.require("dojox.grid._Builder");
dojo.require("dojox.grid.enhanced.plugins._Mixin");
dojo.require("dojox.grid.enhanced.dnd._DndGrid");
dojo.require("dojox.grid.enhanced.dnd._DndBuilder");
dojo.require("dojox.grid.enhanced.dnd._DndRowSelector");
dojo.require("dojox.grid.enhanced.dnd._DndFocusManager");
dojo.declare("dojox.grid.enhanced.dnd._DndSelectingManager", dojox.grid.enhanced.plugins._Mixin, {
//summary:
// _DndSelectingManager is used to enable grid DND selecting feature
//
// list, each item record whether the type is in selecting mode
// type: row, cell, col
typeSelectingMode: null,
// list, each item record whether the type selecting is disabled
// type: row, cell, col
selectingDisabledTypes: null,
// The start point of drag selection
drugSelectionStart: null,
// The point that fire drug select
drugCurrentPoint : null,
// Should be col, row or cell
drugMode: null,
// If user drag select with ctrl key down
// selected cells should be kept state as selected
keepState: false,
extendSelect: false,
// keep the dom nodes of header in a list
headerNodes: null,
// Record the selected cells
selectedCells : null,
// Record the columns selected
selectedColumns : null,
// Record the rows selected
//selectedRows : [],
selectedClass: "dojoxGridRowSelected",
autoScrollRate: 1000,
constructor: function(inGrid){
// inGrid: dojox.Grid
// The dojox.Grid this editor should be attached to
this.grid = inGrid;
this.typeSelectingMode = [];
this.selectingDisabledTypes = [];
this.selectedColumns = [];
// Init the dnd selection start point
this.drugSelectionStart = new Object();
this.drugCurrentPoint = new Object();
this.resetStartPoint();
this.extendGridForDnd(inGrid);
this.selectedCells = [];
this.connect(this.grid, "_onFetchComplete", "refreshColumnSelection");
this.connect(this.grid.scroller, "scroll", "refreshColumnSelection");
//dojo.connect(document, 'onmousedown', this.grid.focus, '_blurRowBar');
this.subscribe(this.grid.rowSelectionChangedTopic, function(publisher){
try{
if(publisher && publisher.grid == this.grid && publisher != this){
this.cleanCellSelection();
}
}catch(e){
console.debug(e);
}
});
},
extendGridForDnd: function(inGrid){
//summary:
// Ectend the current class to enable the DND feature
// inclucing:
// dojox.Grid
// dojox._FocusManager
// dojox.Selection
// dojox._Builder
// dojox._HeaderBuilder
// dojox._RowSelector
// Change the funnelEvents of views, add mouseup and mouseover event
//extend dojox.Grid
var _ctr = inGrid.constructor;
inGrid.mixin(inGrid, dojo.hitch(new dojox.grid.enhanced.dnd._DndGrid(this)));
inGrid.constructor = _ctr;
// workaround for mixin related issues
//inGrid.constructor.prototype.startup = inGrid.startup;
//inGrid.constructor.prototype.onStyleRow = inGrid.onStyleRow;
//extend dojox._FocusManager
inGrid.mixin(inGrid.focus, new dojox.grid.enhanced.dnd._DndFocusManager());
// rewrite the clickSelect function of Selection
inGrid.mixin(inGrid.selection, {clickSelect:function(){}});
dojo.forEach(inGrid.views.views, function(view){
//extend dojox._Builder
inGrid.mixin(view.content, new dojox.grid.enhanced.dnd._DndBuilder());
//extend dojox._HeaderBuilder
inGrid.mixin(view.header, new dojox.grid.enhanced.dnd._DndHeaderBuilder());
if(view.declaredClass =="dojox.grid._RowSelector"){
//extend dojox._RowSelector
inGrid.mixin(view, new dojox.grid.enhanced.dnd._DndRowSelector());
}
// Change the funnelEvents of views, add mouseup and mouseover event
//dojox.grid.util.funnelEvents(view.contentNode, view, "doContentEvent", [ 'mouseup','mouseover', 'mouseout', 'click', 'dblclick', 'contextmenu', 'mousedown' ]);
dojox.grid.util.funnelEvents(view.contentNode, view, "doContentEvent", [ 'mouseup']);
//dojox.grid.util.funnelEvents(view.headerNode, view, "doHeaderEvent", [ 'dblclick','mouseup', 'mouseover', 'mouseout', 'mousemove', 'mousedown', 'click', 'contextmenu' ]);
dojox.grid.util.funnelEvents(view.headerNode, view, "doHeaderEvent", ['mouseup']);
});
dojo.forEach(this.grid.dndDisabledTypes, function(type){
this.disableSelecting(type);
}, this);
this.disableFeatures();
},
disableFeatures: function(){
//summary:
// disable selecting features according to the configuration
if(this.selectingDisabledTypes["cell"]){
this.cellClick = function(){/*console.debug("_DndSelectingManager.cellClick is disabled");*/};
this.drugSelectCell = function(){/*console.debug("_DndSelectingManager.drugSelectCell is disabled");*/};
}
if(this.selectingDisabledTypes["row"]){
this.drugSelectRow = function(){/*console.debug("_DndSelectingManager.drugSelectRow is disabled");*/};
}
if(this.selectingDisabledTypes["col"]){
this.selectColumn = function(){/*console.debug("_DndSelectingManager.selectColumn is disabled");*/};
this.drugSelectColumn = function(){/*console.debug("_DndSelectingManager.drugSelectColumn is disabled");*/