mirror of
https://github.com/samba-team/samba.git
synced 2025-01-27 14:04:05 +03:00
r8720: split form object out to separate include file, and make it a real
object, with a display() method (This used to be commit c45c4e335ed5da1e2e43ffcb9e8d6c32678faa3c)
This commit is contained in:
parent
66526f5e4a
commit
23924170cc
@ -1,4 +1,6 @@
|
|||||||
<% page_header("columns", "ESP Exception test", "/esptest/menu.js"); %>
|
<% page_header("columns", "ESP Exception test", "/esptest/menu.js");
|
||||||
|
include("/scripting/forms.js");
|
||||||
|
%>
|
||||||
|
|
||||||
<h1>Samba4 exception test</h1>
|
<h1>Samba4 exception test</h1>
|
||||||
|
|
||||||
@ -8,7 +10,7 @@ var f = FormObj("ExceptionTest", 0, 2);
|
|||||||
f.submit[0] = "Generate Exception";
|
f.submit[0] = "Generate Exception";
|
||||||
f.submit[1] = "No Exception";
|
f.submit[1] = "No Exception";
|
||||||
|
|
||||||
display_form(f);
|
f.display();
|
||||||
|
|
||||||
if (request['REQUEST_METHOD'] == "POST") {
|
if (request['REQUEST_METHOD'] == "POST") {
|
||||||
function TestFunction(arg1, arg2) {
|
function TestFunction(arg1, arg2) {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<% page_header("columns", "ESP Form Test", "/esptest/menu.js"); %>
|
<% page_header("columns", "ESP Form Test", "/esptest/menu.js");
|
||||||
|
include("/scripting/forms.js");
|
||||||
|
%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
var f = FormObj("FormTest", 3, 2);
|
var f = FormObj("FormTest", 3, 2);
|
||||||
@ -15,7 +17,7 @@ f.element[2].value = form['Color'];
|
|||||||
f.submit[0] = "OK";
|
f.submit[0] = "OK";
|
||||||
f.submit[1] = "Cancel";
|
f.submit[1] = "Cancel";
|
||||||
|
|
||||||
display_form(f);
|
f.display();
|
||||||
|
|
||||||
<%
|
<%
|
||||||
/* if its a post then the user has filled in the form, so
|
/* if its a post then the user has filled in the form, so
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<% page_header("columns", "ESP loadparm test", "/esptest/menu.js" ); %>
|
<% page_header("columns", "ESP loadparm test", "/esptest/menu.js" );
|
||||||
|
include("/scripting/forms.js");
|
||||||
|
%>
|
||||||
|
|
||||||
<h1>Samba4 loadparm test</h1>
|
<h1>Samba4 loadparm test</h1>
|
||||||
|
|
||||||
@ -10,7 +12,7 @@ f.element[0].label = "Share";
|
|||||||
f.element[1].label = "Parameter";
|
f.element[1].label = "Parameter";
|
||||||
f.submit[0] = "OK";
|
f.submit[0] = "OK";
|
||||||
|
|
||||||
display_form(f);
|
f.display();
|
||||||
|
|
||||||
function stringVar(v) {
|
function stringVar(v) {
|
||||||
var type = typeof(v);
|
var type = typeof(v);
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<% page_header("columns", "ESP session test", "/esptest/menu.js"); %>
|
<% page_header("columns", "ESP session test", "/esptest/menu.js");
|
||||||
|
include("/scripting/forms.js");
|
||||||
|
%>
|
||||||
|
|
||||||
<h1>Samba4 session test</h1>
|
<h1>Samba4 session test</h1>
|
||||||
|
|
||||||
@ -12,7 +14,7 @@ f.submit[1] = "Reset";
|
|||||||
f.submit[2] = "Destroy";
|
f.submit[2] = "Destroy";
|
||||||
f.submit[3] = "Cancel";
|
f.submit[3] = "Cancel";
|
||||||
|
|
||||||
display_form(f);
|
f.display();
|
||||||
|
|
||||||
/* if its a post then the user has filled in the form, so
|
/* if its a post then the user has filled in the form, so
|
||||||
report the values
|
report the values
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<% page_header("columns", "Add a user", "/install/menu.js");
|
<% page_header("columns", "Add a user", "/install/menu.js");
|
||||||
|
|
||||||
|
include("/scripting/forms.js");
|
||||||
libinclude("base.js");
|
libinclude("base.js");
|
||||||
libinclude("provision.js");
|
libinclude("provision.js");
|
||||||
%>
|
%>
|
||||||
@ -34,7 +35,7 @@ if (form['submit'] == "Add" &&
|
|||||||
}
|
}
|
||||||
newuser(form.USERNAME, form.UNIXNAME, form.PASSWORD, writefln);
|
newuser(form.USERNAME, form.UNIXNAME, form.PASSWORD, writefln);
|
||||||
} else {
|
} else {
|
||||||
display_form(f);
|
f.display();
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<% page_header("columns", "Provisioning", "/install/menu.js");
|
<% page_header("columns", "Provisioning", "/install/menu.js");
|
||||||
|
|
||||||
|
include("/scripting/forms.js");
|
||||||
libinclude("base.js");
|
libinclude("base.js");
|
||||||
libinclude("provision.js");
|
libinclude("provision.js");
|
||||||
%>
|
%>
|
||||||
@ -58,7 +59,7 @@ lp.set("realm", subobj.REALM);
|
|||||||
if (form['submit'] == "Provision") {
|
if (form['submit'] == "Provision") {
|
||||||
provision(subobj, writefln);
|
provision(subobj, writefln);
|
||||||
} else {
|
} else {
|
||||||
display_form(f);
|
f.display();
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<% page_header("plain", "SWAT Login", "");
|
<% page_header("plain", "SWAT Login", "");
|
||||||
libinclude("auth.js");
|
libinclude("auth.js");
|
||||||
|
include("/scripting/forms.js");
|
||||||
|
|
||||||
if (request['SESSION_EXPIRED'] == "True") {
|
if (request['SESSION_EXPIRED'] == "True") {
|
||||||
write("<b>Your session has expired - please authenticate again<br /></b>\n");
|
write("<b>Your session has expired - please authenticate again<br /></b>\n");
|
||||||
@ -16,7 +17,7 @@ f.element[2].type = "select";
|
|||||||
f.element[2].list = getDomainList();
|
f.element[2].list = getDomainList();
|
||||||
f.submit[0] = "Login";
|
f.submit[0] = "Login";
|
||||||
|
|
||||||
display_form(f);
|
f.display();
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
|
@ -185,87 +185,3 @@ function multi_table(array, header) {
|
|||||||
write("</table>\n");
|
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) {
|
|
||||||
var i, size = 20;
|
|
||||||
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 = "";
|
|
||||||
}
|
|
||||||
if (strlen(e.value) > size) {
|
|
||||||
size = strlen(e.value) + 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i in f.element) {
|
|
||||||
var e = f.element[i];
|
|
||||||
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 {
|
|
||||||
var sizestr = "";
|
|
||||||
if (e.type == "text" || e.type == "password") {
|
|
||||||
sizestr = sprintf('size="%d"', size);
|
|
||||||
}
|
|
||||||
writef('<td><input name="%s" type="%s" value="%s" %s /></td>\n',
|
|
||||||
e.name, e.type, e.value, sizestr);
|
|
||||||
}
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
93
swat/scripting/forms.js
Normal file
93
swat/scripting/forms.js
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
js functions for forms
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 form_display() {
|
||||||
|
var f = this;
|
||||||
|
var i, size = 20;
|
||||||
|
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 = "";
|
||||||
|
}
|
||||||
|
if (strlen(e.value) > size) {
|
||||||
|
size = strlen(e.value) + 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i in f.element) {
|
||||||
|
var e = f.element[i];
|
||||||
|
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 {
|
||||||
|
var sizestr = "";
|
||||||
|
if (e.type == "text" || e.type == "password") {
|
||||||
|
sizestr = sprintf('size="%d"', size);
|
||||||
|
}
|
||||||
|
writef('<td><input name="%s" type="%s" value="%s" %s /></td>\n',
|
||||||
|
e.name, e.type, e.value, sizestr);
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
create a Form object with the defaults filled in, ready for display()
|
||||||
|
*/
|
||||||
|
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 = "";
|
||||||
|
}
|
||||||
|
f.display = form_display;
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user