TableChunker.html
5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-view-TableChunker'>/**
</span> * Produces optimized XTemplates for chunks of tables to be
* used in grids, trees and other table based widgets.
*/
Ext.define('Ext.view.TableChunker', {
singleton: true,
requires: ['Ext.XTemplate'],
metaTableTpl: [
'{%if (this.openTableWrap)out.push(this.openTableWrap())%}',
'<table class="' + Ext.baseCSSPrefix + 'grid-table ' + Ext.baseCSSPrefix + 'grid-table-resizer" border="0" cellspacing="0" cellpadding="0" {[this.embedFullWidth(values)]}>',
'<tbody>',
'<tr class="' + Ext.baseCSSPrefix + 'grid-header-row">',
'<tpl for="columns">',
'<th class="' + Ext.baseCSSPrefix + 'grid-col-resizer-{id}" style="width: {width}px; height: 0px;"></th>',
'</tpl>',
'</tr>',
'{[this.openRows()]}',
'{row}',
'<tpl for="features">',
'{[this.embedFeature(values, parent, xindex, xcount)]}',
'</tpl>',
'{[this.closeRows()]}',
'</tbody>',
'</table>',
'{%if (this.closeTableWrap)out.push(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(values) {
var result = 'style="width:{fullWidth}px;';
// If there are no records, we need to give the table a height so that it
// is displayed and causes q scrollbar if the width exceeds the View's width.
if (!values.rowCount) {
result += 'height:1px;';
}
return result + '"';
},
openRows: function() {
return '<tpl for="rows">';
},
closeRows: function() {
return '</tpl>';
},
metaRowTpl: [
'<tr class="' + Ext.baseCSSPrefix + 'grid-row {[this.embedRowCls()]}" {[this.embedRowAttr()]}>',
'<tpl for="columns">',
'<td class="{cls} ' + Ext.baseCSSPrefix + 'grid-cell ' + Ext.baseCSSPrefix + 'grid-cell-{columnId} {{id}-modified} {{id}-tdCls} {[this.firstOrLastCls(xindex, xcount)]}" {{id}-tdAttr}>',
'<div {unselectableAttr} class="' + Ext.baseCSSPrefix + 'grid-cell-inner {unselectableCls}" style="text-align: {align}; {{id}-style};">{{id}}</div>',
'</td>',
'</tpl>',
'</tr>'
],
firstOrLastCls: function(xindex, xcount) {
if (xindex === 1) {
return Ext.view.Table.prototype.firstCls;
} else if (xindex === xcount) {
return Ext.view.Table.prototype.lastCls;
}
},
embedRowCls: function() {
return '{rowCls}';
},
embedRowAttr: function() {
return '{rowAttr}';
},
openTableWrap: undefined,
closeTableWrap: undefined,
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,
embedRowAttr: this.embedRowAttr,
firstOrLastCls: this.firstOrLastCls,
unselectableAttr: cfg.enableTextSelection ? '' : 'unselectable="on"',
unselectableCls: cfg.enableTextSelection ? '' : Ext.baseCSSPrefix + 'unselectable'
},
// 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].getFragmentTpl());
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;
}
});
</pre>
</body>
</html>