Browse Source

Update navigator items

no-jquery
Artur Arseniev 9 years ago
parent
commit
0814047f25
  1. 57
      src/navigator/view/ItemView.js

57
src/navigator/view/ItemView.js

@ -36,29 +36,32 @@ module.exports = Backbone.View.extend({
this.ppfx = this.em.get('Config').stylePrefix;
this.sorter = o.sorter || '';
this.pfx = this.config.stylePrefix;
if(typeof this.model.get('open') == 'undefined')
this.model.set('open',false);
this.listenTo(this.model.get('components'), 'remove add change reset', this.checkChildren);
this.listenTo(this.model, 'destroy remove', this.remove);
this.listenTo(this.model, 'change:status', this.updateStatus);
this.listenTo(this.model, 'change:open', this.updateOpening);
this.className = this.pfx + 'item no-select';
this.editBtnCls = this.pfx + 'nav-item-edit';
this.inputNameCls = this.ppfx + 'nav-comp-name';
this.caretCls = this.ppfx + 'nav-item-caret';
this.titleCls = this.pfx + 'title';
const pfx = this.pfx;
const ppfx = this.ppfx;
const model = this.model;
const components = model.get('components');
model.set('open', false);
this.listenTo(components, 'remove add change reset', this.checkChildren);
this.listenTo(model, 'destroy remove', this.remove);
this.listenTo(model, 'change:status', this.updateStatus);
this.listenTo(model, 'change:open', this.updateOpening);
this.className = `${pfx}item no-select`;
this.editBtnCls = `${pfx}nav-item-edit`;
this.inputNameCls = `${ppfx}nav-comp-name`;
this.caretCls = `${ppfx}nav-item-caret`;
this.titleCls = `${pfx}title`;
this.events = {};
this.events['click #'+this.pfx+'btn-eye'] = 'toggleVisibility';
this.events[`click #${pfx}btn-eye`] = 'toggleVisibility';
this.events['click .' + this.caretCls] = 'toggleOpening';
this.events['click .' + this.titleCls] = 'handleSelect';
this.events['click .' + this.editBtnCls] = 'handleEdit';
this.events['blur .' + this.inputNameCls] = 'handleEditEnd';
this.$el.data('model', this.model);
this.$el.data('collection', this.model.get('components'));
this.$el.data('model', model);
this.$el.data('collection', components);
if(o.config.sortable)
this.events['mousedown #'+this.pfx+'move'] = 'startSort';
this.events['mousedown #'+pfx+'move'] = 'startSort';
this.delegateEvents();
},
@ -102,13 +105,15 @@ module.exports = Backbone.View.extend({
updateOpening() {
var opened = this.opt.opened || {};
var model = this.model;
if(model.get('open')){
this.$el.addClass("open");
this.getCaret().addClass('fa-chevron-down');
const chvDown = 'fa-chevron-down';
if (model.get('open')) {
this.$el.addClass('open');
this.getCaret().addClass(chvDown);
opened[model.cid] = model;
}else{
} else {
this.$el.removeClass("open");
this.getCaret().removeClass('fa-chevron-down');
this.getCaret().removeClass(chvDown);
delete opened[model.cid];
}
},
@ -263,7 +268,7 @@ module.exports = Backbone.View.extend({
getCaret() {
if (!this.caret) {
const pfx = this.pfx;
this.caret = this.$el.find(`.${pfx}title-c > .${pfx}title > .${pfx}title-inn > #${pfx}caret`);
this.caret = this.$el.children(`.${pfx}title-c`).find(`#${pfx}caret`);
}
return this.caret;
@ -292,9 +297,11 @@ module.exports = Backbone.View.extend({
level
}));
if(typeof ItemsView == 'undefined')
ItemsView = require('./ItemsView');
this.$components = new ItemsView({
if (typeof ItemsView == 'undefined') {
ItemsView = require('./ItemsView');
}
const children = new ItemsView({
collection: model.get('components'),
config: this.config,
sorter: this.sorter,
@ -302,7 +309,7 @@ module.exports = Backbone.View.extend({
parent: model,
level
}).render().$el;
el.find(`.${pfx}children`).append(this.$components);
el.find(`.${pfx}children`).append(children);
if(!model.get('draggable') || !this.config.sortable) {
el.children(`#${pfx}move`).remove();

Loading…
Cancel
Save