Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / tree / Column.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.tree.Column
17  * @extends Ext.grid.column.Column
18  * 
19  * Provides indentation and folder structure markup for a Tree taking into account
20  * depth and position within the tree hierarchy.
21  * 
22  * @private
23  */
24 Ext.define('Ext.tree.Column', {
25     extend: 'Ext.grid.column.Column',
26     alias: 'widget.treecolumn',
27
28     initComponent: function() {
29         var origRenderer = this.renderer || this.defaultRenderer,
30             origScope    = this.scope || window;
31
32         this.renderer = function(value, metaData, record, rowIdx, colIdx, store, view) {
33             var buf   = [],
34                 format = Ext.String.format,
35                 depth = record.getDepth(),
36                 treePrefix  = Ext.baseCSSPrefix + 'tree-',
37                 elbowPrefix = treePrefix + 'elbow-',
38                 expanderCls = treePrefix + 'expander',
39                 imgText     = '<img src="{1}" class="{0}" />',
40                 checkboxText= '<input type="button" role="checkbox" class="{0}" {1} />',
41                 formattedValue = origRenderer.apply(origScope, arguments),
42                 href = record.get('href'),
43                 target = record.get('hrefTarget'),
44                 cls = record.get('cls');
45
46             while (record) {
47                 if (!record.isRoot() || (record.isRoot() && view.rootVisible)) {
48                     if (record.getDepth() === depth) {
49                         buf.unshift(format(imgText,
50                             treePrefix + 'icon ' + 
51                             treePrefix + 'icon' + (record.get('icon') ? '-inline ' : (record.isLeaf() ? '-leaf ' : '-parent ')) +
52                             (record.get('iconCls') || ''),
53                             record.get('icon') || Ext.BLANK_IMAGE_URL
54                         ));
55                         if (record.get('checked') !== null) {
56                             buf.unshift(format(
57                                 checkboxText,
58                                 (treePrefix + 'checkbox') + (record.get('checked') ? ' ' + treePrefix + 'checkbox-checked' : ''),
59                                 record.get('checked') ? 'aria-checked="true"' : ''
60                             ));
61                             if (record.get('checked')) {
62                                 metaData.tdCls += (' ' + treePrefix + 'checked');
63                             }
64                         }
65                         if (record.isLast()) {
66                             if (record.isExpandable()) {
67                                 buf.unshift(format(imgText, (elbowPrefix + 'end-plus ' + expanderCls), Ext.BLANK_IMAGE_URL));
68                             } else {
69                                 buf.unshift(format(imgText, (elbowPrefix + 'end'), Ext.BLANK_IMAGE_URL));
70                             }
71                             
72                         } else {
73                             if (record.isExpandable()) {
74                                 buf.unshift(format(imgText, (elbowPrefix + 'plus ' + expanderCls), Ext.BLANK_IMAGE_URL));
75                             } else {
76                                 buf.unshift(format(imgText, (treePrefix + 'elbow'), Ext.BLANK_IMAGE_URL));
77                             }
78                         }
79                     } else {
80                         if (record.isLast() || record.getDepth() === 0) {
81                             buf.unshift(format(imgText, (elbowPrefix + 'empty'), Ext.BLANK_IMAGE_URL));
82                         } else if (record.getDepth() !== 0) {
83                             buf.unshift(format(imgText, (elbowPrefix + 'line'), Ext.BLANK_IMAGE_URL));
84                         }                      
85                     }
86                 }
87                 record = record.parentNode;
88             }
89             if (href) {
90                 buf.push('<a href="', href, '" target="', target, '">', formattedValue, '</a>');
91             } else {
92                 buf.push(formattedValue);
93             }
94             if (cls) {
95                 metaData.tdCls += ' ' + cls;
96             }
97             return buf.join('');
98         };
99         this.callParent(arguments);
100     },
101
102     defaultRenderer: function(value) {
103         return value;
104     }
105 });