[%#
Shows a user input form, usually for adding a single row to a single table.
Parameters:
self - the site object (if self has a params hash values shown on
the form are taken from it)
view.title - thr browser window title
view.form - a hash with these keys:
method - POST or GET (defaults to POST)
action - url of page to process form (defaults to self.uri)
name - the name of the form (useful for javascript references)
row - the current row object from the table (if available)
javascript - javascript code the form needs (like for date popups.
Consider using Gantry::Plugins::Calendar and calling
its calendar_month_js.
(This could actually be anything, it just gets copied to
the output immediately after the form opening tag)
legend - The title for the legend box wrapping the form.
change_log - An array of change_log entries (optional). Each entry
is a hash with these keys:
date - the date the change happened
by - the name of the person making the change
message - what happened
results - the return value from Data::FormValidator->check
cellspacing - becomes the cellspacing parameter of the form's table
(defaults to 0)
width - becomes the width parameter of the form's table
fields - an array of inputable items. Each element is a has
with these keys:
raw_html - copied to the table before the row for
the field
label - text description displayed to user
width - width of the fields <td>
name - the name of the field in the form
(much match the database column name)
default_value - what shows up if there is no previous
value and nothting is in the
database
type - One of:
select (pick one drop down list)
text
textarea
the rest of the keys in the fields hash depend on the
type:
select
options - An array of hashes with these keys:
value - the form's value for this
option
label - what the user sees in the
list
text
date_select_text - the text of the href link for
the date popup window.
You must include this to
get a date popup link.
display_size - the size attribute of the
input element
(this is called display_size because TT has
a pseudo-method .size which tells how many keys
are in the field's hash)
textarea
rows - how tall the area is
cols - how wide the area is
Default values are taken in the following order:
1. from the params hash (which was made in a previous failed
add/edit attempt)
2. from the data model row object (on first edit attempt)
3. from the default_value entry in the field's hash (if available)
If none of those work, text and textarea fields will be blank and
select lists will rest on the first item in the options list.
%]
[% title = view.title %]
<script type="text/javascript">
<!--
var button_clicked = false;
function AntiClicker() {
if(button_clicked == true) {
return false;
}
button_clicked = true;
return true;
}
-->
</script>
[% IF view.form.editor == 1 %]
[% INCLUDE "editor_init.ttc" %]
[% END %]
<form
method="[% view.form.method || 'post' %]"
action="[% view.form.action || self.uri %]"
name="[% view.form.name %]"
[% IF view.form.enctype != ''; "enctype='$view.form.enctype'"; END; %]
>
[% view.form.javascript %]
<fieldset>
<legend>
[% view.form.legend %]
</legend>
[% IF view.form.change_log %]
<div style="float: right; width: 240px">
<fieldset>
<legend><a href='[% view.form.change_log_url %]'>Change Log</a>
</legend>
<div id="change_log">
[% FOREACH entry IN view.form.change_log %]
<b>[% entry.date %]</b> By [% entry.by %]<br />
· [% entry.message %]<br />
[% END %]
</div>
</fieldset>
</div>
[% END %]
[% IF view.form.results.missing %]
<div style="float: left; color: red">
<b>Missing:</b> [% view.form.results.missing.join( ', <br />' ) %]
<br />
</div>
<br style="clear:both" />
[% END %]
[% IF view.form.results.invalid %]
<div style="float: left; color: red">
<b>Invalid:</b> [% view.form.results.invalid.join( ', <br />' ) %]
<br />
</div>
<br style="clear:both" />
[% END %]
<div id="float_left">
<table class="results"
cellspacing="[% view.form.cellspacing || 0 %]"
border="0"
width="[% view.form.width || '100%' %]" >
[% FOREACH field IN view.form.fields %]
<tr>
[% IF view.form.results.missing( "${field.name}" ) %]
[% style_str = ' style="color: red"' %]
[% ELSE %]
[% style_str = '' %]
[% END %]
<td class="shd" valign="top"[% style_str %] style="width: [%-
label_width || '30%' %]">
[% field.label %]
[% UNLESS field.optional or field.type == 'checkbox'
-%]*[% END %]
</td>
<td class="dta" style="width: [% field.width
|| '70%' %]" valign="top">
[% IF field.type == 'select' %]
<select name="[% field.name %]">
[% default_field = '';
database_field = '';
param_field = '';
row_value = ''; %]
[%- FOR option IN field.options %]
[% IF field.is == 'boolean' %]
[% IF view.form.row.${field.name} %]
[% row_value = 't' %]
[% ELSE %]
[% row_value = 'f' %]
[% END %]
[% ELSE %]
[% row_value = view.form.row.${field.name} %]
[% END %]
[% IF option.value == self.params.${field.name} %]
[% param_field = option.value %]
[% ELSIF option.value == row_value %]
[% database_field = option.value %]
[% ELSIF option.value == field.default_value %]
[% default_field = option.value %]
[% END %]
[% END -%]
[% selected_value = param_field
|| database_field || default_field %]
[% FOR option IN field.options %]
<option value="[% option.value %]"
[% IF ( option.value == selected_value );
"selected='selected'";
END;
%]
>
[% option.label || option.value %]
</option>
[% END %]
</select>
[% ELSIF field.type == 'textarea' %]
<textarea name="[% field.name %]" id="[% field.id %]"
rows="[% field.rows || '0' %]"
cols="[% field.cols || '0' %]"
>[%- self.params.${field.name}
|| view.form.row.${field.name}
|| field.default_value -%]</textarea>
[% ELSIF field.type == 'checkbox' %]
<input type="checkbox"
name="[% field.name %]"
value="[% field.value %]"
[%- IF field.checked -%]checked[%- END -%]
/>
[% ELSIF field.type == 'html' %]
[% field.html %]
[% ELSE %]
<input type="[% field.type %]"
size="[% field.display_size || 30 %]"
value="[% self.params.${field.name}
|| view.form.row.${field.name} %]"
name="[% field.name %]"
/>
[% IF field.date_select_text %]
[% popup = "datepopup('$field.name')" %]
<a href="javascript://" onClick="[% popup %]" >
[% field.date_select_text %]
</a>
[% END %]
[% END %]
</td>
</tr>
[% END %]
<tr>
<td colspan="2" class="shd">
* required field
</td>
</tr>
<tr>
<td colspan="2" class="rshd">
<input type="submit" name="submit" value="Save" />
<input type="submit" name="cancel" value="Cancel" />
</td>
</tr>
</table>
</div>
</fieldset>
</form>