7 % # #? 'primary_key' => #required when the dbdef doesn't know...???
9 % # 'column' => 'Label',
12 % # listref - each item is a literal column name (or method) or hashref
13 % # or (notyet) coderef
14 % # if not specified all columns (except for the primary key) will be editable
17 % # { 'field' => 'another_columname',
18 % # 'type' => 'text', #text
21 % # #hidden - hidden value from object
22 % # #fixed - display fixed value from here
23 % # #fixedhidden - hidden value from here
24 % # 'value' => 'Y', #for checkbox, fixed, fixedhidden
28 % # 'menubar' => '', #menubar arrayref
30 % # #run when re-displaying with an error
31 % # 'error_callback' => sub { my( $cgi, $object ) = @_; },
34 % # 'edit_callback' => sub { my( $cgi, $object ) = @_; },
36 % # # returns a hashref for the new object
37 % # 'new_hashref_callback'
40 % # 'new_callback' => sub { my( $cgi, $object ) = @_; },
43 % # 'field_callback' => sub { },
45 % # #string or coderef of additional HTML to add before </TABLE>
46 % # 'html_table_bottom' => '',
48 % # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
50 % # 'html_bottom' => '', #string
51 % # 'html_bottom' => sub {
52 % # my $object = shift;
59 % #false laziness w/process.html
60 % my $table = $opt{'table'};
61 % my $class = "FS::$table";
62 % my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
63 % my $fields = $opt{'fields'}
64 % #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
65 % || [ grep { $_ ne $pkey } fields($table) ];
66 % #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
69 % if ( $cgi->param('error') ) {
71 % $object = $class->new( {
72 % map { $_ => scalar($cgi->param($_)) } fields($table)
75 % &{$opt{'error_callback'}}($cgi, $object)
76 % if $opt{'error_callback'};
78 % } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
80 % my( $query ) = $cgi->keywords;
81 % $query = $cgi->param($pkey) unless $query;
82 % $query =~ /^(\d+)$/;
83 % $object = qsearchs( $table, { $pkey => $1 } );
84 % warn "$table $pkey => $1"
87 % &{$opt{'edit_callback'}}($cgi, $object)
88 % if $opt{'edit_callback'};
92 % my $hashref = $opt{'new_hashref_callback'}
93 % ? &{$opt{'new_hashref_callback'}}
96 % $object = $class->new( $hashref );
98 % &{$opt{'new_callback'}}($cgi, $object)
99 % if $opt{'new_callback'};
103 % my $action = $object->$pkey() ? 'Edit' : 'Add';
105 % my $title = "$action $opt{'name'}";
107 % my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
108 % $viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
111 % if ( $opt{'menubar'} ) {
112 % @menubar = @{ $opt{'menubar'} };
115 % 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done
116 % #eventually use Lingua::bs to pluralize
117 % "View all $opt{'name'}s" => $viewall_url,
122 <% include("/elements/header.html", $title,
123 include( '/elements/menubar.html', @menubar )
126 % if ( $cgi->param('error') ) {
128 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
133 <FORM ACTION="<% popurl(1) %>process/<% $table %>.html" METHOD=POST>
134 <INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $object->$pkey() %>">
135 <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
136 ? $opt{labels}->{$pkey}
139 #<% $object->$pkey() || "(NEW)" %>
141 <% ntable("#cccccc",2) %>
142 % foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} }
146 % &{ $opt{'field_callback'} }( $f )
147 % if $opt{'field_callback'};
149 % my $field = $f->{'field'};
150 % my $type = $f->{'type'} ||= 'text';
158 <% ( $opt{labels} && exists $opt{labels}->{$field} )
159 ? $opt{labels}->{$field}
164 % if ( $type eq 'fixed' ) {
166 <TD BGCOLOR="#dddddd"><% $f->{'value'} %></TD>
167 <INPUT TYPE="hidden" NAME="<% $field %>" VALUE="<% $f->{'value'} %>">
169 % } elsif ( $type eq 'fixedhidden' ) {
171 <INPUT TYPE="hidden" NAME="<% $field %>" VALUE="<% $f->{'value'} %>">
173 % } elsif ( $type eq 'checkbox' ) {
176 <INPUT TYPE="checkbox" NAME="<% $field %>" VALUE="<% $f->{'value'} %>" <% $object->$field() eq $f->{'value'} ? ' CHECKED' : '' %>>
179 % } elsif ( $type eq 'select' ) {
182 <SELECT NAME="<% $field %>"
183 % my $aref = $f->{'value'}{'values'};
184 % my $vkey = $f->{'value'}{'vcolumn'};
185 % my $ckey = $f->{'value'}{'ccolumn'};
186 % foreach my $v (@$aref) {
187 <OPTION <% ($object->$field() eq $v->$vkey) ? 'SELECTED' : '' %>
188 VALUE="<% $v->$vkey %>"><% $v->$ckey %></OPTION>
196 <INPUT TYPE="<% $type %>" NAME="<% $field %>" VALUE="<% $object->$field() %>">
205 <% ref( $opt{'html_table_bottom'} )
206 ? &{ $opt{'html_table_bottom'} }( $object )
207 : $opt{'html_table_bottom'}
212 <% ref( $opt{'html_bottom'} )
213 ? &{ $opt{'html_bottom'} }( $object )
214 : $opt{'html_bottom'}
219 <INPUT TYPE="submit" VALUE="<% $object->$pkey() ? "Apply changes" : "Add $opt{'name'}" %>">
223 <% include("/elements/footer.html") %>