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
# http://stackoverflow.com/questions/8762635/getting-the-filename-during-the-dragenter-event
DragNDrop = Ember.Namespace.create()
DragNDrop.cancel = (e)->
DragNDrop = Ember.Namespace.create
cancel: (e)->
e.preventDefault()
false
nothing: ->
DragNDrop.Draggable = Ember.Mixin.create
attributeBindings: 'draggable'
@@ -24,27 +25,31 @@ DragNDrop.Draggable = Ember.Mixin.create
DragNDrop.Droppable = Ember.Mixin.create
dragEnter: (e)->
if @dragEntered
e.preventDefault()
# e.preventDefault()
viewId = localStorage.getItem 'draggingView'
view = Ember.View.views[viewId]
@dragEntered view
else
DragNDrop.cancel(e)
dragOver: DragNDrop.cancel
# else
# DragNDrop.cancel(e)
dragOver: DragNDrop.cancel # don't know why, but crucial for the current way of working with section tables
# dragOver: (e)->(e.preventDefault(); false)
dragLeave: ->
if @dragLeft
@dragLeft()
drop: (e)->
e.preventDefault()
# e.preventDefault()
viewId = e.originalEvent.dataTransfer.getData('Text')
view = Ember.View.views[viewId]
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
position =
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)
@dropped view, position if @dropped
@dragLeft() if @dragLeft # not triggered by system itself in case of drop
false
@DragNDrop = DragNDrop
@@ -17,9 +17,11 @@ App.SectionTabHeaderView = Ember.View.extend DragNDrop.Droppable,
dropped: (view)->
if view.constructor.toString().match(/SectionTableView$/)
table = view.get('content')
table.set 'section', @content
#table.get('transaction').commit()
table.save()
section = @get('context')
if section isnt table.get('section')
section.get('tables').addObject table
table.save()
@get('controller').transitionToRoute 'section', section.get('id')
didInsertElement: ->
@$el = $ @get('element')
@@ -65,7 +65,7 @@ Feature: Supplier section view
Then the supplier table actions of the new list should be visible
@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
And there is another table in the section
And I am signed in as supplier