Browse Source

Add `ignoreCategories` option to render options in BlockManager module

pull/1730/head
Artur Arseniev 8 years ago
parent
commit
0da64c86c4
  1. 7
      src/block_manager/index.js
  2. 12
      src/block_manager/view/BlocksView.js

7
src/block_manager/index.js

@ -207,6 +207,7 @@ module.exports = () => {
* @param {Array} blocks Blocks to render, without the argument will render all global blocks * @param {Array} blocks Blocks to render, without the argument will render all global blocks
* @param {Object} [opts={}] Options * @param {Object} [opts={}] Options
* @param {Boolean} [opts.external] Render blocks in a new container (HTMLElement will be returned) * @param {Boolean} [opts.external] Render blocks in a new container (HTMLElement will be returned)
* @param {Boolean} [opts.ignoreCategories] Render blocks without categories
* @return {HTMLElement} Rendered element * @return {HTMLElement} Rendered element
* @example * @example
* // Render all blocks (inside the global collection) * // Render all blocks (inside the global collection)
@ -238,7 +239,10 @@ module.exports = () => {
collection: new Blocks(toRender), collection: new Blocks(toRender),
categories categories
}, },
c {
...c,
...opts
}
).render().el; ).render().el;
} }
@ -247,6 +251,7 @@ module.exports = () => {
blocksView.rendered = 1; blocksView.rendered = 1;
} }
blocksView.updateConfig(opts);
blocksView.collection.reset(toRender); blocksView.collection.reset(toRender);
return this.getContainer(); return this.getContainer();
} }

12
src/block_manager/view/BlocksView.js

@ -27,6 +27,13 @@ module.exports = require('backbone').View.extend({
} }
}, },
updateConfig(opts = {}) {
this.config = {
...this.config,
...opts
};
},
/** /**
* Get sorter * Get sorter
* @private * @private
@ -103,19 +110,20 @@ module.exports = require('backbone').View.extend({
* @private * @private
* */ * */
add(model, fragment) { add(model, fragment) {
const { config } = this;
var frag = fragment || null; var frag = fragment || null;
var view = new BlockView( var view = new BlockView(
{ {
model, model,
attributes: model.get('attributes') attributes: model.get('attributes')
}, },
this.config config
); );
var rendered = view.render().el; var rendered = view.render().el;
var category = model.get('category'); var category = model.get('category');
// Check for categories // Check for categories
if (category && this.categories) { if (category && this.categories && !config.ignoreCategories) {
if (isString(category)) { if (isString(category)) {
category = { category = {
id: category, id: category,

Loading…
Cancel
Save