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 = @_; },
28 # #broken'html_table_bottom' => '', #string or listref of additinal HTML to
29 # #add before </TABLE>
31 # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
33 # 'html_bottom' => '', #string
34 # 'html_bottom' => sub {
42 #false laziness w/process.html
43 my $table = $opt{'table'};
44 my $class = "FS::$table";
45 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
46 my $fields = $opt{'fields'}
47 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
48 || [ grep { $_ ne $pkey } fields($table) ];
49 #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
52 if ( $cgi->param('error') ) {
54 $object = $class->new( {
55 map { $_ => scalar($cgi->param($_)) } fields($table)
58 &{$opt{'error_callback'}}($cgi, $object)
59 if $opt{'error_callback'};
61 } elsif ( $cgi->keywords ) { #editing
63 my( $query ) = $cgi->keywords;
65 $object = qsearchs( $table, { $pkey => $1 } );
67 &{$opt{'edit_callback'}}($cgi, $object)
68 if $opt{'edit_callback'};
72 $object = $class->new( {} );
74 &{$opt{'new_callback'}}($cgi, $object)
75 if $opt{'new_callback'};
79 my $action = $object->$pkey() ? 'Edit' : 'Add';
81 my $title = "$action $opt{'name'}";
84 if ( $opt{'menubar'} ) {
85 @menubar = @{ $opt{'menubar'} };
88 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done
89 #eventually use Lingua::bs to pluralize
90 "View all $opt{'name'}s" => $p. ( $opt{'viewall_dir'} || 'search' ).
95 %><%= include("/elements/header.html", $title,
96 include( '/elements/menubar.html', @menubar )
100 <% if ( $cgi->param('error') ) { %>
101 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
105 <FORM ACTION="<%= popurl(1) %>process/<%= $table %>.html" METHOD=POST>
106 <INPUT TYPE="hidden" NAME="<%= $pkey %>" VALUE="<%= $object->$pkey() %>">
107 <%= ( $opt{labels} && exists $opt{labels}->{$pkey} )
108 ? $opt{labels}->{$pkey}
111 #<%= $object->$pkey() || "(NEW)" %>
113 <%= ntable("#cccccc",2) %>
115 <% foreach my $f ( @$fields ) {
119 $field = $f->{'field'},
120 $type = $f->{'type'} || 'text',
131 <%= ( $opt{labels} && exists $opt{labels}->{$field} )
132 ? $opt{labels}->{$field}
138 #eventually more options for <SELECT>, etc. fields
142 <INPUT TYPE="<%= $type %>" NAME="<%= $field %>" VALUE="<%= $object->$field() %>">
151 <%= ref( $opt{'html_bottom'} )
152 ? &{ $opt{'html_bottom'} }( $object )
153 : $opt{'html_bottom'}
158 <INPUT TYPE="submit" VALUE="<%= $object->$pkey() ? "Apply changes" : "Add $opt{'name'}" %>">
162 <%= include("/elements/footer.html") %>