Browse Source

Add `is` method in Component

pull/652/head
Artur Arseniev 9 years ago
parent
commit
43bd457524
  1. 12
      src/dom_components/model/Component.js
  2. 32
      src/dom_components/model/ComponentTableRow.js

12
src/dom_components/model/Component.js

@ -169,6 +169,18 @@ module.exports = Backbone.Model.extend(Styleable).extend({
this.init(); 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 * Update attributes of the model

32
src/dom_components/model/ComponentTableRow.js

@ -1,42 +1,36 @@
var Component = require('./Component'); const Component = require('./Component');
module.exports = Component.extend({ module.exports = Component.extend({
defaults: _.extend({}, Component.prototype.defaults, { defaults: { ...Component.prototype.defaults,
type: 'row', type: 'row',
tagName: 'tr', tagName: 'tr',
draggable: ['thead', 'tbody', 'tfoot'],
droppable: ['th', 'td'] droppable: ['th', 'td']
}), },
initialize(o, opt) { initialize(o, opt) {
Component.prototype.initialize.apply(this, arguments); Component.prototype.initialize.apply(this, arguments);
// Clean the row from non cell components // Clean the row from non cell components
var cells = []; const cells = [];
var components = this.get('components'); const components = this.get('components');
components.each(model => { components.each(model => {
if(model.get('type') == 'cell'){ if (model.get('type') == 'cell') {
cells.push(model); cells.push(model);
} }
}); });
components.reset(cells); 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) { isComponent(el) {
var result = ''; let result = '';
if(el.tagName == 'TR'){
result = {type: 'row'}; if (el.tagName == 'TR') {
result = { type: 'row' };
} }
return result; return result;
}, },

Loading…
Cancel
Save