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
19 # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
23 #false laziness w/process.html
24 my $table = $opt{'table'};
25 my $class = "FS::$table";
26 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
27 my $fields = $opt{'fields'}
28 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
29 || [ grep { $_ ne $pkey } fields($table) ];
32 if ( $cgi->param('error') ) {
34 $object = $class->new( {
35 map { $_ => scalar($cgi->param($_)) } fields($table)
38 } elsif ( $cgi->keywords ) { #editing
40 my( $query ) = $cgi->keywords;
42 $object = qsearchs( $table, { $pkey => $1 } );
46 $object = $class->new( {} );
50 my $action = $object->$pkey() ? 'Edit' : 'Add';
52 my $title = "$action $opt{'name'}";
55 if ( $opt{'menubar'} ) {
56 @menubar = @{ $opt{'menubar'} };
59 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done
60 #eventually use Lingua::bs to pluralize
61 "View all $opt{'name'}s" => $p. ( $opt{'viewall_dir'} || 'search' ).
69 <%= include("/elements/header.html", $title,
70 include( '/elements/menubar.html', @menubar )
74 <% if ( $cgi->param('error') ) { %>
75 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
79 <FORM ACTION="<%= popurl(1) %>process/<%= $table %>.html" METHOD=POST>
80 <INPUT TYPE="hidden" NAME="<%= $pkey %>" VALUE="<%= $object->$pkey() %>">
81 <%= ( $opt{labels} && exists $opt{labels}->{$pkey} )
82 ? $opt{labels}->{$pkey}
85 #<%= $object->$pkey() || "(NEW)" %>
87 <%= ntable("#cccccc",2) %>
89 <% foreach my $field ( @$fields ) { %>
94 <%= ( $opt{labels} && exists $opt{labels}->{$field} )
95 ? $opt{labels}->{$field}
101 #just text in one size for now... eventually more options for
102 # uneditable, hidden, <SELECT>, etc. fields
106 <INPUT TYPE="text" NAME="<%= $field %>" VALUE="<%= $object->$field() %>">
117 <INPUT TYPE="submit" VALUE="<%= $object->$pkey() ? "Apply changes" : "Add $opt{'name'}" %>">
121 <%= include("/elements/footer.html") %>