Browse Source

Separate not categorized blocks

pull/202/head
Artur Arseniev 9 years ago
parent
commit
7ced423e40
  1. 44
      src/block_manager/view/BlocksView.js

44
src/block_manager/view/BlocksView.js

@ -9,7 +9,11 @@ module.exports = Backbone.View.extend({
this.config = config || {}; this.config = config || {};
this.categories = opts.categories || ''; this.categories = opts.categories || '';
this.renderedCategories = []; this.renderedCategories = [];
this.ppfx = this.config.pStylePrefix || ''; var ppfx = this.config.pStylePrefix || '';
this.ppfx = ppfx;
this.noCatClass = `${ppfx}blocks-no-cat`;
this.blockContClass = `${ppfx}blocks-c`;
this.catsClass = `${ppfx}block-categories`;
this.listenTo(this.collection, 'add', this.addTo); this.listenTo(this.collection, 'add', this.addTo);
this.em = this.config.em; this.em = this.config.em;
this.tac = 'test-tac'; this.tac = 'test-tac';
@ -118,11 +122,7 @@ module.exports = Backbone.View.extend({
model: catModel model: catModel
}, this.config).render(); }, this.config).render();
this.renderedCategories[catId] = catView; this.renderedCategories[catId] = catView;
this.getCategoriesEl().appendChild(catView.el);
if(frag)
frag.appendChild(catView.el);
else
this.$el.append(catView.el);
} }
catView.append(rendered); catView.append(rendered);
@ -132,21 +132,45 @@ module.exports = Backbone.View.extend({
if(frag) if(frag)
frag.appendChild(rendered); frag.appendChild(rendered);
else else
this.$el.append(rendered); this.append(rendered);
}, },
getCategoriesEl() {
if (!this.catsEl) {
this.catsEl = this.el.querySelector(`.${this.catsClass}`);
}
return this.catsEl;
},
getBlocksEl() {
if (!this.blocksEl) {
this.blocksEl = this.el.querySelector(`.${this.noCatClass} .${this.blockContClass}`);
}
return this.blocksEl;
},
append(el) {
this.getBlocksEl().appendChild(el);
},
render() { render() {
var ppfx = this.ppfx;
var frag = document.createDocumentFragment(); var frag = document.createDocumentFragment();
this.$el.empty(); this.el.innerHTML = `
<div class="${this.catsClass}"></div>
<div class="${this.noCatClass}">
<div class="${this.blockContClass}"></div>
</div>
`;
this.collection.each(function(model){ this.collection.each(function(model){
this.add(model, frag); this.add(model, frag);
}, this); }, this);
this.$el.append(frag); this.append(frag);
this.$el.addClass(this.ppfx + 'blocks-c'); this.$el.addClass(this.blockContClass + 's');
return this; return this;
}, },

Loading…
Cancel
Save