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 # #run when re-displaying with an error
20 # 'error_callback' => sub { my $cgi, $object = @_; },
23 # 'edit_callback' => sub { my $cgi, $object = @_; },
26 # 'new_callback' => sub { my $cgi, $object = @_; },
29 # #'html_table_bottom' => '', #string or listref of additinal HTML to
30 # # #add before </TABLE>
32 # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
34 # 'html_bottom' => '', #string
35 # 'html_bottom' => sub {
43 #false laziness w/process.html
44 my $table = $opt{'table'};
45 my $class = "FS::$table";
46 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
47 my $fields = $opt{'fields'}
48 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
49 || [ grep { $_ ne $pkey } fields($table) ];
50 #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
53 if ( $cgi->param('error') ) {
55 $object = $class->new( {
56 map { $_ => scalar($cgi->param($_)) } fields($table)
59 &{$opt{'error_callback'}}($cgi, $object)
60 if $opt{'error_callback'};
62 } elsif ( $cgi->keywords ) { #editing
64 my( $query ) = $cgi->keywords;
66 $object = qsearchs( $table, { $pkey => $1 } );
68 &{$opt{'edit_callback'}}($cgi, $object)
69 if $opt{'edit_callback'};
73 $object = $class->new( {} );
75 &{$opt{'new_callback'}}($cgi, $object)
76 if $opt{'new_callback'};
80 my $action = $object->$pkey() ? 'Edit' : 'Add';
82 my $title = "$action $opt{'name'}";
85 if ( $opt{'menubar'} ) {
86 @menubar = @{ $opt{'menubar'} };
89 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done
90 #eventually use Lingua::bs to pluralize
91 "View all $opt{'name'}s" => $p. ( $opt{'viewall_dir'} || 'search' ).
96 %><%= include("/elements/header.html", $title,
97 include( '/elements/menubar.html', @menubar )
101 <% if ( $cgi->param('error') ) { %>
102 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
106 <FORM ACTION="<%= popurl(1) %>process/<%= $table %>.html" METHOD=POST>
107 <INPUT TYPE="hidden" NAME="<%= $pkey %>" VALUE="<%= $object->$pkey() %>">
108 <%= ( $opt{labels} && exists $opt{labels}->{$pkey} )
109 ? $opt{labels}->{$pkey}
112 #<%= $object->$pkey() || "(NEW)" %>
114 <%= ntable("#cccccc",2) %>
116 <% foreach my $f ( @$fields ) {
120 $field = $f->{'field'},
121 $type = $f->{'type'} || 'text',
132 <%= ( $opt{labels} && exists $opt{labels}->{$field} )
133 ? $opt{labels}->{$field}
139 #eventually more options for <SELECT>, etc. fields
143 <INPUT TYPE="<%= $type %>" NAME="<%= $field %>" VALUE="<%= $object->$field() %>">
152 <%= ref( $opt{'html_bottom'} )
153 ? &{ $opt{'html_bottom'} }( $object )
154 : $opt{'html_bottom'}
159 <INPUT TYPE="submit" VALUE="<%= $object->$pkey() ? "Apply changes" : "Add $opt{'name'}" %>">
163 <%= include("/elements/footer.html") %>