mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +00:00
[Fixed Position] Add element factory
Add element factory, which will take on responsibility for populating initial states of elements and (if necessary) prompting for user input. WTD-880.
This commit is contained in:
48
platform/features/layout/src/elements/ElementFactory.js
Normal file
48
platform/features/layout/src/elements/ElementFactory.js
Normal file
@ -0,0 +1,48 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
var INITIAL_STATES = {
|
||||
"fixed.image": {
|
||||
url: "http://www.nasa.gov/sites/default/themes/NASAPortal/images/nasa-logo.gif"
|
||||
}
|
||||
},
|
||||
DIALOGS = {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The ElementFactory creates new instances of elements for the
|
||||
* fixed position view, prompting for user input where necessary.
|
||||
* @param {DialogService} dialogService service to request user input
|
||||
* @constructor
|
||||
*/
|
||||
function ElementFactory(dialogService) {
|
||||
return {
|
||||
/**
|
||||
* Create a new element for the fixed position view.
|
||||
* @param {string} type the type of element to create
|
||||
* @returns {Promise|object} the created element, or a promise
|
||||
* for that element
|
||||
*/
|
||||
createElement: function (type) {
|
||||
var initialState = INITIAL_STATES[type] || {};
|
||||
|
||||
// Clone that state
|
||||
initialState = JSON.parse(JSON.stringify(initialState));
|
||||
|
||||
// Show a dialog to configure initial state, if appropriate
|
||||
return DIALOGS[type] ? dialogService.getUserInput(
|
||||
DIALOGS[type],
|
||||
initialState
|
||||
) : initialState;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return ElementFactory;
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user