svn commit: samba r7093 - in branches/SAMBA_4_0/swat: . esptest scripting

tridge at samba.org tridge at samba.org
Mon May 30 08:13:34 GMT 2005


Author: tridge
Date: 2005-05-30 08:13:34 +0000 (Mon, 30 May 2005)
New Revision: 7093

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7093

Log:
- added a new Form() ejs object for producing simple forms.

- tidied up the html generation a bit





Modified:
   branches/SAMBA_4_0/swat/esptest/exception.esp
   branches/SAMBA_4_0/swat/esptest/formtest.esp
   branches/SAMBA_4_0/swat/esptest/session.esp
   branches/SAMBA_4_0/swat/esptest/showvars.esp
   branches/SAMBA_4_0/swat/login.esp
   branches/SAMBA_4_0/swat/scripting/common.js


Changeset:
Modified: branches/SAMBA_4_0/swat/esptest/exception.esp
===================================================================
--- branches/SAMBA_4_0/swat/esptest/exception.esp	2005-05-30 06:55:25 UTC (rev 7092)
+++ branches/SAMBA_4_0/swat/esptest/exception.esp	2005-05-30 08:13:34 UTC (rev 7093)
@@ -5,16 +5,10 @@
 <form name="ExceptionTest" method="POST" action="@@request['SCRIPT_NAME']"> 
     <input name="submit" type="submit" value="Generate Exception">
     <input name="submit" type="submit" value="No Exception">
-    <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("/");
-	}
-
 	function TestFunction(arg1, arg2) {
 		 return "OK";
 	}

Modified: branches/SAMBA_4_0/swat/esptest/formtest.esp
===================================================================
--- branches/SAMBA_4_0/swat/esptest/formtest.esp	2005-05-30 06:55:25 UTC (rev 7092)
+++ branches/SAMBA_4_0/swat/esptest/formtest.esp	2005-05-30 08:13:34 UTC (rev 7093)
@@ -1,34 +1,26 @@
 <% page_header("columns", "ESP Form Test"); %>
 
-<form name="FormTest" method="POST" action="@@request['SCRIPT_NAME']"> 
-    firstName: <input name="firstName" type="text" value=""><br>
-    lastName:  <input name="lastName"  type="text" value=""><br>
-    <input name="submit" type="submit" value="OK">
-    <input name="submit" type="submit" value="Cancel"><br>
-</form>
+<%
+var f = Form("FormTest", 2, 2);
+f.element[0].label = "First Name";
+f.element[0].name  = "firstName";
+f.element[1].label = "Last Name";
+f.element[1].name  = "lastName";
+f.submit[0] = "OK";
+f.submit[1] = "Cancel";
 
+display_form(f);
+
 <%
   /* if its a post then the user has filled in the form, so
      report the values 
   */
-  if (request['REQUEST_METHOD'] == "POST") {
-
-  /* if they cancelled then take them back to the list of tests */
-  if (form['submit'] == "Cancel") {
-     redirect("/");
-  }
+  if (form['OK']) {
 %>
-  You chose firstName=@@form['firstName'] lastName=@@form['lastName']
+  You chose firstName=@@form['firstName'] lastName=@@form['lastName']<p>
+  
 <%
-
-   function showArray(name, array) {
-      write("<h3>Array: " + name + "</h3>\n");
-      for (v in array) {
-            write(name + "[" + v + "]=" + array[v] + "<br>\n");
-      }
-   }
-
-   showArray("form",    form);
+   simple_table(form);
   }
 %>
 

Modified: branches/SAMBA_4_0/swat/esptest/session.esp
===================================================================
--- branches/SAMBA_4_0/swat/esptest/session.esp	2005-05-30 06:55:25 UTC (rev 7092)
+++ branches/SAMBA_4_0/swat/esptest/session.esp	2005-05-30 08:13:34 UTC (rev 7093)
@@ -43,18 +43,7 @@
 	}
 }
 
-function showArray(name, array) {
-	write("<h3>Array: " + name + "</h3>\n");
-	if (array == undefined) {
-		write("undefined<br>\n");
-		return;
-	}
-	for (v in array) {
-		write(name + "[" + v + "]=" + array[v] + "<br>\n");
-	}
-}
-
-showArray("session", session);
+simple_table(session);
 write("SessionId=" + request['SESSION_ID'] + "<br>\n");
 %>
 

Modified: branches/SAMBA_4_0/swat/esptest/showvars.esp
===================================================================
--- branches/SAMBA_4_0/swat/esptest/showvars.esp	2005-05-30 06:55:25 UTC (rev 7092)
+++ branches/SAMBA_4_0/swat/esptest/showvars.esp	2005-05-30 08:13:34 UTC (rev 7093)
@@ -8,9 +8,7 @@
       if (array == undefined) {
 	 write("undefined<br>\n");
       } else {
-            for (v in array) {
-	          write(name + "[" + v + "]=" + array[v] + "<br>\n");
-	    }
+	simple_table(array);
       }
    }
 
@@ -23,10 +21,6 @@
    showArray("session", session);
 %>
 
-<form name="Cancel" method="POST" action="/"> 
-    <input name="submit" type="submit" value="Cancel"><br>
-</form>
-
 </ul>
 
 <% page_footer(); %>

Modified: branches/SAMBA_4_0/swat/login.esp
===================================================================
--- branches/SAMBA_4_0/swat/login.esp	2005-05-30 06:55:25 UTC (rev 7092)
+++ branches/SAMBA_4_0/swat/login.esp	2005-05-30 08:13:34 UTC (rev 7093)
@@ -1,12 +1,14 @@
 <% page_header("plain", "SWAT Login"); %>
 
-<form name="login" method="POST" action="@@request.SCRIPT_NAME"> 
-    Username:   <input name="Username"  type="text" value=""><br>
-    Password:  <input name="Password" type="password" value=""><br>
-    <br>
-    <input name="submit" type="submit" value="Login"><br>
-</form>
+<%
+var f = Form("login", 2, 1);
+f.element[0].label = "Username";
+f.element[1].label = "Password";
+f.submit[0] = "Login";
 
+display_form(f);
+%>
+
 <%
 	if (request.REQUEST_METHOD == "POST") {
 		/* for now just authenticate everyone */

Modified: branches/SAMBA_4_0/swat/scripting/common.js
===================================================================
--- branches/SAMBA_4_0/swat/scripting/common.js	2005-05-30 06:55:25 UTC (rev 7092)
+++ branches/SAMBA_4_0/swat/scripting/common.js	2005-05-30 08:13:34 UTC (rev 7093)
@@ -92,3 +92,60 @@
 	}
 	write("</table>\n");
 }
+
+/*
+  create a Form object with the defaults filled in, ready for display_form()
+ */
+function Form(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 = request.REQUEST_URI;
+	f.class = "form";
+	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
+    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');
+	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>");
+		write('<td><input name="' + e.name + '" type="' + 
+		      e.type + '" value="' + e.value + '"></td>\n');
+	}
+	write("</table>\n");
+	for (i in f.submit) {
+		write('<input name="' + f.submit[i] + 
+		      '" type="submit" value="' + f.submit[i] + '">\n');
+	}
+	write("</form>\n");
+}



More information about the samba-cvs mailing list