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;
57 % # # overrides default popurl(1)."process/$table.html"
58 % # 'post_url' => popurl(1).'process/something',
62 % #false laziness w/process.html
63 % my $table = $opt{'table'};
64 % my $class = "FS::$table";
65 % my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
66 % my $fields = $opt{'fields'}
67 % #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
68 % || [ grep { $_ ne $pkey } fields($table) ];
69 % #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
72 % if ( $cgi->param('error') ) {
74 % $object = $class->new( {
75 % map { $_ => scalar($cgi->param($_)) } fields($table)
78 % &{$opt{'error_callback'}}($cgi, $object)
79 % if $opt{'error_callback'};
81 % } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
84 % if ( $cgi->param($pkey) ) {
85 % $value = $cgi->param($pkey)
87 % my( $query ) = $cgi->keywords;
90 % $value =~ /^(\d+)$/ or die "unparsable $pkey";
91 % $object = qsearchs( $table, { $pkey => $1 } );
92 % warn "$table $pkey => $1"
95 % &{$opt{'edit_callback'}}($cgi, $object)
96 % if $opt{'edit_callback'};
100 % my $hashref = $opt{'new_hashref_callback'}
101 % ? &{$opt{'new_hashref_callback'}}
104 % $object = $class->new( $hashref );
106 % &{$opt{'new_callback'}}($cgi, $object)
107 % if $opt{'new_callback'};
111 % my $action = $object->$pkey() ? 'Edit' : 'Add';
113 % my $title = "$action $opt{'name'}";
115 % my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
116 % $viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
119 % if ( $opt{'menubar'} ) {
120 % @menubar = @{ $opt{'menubar'} };
123 % 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done
124 % #eventually use Lingua::bs to pluralize
125 % "View all $opt{'name'}s" => $viewall_url,
130 <% include("/elements/header.html", $title,
131 include( '/elements/menubar.html', @menubar )
134 % if ( $cgi->param('error') ) {
136 <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
140 % my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
142 <FORM ACTION="<% $url %>" METHOD=POST>
143 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
144 <INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $object->$pkey() %>">
145 <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
146 ? $opt{labels}->{$pkey}
149 #<% $object->$pkey() || "(NEW)" %>
151 <% ntable("#cccccc",2) %>
152 % foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} }
156 % &{ $opt{'field_callback'} }( $f )
157 % if $opt{'field_callback'};
159 % my $field = $f->{'field'};
160 % my $type = $f->{'type'} ||= 'text';
168 <% ( $opt{labels} && exists $opt{labels}->{$field} )
169 ? $opt{labels}->{$field}
174 % if ( $type eq 'fixed' ) {
176 <TD BGCOLOR="#dddddd"><% $f->{'value'} %></TD>
177 <INPUT TYPE="hidden" NAME="<% $field %>" VALUE="<% $f->{'value'} %>">
179 % } elsif ( $type eq 'fixedhidden' ) {
181 <INPUT TYPE="hidden" NAME="<% $field %>" VALUE="<% $f->{'value'} %>">
183 % } elsif ( $type eq 'checkbox' ) {
186 <INPUT TYPE="checkbox" NAME="<% $field %>" VALUE="<% $f->{'value'} %>" <% $object->$field() eq $f->{'value'} ? ' CHECKED' : '' %>>
189 % } elsif ( $type eq 'select' ) {
192 <SELECT NAME="<% $field %>"
193 % my $aref = $f->{'value'}{'values'};
194 % my $vkey = $f->{'value'}{'vcolumn'};
195 % my $ckey = $f->{'value'}{'ccolumn'};
196 % foreach my $v (@$aref) {
197 <OPTION <% ($object->$field() eq $v->$vkey) ? 'SELECTED' : '' %>
198 VALUE="<% $v->$vkey %>"><% $v->$ckey %></OPTION>
206 <INPUT TYPE="<% $type %>" NAME="<% $field %>" VALUE="<% $object->$field() %>">
215 <% ref( $opt{'html_table_bottom'} )
216 ? &{ $opt{'html_table_bottom'} }( $object )
217 : $opt{'html_table_bottom'}
222 <% ref( $opt{'html_bottom'} )
223 ? &{ $opt{'html_bottom'} }( $object )
224 : $opt{'html_bottom'}
229 <INPUT TYPE="submit" VALUE="<% $object->$pkey() ? "Apply changes" : "Add $opt{'name'}" %>">
233 <% include("/elements/footer.html") %>