7 # #? 'primary_key' => #required when the dbdef doesn't know...???
12 # listref - each item is a literal column name (or method) or (notyet) coderef
13 # if not specified all columns (except for the primary key) will be editable
17 # 'menubar' => '', #menubar arrayref
21 #false laziness w/process.html
22 my $table = $opt{'table'};
23 my $class = "FS::$table";
24 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
25 my $fields = $opt{'fields'}
26 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
27 || [ grep { $_ ne $pkey } fields($table) ];
30 if ( $cgi->param('error') ) {
32 $object = $class->new( {
33 map { $_ => scalar($cgi->param($_)) } fields($table)
36 } elsif ( $cgi->keywords ) { #editing
38 my( $query ) = $cgi->keywords;
40 $object = qsearchs( $table, { $pkey => $1 } );
44 $object = $class->new( {} );
48 my $action = $object->$pkey() ? 'Edit' : 'Add';
50 my $title = "$action $opt{'name'}";
53 if ( $opt{'menubar'} ) {
54 @menubar = @{ $opt{'menubar'} };
57 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done
58 "View all $opt{'name'}s" => "${p}search/$table.html", #eventually use Lingua::bs to pluralize
65 <%= include("/elements/header.html", $title,
66 include( '/elements/menubar.html', @menubar )
70 <% if ( $cgi->param('error') ) { %>
71 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
75 <FORM ACTION="<%= popurl(1) %>process/<%= $table %>.html" METHOD=POST>
76 <INPUT TYPE="hidden" NAME="<%= $pkey %>" VALUE="<%= $object->$pkey() %>">
77 <%= ( $opt{labels} && exists $opt{labels}->{$pkey} )
78 ? $opt{labels}->{$pkey}
81 #<%= $object->$pkey() || "(NEW)" %>
83 <%= ntable("#cccccc",2) %>
85 <% foreach my $field ( @$fields ) { %>
90 <%= ( $opt{labels} && exists $opt{labels}->{$field} )
91 ? $opt{labels}->{$field}
97 #just text in one size for now... eventually more options for
98 # uneditable, hidden, <SELECT>, etc. fields
102 <INPUT TYPE="text" NAME="<%= $field %>" VALUE="<%= $object->$field() %>">
113 <INPUT TYPE="submit" VALUE="<%= $object->$pkey() ? "Apply changes" : "Add $opt{'name'}" %>">
117 <%= include("/elements/footer.html") %>