Skip to content

Commit 98e1610

Browse files
committed
Initial commit of the Panel class.
1 parent 1009743 commit 98e1610

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

src/panel/Panel.js

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
if(!javaxt) var javaxt={};
2+
if(!javaxt.dhtml) javaxt.dhtml={};
3+
4+
//******************************************************************************
5+
//** Panel
6+
//******************************************************************************
7+
/**
8+
* General purpose container with an optional header, toolbar, and footer.
9+
*
10+
******************************************************************************/
11+
12+
13+
javaxt.dhtml.Panel = function (parent, config) {
14+
15+
var me = this;
16+
var defaultConfig = {
17+
18+
/** CSS class name for the container.
19+
*/
20+
className: null,
21+
22+
/** Style for individual elements within the component. Note that you can
23+
* provide CSS class names instead of individual style definitions.
24+
*/
25+
style: {
26+
header: {},
27+
toolbar: {},
28+
body: {},
29+
footer: {}
30+
}
31+
};
32+
33+
var table, header, toolbar, body, footer;
34+
35+
36+
//**************************************************************************
37+
//** Constructor
38+
//**************************************************************************
39+
var init = function(){
40+
41+
if (typeof parent === "string"){
42+
parent = document.getElementById(parent);
43+
}
44+
if (!parent) return;
45+
46+
47+
//Clone the config so we don't modify the original config object
48+
var clone = {};
49+
merge(clone, config);
50+
51+
52+
//Merge clone with default config
53+
merge(clone, defaultConfig);
54+
config = clone;
55+
56+
57+
//Create main div
58+
var mainDiv = createElement("div", parent, {
59+
width: "100%",
60+
height: "100%",
61+
position: "relative"
62+
});
63+
mainDiv.className = "javaxt-panel";
64+
if (config.className) mainDiv.className += " " + config.className;
65+
66+
me.el = mainDiv;
67+
addShowHide(me);
68+
69+
70+
//Create body
71+
table = createTable(mainDiv);
72+
body = table.addRow().addColumn(config.style.body);
73+
body.style.height = "100%";
74+
};
75+
76+
77+
//**************************************************************************
78+
//** getHeader
79+
//**************************************************************************
80+
/** Returns the header element.
81+
*/
82+
this.getHeader = function(){
83+
if (!header){
84+
85+
var tr = createElement("tr");
86+
if (toolbar){
87+
var tbody = toolbar.parentNode.parentNode;
88+
tbody.insertBefore(tr, toolbar.parentNode);
89+
}
90+
else{
91+
var tbody = body.parentNode.parentNode;
92+
tbody.insertBefore(tr, body.parentNode);
93+
}
94+
95+
96+
header = createElement("td", tr, config.style.header);
97+
}
98+
return header;
99+
};
100+
101+
102+
//**************************************************************************
103+
//** getToolbar
104+
//**************************************************************************
105+
/** Returns the toolbar element.
106+
*/
107+
this.getToolbar = function(){
108+
if (!toolbar){
109+
var tr = createElement("tr");
110+
var tbody = body.parentNode.parentNode;
111+
tbody.insertBefore(tr, body.parentNode);
112+
toolbar = createElement("td", tr, config.style.toolbar);
113+
}
114+
return toolbar;
115+
};
116+
117+
118+
//**************************************************************************
119+
//** getBody
120+
//**************************************************************************
121+
/** Returns the body element.
122+
*/
123+
this.getBody = function(){
124+
return body;
125+
};
126+
127+
128+
//**************************************************************************
129+
//** getFooter
130+
//**************************************************************************
131+
/** Returns the footer element.
132+
*/
133+
this.getFooter = function(){
134+
if (!footer){
135+
footer = table.addRow().addColumn(config.style.footer);
136+
}
137+
return footer;
138+
};
139+
140+
141+
//**************************************************************************
142+
//** Utils
143+
//**************************************************************************
144+
var createElement = javaxt.dhtml.utils.createElement;
145+
var createTable = javaxt.dhtml.utils.createTable;
146+
var addShowHide = javaxt.dhtml.utils.addShowHide;
147+
var merge = javaxt.dhtml.utils.merge;
148+
149+
init();
150+
};

0 commit comments

Comments
 (0)