Skip to content

Commit

Permalink
Update custom name in ItemView
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jul 14, 2017
1 parent 501795d commit 6c993d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/dom_components/model/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ module.exports = Backbone.Model.extend({
* */
getName() {
let customName = this.get('custom-name');
let name = this.get('type') || this.get('tagName');
let tag = this.get('tagName');
tag = tag == 'div' ? 'box' : tag;
let name = this.get('type') || tag;
name = name.charAt(0).toUpperCase() + name.slice(1);
return customName || name;
},
Expand Down
14 changes: 7 additions & 7 deletions src/navigator/view/ItemView.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module.exports = Backbone.View.extend({
this.inputNameCls = this.ppfx + 'nav-comp-name';
this.caretCls = this.ppfx + 'nav-item-caret';
this.titleCls = this.pfx + 'title';
this.customNameProp = 'custom-name';
this.events = {};
this.events['click > #'+this.pfx+'btn-eye'] = 'toggleVisibility';
this.events['click .' + this.caretCls] = 'toggleOpening';
Expand Down Expand Up @@ -77,7 +76,7 @@ module.exports = Backbone.View.extend({
e.stopPropagation();
var inputName = this.getInputName();
inputName.readOnly = true;
this.model.set(this.customNameProp, inputName.value);
this.model.set('custom-name', inputName.value);
},

/**
Expand Down Expand Up @@ -255,12 +254,13 @@ module.exports = Backbone.View.extend({
},

render() {
let model = this.model;
var pfx = this.pfx;
var vis = this.isVisible();
var count = this.countChildren(this.model);
var count = this.countChildren(model);

this.$el.html( this.template({
title: this.model.get(this.customNameProp) || this.model.getName(),
title: model.getName(),
addClass: (count ? '' : pfx+'no-chld'),
editBtnCls: this.editBtnCls,
inputNameCls: this.inputNameCls,
Expand All @@ -275,15 +275,15 @@ module.exports = Backbone.View.extend({
if(typeof ItemsView == 'undefined')
ItemsView = require('./ItemsView');
this.$components = new ItemsView({
collection : this.model.components,
collection : model.components,
config: this.config,
sorter: this.sorter,
opened: this.opt.opened,
parent: this.model
parent: model
}).render().$el;
this.$el.find('.'+ pfx +'children').html(this.$components);
this.$caret = this.$el.find('> .' + pfx + 'title-c > .' + pfx + 'title > #' + pfx + 'caret');
if(!this.model.get('draggable') || !this.config.sortable){
if(!model.get('draggable') || !this.config.sortable){
this.$el.find('> #' + pfx + 'move').detach();
}
if(!vis)
Expand Down

0 comments on commit 6c993d7

Please sign in to comment.