]> git.decadent.org.uk Git - maypole.git/blob - ex/fancy_example/templates/factory/edit
tested and it seems to work
[maypole.git] / ex / fancy_example / templates / factory / edit
1 [%#
2
3 =head1 edit
4
5 This is the edit page. It edits the passed-in object, by displaying a
6 form similar to L<addnew> but with the current values filled in.
7
8 =cut
9
10 #%]
11 [% PROCESS macros %]
12 [% INCLUDE header %]
13 [% INCLUDE title %]
14
15 [% IF request.action == 'edit' %]
16 [% INCLUDE navbar %]
17 [% END %]
18
19 [% IF object %]
20 <div id="title">Edit a [% classmetadata.moniker %]</div>
21 <form action="[% base %]/[% item.table %]/do_edit/[% item.id %]" method="post">
22 <fieldset>
23 <legend>Edit [% object.name %]</legend>
24    [% FOR col = classmetadata.columns;
25     NEXT IF col == "id" OR col == classmetadata.table _ "_id";
26     '<label><span class="field">';
27     classmetadata.colnames.$col || col | ucfirst | replace('_',' '); ":</span>";
28     object.to_field(col).as_XML;
29     "</label>";
30     IF errors.$col; 
31        '<span class="error">'; errors.$col;'</span>';
32     END;
33     END %]
34     <input type="submit" name="edit" value="edit"/>
35     <input type="hidden" name="__form_id" value="[% request.make_random_id %]">
36     </fieldset></form>
37     
38 [% ELSE %]
39
40 <div id="addnew">
41 <form method="post" action="[% base %]/[% classmetadata.table %]/do_edit/">
42 <fieldset>
43 <legend>Add a new [% classmetadata.moniker %]</legend>
44     [% FOR col = classmetadata.columns %]
45         [% NEXT IF col == "id" %]
46             <label><span class="field">[% classmetadata.colnames.$col %]</span>
47             [% 
48             SET elem = classmetadata.cgi.$col.clone;
49             IF request.action == 'do_edit';
50                 IF elem.tag == "textarea";
51                     elem = elem.push_content(request.param(col));
52                 ELSE;
53                     elem.attr("value", request.param(col));
54                 END;
55             END;
56             elem.as_XML; %]
57             </label>
58         [% IF errors.$col %]
59            <span class="error">[% errors.$col | html  %]</span>
60         [% END %]
61
62     [% END; %]
63     <input type="submit" name="create" value="create" />
64     <input type="hidden" name="__form_id" value="[% request.make_random_id %]" />
65 </fieldset>
66 </form>
67 </div>
68
69 [% END %]
70 [% INCLUDE footer %]