mirror of
https://github.com/nasa/openmct.git
synced 2025-01-21 03:55:31 +00:00
[Containment] Implement Link
Implement link as a basic action, to separate it out from drop gesture such that it can be controlled by policy. For WTD-962.
This commit is contained in:
parent
870ff6af32
commit
5adcd3cd6d
47
platform/commonUI/edit/src/actions/LinkAction.js
Normal file
47
platform/commonUI/edit/src/actions/LinkAction.js
Normal file
@ -0,0 +1,47 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
|
||||
/**
|
||||
* Add one domain object to another's composition.
|
||||
*/
|
||||
function LinkAction(context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
selectedObject = (context || {}).selectedObject,
|
||||
selectedId = selectedObject && selectedObject.getId();
|
||||
|
||||
// Add this domain object's identifier
|
||||
function addId(model) {
|
||||
model.composition = model.composition || [];
|
||||
model.composition.push(selectedId);
|
||||
}
|
||||
|
||||
// Persist changes to the domain object
|
||||
function doPersist() {
|
||||
var persistence = domainObject.getCapability('persistence');
|
||||
return persistence.persist();
|
||||
}
|
||||
|
||||
// Link these objects
|
||||
function doLink() {
|
||||
return domainObject.useCapability("mutation", addId)
|
||||
.then(doPersist);
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Perform this action.
|
||||
*/
|
||||
perform: function () {
|
||||
return selectedId && doLink();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return LinkAction;
|
||||
}
|
||||
);
|
Loading…
Reference in New Issue
Block a user