From 4190941bfb1037d12370e26b5c9fca8821626894 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 17 Feb 2015 10:01:27 -0800 Subject: [PATCH] [Views] Broadcast event on drop Broadcast an event when drag-drop domain object composition occurs, such that the view in question may utilize the drop coordinates (e.g. to position elements in a layout or fixed position view.) WTD-877. --- .../representation/src/gestures/DropGesture.js | 18 ++++++++++++++++++ .../src/gestures/GestureConstants.js | 6 +++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/platform/representation/src/gestures/DropGesture.js b/platform/representation/src/gestures/DropGesture.js index bcd49713fe..00faa83710 100644 --- a/platform/representation/src/gestures/DropGesture.js +++ b/platform/representation/src/gestures/DropGesture.js @@ -20,6 +20,19 @@ define( */ function DropGesture($q, element, domainObject) { + function broadcastDrop(id, event) { + // Find the relevant scope... + var scope = element && element.scope && element.scope(); + if (scope && scope.$broadcast) { + // ...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 } + ); + } + } function doPersist() { var persistence = domainObject.getCapability("persistence"); @@ -60,6 +73,11 @@ define( } } )).then(function (result) { + // Broadcast the drop event if it was successful + if (result) { + broadcastDrop(id, event); + } + // If mutation was successful, persist the change return result && doPersist(); }); diff --git a/platform/representation/src/gestures/GestureConstants.js b/platform/representation/src/gestures/GestureConstants.js index ae35fa439f..126a7b3981 100644 --- a/platform/representation/src/gestures/GestureConstants.js +++ b/platform/representation/src/gestures/GestureConstants.js @@ -14,5 +14,9 @@ define({ * An estimate for the dimensions of a context menu, used for * positioning. */ - MCT_MENU_DIMENSIONS: [ 170, 200 ] + MCT_MENU_DIMENSIONS: [ 170, 200 ], + /** + * Identifier for drop events. + */ + MCT_DROP_EVENT: 'mctDrop' }); \ No newline at end of file