From 01d953bf4580be461a38b75b980d2a92bd1ce622 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 17 Feb 2015 10:23:10 -0800 Subject: [PATCH] [Layout] Position frames on drop Position frames within a layout based on the position where they were dropped into the layout, WTD-877. --- .../features/layout/src/LayoutController.js | 20 +++++++++++++++++++ .../src/gestures/DropGesture.js | 13 ++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/platform/features/layout/src/LayoutController.js b/platform/features/layout/src/LayoutController.js index 70a5126d78..9843252afb 100644 --- a/platform/features/layout/src/LayoutController.js +++ b/platform/features/layout/src/LayoutController.js @@ -85,6 +85,26 @@ define( // Position panes when the model field changes $scope.$watch("model.composition", lookupPanels); + // Position panes where they are dropped + $scope.$on("mctDrop", function (e, id, position) { + // Make sure there is a "panels" field in the + // view configuration. + $scope.configuration.panels = + $scope.configuration.panels || {}; + // Store the position of this panel. + $scope.configuration.panels[id] = { + position: [ + Math.floor(position.x / gridSize[0]), + Math.floor(position.y / gridSize[1]) + ], + dimensions: DEFAULT_DIMENSIONS + }; + // Mark change as persistable + if ($scope.commit) { + $scope.commit("Dropped a frame."); + } + }); + return { /** * Get a style object for a frame with the specified domain diff --git a/platform/representation/src/gestures/DropGesture.js b/platform/representation/src/gestures/DropGesture.js index 00faa83710..985fe102d3 100644 --- a/platform/representation/src/gestures/DropGesture.js +++ b/platform/representation/src/gestures/DropGesture.js @@ -22,14 +22,23 @@ define( function DropGesture($q, element, domainObject) { function broadcastDrop(id, event) { // Find the relevant scope... - var scope = element && element.scope && element.scope(); + var scope = element && element.scope && element.scope(), + rect; if (scope && scope.$broadcast) { + // Get the representation's bounds, to convert + // drop position + rect = element[0].getBoundingClientRect(); + // ...and broadcast the event. This allows specific // views to have post-drop behavior which depends on // drop position. scope.$broadcast( GestureConstants.MCT_DROP_EVENT, - { id: id, dropEvent: event } + id, + { + x: event.pageX - rect.left, + y: event.pageY - rect.top + } ); } }