mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 06:08:11 +00:00
[Common UI] Initial commonUI bundles
Bring in work on general-purpose and over-arching user interface bundles from the sandbox transition branch. WTD-574.
This commit is contained in:
@ -0,0 +1,56 @@
|
||||
/*global define*/
|
||||
|
||||
/**
|
||||
* Wrapper for both "context" and "composition" capabilities;
|
||||
* ensures that any domain objects reachable in Edit mode
|
||||
* are also wrapped as EditableDomainObjects
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
return function EditableContextCapability(
|
||||
contextCapability,
|
||||
editableObject,
|
||||
domainObject,
|
||||
factory
|
||||
) {
|
||||
var capability = Object.create(contextCapability);
|
||||
|
||||
function isDomainObject(obj) {
|
||||
return typeof obj.getId === 'function' &&
|
||||
typeof obj.getModel === 'function' &&
|
||||
typeof obj.getCapability === 'function';
|
||||
}
|
||||
|
||||
function makeEditableObject(obj) {
|
||||
return isDomainObject(obj) ?
|
||||
factory.getEditableObject(obj) :
|
||||
obj;
|
||||
}
|
||||
|
||||
function makeEditable(obj) {
|
||||
return Array.isArray(obj) ?
|
||||
obj.map(makeEditableObject) :
|
||||
makeEditableObject(obj);
|
||||
}
|
||||
|
||||
// Replace all methods; return only editable domain objects.
|
||||
Object.keys(contextCapability).forEach(function (k) {
|
||||
capability[k] = function () {
|
||||
var result = contextCapability[k].apply(
|
||||
capability,
|
||||
arguments
|
||||
);
|
||||
|
||||
return result.then ? // promise-like
|
||||
result.then(makeEditable) :
|
||||
makeEditable(result);
|
||||
};
|
||||
});
|
||||
|
||||
return capability;
|
||||
};
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user