functional
[nodejsws.git] / lib / layouts.js
1 exports.standard = function () {
2         var lay = "<html><head><?njs header ?></head><body><?njs title ?>";
3         lay += "<table width=\"100%\"><tr><td><?njs menu ?></td></tr>";
4         lay += "<tr valign=\"top\"><td width=\"15%\"><?njs sidebar ?></td><td><?njs body ?></td></tr>";
5         lay += "<tr><td><?njs footer ?></td></tr></table><?njs totalend ?></body></html>";
6         
7         return lay;
8 }
9
10
11 exports.straight = function () {
12         var lay = "<html><head><?njs header ?></head><body><?njs title ?>";
13         lay += "<table width=\"100%\"><tr><td><?njs menu ?></td></tr>";
14         lay += "<tr valign=\"top\"><td width=\"15%\"><?njs sidebar ?></td><td><?njs body ?></td></tr>";
15         lay += "<tr><td><?njs footer ?></td></tr></table><?njs totalend ?></body></html>";
16                 
17         return lay;
18 }
19
20 exports.header = function(request, response, callback) {
21         // this function is the default header builder.
22         response.write("<title>"+global.njsAppName+"</title>");
23         callback(request, response);
24 }
25
26 exports.title = function(request, response, callback) {
27         // this is the default title builder
28         response.write("<h1>"+global.njsAppName+"</h1>");
29         callback(request, response);
30 }
31
32 exports.menu = function(request, response, callback) {
33         // this is the default title builder
34         //response.write("<table><tr><th>Menu</th><td>item 1</td><td>item2</td></tr></table>");
35         if(typeof global.menu != "undefined") {
36                 response.write("<table><tr>");
37                 for(key in global.menu) {
38                         response.write("<td><a href=\""+global.menu[key]+"\">"+key+"</a></td>");
39                         console.log("menu: '%s', '%s'", key, global.menu[key]);
40                 }
41                 response.write("</tr></table>");
42         } else {
43                 response.write("No Menu Defined");
44         }
45         callback(request, response);
46 }
47
48 exports.sidebar = function(request, response, callback) {
49         // this is the default title builder
50         response.write("Sidebar!");
51         callback(request, response);
52 }
53
54 exports.body = function(request, response, callback) {
55         // this is the default title builder
56         response.write("Body!");
57         callback(request, response);
58 }
59
60 exports.footer = function(request, response, callback) {
61         // this is the default title builder
62         if(typeof global.footerText != "undefined") {
63                 response.write(global.footerText);
64         } else {
65                 response.write("<br><br><font size=\"-1\"><i>Copyright PJR.cc</i></font>");
66         }
67         callback(request, response);
68 }
69
70 exports.preResponse = function(request, response, callback) {
71         console.log("in preresponse - doing nothing");
72         callback();
73 }
74
75
76 // global menu management functions
77 exports.addMenu = function(menuname, menulink) {
78         console.log("add menu item, '%s' -> '%s'", menuname, menulink);
79         if(typeof global.menu == "undefined") {
80                 global.menu = new Array();
81                 global.menu[menuname] = menulink;
82         } else {
83                 global.menu[menuname] = menulink;
84         }
85 }
86
87 exports.delMenu = function(menuname) {
88         var t = new Array();
89         for(key in global.menu) {
90                 if(key != menuname) {
91                         t[key] = global.menu[key];
92                 }
93         }
94         global.menu = t;
95 }
96
97 exports.clearMenu = function() {
98         delete global.menu;
99 }
100
101 global.addMenu = exports.addMenu;
102 global.delMenu = exports.delMenu;
103 global.clearMenu = exports.clearMenu;