mirror of
https://github.com/nasa/openmct.git
synced 2025-06-14 21:28:12 +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:
@ -1,29 +1,44 @@
|
||||
/*global define,window*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
['./elements/ElementFactory'],
|
||||
function (ElementFactory) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Proxy for configuring a fixed position view via the toolbar.
|
||||
* @constructor
|
||||
* @param configuration the view configuration object
|
||||
* @param configuration the view configuration object to manage
|
||||
*/
|
||||
function FixedProxy(configuration) {
|
||||
function FixedProxy(configuration, $q, dialogService, callback) {
|
||||
var factory = new ElementFactory(dialogService);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Add a new visual element to this view.
|
||||
*/
|
||||
add: function (type) {
|
||||
configuration.elements = configuration.elements || [];
|
||||
configuration.elements.push({
|
||||
x: configuration.elements.length,
|
||||
y: configuration.elements.length,
|
||||
width: 2,
|
||||
height: 1,
|
||||
type: type
|
||||
});
|
||||
// Place a configured element into the view configuration
|
||||
function addElement(element) {
|
||||
// Ensure that there is an Elements array
|
||||
configuration.elements = configuration.elements || [];
|
||||
|
||||
// Configure common properties of the element
|
||||
element.x = element.x || 0;
|
||||
element.y = element.y || 0;
|
||||
element.width = element.width || 1;
|
||||
element.height = element.height || 1;
|
||||
element.type = type;
|
||||
|
||||
// Finally, add it to the view's configuration
|
||||
configuration.elements.push(element);
|
||||
|
||||
// Let the view know it needs to refresh
|
||||
callback();
|
||||
}
|
||||
|
||||
// Defer creation to the factory
|
||||
$q.when(factory.createElement(type)).then(addElement);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user