aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/document/templates/app/main.js2
-rwxr-xr-xjs/panels/components-panel.reel/components-panel.js35
-rwxr-xr-xnode_modules/tools/template/template-creator.js2
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, {
61 var componentRequire = component[data.name]; 61 var componentRequire = component[data.name];
62 var componentInstance = componentRequire.create(); 62 var componentInstance = componentRequire.create();
63 63
64 componentInstance._montage_metadata.label = componentInstance.identifier = data.name; 64 componentInstance.identifier = data.identifier;
65 componentInstance.addEventListener("firstDraw", self, false); 65 componentInstance.addEventListener("firstDraw", self, false);
66 66
67 componentInstance.element = element; 67 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, {
267 } 267 }
268 that = this; 268 that = this;
269 element = this.makeComponent(component.component); 269 element = this.makeComponent(component.component);
270 270 this.application.ninja.currentDocument.model.views.design.iframe.contentWindow.addComponent(element, {
271 this.application.ninja.currentDocument.model.views.design.iframe.contentWindow.addComponent(element, 271 identifier: this.CreateUniqueComponentName(component.name),
272 {name: component.name, path: component.module, firstDraw: {cb: this.componentInstanceOnFirstDraw, ctx: this}}, 272 name: component.name,
273 path: component.module,
274 firstDraw: {cb: this.componentInstanceOnFirstDraw, ctx: this}
275 },
273 function(instance, element) { 276 function(instance, element) {
274 277
275 //var pos = that.getStageCenter(); 278 //var pos = that.getStageCenter();
@@ -289,7 +292,8 @@ exports.ComponentsPanel = Montage.create(Component, {
289 292
290 //that.application.ninja.elementMediator.addElements(element, styles); 293 //that.application.ninja.elementMediator.addElements(element, styles);
291 ElementController.addElement(element, styles); 294 ElementController.addElement(element, styles);
292 }); 295 }
296 );
293 297
294 } 298 }
295 }, 299 },
@@ -388,5 +392,28 @@ exports.ComponentsPanel = Montage.create(Component, {
388 392
389 //return this.centerStage; 393 //return this.centerStage;
390 } 394 }
395 },
396
397 CreateUniqueComponentName: {
398 value: function(name) {
399 for(var i=1; i < 1000; i++) {
400 if(!this.ComponentNameExists(name + i)) {
401 return name + i;
402 }
403 }
404 }
405 },
406
407 ComponentNameExists: {
408 value: function(name) {
409 var filteredList = this.application.ninja.currentDocument.model.mObjects.filter(function(obj){
410 if(name === obj.identifier) return true;
411 });
412 if (filteredList.length > 0) {
413 return true;
414 } else {
415 return false;
416 }
417 }
391 } 418 }
392}); \ No newline at end of file 419}); \ 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
105 105
106 _generateLabelForComponent: {value: function(component, labels) { 106 _generateLabelForComponent: {value: function(component, labels) {
107 var componentInfo = Montage.getInfoForObject(component), 107 var componentInfo = Montage.getInfoForObject(component),
108 componentLabel = componentInfo.label, 108 componentLabel = componentInfo.label || component.identifier,
109 componentName, 109 componentName,
110 index; 110 index;
111 111