/**
* @class Ext.grid.TableChunker
*
* Produces optimized XTemplates for chunks of tables to be
* used in grids, trees and other table based widgets.
*
* @singleton
*/
Ext.define('Ext.grid.TableChunker', {
singleton: true,
requires: ['Ext.XTemplate'],
metaTableTpl: [
'{[this.openTableWrap()]}',
'
',
'',
'',
'',
' | ',
'',
'
',
'{[this.openRows()]}',
'{row}',
'',
'{[this.embedFeature(values, parent, xindex, xcount)]}',
'',
'{[this.closeRows()]}',
'',
'
',
'{[this.closeTableWrap()]}'
],
constructor: function() {
Ext.XTemplate.prototype.recurse = function(values, reference) {
return this.apply(reference ? values[reference] : values);
};
},
embedFeature: function(values, parent, x, xcount) {
var tpl = '';
if (!values.disabled) {
tpl = values.getFeatureTpl(values, parent, x, xcount);
}
return tpl;
},
embedFullWidth: function() {
return 'style="width: {fullWidth}px;"';
},
openRows: function() {
return '';
},
closeRows: function() {
return '';
},
metaRowTpl: [
'',
'',
'{{id}} | ',
'',
'
'
],
embedRowCls: function() {
return '{rowCls}';
},
openTableWrap: function() {
return '';
},
closeTableWrap: function() {
return '';
},
getTableTpl: function(cfg, textOnly) {
var tpl,
tableTplMemberFns = {
openRows: this.openRows,
closeRows: this.closeRows,
embedFeature: this.embedFeature,
embedFullWidth: this.embedFullWidth,
openTableWrap: this.openTableWrap,
closeTableWrap: this.closeTableWrap
},
tplMemberFns = {},
features = cfg.features || [],
ln = features.length,
i = 0,
memberFns = {
embedRowCls: this.embedRowCls
},
// copy the default
metaRowTpl = Array.prototype.slice.call(this.metaRowTpl, 0),
metaTableTpl;
for (; i < ln; i++) {
if (!features[i].disabled) {
features[i].mutateMetaRowTpl(metaRowTpl);
Ext.apply(memberFns, features[i].getMetaRowTplFragments());
Ext.apply(tplMemberFns, features[i].getTplFragments());
Ext.apply(tableTplMemberFns, features[i].getTableFragments());
}
}
metaRowTpl = new Ext.XTemplate(metaRowTpl.join(''), memberFns);
cfg.row = metaRowTpl.applyTemplate(cfg);
metaTableTpl = new Ext.XTemplate(this.metaTableTpl.join(''), tableTplMemberFns);
tpl = metaTableTpl.applyTemplate(cfg);
// TODO: Investigate eliminating.
if (!textOnly) {
tpl = new Ext.XTemplate(tpl, tplMemberFns);
}
return tpl;
}
});