2015-02-19 17:37:02 +00:00
|
|
|
/*global define,window*/
|
2015-02-18 17:03:50 +00:00
|
|
|
|
|
|
|
define(
|
2015-02-20 20:21:28 +00:00
|
|
|
['./elements/ElementFactory'],
|
|
|
|
function (ElementFactory) {
|
2015-02-18 17:03:50 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Proxy for configuring a fixed position view via the toolbar.
|
|
|
|
* @constructor
|
2015-02-20 23:47:07 +00:00
|
|
|
* @param {Function} addElementCallback callback to invoke when
|
|
|
|
* elements are created
|
|
|
|
* @param $q Angular's $q, for promise-handling
|
|
|
|
* @param {DialogService} dialogService dialog service to use
|
|
|
|
* when adding a new element will require user input
|
2015-02-18 17:03:50 +00:00
|
|
|
*/
|
2015-02-20 23:47:07 +00:00
|
|
|
function FixedProxy(addElementCallback, $q, dialogService) {
|
2015-02-20 20:21:28 +00:00
|
|
|
var factory = new ElementFactory(dialogService);
|
|
|
|
|
2015-02-18 17:03:50 +00:00
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Add a new visual element to this view.
|
|
|
|
*/
|
|
|
|
add: function (type) {
|
2015-02-20 20:21:28 +00:00
|
|
|
// Place a configured element into the view configuration
|
|
|
|
function addElement(element) {
|
|
|
|
// 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
|
2015-02-20 23:47:07 +00:00
|
|
|
addElementCallback(element);
|
2015-02-20 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Defer creation to the factory
|
|
|
|
$q.when(factory.createElement(type)).then(addElement);
|
2015-02-18 17:03:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return FixedProxy;
|
|
|
|
}
|
|
|
|
);
|