r7092: added some js for formatting table results in a nicer fashion
authorAndrew Tridgell <tridge@samba.org>
Mon, 30 May 2005 06:55:25 +0000 (06:55 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:17:15 +0000 (13:17 -0500)
(This used to be commit 5f91db4d60a5b5b03b1b14d1348f9db6807ab18b)

swat/esptest/ldb.esp
swat/scripting/common.js
swat/style/main.css

index 1bc75bce73063862e6043ed5768f43c395deb02b..385a8918c6ae5176d6f1b51af3fef84ad4ce16bd 100644 (file)
@@ -2,60 +2,26 @@
 
 <h1>Samba4 ldb test</h1>
 
-<form name="LdbTest" method="post" action="@@request['SCRIPT_NAME']"> 
-    <input name="submit" type="submit" value="Cancel" /><br />
-</form>
-
-<%
-if (request['REQUEST_METHOD'] == "POST") {
-       /* if they cancelled then take them back to the list of tests */
-       if (form['submit'] == "Cancel") {
-               redirect("/");
-       }
-}
-
-/*
-  hmm, this gets fairly involved ...
-*/
-function showLdbRes(res) {
-       for (i in res) {
-               var r = res[i];
-               for (j in r) {
-                       var a = r[j];
-                       if (typeof(a) == "object") {
-                               for (k in a) {
-                                       write(j + "[" + k + "]=" + a[k] + "<br />\n");
-                               }
-                       } else {
-                               write(j + "=" + r[j] + "<br />\n");
-                       }
-               }
-               write("<p>");
-       }
-}
-
-%>
-
-Trying a attribute constrained search on samdb:<p>
+<h3>An attribute constrained search</h3>
 
 <%
 var dbfile = lpGet("sam database");
 var attrs = new Array("name", "dnsDomain", "objectSid", "dn");
 
 res = ldbSearch(dbfile, "(objectClass=domain)", attrs);
-showLdbRes(res);
+multi_table(res, "dn");
 %>
 
-and now an unconstrained search:<p>
+<h3>An unconstrained search</h3>
 
 <%
 var dbfile = lpGet("sam database");
 
 res = ldbSearch(dbfile, "(objectClass=user)");
-showLdbRes(res);
+multi_table(res, "dn");
 %>
 
-and a bad search<br>
+<h3>A search with bad arguments</h3>
 
 <%
 res = ldbSearch("foo");
index 34f5a958dacd7589f22a9cf258ce32bf91ab1ae9..cc3ca55468130dc73902d18d5dc8a2f270491d06 100644 (file)
@@ -61,3 +61,34 @@ function simple_menu() {
        }
        write("</ul>\n");
 }
+
+
+/*
+  display a ejs object as a table
+*/
+function simple_table(v) {
+       write("<table class=\"data\">\n");
+       for (r in v) {
+               write("<tr><td>" + r + "</td><td>" + v[r] + "</td></tr>\n");
+       }
+       write("</table>\n");
+}
+
+/*
+  display an array of objects, with the header for each element from the given 
+  attribute
+*/
+function multi_table(array, header) {
+       write("<table class=\"data\">\n");
+       for (i in array) {
+               var v = array[i];
+               write("<tr><th colspan=2>" + v[header] + "</th></tr>\n");
+               for (r in v) {
+                       if (r != header) {
+                               write("<tr><td align=left>" + r + 
+                                     "</td><td align=left>" + v[r] + "</td></tr>\n");
+                       }
+               }
+       }
+       write("</table>\n");
+}
index 15f768d186771d90ba8309d738ed50fa26b5853c..791a89d9e09013b1e78de1a8d77794799eb0bdb5 100644 (file)
     text-align:center;
     margin:10px 0 25px 0;
 }
+
+/*
+       styles for data tables
+*/
+table.data {
+          border: 2px;
+}
+table.data th {
+       margin-top:20px;
+       text-align:left;
+        background-color: #F5C915;
+}
+table.data tr {
+        background-color: #E5C995;
+       text-align:left;
+}