Drag and drop now working more like expected

This commit is contained in:
2014-08-21 14:30:42 +02:00
parent a93f6e6226
commit e735c17b7a
3 changed files with 18 additions and 11 deletions
@@ -1,9 +1,10 @@
# on why local storage is used in the enter events # on why local storage is used in the enter events
# http://stackoverflow.com/questions/8762635/getting-the-filename-during-the-dragenter-event # http://stackoverflow.com/questions/8762635/getting-the-filename-during-the-dragenter-event
DragNDrop = Ember.Namespace.create() DragNDrop = Ember.Namespace.create
DragNDrop.cancel = (e)-> cancel: (e)->
e.preventDefault() e.preventDefault()
false false
nothing: ->
DragNDrop.Draggable = Ember.Mixin.create DragNDrop.Draggable = Ember.Mixin.create
attributeBindings: 'draggable' attributeBindings: 'draggable'
@@ -24,27 +25,31 @@ DragNDrop.Draggable = Ember.Mixin.create
DragNDrop.Droppable = Ember.Mixin.create DragNDrop.Droppable = Ember.Mixin.create
dragEnter: (e)-> dragEnter: (e)->
if @dragEntered if @dragEntered
e.preventDefault() # e.preventDefault()
viewId = localStorage.getItem 'draggingView' viewId = localStorage.getItem 'draggingView'
view = Ember.View.views[viewId] view = Ember.View.views[viewId]
@dragEntered view @dragEntered view
else # else
DragNDrop.cancel(e) # DragNDrop.cancel(e)
dragOver: DragNDrop.cancel dragOver: DragNDrop.cancel # don't know why, but crucial for the current way of working with section tables
# dragOver: (e)->(e.preventDefault(); false)
dragLeave: -> dragLeave: ->
if @dragLeft if @dragLeft
@dragLeft() @dragLeft()
drop: (e)-> drop: (e)->
e.preventDefault() # e.preventDefault()
viewId = e.originalEvent.dataTransfer.getData('Text') viewId = e.originalEvent.dataTransfer.getData('Text')
view = Ember.View.views[viewId] view = Ember.View.views[viewId]
return unless view return unless view
view.dragEnd(e) if view.dragEnd # not triggered on its own on drop
# Calculate the element's center drop position relative to container # Calculate the element's center drop position relative to container
position = position =
left: Math.max(e.originalEvent.pageX - view.$el.offsetParent().offset().left - (view.$el.outerWidth()/2), 0) left: Math.max(e.originalEvent.pageX - view.$el.offsetParent().offset().left - (view.$el.outerWidth()/2), 0)
top: Math.max(e.originalEvent.pageY - view.$el.offsetParent().offset().top - (view.$el.outerHeight()/2), 0) top: Math.max(e.originalEvent.pageY - view.$el.offsetParent().offset().top - (view.$el.outerHeight()/2), 0)
@dropped view, position if @dropped @dropped view, position if @dropped
@dragLeft() if @dragLeft # not triggered by system itself in case of drop
false false
@DragNDrop = DragNDrop @DragNDrop = DragNDrop
@@ -17,9 +17,11 @@ App.SectionTabHeaderView = Ember.View.extend DragNDrop.Droppable,
dropped: (view)-> dropped: (view)->
if view.constructor.toString().match(/SectionTableView$/) if view.constructor.toString().match(/SectionTableView$/)
table = view.get('content') table = view.get('content')
table.set 'section', @content section = @get('context')
#table.get('transaction').commit() if section isnt table.get('section')
table.save() section.get('tables').addObject table
table.save()
@get('controller').transitionToRoute 'section', section.get('id')
didInsertElement: -> didInsertElement: ->
@$el = $ @get('element') @$el = $ @get('element')
@@ -65,7 +65,7 @@ Feature: Supplier section view
Then the supplier table actions of the new list should be visible Then the supplier table actions of the new list should be visible
@javascript @javascript
Scenario: List moves table in section view when the table changes Scenario: List moves to another table when section view is already loaded
Given there is an active list and order Given there is an active list and order
And there is another table in the section And there is another table in the section
And I am signed in as supplier And I am signed in as supplier