diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index 1d5f4362d..62a87075e 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -169,6 +169,18 @@ module.exports = Backbone.Model.extend(Styleable).extend({ this.init(); }, + /** + * Check component's type + * @param {string} type Component type + * @return {Boolean} + * @example + * model.is('image') + * // -> false + */ + is(type) { + return !!this.get('type') == type; + }, + /** * Update attributes of the model diff --git a/src/dom_components/model/ComponentTableRow.js b/src/dom_components/model/ComponentTableRow.js index 958a2949b..0d11141be 100644 --- a/src/dom_components/model/ComponentTableRow.js +++ b/src/dom_components/model/ComponentTableRow.js @@ -1,42 +1,36 @@ -var Component = require('./Component'); +const Component = require('./Component'); module.exports = Component.extend({ - defaults: _.extend({}, Component.prototype.defaults, { + defaults: { ...Component.prototype.defaults, type: 'row', tagName: 'tr', + draggable: ['thead', 'tbody', 'tfoot'], droppable: ['th', 'td'] - }), + }, initialize(o, opt) { Component.prototype.initialize.apply(this, arguments); // Clean the row from non cell components - var cells = []; - var components = this.get('components'); + const cells = []; + const components = this.get('components'); components.each(model => { - if(model.get('type') == 'cell'){ + if (model.get('type') == 'cell') { cells.push(model); } }); components.reset(cells); } -},{ - - /** - * Detect if the passed element is a valid component. - * In case the element is valid an object abstracted - * from the element will be returned - * @param {HTMLElement} - * @return {Object} - * @private - */ +}, { isComponent(el) { - var result = ''; - if(el.tagName == 'TR'){ - result = {type: 'row'}; + let result = ''; + + if (el.tagName == 'TR') { + result = { type: 'row' }; } + return result; },