initial import
[roojs1] / Roo / tree / ColumnNodeUI.js
1 //<Script type="text/javascript">
2 /*
3  * Based on:
4  * Ext JS Library 1.1.1
5  * Copyright(c) 2006-2007, Ext JS, LLC.
6  *
7  * Originally Released Under LGPL - original licence link has changed is not relivant.
8  *
9  * Fork - LGPL
10  * <script type="text/javascript">
11  */
12  
13 /**
14  * Not documented??? - probably should be...
15  */
16
17 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
18     //focus: Roo.emptyFn, // prevent odd scrolling behavior
19     
20     renderElements : function(n, a, targetNode, bulkRender){
21         //consel.log("renderElements?");
22         this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
23
24         var t = n.getOwnerTree();
25         var tid = Pman.Tab.Document_TypesTree.tree.el.id;
26         
27         var cols = t.columns;
28         var bw = t.borderWidth;
29         var c = cols[0];
30         var href = a.href ? a.href : Roo.isGecko ? "" : "#";
31          var cb = typeof a.checked == "boolean";
32         var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
33         var colcls = 'x-t-' + tid + '-c0';
34         var buf = [
35             '<li class="x-tree-node">',
36             
37                 
38                 '<div class="x-tree-node-el ', a.cls,'">',
39                     // extran...
40                     '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
41                 
42                 
43                         '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
44                         '<img src="', this.emptyIcon, '" class="x-tree-ec-icon  " />',
45                         '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
46                            (a.icon ? ' x-tree-node-inline-icon' : ''),
47                            (a.iconCls ? ' '+a.iconCls : ''),
48                            '" unselectable="on" />',
49                         (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + 
50                              (a.checked ? 'checked="checked" />' : ' />')) : ''),
51                              
52                         '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
53                             (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
54                             '<span unselectable="on" qtip="' + tx + '">',
55                              tx,
56                              '</span></a>' ,
57                     '</div>',
58                      '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
59                             (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
60                  ];
61         
62         for(var i = 1, len = cols.length; i < len; i++){
63             c = cols[i];
64             colcls = 'x-t-' + tid + '-c' +i;
65             tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
66             buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
67                         '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
68                       "</div>");
69          }
70          
71          buf.push(
72             '</a>',
73             '<div class="x-clear"></div></div>',
74             '<ul class="x-tree-node-ct" style="display:none;"></ul>',
75             "</li>");
76         
77         if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
78             this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
79                                 n.nextSibling.ui.getEl(), buf.join(""));
80         }else{
81             this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
82         }
83         var el = this.wrap.firstChild;
84         this.elRow = el;
85         this.elNode = el.firstChild;
86         this.ranchor = el.childNodes[1];
87         this.ctNode = this.wrap.childNodes[1];
88         var cs = el.firstChild.childNodes;
89         this.indentNode = cs[0];
90         this.ecNode = cs[1];
91         this.iconNode = cs[2];
92         var index = 3;
93         if(cb){
94             this.checkbox = cs[3];
95             index++;
96         }
97         this.anchor = cs[index];
98         
99         this.textNode = cs[index].firstChild;
100         
101         //el.on("click", this.onClick, this);
102         //el.on("dblclick", this.onDblClick, this);
103         
104         
105        // console.log(this);
106     },
107     initEvents : function(){
108         Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
109         
110             
111         var a = this.ranchor;
112
113         var el = Roo.get(a);
114
115         if(Roo.isOpera){ // opera render bug ignores the CSS
116             el.setStyle("text-decoration", "none");
117         }
118
119         el.on("click", this.onClick, this);
120         el.on("dblclick", this.onDblClick, this);
121         el.on("contextmenu", this.onContextMenu, this);
122         
123     },
124     
125     /*onSelectedChange : function(state){
126         if(state){
127             this.focus();
128             this.addClass("x-tree-selected");
129         }else{
130             //this.blur();
131             this.removeClass("x-tree-selected");
132         }
133     },*/
134     addClass : function(cls){
135         if(this.elRow){
136             Roo.fly(this.elRow).addClass(cls);
137         }
138         
139     },
140     
141     
142     removeClass : function(cls){
143         if(this.elRow){
144             Roo.fly(this.elRow).removeClass(cls);
145         }
146     }
147
148     
149     
150 });