lock dragging when sorted

This commit is contained in:
Anton Dyudin 2015-08-21 16:33:14 -07:00
parent b4a80eb17f
commit b95a282b22
4 changed files with 33 additions and 6 deletions

View File

@ -5,6 +5,9 @@ WorkActions = require '../actions/WorkActions.coffee'
module.exports = recl module.exports = recl
onDragStart: (e) -> onDragStart: (e) ->
unless @props.draggable
e.preventDefault()
return
$t = $(e.target) $t = $(e.target)
@dragged = $t.closest('.item') @dragged = $t.closest('.item')
e.dataTransfer.effectAllowed = 'move' e.dataTransfer.effectAllowed = 'move'

View File

@ -11,8 +11,9 @@ FilterComponent = require './FilterComponent.coffee'
SortComponent = require './SortComponent.coffee' SortComponent = require './SortComponent.coffee'
module.exports = recl module.exports = recl
stateFromStore: -> { stateFromStore: -> window.canSort = WorkStore.canSort(); {
list:WorkStore.getList() list:WorkStore.getList()
canSort:WorkStore.canSort()
listening:WorkStore.getListening() listening:WorkStore.getListening()
sorts:WorkStore.getSorts() sorts:WorkStore.getSorts()
filters:WorkStore.getFilters() filters:WorkStore.getFilters()
@ -144,6 +145,7 @@ module.exports = recl
item item
@_focus @_focus
@_keyDown @_keyDown
draggable:@state.canSort
@_dragStart @_dragStart
@_dragEnd}) @_dragEnd})
) )

View File

@ -253,6 +253,10 @@ WorkActions = require('../actions/WorkActions.coffee');
module.exports = recl({ module.exports = recl({
onDragStart: function(e) { onDragStart: function(e) {
var $t; var $t;
if (!this.props.draggable) {
e.preventDefault();
return;
}
$t = $(e.target); $t = $(e.target);
this.dragged = $t.closest('.item'); this.dragged = $t.closest('.item');
e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.effectAllowed = 'move';
@ -571,8 +575,10 @@ SortComponent = require('./SortComponent.coffee');
module.exports = recl({ module.exports = recl({
stateFromStore: function() { stateFromStore: function() {
window.canSort = WorkStore.canSort();
return { return {
list: WorkStore.getList(), list: WorkStore.getList(),
canSort: WorkStore.canSort(),
listening: WorkStore.getListening(), listening: WorkStore.getListening(),
sorts: WorkStore.getSorts(), sorts: WorkStore.getSorts(),
filters: WorkStore.getFilters(), filters: WorkStore.getFilters(),
@ -762,6 +768,7 @@ module.exports = recl({
item: item, item: item,
_focus: _this._focus, _focus: _this._focus,
_keyDown: _this._keyDown, _keyDown: _this._keyDown,
draggable: _this.state.canSort,
_dragStart: _this._dragStart, _dragStart: _this._dragStart,
_dragEnd: _this._dragEnd _dragEnd: _this._dragEnd
})); }));
@ -1465,6 +1472,18 @@ WorkStore = assign({}, EventEmitter.prototype, {
} }
return _sorts[key] = val; return _sorts[key] = val;
}, },
canSort: function() {
var k, v;
for (k in _sorts) {
v = _sorts[k];
if (k === "sort" && v === 1) {
return true;
} else if (v !== 0) {
return false;
}
}
return true;
},
itemFromData: function(item, index) { itemFromData: function(item, index) {
var _item; var _item;
if (index == null) { if (index == null) {

View File

@ -102,18 +102,21 @@ WorkStore = assign {},EventEmitter.prototype,{
list list
getListening: -> _listening getListening: -> _listening
getFilters: -> _filters getFilters: -> _filters
setFilter: ({key,val}) -> _filters[key] = val setFilter: ({key,val}) -> _filters[key] = val
getSorts: -> _sorts getSorts: -> _sorts
setSort: ({key,val}) -> setSort: ({key,val}) ->
for k,v of _sorts for k,v of _sorts
_sorts[k] = 0 _sorts[k] = 0
_sorts[key] = val _sorts[key] = val
canSort: ->
for k,v of _sorts
if k is "sort" and v is 1
return true
else if v isnt 0
return false
true
itemFromData: (item,index=0)-> itemFromData: (item,index=0)->
_item = _.extend {sort:index}, item _item = _.extend {sort:index}, item