aboutsummaryrefslogtreecommitdiff
path: root/js/panels/properties/sections/custom.reel/custom.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/properties/sections/custom.reel/custom.js')
-rw-r--r--js/panels/properties/sections/custom.reel/custom.js296
1 files changed, 296 insertions, 0 deletions
diff --git a/js/panels/properties/sections/custom.reel/custom.js b/js/panels/properties/sections/custom.reel/custom.js
new file mode 100644
index 00000000..2b5b522a
--- /dev/null
+++ b/js/panels/properties/sections/custom.reel/custom.js
@@ -0,0 +1,296 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage;
8var Component = require("montage/ui/component").Component;
9
10//Custom Rows
11var SingleRow = require("js/panels/properties/sections/custom-rows/single-row.reel").SingleRow;
12var DualRow = require("js/panels/properties/sections/custom-rows/dual-row.reel").DualRow;
13var ColorSelect = require("js/panels/properties/sections/custom-rows/color-select.reel").ColorSelect;
14
15// Components Needed to make this work
16var Hottext = require("js/components/hottextunit.reel").HotTextUnit;
17var Dropdown = require("js/components/combobox.reel").Combobox;
18var TextField = require("js/components/textfield.reel").TextField;
19var FileInput = require("js/components/ui/file-input.reel").FileInput;
20var Checkbox = require("js/components/checkbox.reel").Checkbox;
21
22
23exports.CustomSection = Montage.create(Component, {
24
25 repeat: {
26 value: null
27 },
28
29 _fields: {
30
31 },
32
33 fields: {
34 get: function() {
35 return this._fields;
36 },
37 set: function(val) {
38 this.controls = {};
39 this.rows = [];
40 this._fields = val;
41 for(var i=0; i < this._fields.length; i++) {
42 var tmpRow, fields;
43 if(this._fields[i].length === 1) {
44 fields = this._fields[i][0];
45 tmpRow = SingleRow.create();
46 tmpRow.content = this.generateObject(fields);
47 if (fields.label) tmpRow.label = fields.label;
48 if (fields.divider) tmpRow.divider = fields.divider;
49 this.rows.push(tmpRow);
50 } else if(this._fields[i].length === 2) {
51
52 var obj1 = this._fields[i][0];
53 var obj2 = this._fields[i][1];
54
55
56 if (obj1.type == "color" && obj2.type == "color") {
57 tmpRow = Montage.create(ColorSelect);
58 if(obj1.visible === false) tmpRow.colorVisible = obj1.visible;
59 if(obj2.visible === false) tmpRow.color2Visible = obj2.visible;
60
61 }
62 else
63 {
64 tmpRow = DualRow.create();
65 if (obj1.label) tmpRow.label = obj1.label;
66 if (obj2.label) tmpRow.label2 = obj2.label;
67 tmpRow.content = this.generateObject(obj1);
68 tmpRow.content2 = this.generateObject(obj2);
69 }
70
71 if (obj1.divider === true || obj2.divider === true) tmpRow.divider = true;
72 this.rows.push(tmpRow);
73
74 } else if(this._fields[i].length === 3) {
75
76 }
77
78 }
79 }
80
81 },
82
83 rows: {
84 value: []
85 },
86
87 controls: {
88 value:{}
89 },
90
91 handleChanging:
92 {
93 value:function(event)
94 {
95 var obj = event.currentTarget;
96 this._dispatchPropEvent({"type": "changing", "id": obj.id, "prop": obj.prop, "value": obj.value, "control": obj});
97 }
98 },
99
100 handleChange: {
101 value:function(event) {
102 if(event._event.wasSetByCode) return;
103
104 var obj = event.currentTarget;
105 this._dispatchPropEvent({"type": "change", "id": obj.id, "prop": obj.prop, "value": obj.value, "control": obj});
106 }
107 },
108
109 _dispatchPropEvent: {
110 value: function(event) {
111// console.log(event);
112 var propEvent = document.createEvent("CustomEvent");
113 if(event.type === "changing")
114 {
115 propEvent.initEvent("propertyChanging", true, true);
116 propEvent.type = "propertyChanging";
117 }
118 else
119 {
120 propEvent.initEvent("propertyChange", true, true);
121 propEvent.type = "propertyChange";
122 }
123
124 propEvent.id = event.id;
125 propEvent.prop = event.prop;
126 propEvent.text = event.text;
127 propEvent.value = event.value;
128
129 event.control.units ? propEvent.units = event.control.units : propEvent.units = "";
130
131 this.dispatchEvent(propEvent);
132 }
133 },
134
135 generateObject: {
136 value: function(fields) {
137 switch(fields.type) {
138 case "hottext" : return this.createHottext(fields);
139 case "dropdown" : return this.createDropdown(fields);
140 case "textbox" : return this.createTextField(fields);
141 case "file" : return this.createFileInput(fields);
142 case "checkbox" : return this.createCheckbox(fields);
143 }
144 }
145 },
146
147 //Breaking Up Switch Case Statement to functions to return a row
148 createHottext: {
149 value: function(aField) {
150
151 // Generate Hottext
152 var obj = Hottext.create();
153
154 // Set Values for HottextRow
155 if (aField.id) obj.id = aField.id;
156 if (aField.value) obj.value = aField.value;
157 if (aField.acceptableUnits) obj.acceptableUnits = aField.acceptableUnits;
158 if (aField.unit) obj.units = aField.unit;
159 if (aField.min) obj._minValue = aField.min;
160 if (aField.max) obj._maxValue = aField.max;
161 if (aField.prop) obj.prop = aField.prop;
162
163 //Initiate onChange Events
164 obj.addEventListener("change", this, false);
165 obj.addEventListener("changing", this, false);
166
167 //Bind object value to controls list so it can be manipulated
168 Object.defineBinding(this.controls, aField.id, {
169 boundObject: obj,
170 boundObjectPropertyPath: "value"
171 });
172
173 return obj;
174 }
175 },
176
177 createDropdown: {
178 value: function(aField) {
179
180 //Generate Dropdown
181 var obj = Dropdown.create();
182
183 // Set Values for Dropdown
184 if (aField.id) obj.id = aField.id;
185 if (aField.prop) obj.prop = aField.prop;
186 if (aField.value) obj.value = aField.value;
187 if (aField.labelField) obj.labelField = aField.labelField;
188 if (aField.labelFunction) obj.labelFunction = aField.labelFunction;
189 if (aField.items) {
190 if(aField.items.boundObject) {
191 obj.items = eval(aField.items.boundObject)[aField.items.boundProperty];
192 } else {
193 obj.items = aField.items;
194 }
195 }
196
197 obj.addEventListener("change", this, false);
198//
199// Object.defineBinding(obj, "value", {
200// boundObject: this.controls,
201// boundObjectPropertyPath: aField.id,
202// oneway: false,
203// boundValueMutator: function(value) {
204// console.log("In the binding ", value);
205// return value;
206// }
207// });
208
209 Object.defineBinding(this.controls, aField.id, {
210 boundObject: obj,
211 boundObjectPropertyPath: "value",
212 oneway: false
213 });
214
215
216 obj.needsDraw = true;
217
218 return obj;
219 }