From b73e0aa2cffa3ffd2b574645f6ec88dc34726caa Mon Sep 17 00:00:00 2001 From: Armen Kesablyan Date: Mon, 25 Jun 2012 14:05:38 -0700 Subject: Can bind Multiple instance Signed-off-by: Armen Kesablyan --- .../components-panel.reel/components-panel.js | 35 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'js/panels/components-panel.reel/components-panel.js') diff --git a/js/panels/components-panel.reel/components-panel.js b/js/panels/components-panel.reel/components-panel.js index a57c9efc..ab033433 100755 --- a/js/panels/components-panel.reel/components-panel.js +++ b/js/panels/components-panel.reel/components-panel.js @@ -267,9 +267,12 @@ exports.ComponentsPanel = Montage.create(Component, { } that = this; element = this.makeComponent(component.component); - - this.application.ninja.currentDocument.model.views.design.iframe.contentWindow.addComponent(element, - {name: component.name, path: component.module, firstDraw: {cb: this.componentInstanceOnFirstDraw, ctx: this}}, + this.application.ninja.currentDocument.model.views.design.iframe.contentWindow.addComponent(element, { + identifier: this.CreateUniqueComponentName(component.name), + name: component.name, + path: component.module, + firstDraw: {cb: this.componentInstanceOnFirstDraw, ctx: this} + }, function(instance, element) { //var pos = that.getStageCenter(); @@ -289,7 +292,8 @@ exports.ComponentsPanel = Montage.create(Component, { //that.application.ninja.elementMediator.addElements(element, styles); ElementController.addElement(element, styles); - }); + } + ); } }, @@ -388,5 +392,28 @@ exports.ComponentsPanel = Montage.create(Component, { //return this.centerStage; } + }, + + CreateUniqueComponentName: { + value: function(name) { + for(var i=1; i < 1000; i++) { + if(!this.ComponentNameExists(name + i)) { + return name + i; + } + } + } + }, + + ComponentNameExists: { + value: function(name) { + var filteredList = this.application.ninja.currentDocument.model.mObjects.filter(function(obj){ + if(name === obj.identifier) return true; + }); + if (filteredList.length > 0) { + return true; + } else { + return false; + } + } } }); \ No newline at end of file -- cgit v1.2.3