]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/ytree/TreeView/TextNode.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / ytree / TreeView / TextNode.js
1 /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
2
3 /**
4  * The default node presentation.  The first parameter should be
5  * either a string that will be used as the node's label, or an object
6  * that has a string propery called label.  By default, the clicking the
7  * label will toggle the expanded/collapsed state of the node.  By
8  * changing the href property of the instance, this behavior can be
9  * changed so that the label will go to the specified href.
10  *
11  * @extends YAHOO.widget.Node
12  * @constructor
13  * @param oData {object} a string or object containing the data that will
14  * be used to render this node
15  * @param oParent {YAHOO.widget.Node} this node's parent node
16  * @param expanded {boolean} the initial expanded/collapsed state
17  */
18 YAHOO.widget.TextNode = function(oData, oParent, expanded) {
19         if (oParent) { 
20                 this.init(oData, oParent, expanded);
21                 this.setUpLabel(oData);
22         }
23 };
24
25 YAHOO.widget.TextNode.prototype = new YAHOO.widget.Node();
26
27 /**
28  * The CSS class for the label href.  Defaults to ygtvlabel, but can be
29  * overridden to provide a custom presentation for a specific node.
30  *
31  * @type string
32  */
33 YAHOO.widget.TextNode.prototype.labelStyle = "ygtvlabel";
34
35 /**
36  * The derived element id of the label for this node
37  *
38  * @type string
39  */
40 YAHOO.widget.TextNode.prototype.labelElId = null;
41
42 /**
43  * The text for the label.  It is assumed that the oData parameter will
44  * either be a string that will be used as the label, or an object that
45  * has a property called "label" that we will use.
46  *
47  * @type string
48  */
49 YAHOO.widget.TextNode.prototype.label = null;
50
51 /**
52  * Sets up the node label
53  * 
54  * @param oData string containing the label, or an object with a label property
55  */
56 YAHOO.widget.TextNode.prototype.setUpLabel = function(oData) { 
57         if (typeof oData == "string") {
58                 oData = { label: oData };
59         }
60         this.label = oData.label;
61         
62         // update the link
63         if (oData.href) {
64                 this.href = oData.href;
65         }
66
67         // set the target
68         if (oData.target) {
69                 this.target = oData.target;
70         }
71
72         this.labelElId = "ygtvlabelel" + this.index;
73 };
74
75 /**
76  * Returns the label element
77  *
78  * @return {object} the element
79  */
80 YAHOO.widget.TextNode.prototype.getLabelEl = function() { 
81         return document.getElementById(this.labelElId);
82 };
83
84 // overrides YAHOO.widget.Node
85 YAHOO.widget.TextNode.prototype.getNodeHtml = function() { 
86         var sb = new Array();
87
88         sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
89         sb[sb.length] = '<tr>';
90         
91         for (i=0;i<this.depth;++i) {
92                 // sb[sb.length] = '<td class="ygtvdepthcell">&nbsp;</td>';
93                 sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&nbsp;</td>';
94         }
95
96         var getNode = 'YAHOO.widget.TreeView.getNode(\'' +
97                                         this.tree.id + '\',' + this.index + ')';
98
99         sb[sb.length] = '<td';
100         // sb[sb.length] = ' onselectstart="return false"';
101         sb[sb.length] = ' id="' + this.getToggleElId() + '"';
102         sb[sb.length] = ' class="' + this.getStyle() + '"';
103         if (this.hasChildren(true)) {
104                 sb[sb.length] = ' onmouseover="this.className=';
105                 sb[sb.length] = getNode + '.getHoverStyle()"';
106                 sb[sb.length] = ' onmouseout="this.className=';
107                 sb[sb.length] = getNode + '.getStyle()"';
108         }
109         sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '">&nbsp;';
110         sb[sb.length] = '</td>';
111         sb[sb.length] = '<td>';
112         sb[sb.length] = '<a';
113         sb[sb.length] = ' id="' + this.labelElId + '"';
114         sb[sb.length] = ' class="' + this.labelStyle + '"';
115 //      sb[sb.length] = ' href="' + this.href + '"';
116         sb[sb.length] = ' href="javascript:set_selected_node(\''+this.tree.id + '\',\''+this.index+'\');'+ this.href +'"';
117         sb[sb.length] = ' target="' + this.target + '"';
118         if (this.hasChildren(true)) {
119                 sb[sb.length] = ' onmouseover="document.getElementById(\'';
120                 sb[sb.length] = this.getToggleElId() + '\').className=';
121                 sb[sb.length] = getNode + '.getHoverStyle()"';
122                 sb[sb.length] = ' onmouseout="document.getElementById(\'';
123                 sb[sb.length] = this.getToggleElId() + '\').className=';
124                 sb[sb.length] = getNode + '.getStyle()"';
125         }
126         sb[sb.length] = ' >';
127         sb[sb.length] = this.label;
128         sb[sb.length] = '</a>';
129         sb[sb.length] = '</td>';
130         sb[sb.length] = '</tr>';
131         sb[sb.length] = '</table>';
132
133         return sb.join("");
134 };
135