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 --- js/document/templates/app/main.js | 2 +- .../components-panel.reel/components-panel.js | 35 +++++++++++++++++++--- node_modules/tools/template/template-creator.js | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/js/document/templates/app/main.js b/js/document/templates/app/main.js index 7737ae4c..0da1b87e 100644 --- a/js/document/templates/app/main.js +++ b/js/document/templates/app/main.js @@ -61,7 +61,7 @@ exports.Main = Montage.create(Component, { var componentRequire = component[data.name]; var componentInstance = componentRequire.create(); - componentInstance._montage_metadata.label = componentInstance.identifier = data.name; + componentInstance.identifier = data.identifier; componentInstance.addEventListener("firstDraw", self, false); componentInstance.element = element; 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 diff --git a/node_modules/tools/template/template-creator.js b/node_modules/tools/template/template-creator.js index 646c4171..7cc66093 100755 --- a/node_modules/tools/template/template-creator.js +++ b/node_modules/tools/template/template-creator.js @@ -105,7 +105,7 @@ var TemplateCreator = exports.TemplateCreator = Montage.create(Template, /** @le _generateLabelForComponent: {value: function(component, labels) { var componentInfo = Montage.getInfoForObject(component), - componentLabel = componentInfo.label, + componentLabel = componentInfo.label || component.identifier, componentName, index; -- cgit v1.2.3