diff --git a/pub/work/src/js/components/ItemComponent.coffee b/pub/work/src/js/components/ItemComponent.coffee index 14951654d..7780b4847 100644 --- a/pub/work/src/js/components/ItemComponent.coffee +++ b/pub/work/src/js/components/ItemComponent.coffee @@ -5,6 +5,9 @@ WorkActions = require '../actions/WorkActions.coffee' module.exports = recl onDragStart: (e) -> + unless @props.draggable + e.preventDefault() + return $t = $(e.target) @dragged = $t.closest('.item') e.dataTransfer.effectAllowed = 'move' diff --git a/pub/work/src/js/components/ListComponent.coffee b/pub/work/src/js/components/ListComponent.coffee index 2c1a74a43..4bbc2b7a2 100644 --- a/pub/work/src/js/components/ListComponent.coffee +++ b/pub/work/src/js/components/ListComponent.coffee @@ -11,8 +11,9 @@ FilterComponent = require './FilterComponent.coffee' SortComponent = require './SortComponent.coffee' module.exports = recl - stateFromStore: -> { + stateFromStore: -> window.canSort = WorkStore.canSort(); { list:WorkStore.getList() + canSort:WorkStore.canSort() listening:WorkStore.getListening() sorts:WorkStore.getSorts() filters:WorkStore.getFilters() @@ -144,6 +145,7 @@ module.exports = recl item @_focus @_keyDown + draggable:@state.canSort @_dragStart @_dragEnd}) ) diff --git a/pub/work/src/js/main.js b/pub/work/src/js/main.js index 2ab60780d..292a30199 100644 --- a/pub/work/src/js/main.js +++ b/pub/work/src/js/main.js @@ -253,6 +253,10 @@ WorkActions = require('../actions/WorkActions.coffee'); module.exports = recl({ onDragStart: function(e) { var $t; + if (!this.props.draggable) { + e.preventDefault(); + return; + } $t = $(e.target); this.dragged = $t.closest('.item'); e.dataTransfer.effectAllowed = 'move'; @@ -571,8 +575,10 @@ SortComponent = require('./SortComponent.coffee'); module.exports = recl({ stateFromStore: function() { + window.canSort = WorkStore.canSort(); return { list: WorkStore.getList(), + canSort: WorkStore.canSort(), listening: WorkStore.getListening(), sorts: WorkStore.getSorts(), filters: WorkStore.getFilters(), @@ -762,6 +768,7 @@ module.exports = recl({ item: item, _focus: _this._focus, _keyDown: _this._keyDown, + draggable: _this.state.canSort, _dragStart: _this._dragStart, _dragEnd: _this._dragEnd })); @@ -1465,6 +1472,18 @@ WorkStore = assign({}, EventEmitter.prototype, { } 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) { var _item; if (index == null) { diff --git a/pub/work/src/js/stores/WorkStore.coffee b/pub/work/src/js/stores/WorkStore.coffee index 61cdaf47e..93a932822 100644 --- a/pub/work/src/js/stores/WorkStore.coffee +++ b/pub/work/src/js/stores/WorkStore.coffee @@ -102,18 +102,21 @@ WorkStore = assign {},EventEmitter.prototype,{ list getListening: -> _listening - getFilters: -> _filters - setFilter: ({key,val}) -> _filters[key] = val - getSorts: -> _sorts - setSort: ({key,val}) -> for k,v of _sorts _sorts[k] = 0 _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)-> _item = _.extend {sort:index}, item