summaryrefslogtreecommitdiff
path: root/swat/scripting
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-05-30 08:13:34 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:17:15 -0500
commit0f7314ea019a42e202346fc429330f1e8dfa9b7d (patch)
tree2b799a07ac270fb01b23e5c6c47a1c1d8d193d39 /swat/scripting
parent3f4f393c98e7bc3b2853c699a67a9f5fc2e7d20a (diff)
downloadsamba-0f7314ea019a42e202346fc429330f1e8dfa9b7d.tar.gz
samba-0f7314ea019a42e202346fc429330f1e8dfa9b7d.tar.bz2
samba-0f7314ea019a42e202346fc429330f1e8dfa9b7d.zip
r7093: - added a new Form() ejs object for producing simple forms.
- tidied up the html generation a bit (This used to be commit ddccf6d2f5c4757111010e3116b41e379a7dc2dd)
Diffstat (limited to 'swat/scripting')
-rw-r--r--swat/scripting/common.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/swat/scripting/common.js b/swat/scripting/common.js
index cc3ca55468..d9e3b56bce 100644
--- a/swat/scripting/common.js
+++ b/swat/scripting/common.js
@@ -92,3 +92,60 @@ function multi_table(array, header) {
}
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");
+}