Merge branch 'master' of http://git.roojs.com/roojs1
[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         for(var i = 1, len = cols.length; i < len; i++){
62             c = cols[i];
63             colcls = 'x-t-' + tid + '-c' +i;
64             tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
65             buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
66                         '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
67                       "</div>");
68          }
69          
70          buf.push(
71             '</a>',
72             '<div class="x-clear"></div></div>',
73             '<ul class="x-tree-node-ct" style="display:none;"></ul>',
74             "</li>");
75         
76         if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
77             this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
78                                 n.nextSibling.ui.getEl(), buf.join(""));
79         }else{
80             this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
81         }
82         var el = this.wrap.firstChild;
83         this.elRow = el;
84         this.elNode = el.firstChild;
85         this.ranchor = el.childNodes[1];
86         this.ctNode = this.wrap.childNodes[1];
87         var cs = el.firstChild.childNodes;
88         this.indentNode = cs[0];
89         this.ecNode = cs[1];
90         this.iconNode = cs[2];
91         var index = 3;
92         if(cb){
93             this.checkbox = cs[3];
94             index++;
95         }
96         this.anchor = cs[index];
97         
98         this.textNode = cs[index].firstChild;
99         
100         //el.on("click", this.onClick, this);
101         //el.on("dblclick", this.onDblClick, this);
102         
103         
104        // console.log(this);
105     },
106     initEvents : function(){
107         Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
108         
109             
110         var a = this.ranchor;
111
112         var el = Roo.get(a);
113
114         if(Roo.isOpera){ // opera render bug ignores the CSS
115             el.setStyle("text-decoration", "none");
116         }
117
118         el.on("click", this.onClick, this);
119         el.on("dblclick", this.onDblClick, this);
120         el.on("contextmenu", this.onContextMenu, this);
121         
122     },
123     
124     /*onSelectedChange : function(state){
125         if(state){
126             this.focus();
127             this.addClass("x-tree-selected");
128         }else{
129             //this.blur();
130             this.removeClass("x-tree-selected");
131         }
132     },*/
133     addClass : function(cls){
134         if(this.elRow){
135             Roo.fly(this.elRow).addClass(cls);
136         }
137         
138     },
139     
140     
141     removeClass : function(cls){
142         if(this.elRow){
143             Roo.fly(this.elRow).removeClass(cls);
144         }
145     }
146
147     
148     
149 });