From e735c17b7a9063307e00f67ceb1a4f5e5fa9ed7b Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Thu, 21 Aug 2014 14:30:42 +0200 Subject: [PATCH] Drag and drop now working more like expected --- .../app/helpers/drag_n_drop.js.coffee | 19 ++++++++++++------- .../views/section_tab_header_view.js.coffee | 8 +++++--- .../acceptance/suppliers/section_view.feature | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/supplier/app/helpers/drag_n_drop.js.coffee b/app/assets/javascripts/supplier/app/helpers/drag_n_drop.js.coffee index bd8244a8..2fa543dc 100644 --- a/app/assets/javascripts/supplier/app/helpers/drag_n_drop.js.coffee +++ b/app/assets/javascripts/supplier/app/helpers/drag_n_drop.js.coffee @@ -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 diff --git a/app/assets/javascripts/supplier/app/views/section_tab_header_view.js.coffee b/app/assets/javascripts/supplier/app/views/section_tab_header_view.js.coffee index c8fbe711..201fe4e4 100644 --- a/app/assets/javascripts/supplier/app/views/section_tab_header_view.js.coffee +++ b/app/assets/javascripts/supplier/app/views/section_tab_header_view.js.coffee @@ -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') diff --git a/spec/acceptance/suppliers/section_view.feature b/spec/acceptance/suppliers/section_view.feature index 86aff0ff..18696766 100644 --- a/spec/acceptance/suppliers/section_view.feature +++ b/spec/acceptance/suppliers/section_view.feature @@ -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