diff options
Diffstat (limited to 'js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js')
-rw-r--r-- | js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js | 278 |
1 files changed, 228 insertions, 50 deletions
diff --git a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js index 41afefa5..4828839b 100644 --- a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js +++ b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js | |||
@@ -4,70 +4,241 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | Component = require("montage/ui/component").Component, | 8 | Component = require("montage/ui/component").Component, |
9 | NJUtils = require("js/lib/NJUtils").NJUtils; | 9 | NJUtils = require("js/lib/NJUtils").NJUtils; |
10 | |||
11 | var treeControlModule = require("js/components/tree.reel"); | ||
12 | var PIData = require("js/data/pi/pi-data").PiData; | ||
13 | |||
14 | String.prototype.capitalizeFirstChar = function() { | ||
15 | return this.charAt(0).toUpperCase() + this.slice(1); | ||
16 | }; | ||
10 | 17 | ||
11 | var treeControlModule = require("js/components/tree.reel"); | ||
12 | 18 | ||
13 | var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component, { | 19 | var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component, { |
14 | _hasFocus: { | 20 | |
15 | enumerable: false, | 21 | components: { |
16 | value: false | 22 | value: { |
23 | "text": "styles", | ||
24 | "children": [ | ||
25 | { | ||
26 | "text": "Montage Components", | ||
27 | "children": [ | ||
28 | { | ||
29 | "text": "Button", | ||
30 | "dataFile" : "node_modules/components-data/button.json", | ||
31 | "component": "button" | ||
32 | }, | ||
33 | { | ||
34 | "text": "Text Field", | ||
35 | "dataFile" : "node_modules/components-data/textfield.json", | ||
36 | "component": "textfield" | ||
37 | } | ||
38 | ] | ||
39 | } | ||
40 | ] | ||
41 | } | ||
42 | }, | ||
43 | |||
44 | componentsData: { | ||
45 | value: {} | ||
17 | }, | 46 | }, |
18 | prepareForDraw: { | 47 | |
19 | enumerable: false, | 48 | componentsToLoad: { |
20 | value: function() { | 49 | value: null |
21 | var treeHolderDiv = document.getElementById("comp_tree"); | ||
22 | var componentsTree = treeControlModule.Tree.create(); | ||
23 | componentsTree.element = treeHolderDiv; | ||
24 | componentsTree.dataProvider = this._loadXMLDoc("js/panels/Components/Components.xml"); | ||
25 | componentsTree.needsDraw = true; | ||
26 | |||
27 | this.eventManager.addEventListener( "executeAddComponent", this, false); | ||
28 | } | ||
29 | }, | 50 | }, |
30 | willDraw: { | ||
31 | enumerable: false, | ||
32 | value: function() { | ||
33 | 51 | ||
34 | } | 52 | componentsLoaded: { |
53 | value: 0 | ||
35 | }, | 54 | }, |
36 | draw: { | ||
37 | enumerable: false, | ||
38 | value: function() { | ||
39 | 55 | ||
40 | } | 56 | didCreate: { |
57 | value: function() { | ||
58 | // Loop through the component and load the JSON data for them | ||
59 | this._loadComponents(); | ||
60 | |||
61 | } | ||
41 | }, | 62 | }, |
42 | 63 | ||
43 | _loadXMLDoc: { | 64 | _loadComponents: { |
44 | value:function(dname) { | 65 | value: function() { |
45 | if (window.XMLHttpRequest) { | 66 | |
46 | xhttp = new XMLHttpRequest(); | 67 | this.componentsToLoad = this.components.children[0].children.length; |
68 | |||
69 | // Build the PI objects for each component | ||
70 | for(var i = 0, component; component = this.components.children[0].children[i]; i++) { | ||
71 | var req = new XMLHttpRequest(); | ||
72 | //req.identifier = "searchRequest"; | ||
73 | req.open("GET", component.dataFile); | ||
74 | req.addEventListener("load", this, false); | ||
75 | req.addEventListener("error", this, false); | ||
76 | req.send(); | ||
77 | |||
47 | } | 78 | } |
48 | xhttp.open("GET", dname, false); | 79 | |
49 | xhttp.send(); | 80 | |
50 | return xhttp.responseXML; | 81 | } |
82 | }, | ||
83 | |||
84 | handleLoad: { | ||
85 | value: function(evt) { | ||
86 | var componentData = JSON.parse(evt.target.responseText); | ||
87 | |||
88 | //var component = response.component.capitalizeFirstChar(); | ||
89 | var component = componentData.name; | ||
90 | |||
91 | var piIdentifier = component + "Pi"; | ||
92 | var piObj = []; | ||
93 | var section = {}; | ||
94 | |||
95 | |||
96 | section.label = component + " Properties"; | ||
97 | section.Section = []; | ||
98 | |||
99 | for(var j = 0, props; props = componentData.properties[j]; j++) { | ||
100 | var row = {}; | ||
101 | row.type = this.getControlType(props.type); | ||
102 | row.id = props.name; | ||
103 | row.prop = props.name; | ||
104 | row.defaultValue = props["default"]; | ||
105 | row.label = props.name; | ||
106 | |||
107 | section.Section.push([row]); | ||
108 | } | ||
109 | |||
110 | PIData[piIdentifier] = []; | ||
111 | PIData[piIdentifier].push(section); | ||
112 | |||
113 | // Setup the componentsData | ||
114 | this.componentsData[componentData.component] = componentData; | ||
115 | |||
116 | this.componentsLoaded++; | ||
117 | |||
118 | if(this.componentsLoaded === this.componentsToLoad) { | ||
119 | console.log("all loaded"); | ||
120 | } | ||
121 | |||
122 | } | ||
123 | }, | ||
124 | |||
125 | getControlType: { | ||
126 | value: function(type) { | ||
127 | switch(type) { | ||
128 | case "string": | ||
129 | return "textbox"; | ||
130 | case "boolean": | ||
131 | return "checkbox"; | ||
132 | default: | ||
133 | alert("Conversion not implemented for ", type); | ||
134 | } | ||
135 | } | ||
136 | }, | ||
137 | |||
138 | applySelection: { | ||
139 | value: function(selection) { | ||
140 | console.log(selection); | ||
141 | console.log(this.componentsData[selection.component]); | ||
142 | this._stash.dropx = 200; | ||
143 | this._stash.dropy = 200; | ||
144 | this.addComponentToStage(this.componentsData[selection.component]);// evt.detail.dropX, evt.detail.dropY); | ||
145 | |||
51 | } | 146 | } |
52 | }, | 147 | }, |
53 | 148 | ||
149 | _stash: { | ||
150 | value: {} | ||
151 | }, | ||
152 | |||
54 | handleExecuteAddComponent: { | 153 | handleExecuteAddComponent: { |
55 | value: function(evt) { | 154 | value: function(evt) { |
56 | this.addComponentToStage(evt.detail.component, evt.detail.dropX, evt.detail.dropY) | 155 | //var component = evt.detail.component; |
156 | // Get the data from the event detail component | ||
157 | var component = this._testButtonJson; | ||
158 | this._stash.dropx = evt.detail.dropX; | ||
159 | this._stash.dropy = evt.detail.dropY; | ||
160 | this.addComponentToStage(component);// evt.detail.dropX, evt.detail.dropY); | ||
57 | } | 161 | } |
58 | }, | 162 | }, |
59 | 163 | ||
60 | addComponentToStage:{ | 164 | /** |
61 | value:function(componentType, dropX, dropY){ | 165 | * Send a request to add a component to the user document and waits for a callback to continue |