4 * @class Roo.htmleditor.BlockTable
5 * Block that manages a table
9 * @param {Object} config Configuration options
12 Roo.htmleditor.BlockTable = function(cfg)
15 this.readElement(cfg.node);
16 this.updateElement(cfg.node);
21 for(var r = 0; r < this.no_row; r++) {
23 for(var c = 0; c < this.no_col; c++) {
24 this.rows[r][c] = this.emptyCell();
31 Roo.extend(Roo.htmleditor.BlockTable, Roo.htmleditor.Block, {
40 // used by context menu
41 friendly_name : 'Table',
42 deleteTitle : 'Delete Table',
43 // context menu is drawn once..
45 contextMenu : function(toolbar)
48 var block = function() {
49 return Roo.htmleditor.Block.factory(toolbar.tb.selectedNode);
53 var rooui = typeof(Roo.bootstrap) == 'undefined' ? Roo : Roo.bootstrap;
55 var syncValue = toolbar.editorcore.syncValue;
66 triggerAction : 'all',
72 select : function (combo, r, index)
75 b.width = r.get('val');
83 xtype : 'SimpleStore',
97 xns : rooui.Toolbar //Boostrap?
104 click : function (_self, e)
106 block().removeColumn();
116 click : function (_self, e)
128 xns : rooui.Toolbar //Boostrap?
135 click : function (_self, e)
147 click : function (_self, e)
158 text: 'Reset Column Widths',
161 click : function (_self, e)
163 block().resetWidths();
178 * create a DomHelper friendly object - for use with
179 * Roo.DomHelper.markup / overwrite / etc..
180 * ?? should it be called with option to hide all editing features?
182 toObject : function()
187 contenteditable : 'false', // this stops cell selection from picking the table.
188 'data-block' : 'Table',
191 border : 'solid 1px #000', // ??? hard coded?
192 'border-collapse' : 'collapse',
195 { tag : 'tbody' , cn : [] }
199 // do we have a head = not really
201 Roo.each(this.rows, function( row ) {
206 border : 'solid 1px #000',
212 ret.cn[0].cn.push(tr);
213 // does the row have any properties? ?? height?
215 Roo.each(row, function( cell ) {
219 contenteditable : 'true',
224 if (cell.colspan > 1) {
225 td.colspan = cell.colspan ;
230 if (cell.rowspan > 1) {
231 td.rowspan = cell.rowspan ;
240 ncols = Math.max(nc, ncols);
244 // add the header row..
253 readElement : function(node)
255 node = node ? node : this.node ;
256 this.width = this.getVal(node, true, 'style', 'width') || '100%';
260 var trs = Array.from(node.getElementsByTagName('tr'));
261 trs.forEach(function(tr) {
264 if (Roo.get(tr).hasClass('roo-html-editor-el')) { // ??? this is for our 'row' selection'
269 Array.from(tr.getElementsByTagName('td')).forEach(function(td) {
270 if (Roo.get(td).hasClass('roo-html-editor-el')) { // ??? this is for our 'row' selection'
274 colspan : td.hasAttribute('colspan') ? td.getAttribute('colspan') : 1,
275 rowspan : td.hasAttribute('rowspan') ? td.getAttribute('rowspan') : 1,
276 style : td.hasAttribute('style') ? td.getAttribute('style') : '',
279 no_column += add.colspan;
286 this.no_col = Math.max(this.no_col, no_column);
293 normalizeRows: function()
297 this.rows.forEach(function(row) {
300 row = this.normalizeRow(row);
302 row.forEach(function(c) {
303 while (typeof(ret[rid][cid]) != 'undefined') {
306 if (typeof(ret[rid]) == 'undefined') {
316 for(var i = 1 ;i < c.rowspan; i++) {
317 if (typeof(ret[rid+i]) == 'undefined') {
328 normalizeRow: function(row)
331 row.forEach(function(c) {
336 for(var i =0 ;i < c.colspan; i++) {
344 deleteColumn : function(sel)
346 if (!sel || sel.type != 'col') {
349 if (this.no_col < 2) {
353 this.rows.forEach(function(row) {
354 var cols = this.normalizeRow(row);
355 var col = cols[sel.col];
356 if (col.colspan > 1) {
366 removeColumn : function()
372 this.updateElement();
376 addColumn : function()
379 this.rows.forEach(function(row) {
380 row.push(this.emptyCell());
383 this.updateElement();
386 deleteRow : function(sel)
388 if (!sel || sel.type != 'row') {
392 if (this.no_row < 2) {
396 var rows = this.normalizeRows();
399 rows[sel.row].forEach(function(col) {
400 if (col.rowspan > 1) {
403 col.remove = 1; // flage it as removed.
408 this.rows.forEach(function(row) {
410 row.forEach(function(c) {
411 if (typeof(c.remove) == 'undefined') {
416 if (newrow.length > 0) {
425 this.updateElement();
428 removeRow : function()
442 for (var i = 0; i < this.no_col; i++ ) {
444 row.push(this.emptyCell());
448 this.updateElement();
452 // the default cell object... at present...
453 emptyCell : function() {
454 return (new Roo.htmleditor.BlockTd({})).toObject();
459 removeNode : function()
466 resetWidths : function()
468 Array.from(this.node.getElementsByTagName('td')).forEach(function(n) {
469 var nn = Roo.htmleditor.Block.factory(n);