[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.
This commit is contained in:
Victor Woeltjen 2015-02-17 10:01:27 -08:00
parent 8d6b218646
commit 4190941bfb
2 changed files with 23 additions and 1 deletions

View File

@ -20,6 +20,19 @@ define(
*/ */
function DropGesture($q, element, domainObject) { 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() { function doPersist() {
var persistence = domainObject.getCapability("persistence"); var persistence = domainObject.getCapability("persistence");
@ -60,6 +73,11 @@ define(
} }
} }
)).then(function (result) { )).then(function (result) {
// Broadcast the drop event if it was successful
if (result) {
broadcastDrop(id, event);
}
// If mutation was successful, persist the change // If mutation was successful, persist the change
return result && doPersist(); return result && doPersist();
}); });

View File

@ -14,5 +14,9 @@ define({
* An estimate for the dimensions of a context menu, used for * An estimate for the dimensions of a context menu, used for
* positioning. * positioning.
*/ */
MCT_MENU_DIMENSIONS: [ 170, 200 ] MCT_MENU_DIMENSIONS: [ 170, 200 ],
/**
* Identifier for drop events.
*/
MCT_DROP_EVENT: 'mctDrop'
}); });