Permalink
Browse files

Users need to set properties on sub-items of complex widgets: Trees

(#79)
  • Loading branch information...
1 parent 27c032c commit 4eea205b119d34b73e9ae7810c68334af0c7f357 @aerwin aerwin committed Jul 6, 2012
@@ -0,0 +1,63 @@
+define([],
+function(){
+
+var HTMLSubElementHelper = function() {};
+HTMLSubElementHelper.prototype = {
+
+ /* We're getting some widgets (and likely will get more) that contain HTML elements that
+ * need to be part of the child data. For example: dijit.Tree, dojo.store.Memory, and
+ * gridx.GridX. In light of that, creating a single place from which such widget helpers
+ * can access and reuse these routines.
+ */
+
+ getChildrenData: function(/*Widget*/ widget, /*Object*/ options){
+ if(!widget || !widget._srcElement){
+ return undefined;
+ }
+
+ var children = [];
+ dojo.forEach(widget._srcElement.children, function(child) {
+ this._getChildrenDataHelper(child, children);
+ }.bind(this));
+
+ return children;
+ },
+
+ _getChildrenDataHelper: function(element, children) {
+ var elementData = this._getElementData(element);
+ if (elementData) {
+ children.push(elementData);
+ dojo.forEach(element.children, function(child) {
+ this._getChildrenDataHelper(child, elementData.children);
+ }.bind(this));
+ }
+ },
+
+ _getElementData: function(element) {
+ var elementData = null;
+
+ if (element.elementType == "HTMLElement") {
+ //Create a base data structure
+ elementData = {
+ type: "html." + element.tag,
+ properties: {},
+ children: []
+ };
+
+ //Get the element attributes and add to data structure
+ dojo.forEach(element.attributes, function(attribute) {
+ if (!attribute.noPersist) {
+ elementData.properties[attribute.name] = attribute.value;
+ }
+ });
+ } else if (element.elementType == "HTMLText") {
+ elementData = element.value.trim();
+ }
+
+ return elementData;
+ }
+};
+
+return HTMLSubElementHelper;
+
+});
@@ -25,7 +25,6 @@ return declare(CreateTool, {
},
_create: function(args){
-
var command = this._getCreateCommand(args);
this._context.getCommandStack().execute(command);
this._select(this._tree);
@@ -40,8 +39,10 @@ return declare(CreateTool, {
var modelData = this._data[1];
var treeData = this._data[2];
- if(!this._context.loadRequires(storeData.type,true) || !this._context.loadRequires(modelData.type,true) ||
- !this._context.loadRequires(treeData.type,true)){
+ if(!this._context.loadRequires(storeData.type,true) ||
+ !this._context.loadRequires(modelData.type,true) ||
+ !this._context.loadRequires(treeData.type,true) ||
+ !this._context.loadRequires("html.script",true)) { //We're using html.script in our declarative HTML
return;
}
@@ -53,27 +54,6 @@ return declare(CreateTool, {
storeData.properties.id = storeId;
storeData.context = this._context;
- var data = storeData.properties.data;
- var items = data.items;
-
- // Kludge to workaround lack of support for frames in dojo's ItemFileReadStore
- // Replaces objects and arrays in metadata that were created with the top context with ones created in the frame context
- var copyUsingFrameObject = dojo.hitch(this, function (items) {
- var win = this._context.getGlobal();
- var copyOfItems = win.eval("[]");
- for (var i = 0; i < items.length; i++) {
- var item = items[i];
- var object = win.eval("new Object()");
- var copy = this._context.getDojo().mixin(object, item);
- copyOfItems.push(copy);
- if (copy.children) {
- copy.children = copyUsingFrameObject(copy.children);
- }
- }
- return copyOfItems;
- });
- data.items = copyUsingFrameObject(items);
-
var modelId = Widget.getUniqueObjectId(modelData.type, this._context.getDocument());
if(!modelData.properties){
modelData.properties = {};
@@ -95,6 +75,9 @@ return declare(CreateTool, {
dojo.withDoc(this._context.getDocument(), function(){
store = Widget.createWidget(storeData);
modelData.properties.store = dj.getObject(storeId);
+ if (!modelData.properties.store.getChildren) {
+ modelData.properties.store.getChildren = function(object) {return this.query({parent: object.id});};
+ }
model = Widget.createWidget(modelData);
treeData.properties.model = dj.getObject(modelId);
tree = Widget.createWidget(treeData);
@@ -124,15 +107,11 @@ return declare(CreateTool, {
command.add(new ResizeCommand(tree, args.size.w, args.size.h));
}
- //this._context.getCommandStack().execute(command);
-
- //this._select(tree);
this._tree = tree;
return command;
},
addPasteCreateCommand: function(command, args){
-
this._context = this._data.context;
var model = this._data.properties.model;
var modelWidget = Widget.byId(model.id);
@@ -147,7 +126,6 @@ return declare(CreateTool, {
command.add( this._getCreateCommand(args));
return this._tree;
}
-
});
});
@@ -2,9 +2,10 @@ define(["davinci/ve/widget",
"davinci/ve/commands/RemoveCommand",
"davinci/commands/CompoundCommand",
"../dojo/data/DataStoreBasedWidgetInput",
+ "./HTMLSubElementHelper",
"davinci/ve/commands/ReparentCommand",
],
-function(Widget, RemoveCommand, CompoundCommand, DataStoreBasedWidgetInput, ReparentCommand){
+function(Widget, RemoveCommand, CompoundCommand, DataStoreBasedWidgetInput, HTMLSubElementHelper, ReparentCommand){
var TreeHelper = function() {};
TreeHelper.prototype = {
@@ -107,7 +108,7 @@ TreeHelper.prototype = {
}
var command = new ReparentCommand(assocatedWidget, parent, newIndex);
command.execute();
- }/*,
+ }, /*,
updateStore: function(widget, storeWidget, w, useDataDojoProps){
var store = widget.dijitWidget.store;
@@ -146,7 +147,15 @@ TreeHelper.prototype = {
store.close();
}
}*/
-
+
+ // We need to provide getChildrenData because we're relying on <script> elements in the declarative HTML. We'll
+ // delegate to HTMLSubElementHelper
+ getChildrenData: function(/*Widget*/ widget, /*Object*/ options){
+ if (!this._htmlSubElementHelper) {
+ this._htmlSubElementHelper = new HTMLSubElementHelper();
+ }
+ return this._htmlSubElementHelper.getChildrenData(widget, options);
+ }
};
return TreeHelper;
Oops, something went wrong.

0 comments on commit 4eea205

Please sign in to comment.