Browse Source

Add `ignoreCategories` option to render options in BlockManager module

pull/1730/head
Artur Arseniev 7 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 {Object} [opts={}] Options
* @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
* @example
* // Render all blocks (inside the global collection)
@ -238,7 +239,10 @@ module.exports = () => {
collection: new Blocks(toRender),
categories
},
c
{
...c,
...opts
}
).render().el;
}
@ -247,6 +251,7 @@ module.exports = () => {
blocksView.rendered = 1;
}
blocksView.updateConfig(opts);
blocksView.collection.reset(toRender);
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
* @private
@ -103,19 +110,20 @@ module.exports = require('backbone').View.extend({
* @private
* */
add(model, fragment) {
const { config } = this;
var frag = fragment || null;
var view = new BlockView(
{
model,
attributes: model.get('attributes')
},
this.config
config
);
var rendered = view.render().el;
var category = model.get('category');
// Check for categories
if (category && this.categories) {
if (category && this.categories && !config.ignoreCategories) {
if (isString(category)) {
category = {
id: category,

Loading…
Cancel
Save