diff options
author | Valerio Virgillito | 2012-06-05 11:32:10 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-06-05 11:32:10 -0700 |
commit | 73a62c95b5635fee903457279f0f5b57f164e0b5 (patch) | |
tree | 2d93494abb9d9d6d446655d7006341336e4b64cc /js/panels/components-panel.reel | |
parent | 7933020ed6261052b01ac29bdb29794a3f2c8c8b (diff) | |
parent | 563935933c191093b8ccd88fd1377775c5641b0d (diff) | |
download | ninja-73a62c95b5635fee903457279f0f5b57f164e0b5.tar.gz |
Merge pull request #266 from mencio/element-model-fixes
components fix: adding a first draw event to components
Diffstat (limited to 'js/panels/components-panel.reel')
-rwxr-xr-x | js/panels/components-panel.reel/components-panel.js | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/js/panels/components-panel.reel/components-panel.js b/js/panels/components-panel.reel/components-panel.js index 5a9d2ca5..0b453c4a 100755 --- a/js/panels/components-panel.reel/components-panel.js +++ b/js/panels/components-panel.reel/components-panel.js | |||
@@ -4,11 +4,11 @@ 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 | ElementController = require("js/controllers/elements/element-controller").ElementController, |
10 | ClassUUID = require("js/components/core/class-uuid").ClassUuid, | 10 | ClassUUID = require("js/components/core/class-uuid").ClassUuid, |
11 | PIData = require("js/data/pi/pi-data").PiData; | 11 | PIData = require("js/data/pi/pi-data").PiData; |
12 | 12 | ||
13 | String.prototype.capitalizeFirstChar = function() { | 13 | String.prototype.capitalizeFirstChar = function() { |
14 | return this.charAt(0).toUpperCase() + this.slice(1); | 14 | return this.charAt(0).toUpperCase() + this.slice(1); |
@@ -273,28 +273,42 @@ exports.ComponentsPanel = Montage.create(Component, { | |||
273 | that = this; | 273 | that = this; |
274 | element = this.makeComponent(component.component); | 274 | element = this.makeComponent(component.component); |
275 | 275 | ||
276 | this.application.ninja.currentDocument.model.views.design.iframe.contentWindow.addComponent(element, {name: component.name, path: component.module}, function(instance, element) { | 276 | this.application.ninja.currentDocument.model.views.design.iframe.contentWindow.addComponent(element, |
277 | {name: component.name, path: component.module, firstDraw: {cb: this.componentInstanceOnFirstDraw, ctx: this}}, | ||
278 | function(instance, element) { | ||
277 | 279 | ||
278 | //var pos = that.getStageCenter(); | 280 | //var pos = that.getStageCenter(); |
279 | 281 | ||
280 | var styles = { | 282 | var styles = { |
281 | 'position': 'absolute', | 283 | 'position': 'absolute', |
282 | 'left' : that.dragPosition[0] + 'px', | 284 | 'left' : that.dragPosition[0] + 'px', |
283 | 'top' : that.dragPosition[1] + 'px' | 285 | 'top' : that.dragPosition[1] + 'px' |
284 | }; | 286 | }; |
285 | 287 | ||
286 | var defaultStyles = component.defaultStyles; | 288 | var defaultStyles = component.defaultStyles; |
287 | if(defaultStyles) { | 289 | if(defaultStyles) { |
288 | for(var n in defaultStyles) { | 290 | for(var n in defaultStyles) { |
289 | styles[n] = defaultStyles[n]; | 291 | styles[n] = defaultStyles[n]; |
292 | } | ||
290 | } | 293 | } |
291 | } | ||
292 | |||
293 | that.application.ninja.currentDocument.model.setComponentInstance(instance, element); | ||
294 | 294 | ||
295 | that.application.ninja.elementMediator.addElements(element, styles); | 295 | // that.application.ninja.currentDocument.model.setComponentInstance(instance, element); |
296 | }); | ||
297 | 296 | ||
297 | //that.application.ninja.elementMediator.addElements(element, styles); | ||
298 | ElementController.addElement(element, styles); | ||
299 | }); | ||
300 | |||
301 | } | ||
302 | }, | ||
303 | |||
304 | componentInstanceOnFirstDraw: { | ||
305 | value: function(instance) { | ||
306 | // Temporary hack until the element model rework goes into place | ||
307 | // TODO: Remove this once we have the element model define property code in place. | ||
308 | if(!instance.element.elementModel) { | ||
309 | this.application.njUtils.makeModelFromElement(instance.element); | ||
310 | } | ||
311 | this.application.ninja.elementMediator.addElements(instance.element); | ||
298 | } | 312 | } |
299 | }, | 313 | }, |
300 | 314 | ||