r9139: cleanup the layout a bit
[kai/samba.git] / swat / scripting / common.js
index 3321cfb77229375c74f8a6a338e6a1f0916f7865..dde40c8e38a469032248b7d79c3c3ec4980c189b 100644 (file)
@@ -8,6 +8,8 @@ global.page = new Object();
 /* fill in some defaults */
 global.page.title = "Samba Web Administration Tool";
 
+libinclude("base.js");
+
 /* to cope with browsers that don't support cookies we append the sessionid
    to the URI */
 global.SESSIONURI = "";
@@ -23,6 +25,22 @@ function session_uri(uri) {
        return uri + global.SESSIONURI;
 }
 
+/*
+  like printf, but to the web page
+*/
+function writef()
+{
+       write(vsprintf(arguments));
+}
+
+/*
+  like writef with a <br>
+*/
+function writefln()
+{
+       write(vsprintf(arguments));
+       write("<br/>\n");
+}
 
 
 /* if the browser was too dumb to set the HOST header, then
@@ -34,9 +52,10 @@ if (headers['HOST'] == undefined) {
 /*
   show the page header. page types include "plain" and "column" 
 */
-function page_header(pagetype, title) {
+function page_header(pagetype, title, menu) {
        global.page.pagetype = pagetype;
        global.page.title = title;
+       global.page.menu = menu;
        include("/scripting/header_" + pagetype + ".esp");
 }
 
@@ -57,8 +76,9 @@ function always_allowed(uri) {
        var allowed = new Array("/images/favicon.ico", 
                                "/images/linkpad.gif",
                                "/images/logo.png",
-                               "/images/logo.gif",
-                               "/style/main.css",
+                               "/images/stripes.png",
+                               "/style/columns.css",
+                               "/style/swat.css",
                                "/style/common.css");
        for (i in allowed) {
                if (allowed[i] == uri) {
@@ -68,47 +88,6 @@ function always_allowed(uri) {
        return false;
 }
 
-/*
-  create a menu object with the defaults filled in, ready for display_menu()
- */
-function MenuObj(name, num_elements)
-{
-       var o = new Object();
-       o.name = name;
-       o.class = "menu";
-       o.style = "simple";
-       o.orientation = "vertical"
-       o.element = new Array(num_elements);
-       for (i in o.element) {
-               o.element[i] = new Object();
-       }
-       return o;
-}
-
-/*
-  display a menu object. Currently only the "simple", "vertical" menu style
-  is supported
-*/
-function display_menu(m) {
-       assert(m.style == "simple" && m.orientation == "vertical");
-       write('<div class="' + m.class + '">\n');
-       write("<i>" + m.name + "</i><br /><ul>\n");
-       for (i = 0; i < m.element.length; i++) {
-               var e = m.element[i];
-               write("<li><a href=\"" + e.link + "\">" + e.label + "</a></li>\n");
-       }
-       write("</ul></div>\n");
-}
-
-function simple_menu() {
-       var m = MenuObj(arguments[0], (arguments.length-1)/2);
-       for (i=0;i<m.element.length;i++) {
-               m.element[i].label = arguments[1+(i*2)];
-               m.element[i].link = arguments[2+(i*2)];
-       }
-       display_menu(m);
-}
-
 /*
   display a table element
 */
@@ -164,76 +143,3 @@ function multi_table(array, header) {
        write("</table>\n");
 }
 
-/*
-  create a Form object with the defaults filled in, ready for display_form()
- */
-function FormObj(name, num_elements, num_submits)
-{
-       var f = new Object();
-       f.name = name;
-       f.element = new Array(num_elements);
-       f.submit =  new Array(num_submits);
-       f.action = session_uri(request.REQUEST_URI);
-       f.class = "defaultform";
-       for (i in f.element) {
-               f.element[i] = new Object();
-               f.element[i].type = "text";
-               f.element[i].value = "";
-       }
-       return f;
-}
-
-/*
-  display a simple form from a ejs Form object
-  caller should fill in
-    f.name          = form name
-    f.action        = action to be taken on submit (optional, defaults to current page)
-    f.class         = css class (optional, defaults to 'form')
-    f.submit        = an array of submit labels
-    f.element[i].label = element label
-    f.element[i].name  = element name (defaults to label)
-    f.element[i].type  = element type (defaults to text)
-    f.element[i].value = current value (optional, defaults to "")
- */
-function display_form(f) {
-       write('<form name="' + f.name +
-             '" method="post" action="' + f.action + 
-             '" class="' + f.class + '">\n');
-       if (f.element.length > 0) {
-               write("<table>\n");
-       }
-       for (i in f.element) {
-               var e = f.element[i];
-               if (e.name == undefined) {
-                       e.name = e.label;
-               }
-               if (e.value == undefined) {
-                       e.value = "";
-               }
-               write("<tr>");
-               write("<td>" + e.label + "</td>");
-               if (e.type == "select") {
-                       write('<td><select name="' + e.name + '">\n');
-                       for (s in e.list) {
-                               if (e.value == e.list[s]) {
-                                       write('<option selected=selected>' + e.list[s] + '</option>\n');
-                               } else {
-                                       write('<option>' + e.list[s] + '</option>\n');
-                               }
-                       }
-                       write('</select></td>\n');
-               } else {
-                       write('<td><input name="' + e.name + '" type="' + 
-                             e.type + '" value="' + e.value + '" /></td>\n');
-               }
-               write("</tr>");
-       }
-       if (f.element.length > 0) {
-               write("</table>\n");
-       }
-       for (i in f.submit) {
-               write('<input name="submit" type="submit" value="' + f.submit[i] + '" />\n');
-       }
-       write("</form>\n");
-}
-