Skip to content

Commit

Permalink
Update event handling for grid.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Smirnov committed Dec 25, 2018
1 parent 9b6ea47 commit c4da6df
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 57 deletions.
51 changes: 35 additions & 16 deletions src/list/views/CollectionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,40 @@ export default Marionette.CollectionView.extend({
},

events: {
click: '__handleClick',
dblclick: '__handleDblClick',
//'click @ui.collapsibleButton': '__toggleCollapse',
dragover: '__handleDragOver',
dragenter: '__handleDragEnter',
dragleave: '__handleDragLeave',
drop: '__handleDrop',
mouseenter: '__handleMouseEnter',
mouseleave: '__handleMouseLeave',
contextmenu: '__handleContextMenu',
keydown: '__handleKeydown'
},

modelEvents: {
click: '__handleModelClick',
dblclick: '__handleModelDblClick',
selected: '__handleSelection',
deselected: '__handleDeselection',
'select:pointed': '__selectPointed',
'selected:enter': '__handleEnter',
highlighted: '__handleHighlight',
unhighlighted: '__handleUnhighlight',
change: '__handleChange',
dragover: '__handleModelDragOver',
dragleave: '__handleModelDragLeave',
drop: '__handleModelDrop',
mouseenter: '__handleModelMouseEnter',
mouseleave: '__handleModelMouseLeave',
blink: '__blink',
'toggle:collapse': 'updateCollapsed',
checked: '__addCheckedClass',
unchecked: '__removeCheckedClass'
},

className() {
return `visible-collection ${this.options.class || ''}`;
},
Expand Down Expand Up @@ -268,10 +299,7 @@ export default Marionette.CollectionView.extend({
},

// Move the cursor to a new position [cursorIndex + positionDelta] (like when user changes selected item using keyboard)
moveCursorBy(cursorIndexDelta, {
shiftPressed,
isLoop = false
}) {
moveCursorBy(cursorIndexDelta, { shiftPressed, isLoop = false }) {
const indexCurrentModel = this.__getIndexSelectedModel();
const nextIndex = indexCurrentModel + cursorIndexDelta;
this.__moveCursorTo(nextIndex, {
Expand All @@ -282,12 +310,7 @@ export default Marionette.CollectionView.extend({
});
},

__moveCursorTo(newCursorIndex, {
shiftPressed,
isPositiveDelta = false,
indexCurrentModel = this.__getIndexSelectedModel(),
isLoop = false
}) {
__moveCursorTo(newCursorIndex, { shiftPressed, isPositiveDelta = false, indexCurrentModel = this.__getIndexSelectedModel(), isLoop = false }) {
let correctIndex;
let isOverflow;
if (isLoop) {
Expand All @@ -301,18 +324,14 @@ export default Marionette.CollectionView.extend({
if (correctIndex !== indexCurrentModel) {
this.__selectModelByIndex(correctIndex, shiftPressed);
if (this.__getIsModelInScrollByIndex(correctIndex)) {
(isInverseScrollLogic ?
!isPositiveDelta :
isPositiveDelta) ?
this.scrollToByLast(correctIndex) :
this.scrollToByFirst(correctIndex);
(isInverseScrollLogic ? !isPositiveDelta : isPositiveDelta) ? this.scrollToByLast(correctIndex) : this.scrollToByFirst(correctIndex);
}
}
},

__getIsModelInScrollByIndex(modelIndex) {
const modelTopOffset = modelIndex * this.childHeight;
const scrollTop = this.parent$el.scrollTop();
const scrollTop = this.parent$el.scrollTop();
return scrollTop > modelTopOffset || modelTopOffset > scrollTop + this.state.viewportHeight * this.childHeight;
},

Expand Down
51 changes: 10 additions & 41 deletions src/list/views/RowView.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,6 @@ export default Marionette.View.extend({
collapsibleButton: '.js-collapsible-button'
},

events: {
click: '__handleClick',
dblclick: '__handleDblClick',
'click @ui.collapsibleButton': '__toggleCollapse',
dragover: '__handleDragOver',
dragenter: '__handleDragEnter',
dragleave: '__handleDragLeave',
drop: '__handleDrop',
mouseenter: '__handleMouseEnter',
mouseleave: '__handleMouseLeave',
contextmenu: '__handleContextMenu'
},

modelEvents: {
click: '__handleModelClick',
dblclick: '__handleModelDblClick',
selected: '__handleSelection',
deselected: '__handleDeselection',
'select:pointed': '__selectPointed',
'selected:enter': '__handleEnter',
highlighted: '__handleHighlight',
unhighlighted: '__handleUnhighlight',
change: '__handleChange',
dragover: '__handleModelDragOver',
dragleave: '__handleModelDragLeave',
drop: '__handleModelDrop',
mouseenter: '__handleModelMouseEnter',
mouseleave: '__handleModelMouseLeave',
blink: '__blink',
'toggle:collapse': 'updateCollapsed',
checked: '__addCheckedClass',
unchecked: '__removeCheckedClass'
},

initialize() {
_.defaults(this.options, defaultOptions);
this.gridEventAggregator = this.options.gridEventAggregator;
Expand Down Expand Up @@ -138,14 +104,11 @@ export default Marionette.View.extend({
this.cellViewsByKey = {};

const isTree = this.getOption('isTree');
this.options.columns.forEach((gridColumn, index) => {
this.options.columns.forEach(gridColumn => {
const cell = gridColumn.cellView || CellViewFactory.getCellViewForColumn(gridColumn, this.model); // move to factory

if (typeof cell === 'string') {
this.el.insertAdjacentHTML('beforeend', cell);
if (isTree && index === 0) {
this.insertFirstCellHtml();
}
return;
}

Expand All @@ -161,16 +124,22 @@ export default Marionette.View.extend({

cellView.el.setAttribute('tabindex', -1);

if (isTree && index === 0) {
cellView.on('render', () => this.insertFirstCellHtml(true));
}
cellView.render();
this.el.insertAdjacentElement('beforeend', cellView.el);
cellView.triggerMethod('attach');

this.cellViewsByKey[gridColumn.key] = cellView;
this.cellViews.push(cellView);
});
if (isTree) {
const firstCell = this.options.columns[0];

if (typeof firstCell.cellView === 'string' || !firstCell.editable) {
this.insertFirstCellHtml();
} else {
this.insertFirstCellHtml(true);
}
}
},

__handleChange() {
Expand Down

0 comments on commit c4da6df

Please sign in to comment.