mirror of
https://github.com/nasa/openmct.git
synced 2025-06-05 17:01:41 +00:00
[Containment] Fire a link action on drop
Fire a link action as the result of a drag-drop operation, WTD-962.
This commit is contained in:
parent
5045795a7c
commit
44eb54884b
@ -16,8 +16,10 @@ define(
|
|||||||
|
|
||||||
// Add this domain object's identifier
|
// Add this domain object's identifier
|
||||||
function addId(model) {
|
function addId(model) {
|
||||||
model.composition = model.composition || [];
|
if (Array.isArray(model.composition) &&
|
||||||
model.composition.push(selectedId);
|
model.composition.indexOf(selectedId) < 0) {
|
||||||
|
model.composition.push(selectedId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Persist changes to the domain object
|
// Persist changes to the domain object
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
{
|
{
|
||||||
"key": "drop",
|
"key": "drop",
|
||||||
"implementation": "gestures/DropGesture.js",
|
"implementation": "gestures/DropGesture.js",
|
||||||
"depends": [ "$q" ]
|
"depends": [ "dndService", "$q" ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "menu",
|
"key": "menu",
|
||||||
|
@ -19,7 +19,10 @@ define(
|
|||||||
* composition should be modified as a result of the drop.
|
* composition should be modified as a result of the drop.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function DropGesture($q, element, domainObject) {
|
function DropGesture(dndService, $q, element, domainObject) {
|
||||||
|
var actionCapability = domainObject.getCapability('action'),
|
||||||
|
action; // Action for the drop, when it occurs
|
||||||
|
|
||||||
function broadcastDrop(id, event) {
|
function broadcastDrop(id, event) {
|
||||||
// Find the relevant scope...
|
// Find the relevant scope...
|
||||||
var scope = element && element.scope && element.scope(),
|
var scope = element && element.scope && element.scope(),
|
||||||
@ -43,20 +46,27 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doPersist() {
|
|
||||||
var persistence = domainObject.getCapability("persistence");
|
|
||||||
return $q.when(persistence && persistence.persist());
|
|
||||||
}
|
|
||||||
|
|
||||||
function dragOver(e) {
|
function dragOver(e) {
|
||||||
var event = (e || {}).originalEvent || e;
|
var event = (e || {}).originalEvent || e,
|
||||||
|
selectedObject = dndService.getData(
|
||||||
|
GestureConstants.MCT_EXTENDED_DRAG_TYPE
|
||||||
|
);
|
||||||
|
|
||||||
// TODO: Vary this based on modifier keys
|
if (selectedObject) {
|
||||||
event.dataTransfer.dropEffect = 'move';
|
// TODO: Vary this based on modifier keys
|
||||||
|
action = actionCapability.getActions({
|
||||||
|
key: 'link',
|
||||||
|
selectedObject: selectedObject
|
||||||
|
})[0];
|
||||||
|
|
||||||
// Indicate that we will accept the drag
|
if (action) {
|
||||||
event.preventDefault(); // Required in Chrome?
|
event.dataTransfer.dropEffect = 'move';
|
||||||
return false;
|
|
||||||
|
// Indicate that we will accept the drag
|
||||||
|
event.preventDefault(); // Required in Chrome?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drop(e) {
|
function drop(e) {
|
||||||
@ -67,38 +77,24 @@ define(
|
|||||||
// destination domain object's composition, and persist
|
// destination domain object's composition, and persist
|
||||||
// the change.
|
// the change.
|
||||||
if (id) {
|
if (id) {
|
||||||
$q.when(domainObject.useCapability(
|
$q.when(action && action.perform()).then(function (result) {
|
||||||
'mutation',
|
|
||||||
function (model) {
|
|
||||||
var composition = model.composition;
|
|
||||||
// Don't store the same id more than once
|
|
||||||
if (composition && // not-contains
|
|
||||||
!(composition.map(function (i) {
|
|
||||||
return i === id;
|
|
||||||
}).reduce(function (a, b) {
|
|
||||||
return a || b;
|
|
||||||
}, false))) {
|
|
||||||
model.composition.push(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)).then(function (result) {
|
|
||||||
// Broadcast the drop event if it was successful
|
// Broadcast the drop event if it was successful
|
||||||
if (result) {
|
if (result) {
|
||||||
broadcastDrop(id, event);
|
broadcastDrop(id, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If mutation was successful, persist the change
|
|
||||||
return result && doPersist();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for dragover, to indicate we'll accept a drag
|
// We can only handle drops if we have access to actions...
|
||||||
element.on('dragover', dragOver);
|
if (actionCapability) {
|
||||||
|
// Listen for dragover, to indicate we'll accept a drag
|
||||||
|
element.on('dragover', dragOver);
|
||||||
|
|
||||||
// Listen for the drop itself
|
// Listen for the drop itself
|
||||||
element.on('drop', drop);
|
element.on('drop', drop);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user