aboutsummaryrefslogtreecommitdiff
path: root/js/panels/properties.reel/sections/custom.reel/custom.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-03-02 12:24:33 -0800
committerPushkar Joshi2012-03-02 12:24:33 -0800
commit4419209a1fd850ab468209b562b66b0242b42a9c (patch)
treebd7ca04f963f5a3aeb4b3c06db6f187903307d45 /js/panels/properties.reel/sections/custom.reel/custom.js
parent1b68bb87c458877cb850a96d8a093d6064bc41dc (diff)
parentff0a956f33df034e9a009cfcb8999e469456a4b5 (diff)
downloadninja-4419209a1fd850ab468209b562b66b0242b42a9c.tar.gz
Merge branch 'master' into brushtool
Diffstat (limited to 'js/panels/properties.reel/sections/custom.reel/custom.js')
-rwxr-xr-xjs/panels/properties.reel/sections/custom.reel/custom.js356
1 files changed, 356 insertions, 0 deletions
diff --git a/js/panels/properties.reel/sections/custom.reel/custom.js b/js/panels/properties.reel/sections/custom.reel/custom.js
new file mode 100755
index 00000000..3c595980
--- /dev/null
+++ b/js/panels/properties.reel/sections/custom.reel/custom.js
@@ -0,0 +1,356 @@
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;
9var ElementsMediator = require("js/mediators/element-mediator").ElementMediator;
10
11//Custom Rows
12var SingleRow = require("js/panels/properties.reel/sections/custom-rows/single-row.reel").SingleRow;
13var DualRow = require("js/panels/properties.reel/sections/custom-rows/dual-row.reel").DualRow;
14var ColorSelect = require("js/panels/properties.reel/sections/custom-rows/color-select.reel").ColorSelect;
15
16// Components Needed to make this work
17var Hottext = require("js/components/hottextunit.reel").HotTextUnit;
18var Dropdown = require("js/components/combobox.reel").Combobox;
19var TextField = require("js/components/textfield.reel").TextField;
20var FileInput = require("js/components/ui/file-input.reel").FileInput;
21var Checkbox = require("js/components/checkbox.reel").Checkbox;
22var ColorChip = require("js/components/ui/color-chip.reel").ColorChip;
23
24exports.CustomSection = Montage.create(Component, {
25
26 repeat: {
27 value: null
28 },
29
30 _fields: {
31
32 },
33
34 fields: {
35 get: function() {
36 return this._fields;
37 },
38 set: function(val) {
39 this.controls = {};
40 this.rows = [];
41 this._fields = val;
42 for(var i=0; i < this._fields.length; i++) {
43 var tmpRow, fields;
44 if(this._fields[i].length === 1) {
45 fields = this._fields[i][0];
46 tmpRow = SingleRow.create();
47 tmpRow.content = this.generateObject(fields);
48 if (fields.label) tmpRow.label = fields.label;
49 if (fields.divider) tmpRow.divider = fields.divider;
50 this.rows.push(tmpRow);
51 } else if(this._fields[i].length === 2) {
52
53 var obj1 = this._fields[i][0];
54 var obj2 = this._fields[i][1];
55
56
57 if (obj1.type == "color" && obj2.type == "color") {
58 tmpRow = Montage.create(ColorSelect);
59 if(obj1.visible === false) tmpRow.colorVisible = obj1.visible;
60 if(obj2.visible === false) tmpRow.color2Visible = obj2.visible;
61
62 // TODO - Hack for now to reference the color select object to unregister color chips
63 this.controls["colorSelect"] = tmpRow;
64 }
65 else
66 {
67 tmpRow = DualRow.create();
68 if (obj1.label) tmpRow.label = obj1.label;
69 if (obj2.label) tmpRow.label2 = obj2.label;
70 tmpRow.content = this.generateObject(obj1);
71 tmpRow.content2 = this.generateObject(obj2);
72 }
73
74 if (obj1.divider === true || obj2.divider === true) tmpRow.divider = true;
75 this.rows.push(tmpRow);
76
77 } else if(this._fields[i].length === 3) {
78
79 }
80
81 }
82 }
83
84 },
85
86 rows: {
87 value: []
88 },
89
90 controls: {
91 value:{}
92 },
93
94 handleChanging: {
95 value:function(event) {
96 var obj = event.currentTarget;
97 this._dispatchPropEvent({"type": "changing", "id": obj.id, "prop": obj.prop, "value": obj.value, "control": obj});
98 }
99 },
100
101 handleChange: {
102 value:function(event) {
103 if(event._event.wasSetByCode) return;
104
105 var obj = event.currentTarget;
106 this._dispatchPropEvent({"type": "change", "id": obj.id, "prop": obj.prop, "value": obj.value, "control": obj});
107 }
108 },
109
110 /**
111 * Color change handler. Hard coding the stage for now since only the stage PI uses this color chip
112 */
113 handleColorChange: {
114 value: function(event) {
115 // Change the stage color for now
116 //console.log(this, event);
117 ElementsMediator.setProperty([this.application.ninja.currentDocument.documentRoot], this.id, [event._event.color.css], "Change", "pi", '');
118 /*
119 var propEvent = document.createEvent("CustomEvent");
120 propEvent.initEvent("propertyChange", true, true);
121 propEvent.type = "propertyChange";
122
123 propEvent.prop = "background";//event.prop;
124 propEvent.value = event._event.color.css;
125
126 this.dispatchEvent(propEvent);
127 */
128 }
129 },
130
131 _dispatchPropEvent: {
132 value: function(event) {
133// console.log(event);
134 var propEvent = document.createEvent("CustomEvent");
135 if(event.type === "changing")
136 {
137 propEvent.initEvent("propertyChanging", true, true);
138 propEvent.type = "propertyChanging";
139 }
140 else
141 {
142 propEvent.initEvent("propertyChange", true, true);
143 propEvent.type = "propertyChange";
144 }
145
146 propEvent.id = event.id;
147 propEvent.prop = event.prop;
148 propEvent.text = event.text;
149 propEvent.value = event.value;
150
151 event.control.units ? propEvent.units = event.control.units : propEvent.units = "";
152
153 this.dispatchEvent(propEvent);
154 }
155 },
156
157 generateObject: {
158 value: function(fields) {
159 switch(fields.type) {
160 case "hottext" : return this.createHottext(fields);
161 case "dropdown" : return this.createDropdown(fields);
162 case "textbox" : return this.createTextField(fields);
163 case "file" : return this.createFileInput(fields);
164 case "checkbox" : return this.createCheckbox(fields);
165 case "chip" : return this.createColorChip(fields);
166 }
167 }
168 },
169
170 //Breaking Up Switch Case Statement to functions to return a row
171 createHottext: {
172 value: function(aField) {
173
174 // Generate Hottext
175 var obj = Hottext.create();
176
177 // Set Values for HottextRow
178 if (aField.id) obj.id = aField.id;
179 if (aField.value) obj.value = aField.value;
180 if (aField.acceptableUnits) obj.acceptableUnits = aField.acceptableUnits;
181 if (aField.unit) obj.units = aField.unit;
182 if (aField.min) obj._minValue = aField.min;
183 if (aField.max) obj._maxValue = aField.max;
184 if (aField.prop) obj.prop = aField.prop;
185
186 //Initiate onChange Events
187 obj.addEventListener("change", this, false);
188 obj.addEventListener("changing", this, false);
189
190 //Bind object value to controls list so it can be manipulated
191 Object.defineBinding(this.controls, aField.id, {
192 boundObject: obj,
193 boundObjectPropertyPath: "value"
194 });
195
196 return obj;
197 }
198 },
199
200 createDropdown: {
201 value: function(aField) {
202
203 //Generate Dropdown
204 var obj = Dropdown.create();
205
206 // Set Values for Dropdown