]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/ytree/TreeView/HTMLNode.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / ytree / TreeView / HTMLNode.js
1 /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
2
3 /**
4  * This implementation takes either a string or object for the
5  * oData argument.  If is it a string, we will use it for the display
6  * of this node (and it can contain any html code).  If the parameter
7  * is an object, we look for a parameter called "html" that will be
8  * used for this node's display.
9  *
10  * @extends YAHOO.widget.Node
11  * @constructor
12  * @param oData {object} a string or object containing the data that will
13  * be used to render this node
14  * @param oParent {YAHOO.widget.Node} this node's parent node
15  * @param expanded {boolean} the initial expanded/collapsed state
16  * @param hasIcon {boolean} specifies whether or not leaf nodes should
17  * have an icon
18  */
19 YAHOO.widget.HTMLNode = function(oData, oParent, expanded, hasIcon) {
20         if (oParent) { 
21                 this.init(oData, oParent, expanded);
22                 this.initContent(oData, hasIcon);
23         }
24 };
25
26 YAHOO.widget.HTMLNode.prototype = new YAHOO.widget.Node();
27
28 /**
29  * The CSS class for the label href.  Defaults to ygtvlabel, but can be
30  * overridden to provide a custom presentation for a specific node.
31  *
32  * @type string
33  */
34 YAHOO.widget.HTMLNode.prototype.contentStyle = "ygtvhtml";
35
36 /**
37  * The generated id that will contain the data passed in by the implementer.
38  *
39  * @type string
40  */
41 YAHOO.widget.HTMLNode.prototype.contentElId = null;
42
43 /**
44  * The HTML content to use for this node's display
45  *
46  * @type string
47  */
48 YAHOO.widget.HTMLNode.prototype.content = null;
49
50 /**
51  * Sets up the node label
52  *
53  * @param {object} An html string or object containing an html property
54  * @param {boolean} hasIcon determines if the node will be rendered with an
55  * icon or not
56  */
57 YAHOO.widget.HTMLNode.prototype.initContent = function(oData, hasIcon) { 
58         if (typeof oData == "string") {
59                 oData = { html: oData };
60         }
61
62         this.html = oData.html;
63         this.contentElId = "ygtvcontentel" + this.index;
64         this.hasIcon = hasIcon;
65 };
66
67 /**
68  * Returns the outer html element for this node's content
69  *
70  * @return {HTMLElement} the element
71  */
72 YAHOO.widget.HTMLNode.prototype.getContentEl = function() { 
73         return document.getElementById(this.contentElId);
74 };
75
76 // overrides YAHOO.widget.Node
77 YAHOO.widget.HTMLNode.prototype.getNodeHtml = function() { 
78         var sb = new Array();
79
80         sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
81         sb[sb.length] = '<tr>';
82         
83         for (i=0;i<this.depth;++i) {
84                 sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&nbsp;</td>';
85         }
86
87         if (this.hasIcon) {
88                 sb[sb.length] = '<td';
89                 sb[sb.length] = ' id="' + this.getToggleElId() + '"';
90                 sb[sb.length] = ' class="' + this.getStyle() + '"';
91                 sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '">&nbsp;';
92                 if (this.hasChildren(true)) {
93                         sb[sb.length] = ' onmouseover="this.className=';
94                         sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
95                         sb[sb.length] = this.tree.id + '\',' + this.index +  ').getHoverStyle()"';
96                         sb[sb.length] = ' onmouseout="this.className=';
97                         sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
98                         sb[sb.length] = this.tree.id + '\',' + this.index +  ').getStyle()"';
99                 }
100                 sb[sb.length] = '</td>';
101         }
102
103         sb[sb.length] = '<td';
104         sb[sb.length] = ' id="' + this.contentElId + '"';
105         sb[sb.length] = ' class="' + this.contentStyle + '"';
106         sb[sb.length] = ' >';
107         sb[sb.length] = this.html;
108         sb[sb.length] = '</td>';
109         sb[sb.length] = '</tr>';
110         sb[sb.length] = '</table>';
111
112         return sb.join("");
113 };
114