[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:
Victor Woeltjen
2015-02-20 12:21:28 -08:00
parent f1a8e84a93
commit a947ff1274
5 changed files with 90 additions and 16 deletions

View 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;
}
);