2 js functions and code common to all pages
5 /* define some global variables for this request */
6 global.page = new Object();
8 /* fill in some defaults */
9 global.page.title = "Samba Web Administration Tool";
12 /* if the browser was too dumb to set the HOST header, then
14 if (headers['HOST'] == undefined) {
15 headers['HOST'] = server['SERVER_HOST'] + ":" + server['SERVER_PORT'];
19 show the page header. page types include "plain" and "column"
21 function page_header(pagetype, title) {
22 global.page.pagetype = pagetype;
23 global.page.title = title;
24 include("/scripting/header_" + pagetype + ".esp");
28 show the page footer, getting the page type from page.pagetype
31 function page_footer() {
32 include("/scripting/footer_" + global.page.pagetype + ".esp");
36 check if a uri is one of the 'always allowed' pages, even when not logged in
37 This allows the login page to use the same style sheets and images
39 function always_allowed(uri) {
40 var allowed = new Array("/images/favicon.ico",
41 "/images/linkpad.gif",
46 if (allowed[i] == uri) {
54 display a simple menu. First argument is menu title, followed by
55 pairs of menu item name and link
57 function simple_menu() {
58 write("<i>" + arguments[0] + "</i><br /><ul>\n");
59 for (i = 1; i < arguments.length; i = i + 2) {
60 write("<li><a href=\"" + arguments[i+1] + "\">" + arguments[i] + "</a></li>\n");
67 display a ejs object as a table
69 function simple_table(v) {
70 write("<table class=\"data\">\n");
72 write("<tr><td>" + r + "</td><td>" + v[r] + "</td></tr>\n");
78 display an array of objects, with the header for each element from the given
81 function multi_table(array, header) {
82 write("<table class=\"data\">\n");
85 write("<tr><th colspan=2>" + v[header] + "</th></tr>\n");
88 write("<tr><td align=left>" + r +
89 "</td><td align=left>" + v[r] + "</td></tr>\n");
97 create a Form object with the defaults filled in, ready for display_form()
99 function Form(name, num_elements, num_submits)
101 var f = new Object();
103 f.element = new Array(num_elements);
104 f.submit = new Array(num_submits);
105 f.action = request.REQUEST_URI;
107 for (i in f.element) {
108 f.element[i] = new Object();
109 f.element[i].type = "text";
110 f.element[i].value = "";
116 display a simple form from a ejs Form object
117 caller should fill in
119 f.action = action to be taken on submit (optional, defaults to current page)
120 f.class = css class (optional, defaults to 'form')
121 f.submit = an array of submit labels
122 f.element[i].label = element label
123 f.element[i].name = element name (defaults to label)
124 f.element[i].type = element type (defaults to text)
125 f.element[i].value = current value (optional, defaults to "")
127 function display_form(f) {
128 write('<form name="' + f.name +
129 '" method="post" action="' + f.action +
130 '" class="' + f.class + '">\n');
132 for (i in f.element) {
133 var e = f.element[i];
134 if (e.name == undefined) {
137 if (e.value == undefined) {
141 write("<td>" + e.label + "</td>");
142 if (e.type == "select") {
143 write('<td><select name="' + e.name + '">\n');
145 if (e.value == e.list[s]) {
146 write('<option selected=selected>' + e.list[s] + '</option>\n');
148 write('<option>' + e.list[s] + '</option>\n');
151 write('</select></td>\n');
153 write('<td><input name="' + e.name + '" type="' +
154 e.type + '" value="' + e.value + '"></td>\n');
158 for (i in f.submit) {
159 write('<input name="submit" type="submit" value="' + f.submit[i] + '">\n');