X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Felements%2Fedit.html;h=c2ea22f276fa0f7ececb4f839e85faa221f2513b;hb=6e3477c3068b88ad702316cd2d57e04c52de5855;hp=ce6e2dbb1378d21b1e71b8e315d12fd5d67020dc;hpb=600a0939e7e7e589dae4f4f5bfef3650728940b7;p=freeside.git diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index ce6e2dbb1..c2ea22f27 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -1,118 +1,224 @@ -<% - - # options example... - # - # 'name' => - # 'table' => - # #? 'primary_key' => #required when the dbdef doesn't know...??? - # 'labels' => { - # 'column' => 'Label', - # } - # - # listref - each item is a literal column name (or method) or (notyet) coderef - # if not specified all columns (except for the primary key) will be editable - # 'fields' => [ - # ] - # - # 'menubar' => '', #menubar arrayref - - my(%opt) = @_; - - #false laziness w/process.html - my $table = $opt{'table'}; - my $class = "FS::$table"; - my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} || - my $fields = $opt{'fields'} - #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ]; - || [ grep { $_ ne $pkey } fields($table) ]; - - my $object; - if ( $cgi->param('error') ) { - - $object = $class->new( { - map { $_ => scalar($cgi->param($_)) } fields($table) - }); - - } elsif ( $cgi->keywords ) { #editing - - my( $query ) = $cgi->keywords; - $query =~ /^(\d+)$/; - $object = qsearchs( $table, { $pkey => $1 } ); - - } else { #adding - - $object = $class->new( {} ); - - } - - my $action = $object->$pkey() ? 'Edit' : 'Add'; - - my $title = "$action $opt{'name'}"; - - my @menubar = (); - if ( $opt{'menubar'} ) { - @menubar = @{ $opt{'menubar'} }; - } else { - @menubar = ( - 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done - "View all $opt{'name'}s" => "${p}search/$table.html", #eventually use Lingua::bs to pluralize - ); - } - -%> - - -<%= include("/elements/header.html", $title, +% +% +% # options example... +% # +% # 'name' => +% # 'table' => +% # #? 'primary_key' => #required when the dbdef doesn't know...??? +% # 'labels' => { +% # 'column' => 'Label', +% # } +% # +% # listref - each item is a literal column name (or method) or hashref +% # or (notyet) coderef +% # if not specified all columns (except for the primary key) will be editable +% # 'fields' => [ +% # 'columname', +% # { 'field' => 'another_columname', +% # 'type' => 'text', #text +% # #checkbox +% # #select +% # #hidden - hidden value from object +% # #fixed - display fixed value from here +% # #fixedhidden - hidden value from here +% # 'value' => 'Y', #for checkbox, fixed, fixedhidden +% # }, +% # ] +% # +% # 'menubar' => '', #menubar arrayref +% # +% # #run when re-displaying with an error +% # 'error_callback' => sub { my( $cgi, $object ) = @_; }, +% # +% # #run when editing +% # 'edit_callback' => sub { my( $cgi, $object ) = @_; }, +% # +% # # returns a hashref for the new object +% # 'new_hashref_callback' +% # +% # #run when adding +% # 'new_callback' => sub { my( $cgi, $object ) = @_; }, +% # +% # #XXX describe +% # 'field_callback' => sub { }, +% # +% # #string or coderef of additional HTML to add before +% # 'html_table_bottom' => '', +% # +% # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search' +% # +% # 'html_bottom' => '', #string +% # 'html_bottom' => sub { +% # my $object = shift; +% # # ... +% # "html_string"; +% # }, +% +% my(%opt) = @_; +% +% #false laziness w/process.html +% my $table = $opt{'table'}; +% my $class = "FS::$table"; +% my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} || +% my $fields = $opt{'fields'} +% #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ]; +% || [ grep { $_ ne $pkey } fields($table) ]; +% #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields; +% +% my $object; +% if ( $cgi->param('error') ) { +% +% $object = $class->new( { +% map { $_ => scalar($cgi->param($_)) } fields($table) +% }); +% +% &{$opt{'error_callback'}}($cgi, $object) +% if $opt{'error_callback'}; +% +% } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing +% +% my( $query ) = $cgi->keywords; +% $query = $cgi->param($pkey) unless $query; +% $query =~ /^(\d+)$/; +% $object = qsearchs( $table, { $pkey => $1 } ); +% warn "$table $pkey => $1" +% if $opt{'debug'}; +% +% &{$opt{'edit_callback'}}($cgi, $object) +% if $opt{'edit_callback'}; +% +% } else { #adding +% +% my $hashref = $opt{'new_hashref_callback'} +% ? &{$opt{'new_hashref_callback'}} +% : {}; +% +% $object = $class->new( $hashref ); +% +% &{$opt{'new_callback'}}($cgi, $object) +% if $opt{'new_callback'}; +% +% } +% +% my $action = $object->$pkey() ? 'Edit' : 'Add'; +% +% my $title = "$action $opt{'name'}"; +% +% my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html"; +% $viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'}; +% +% my @menubar = (); +% if ( $opt{'menubar'} ) { +% @menubar = @{ $opt{'menubar'} }; +% } else { +% @menubar = ( +% 'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done +% #eventually use Lingua::bs to pluralize +% "View all $opt{'name'}s" => $viewall_url, +% ); +% } +% +% +<% include("/elements/header.html", $title, include( '/elements/menubar.html', @menubar ) ) %> +% if ( $cgi->param('error') ) { -<% if ( $cgi->param('error') ) { %> - Error: <%= $cgi->param('error') %> + Error: <% $cgi->param('error') %>

-<% } %> +% } + -
- -<%= ( $opt{labels} && exists $opt{labels}->{$pkey} ) + + +<% ( $opt{labels} && exists $opt{labels}->{$pkey} ) ? $opt{labels}->{$pkey} : $pkey %> -#<%= $object->$pkey() || "(NEW)" %> +#<% $object->$pkey() || "(NEW)" %> + +<% ntable("#cccccc",2) %> +% foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} } +% @$fields +% ) { +% +% &{ $opt{'field_callback'} }( $f ) +% if $opt{'field_callback'}; +% +% my $field = $f->{'field'}; +% my $type = $f->{'type'} ||= 'text'; +% +% -<%= ntable("#cccccc",2) %> - -<% foreach my $field ( @$fields ) { %> - <%= ( $opt{labels} && exists $opt{labels}->{$field} ) + <% ( $opt{labels} && exists $opt{labels}->{$field} ) ? $opt{labels}->{$field} : $field %> - <% - #just text in one size for now... eventually more options for - # uneditable, hidden, + +% } elsif ( $type eq 'fixedhidden' ) { + + + +% } elsif ( $type eq 'checkbox' ) { - - - + + $field() eq $f->{'value'} ? ' CHECKED' : '' %>> + + +% } elsif ( $type eq 'select' ) { + + + + + +% } else { + + + + + +% } -<% } %> +% } + +<% ref( $opt{'html_table_bottom'} ) + ? &{ $opt{'html_table_bottom'} }( $object ) + : $opt{'html_table_bottom'} +%> +<% ref( $opt{'html_bottom'} ) + ? &{ $opt{'html_bottom'} }( $object ) + : $opt{'html_bottom'} +%> +
-"> +">
-<%= include("/elements/footer.html") %> +<% include("/elements/footer.html") %>