diff options
Diffstat (limited to 'js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js')
-rw-r--r-- | js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js | 295 |
1 files changed, 186 insertions, 109 deletions
diff --git a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js index 41afefa5..953c0484 100644 --- a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js +++ b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js | |||
@@ -4,142 +4,219 @@ 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": "Textfield", | ||
35 | "dataFile" : "node_modules/components-data/textfield.json", | ||
36 | "component": "textfield" | ||
37 | } | ||
38 | ] | ||
39 | } | ||
40 | ] | ||
41 | } | ||
17 | }, | 42 | }, |
18 | prepareForDraw: { | 43 | |
19 | enumerable: false, | 44 | componentsData: { |
20 | value: function() { | 45 | value: {} |
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 | }, | 46 | }, |
30 | willDraw: { | ||
31 | enumerable: false, | ||
32 | value: function() { | ||
33 | 47 | ||
34 | } | 48 | componentsToLoad: { |
49 | value: null | ||
35 | }, | 50 | }, |
36 | draw: { | ||
37 | enumerable: false, | ||
38 | value: function() { | ||
39 | 51 | ||
40 | } | 52 | componentsLoaded: { |
53 | value: 0 | ||
41 | }, | 54 | }, |
42 | 55 | ||
43 | _loadXMLDoc: { | 56 | centerStage: { |
44 | value:function(dname) { | 57 | value: null |
45 | if (window.XMLHttpRequest) { | 58 | }, |
46 | xhttp = new XMLHttpRequest(); | 59 | |
60 | didCreate: { | ||
61 | value: function() { | ||
62 | // Loop through the component and load the JSON data for them | ||
63 | this._loadComponents(); | ||
64 | } | ||
65 | }, | ||
66 | |||
67 | // Load all the data files for each component | ||
68 | // TODO: Implement the error case | ||
69 | _loadComponents: { | ||
70 | value: function() { | ||
71 | |||
72 | this.componentsToLoad = this.components.children[0].children.length; | ||
73 | |||
74 | for(var i = 0, component; component = this.components.children[0].children[i]; i++) { | ||
75 | var req = new XMLHttpRequest(); | ||
76 | //req.identifier = "searchRequest"; | ||
77 | req.open("GET", component.dataFile); | ||
78 | req.addEventListener("load", this, false); | ||
79 | req.addEventListener("error", this, false); | ||
80 | req.send(); | ||
47 | } | 81 | } |
48 | xhttp.open("GET", dname, false); | ||
49 | xhttp.send(); | ||
50 | return xhttp.responseXML; | ||
51 | } | 82 | } |
52 | }, | 83 | }, |
53 | 84 | ||
54 | handleExecuteAddComponent: { | 85 | handleLoad: { |
55 | value: function(evt) { | 86 | value: function(evt) { |
56 | this.addComponentToStage(evt.detail.component, evt.detail.dropX, evt.detail.dropY) | 87 | var componentData, component, piID, piObj, section; |
88 | |||
89 | componentData = JSON.parse(evt.target.responseText); | ||
90 | |||
91 | component = componentData.name; | ||
92 | |||
93 | // Build the PI data and create a new object for Ninja PI | ||
94 | piID = component + "Pi"; | ||
95 | piObj = []; | ||
96 | section = {}; | ||
97 | section.label = component + " Properties"; | ||
98 | section.Section = []; | ||
99 | |||
100 | for(var j = 0, props; props = componentData.properties[j]; j++) { | ||
101 | var row = {}; | ||
102 | row.type = this.getControlType(props.type); | ||
103 | row.id = props.name; | ||
104 | row.prop = props.name; | ||
105 | row.defaultValue = props["default"]; | ||
106 | row.label = props.name; | ||
107 | |||
108 | section.Section.push([row]); | ||
109 | } | ||
110 | |||
111 | PIData[piID] = []; | ||
112 | PIData[piID].push(section); | ||
113 | |||
114 | // Setup the component hash object to store references to each component data | ||
115 | this.componentsData[componentData.component] = componentData; | ||
116 | |||
117 | this.componentsLoaded++; | ||
118 | |||
119 | if(this.componentsLoaded === this.componentsToLoad) { | ||
120 | // console.log("all loaded"); | ||
121 | // Here we need to stop some sort of loading animation | ||
122 | } | ||
123 | |||
57 | } | 124 | } |
58 | }, | 125 | }, |
59 | 126 | ||
60 | addComponentToStage:{ | 127 | // PI conversion method. This will convert the property type into a Ninja component |
61 | value:function(componentType, dropX, dropY){ | 128 | getControlType: { |
62 | var compW = 100, | 129 | value: function(type) { |
63 | compH = 100, | 130 | switch(type) { |
64 | elementType = "div", | 131 | case "string": |
65 | componentContainer, | 132 | return "textbox"; |
66 | componentElement; | 133 | case "boolean": |
67 | 134 | return "checkbox"; | |
68 | if(componentType == "Button"){ | 135 | default: |
69 | compW = 118; | 136 | alert("Conversion not implemented for ", type); |
70 | compH = 52; | ||
71 | }else if(componentType == "Checkbox"){ | ||
72 | compW = 53; | ||
73 | compH = 53; | ||
74 | // elementType = "input"; | ||
75 | }else if(componentType == "DynamicText"){ | ||
76 | compW = 100; | ||
77 | compH = 20; | ||
78 | }else if(componentType == "FlowController"){ | ||
79 | compW = 800; | ||
80 | compH = 320; | ||
81 | }else if(componentType == "HotText"){ | ||
82 | compW = 50; | ||
83 | compH = 18; | ||
84 | // elementType = "input"; | ||
85 | }else if(componentType == "HotTextUnit"){ | ||
86 | compW = 45; | ||
87 | compH = 18; | ||
88 | }else if(componentType == "ImageContainer"){ | ||
89 | compW = 285; | ||
90 | compH = 232; | ||
91 | }else if(componentType == "Progress"){ |