Browse Source

Listen BlocksView reset

no-jquery^2
Artur Arseniev 9 years ago
parent
commit
074b7bc7e4
  1. 11
      src/block_manager/index.js
  2. 12
      src/block_manager/view/BlocksView.js

11
src/block_manager/index.js

@ -198,14 +198,21 @@ module.exports = () => {
* @param {Array} blocks Blocks to render, without the argument will render * @param {Array} blocks Blocks to render, without the argument will render
* all global blocks * all global blocks
* @example * @example
* // Render all blocks * // Render all blocks (inside the global collection)
* blockManager.render(); * blockManager.render();
* *
* // Render some blocks * // Render new set of blocks
* const blocks = blockManager.getAll(); * const blocks = blockManager.getAll();
* blockManager.render(blocks.filter( * blockManager.render(blocks.filter(
* block => block.get('category') == 'sections' * block => block.get('category') == 'sections'
* )); * ));
* // Or a new set from an array
* blockManager.render([
* {label: 'Label text', content: '<div>Content</div>'}
* ]);
*
* // Back to blocks from the global collection
* blockManager.render();
*/ */
render(blocks) { render(blocks) {
const toRender = blocks || this.getAll().models; const toRender = blocks || this.getAll().models;

12
src/block_manager/view/BlocksView.js

@ -14,7 +14,9 @@ module.exports = Backbone.View.extend({
this.noCatClass = `${ppfx}blocks-no-cat`; this.noCatClass = `${ppfx}blocks-no-cat`;
this.blockContClass = `${ppfx}blocks-c`; this.blockContClass = `${ppfx}blocks-c`;
this.catsClass = `${ppfx}block-categories`; this.catsClass = `${ppfx}block-categories`;
this.listenTo(this.collection, 'add', this.addTo); const coll = this.collection;
this.listenTo(coll, 'add', this.addTo);
this.listenTo(coll, 'reset', this.render);
this.em = this.config.em; this.em = this.config.em;
this.tac = 'test-tac'; this.tac = 'test-tac';
this.grabbingCls = this.ppfx + 'grabbing'; this.grabbingCls = this.ppfx + 'grabbing';
@ -167,8 +169,7 @@ module.exports = Backbone.View.extend({
}, },
render() { render() {
var ppfx = this.ppfx; const frag = document.createDocumentFragment();
var frag = document.createDocumentFragment();
this.catsEl = null; this.catsEl = null;
this.blocksEl = null; this.blocksEl = null;
this.renderedCategories = []; this.renderedCategories = [];
@ -179,10 +180,7 @@ module.exports = Backbone.View.extend({
</div> </div>
`; `;
this.collection.each(function(model){ this.collection.each(model => this.add(model, frag));
this.add(model, frag);
}, this);
this.append(frag); this.append(frag);
this.$el.addClass(this.blockContClass + 's') this.$el.addClass(this.blockContClass + 's')
return this; return this;

Loading…
Cancel
Save