diff options
Diffstat (limited to 'js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js')
-rw-r--r-- | js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js | 300 |
1 files changed, 265 insertions, 35 deletions
diff --git a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js index 41afefa5..338e7e0d 100644 --- a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js +++ b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js | |||
@@ -4,20 +4,189 @@ 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: null |
23 | }, | ||
24 | |||
25 | componentsToLoad: { | ||
26 | value: null | ||
27 | }, | ||
28 | |||
29 | componentsLoaded: { | ||
30 | value: 0 | ||
31 | }, | ||
32 | |||
33 | data2: { | ||
34 | value: { | ||
35 | "text": "styles", | ||
36 | "children": [{ | ||
37 | "text": "Box Styles", | ||
38 | "children": [ | ||
39 | { | ||
40 | "text": "Border-Radius", | ||
41 | "classNameBase" : "border-radius", | ||
42 | "styles" : { | ||
43 | "border-radius": "100px", | ||
44 | "border" : "1px solid #333" | ||
45 | } | ||
46 | }, | ||
47 | { | ||
48 | "text": "Drop Shadow", | ||
49 | "classNameBase" : "drop-shadow", | ||
50 | "styles" : { | ||
51 | "box-shadow": "2px 2px 50px rgba(0,0,0,0.5)", | ||
52 | "border" : "1px solid #CCC" | ||
53 | } | ||
54 | }, | ||
55 | { | ||
56 | "text": "Fancy Box", | ||
57 | "classNameBase" : "fancy-box", | ||
58 | "styles" : { | ||
59 | "box-shadow": "inset 0 0 0 1px #666, inset 0 0 0 2px rgba(225, 225, 225, 0.4), 0 0 20px -10px #333", | ||
60 | "border" : "1px solid #FFF", | ||
61 | "border-radius": "30px", | ||
62 | "background-color": "#7db9e8", | ||
63 | "background-image": "-webkit-linear-gradient(top, rgba(255,255,255,0.74) 0%,rgba(255,255,255,0) 100%)" | ||
64 | } | ||
65 | }] | ||
66 | }, { | ||
67 | "text": "Text Styles", | ||
68 | "children": [ | ||
69 | { "text": "Italic" }, | ||
70 | { "text": "Text Shadow" }, | ||
71 | { "text": "Text Color" } ] | ||
72 | }, { | ||
73 | "text": "Color Styles", | ||
74 | "children": [ | ||
75 | { "text": "Background Gradient" }, | ||
76 | { "text": "Background Color" }, | ||
77 | { "text": "Text Highlight" } ] | ||
78 | }] | ||
79 | } | ||
80 | }, | ||
81 | |||
82 | _testButtonJson: { | ||
83 | value: { | ||
84 | "component": "button", | ||
85 | |||
86 | "module": "montage/ui/button.reel", | ||
87 | |||
88 | "name": "Button", | ||
89 | |||
90 | "properties": [ | ||
91 | { | ||
92 | "name": "label", | ||
93 | "type": "string", | ||
94 | "default": "Button" | ||
95 | }, | ||
96 | { | ||
97 | "name": "enabled", | ||
98 | "type": "boolean", | ||
99 | "default": "true" | ||
100 | } | ||
101 | ] | ||
102 | } | ||
103 | }, | ||
104 | |||
105 | didCreate: { | ||
106 | value: function() { | ||
107 | |||
108 | this._loadComponents(); | ||
109 | |||
110 | } | ||
17 | }, | 111 | }, |
112 | |||
113 | _loadComponents: { | ||
114 | value: function() { | ||
115 | this.components = [ | ||
116 | {name: "Button", data: "node_modules/components-data/button.json"}, | ||
117 | {name: "Textfield", data: "node_modules/components-data/textfield.json"} | ||
118 | ]; | ||
119 | |||
120 | this.componentsToLoad = this.components.length; | ||
121 | |||
122 | // Build the PI objects for each component | ||
123 | for(var i = 0, component; component = this.components[i]; i++) { | ||
124 | var req = new XMLHttpRequest(); | ||
125 | //req.identifier = "searchRequest"; | ||
126 | req.open("GET", component.data); | ||
127 | req.addEventListener("load", this, false); | ||
128 | req.addEventListener("error", this, false); | ||
129 | req.send(); | ||
130 | |||
131 | } | ||
132 | |||
133 | } | ||
134 | }, | ||
135 | |||
136 | handleLoad: { | ||
137 | value: function(evt) { | ||
138 | var response = JSON.parse(evt.target.responseText); | ||
139 | |||
140 | var component = response.component.capitalizeFirstChar(); | ||
141 | |||
142 | var piIdentifier = component + "Pi"; | ||
143 | var piObj = []; | ||
144 | var section = {}; | ||
145 | |||
146 | |||
147 | section.label = component + " Properties"; | ||
148 | section.Section = []; | ||
149 | |||
150 | for(var j = 0, props; props = response.properties[j]; j++) { | ||
151 | var row = {}; | ||
152 | row.type = this.getControlType(props.type); | ||
153 | row.id = props.name; | ||
154 | row.prop = props.name; | ||
155 | row.defaultValue = props["default"]; | ||
156 | row.label = props.name; | ||
157 | |||
158 | section.Section.push([row]); | ||
159 | } | ||
160 | |||
161 | PIData[piIdentifier] = []; | ||
162 | PIData[piIdentifier].push(section); | ||
163 | |||
164 | this.componentsLoaded++; | ||
165 | |||
166 | if(this.componentsLoaded === this.componentsToLoad) { | ||
167 | console.log("all loaded"); | ||
168 | } | ||
169 | |||
170 | } | ||
171 | }, | ||
172 | |||
173 | getControlType: { | ||
174 | value: function(type) { | ||
175 | switch(type) { | ||
176 | case "string": | ||
177 | return "textbox"; | ||
178 | case "boolean": | ||
179 | return "checkbox"; | ||
180 | default: | ||
181 | alert("Conversion not implemented for ", type); | ||
182 | } | ||
183 | } | ||
184 | }, | ||
185 | |||
18 | prepareForDraw: { | 186 | prepareForDraw: { |
19 | enumerable: false, | 187 | enumerable: false, |
20 | value: function() { | 188 | value: function() { |
189 | |||
21 | var treeHolderDiv = document.getElementById("comp_tree"); | 190 | var treeHolderDiv = document.getElementById("comp_tree"); |
22 | var componentsTree = treeControlModule.Tree.create(); | 191 | var componentsTree = treeControlModule.Tree.create(); |
23 | componentsTree.element = treeHolderDiv; | 192 | componentsTree.element = treeHolderDiv; |
@@ -25,17 +194,6 @@ var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component | |||