Commit 16f40f8f authored by Leigh Stoller's avatar Leigh Stoller

Add first cut at a search templates page. I ended up making a bunch

of changes to the new form wrapper stuff to support more interesting
forms.
parent bfce32d9
......@@ -126,6 +126,7 @@ function FormRenderRadio($name, $attrs)
return $html;
}
function FormRenderSelect($name, $attrs)
{
$html = "<select name=\"formfields[$name]\" ";
......@@ -139,7 +140,12 @@ function FormRenderSelect($name, $attrs)
$html .= $attrs['#javascript'] . " ";
}
$html .= ">\n";
$html .= "<option value=''>Please Select &nbsp</option>\n";
if (isset($attrs['#default']))
$default = $attrs['#default'];
else
$default = "Please Select";
$html .= "<option value=''>$default &nbsp</option>\n";
if (isset($attrs['#options'])) {
while (list ($selectvalue, $selectlabel) = each ($attrs['#options'])) {
......@@ -182,7 +188,6 @@ function FormRenderSubmit($name, $attrs)
{
$html = "";
$html .= "<td align=center colspan=2>";
$html .= "<input type=submit name=\"$name\" ";
if (isset($attrs['#value'])) {
$html .= "value=\"" . $attrs['#value'] . "\" ";
......@@ -199,7 +204,34 @@ function FormRenderSubmit($name, $attrs)
if (isset($attrs['#javascript'])) {
$html .= $attrs['#javascript'] . " ";
}
$html .= "></td>";
$html .= ">";
return $html;
}
function FormRenderImage($name, $attrs)
{
$html = "";
$img = $attrs['#image'];
$html .= "<input type=image name=\"formfields[$name]\" ";
if (isset($attrs['#value'])) {
$html .= "value=\"" . $attrs['#value'] . "\" ";
}
else {
$html .= "value=Submit ";
}
if (isset($attrs['#class'])) {
$html .= "class=\"" . $attrs['#class'] . "\" ";
}
else {
$html .= "class=\"form-image\" ";
}
if (isset($attrs['#javascript'])) {
$html .= $attrs['#javascript'] . " ";
}
$html .= "src=$img ";
$html .= ">";
return $html;
}
......@@ -213,6 +245,23 @@ function FormRenderTable($name, $attributes, $submitted)
return $html;
}
# Render a list of elements together.
function FormRenderList($name, $attributes, $submitted)
{
$html = "";
while (list ($subname, $subattrs) = each ($attributes['#elements'])) {
if ($submitted && array_key_exists($subname, $submitted)) {
$subattrs['#value'] = $submitted[$subname];
}
$html .= FormRenderElement($subname, $subattrs, $submitted);
if (isset($subattrs['#label']))
$html .= $subattrs['#label'] . " &nbsp; ";
$html .= " &nbsp; ";
}
return $html;
}
function FormRenderElement($name, $attributes, $submitted)
{
$field_html = null;
......@@ -232,11 +281,16 @@ function FormRenderElement($name, $attributes, $submitted)
break;
case "hidden":
$value = $attributes['#value'];
$field_html .= "<input type=hidden name=$name value=\"$value\">\n";
$field_html .=
"<input type=hidden name=\"formfields[$name]\" ".
"value=\"$value\">\n";
break;
case "submit":
$field_html = FormRenderSubmit($name, $attributes);
break;
case "image":
$field_html = FormRenderImage($name, $attributes);
break;
case "checkbox":
$field_html = FormRenderCheckBox($name, $attributes);
break;
......@@ -262,6 +316,9 @@ function FormRenderElement($name, $attributes, $submitted)
case "table":
$field_html = FormRenderTable($name, $attributes, $submitted);
break;
case "list":
$field_html = FormRenderList($name, $attributes, $submitted);
break;
}
return $field_html;
}
......@@ -311,7 +368,8 @@ function FormRenderElements($fields, $submitted)
}
$html .= "<tr>";
if ($attributes['#type'] != "submit") {
if ($attributes['#type'] != "submit" &&
!isset($attributes['#colspan'])) {
$html .= "<td $mouseover $cols>";
# Required fields mark with *
......@@ -335,8 +393,11 @@ function FormRenderElements($fields, $submitted)
$html .= "<td>$field_html</td>";
}
}
else
else {
$html .= "<td align=center colspan=2>";
$html .= "$field_html";
$html .= "</td>\n";
}
$html .= "</tr>\n";
}
}
......@@ -416,30 +477,76 @@ function FormRender($attributes, $errors, $fields, $submitted = null)
echo "$html\n";
}
function FormValidate($form, &$errors, $fields, $submitted)
function FormValidateElement($name, &$errors, $attributes, &$submitted)
{
while (list ($name, $attributes) = each ($fields)) {
# Check for required fields not filled out
if (isset($attributes['#required']) && $attributes['#required'] &&
!(isset($submitted[$name]) && $submitted[$name] != "")) {
$errors[$attributes['#label']] = "Missing required value";
# Check for required fields not filled out
if (isset($attributes['#required']) && $attributes['#required'] &&
!(isset($submitted[$name]) && $submitted[$name] != "")) {
$errors[$attributes['#label']] = "Missing required value";
}
elseif (isset($attributes['#checkslot'])) {
$check = $attributes['#checkslot'];
if (function_exists($check)) {
$check($name, $errors, $attributes, $submitted[$name]);
}
else if (isset($attributes['#checkslot']) &&
isset($submitted[$name]) && $submitted[$name] != "") {
# Check slot
if (preg_match("/^([-\w]+):([-\w]+)$/",
$attributes['#checkslot'], $matches)) {
if (!TBcheck_dbslot($submitted[$name],
$matches[1], $matches[2],
TBDB_CHECKDBSLOT_WARN|
TBDB_CHECKDBSLOT_ERROR)) {
$errors[$attributes['#label']] = TBFieldErrorString();
}
elseif (preg_match("/^([-\w]+):([-\w]+)$/", $check, $matches)) {
#
# What if not required and not set?
#
if (!isset($submitted[$name]) || $submitted[$name] == "") {
$submitted[$name] = "";
}
else {
TBERROR("Could not parse " . $attributes['#checkslot'], 1);
if (!TBcheck_dbslot($submitted[$name],
$matches[1], $matches[2],
TBDB_CHECKDBSLOT_WARN|
TBDB_CHECKDBSLOT_ERROR)) {
$errors[$attributes['#label']] = TBFieldErrorString();
}
}
elseif (substr($check, 0, 1) == "/") {
# Regular expression.
if (!preg_match($check, $submitted[$name])) {
$errors[$attributes['#label']] = "Illegal characters";
}
}
else {
TBERROR("Could not parse checkslot: $check", 1);
}
}
}
function FormValidate($form, &$errors, $fields, &$submitted)
{
while (list ($name, $attributes) = each ($fields)) {
switch ($attributes['#type']) {
case "textfield":
case "password":
case "hidden":
case "submit":
case "checkbox":
case "radio":
case "file":
case "select":
FormValidateElement($name, $errors, $attributes, $submitted);
break;
case "checkboxes":
while (list ($subname, $subattrs) = each ($attributes['#boxes'])) {
FormValidateElement($subname, $errors, $subattrs, $submitted);
}
break;
case "table":
FormValidate($form, $errors, $attributes['#fields'], $submitted);
break;
case "list":
while (list ($subname, $subattrs) =
each ($attributes['#elements'])) {
FormValidateElement($subname, $errors, $subattrs, $submitted);
}
break;
default:
$errors[$name] = "Invalid slot type: " . $attributes['#type'];
break;
}
}
}
......
This diff is collapsed.
......@@ -310,6 +310,8 @@ WRITESUBMENUBUTTON("Modify Template",
WRITESUBMENUBUTTON("Instantiate Template",
CreateURL("template_swapin", $template));
WRITESUBMENUBUTTON("Create New Template", CreateURL("template_create"));
WRITESUBMENUBUTTON("Add Metadata",
CreateURL("template_metadata", $template) . "&action=add");
......@@ -318,6 +320,9 @@ if ($template->EventCount() > 0) {
CreateURL("template_editevents", $template));
}
WRITESUBMENUBUTTON("Search Template",
CreateURL("template_search", $template));
# We show the user the datastore for the template;
# the rest of it is not important.
WRITESUBMENUBUTTON("Browse Datastore",
......
......@@ -96,6 +96,7 @@ $url_mapping["template_metadata"] = "template_metadata.php";
$url_mapping["template_modify"] = "template_modify.php";
$url_mapping["template_show"] = "template_show.php";
$url_mapping["template_swapin"] = "template_swapin.php";
$url_mapping["template_search"] = "template_search.php";
$url_mapping["record_revise"] = "record_revise.php";
$url_mapping["linkgraph_image"] = "linkgraph_image.php";
$url_mapping["resendapproval"] = "resendapproval.php";
......@@ -106,6 +107,7 @@ $url_mapping["statechange"] = "statechange.php";
$url_mapping["experimentrun_show"] = "experimentrun_show.php";
$url_mapping["instance_show"] = "instance_show.php";
$url_mapping["cvswebwrap"] = "cvsweb/cvswebwrap.php3";
$url_mapping["profile"] = "profile.php";
#
# The caller will pass in a page id, and a list of things. If the thing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment