X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fedit%2Felements%2Fedit.html;h=73faad4c057c0ef5bbb9c5c54a20f09fd3c0606c;hp=4e896f2395af01a1c9f09c39704d01710fb91117;hb=9b4209f91ad9e3c4cef7deebfb0180f6faf1d0dc;hpb=5561349c87fdcc646c18010ea57925f90170f321 diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 4e896f239..73faad4c0 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -111,6 +111,11 @@ Example: #we're in a popup (no title/menu/searchboxes) 'popup' => 1, + #we're embedded (rows only: no header at all, no html_init, no error + # display, no
, no hidden fields for table name or primary key, no + # display of primary key, no submit button, no html_foot, no footer) + 'embed' => $object, #need to pass the object + ### # HTML callbacks ### @@ -186,41 +191,60 @@ Example: -<% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html', - $title, - include( '/elements/menubar.html', @menubar ), - $opt{'body_etc'}, - ) -%> +% unless ( $opt{embed} ) { +% +% my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} ); +% +% 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 { +% my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'}); +% @menubar = ( +% "View all $items" => $viewall_url, +% ); +% } -<% defined($opt{'html_init'}) - ? ( ref($opt{'html_init'}) - ? &{$opt{'html_init'}}() - : $opt{'html_init'} - ) - : '' -%> + <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html', + $title, + include( '/elements/menubar.html', @menubar ), + $opt{'body_etc'}, + ) + %> + + <% defined($opt{'html_init'}) + ? ( ref($opt{'html_init'}) + ? &{$opt{'html_init'}}() + : $opt{'html_init'} + ) + : '' + %> -<% include('/elements/error.html') %> + <% include('/elements/error.html') %> % my $url = $opt{'post_url'} || popurl(1)."process/$table.html"; - -> + + > - - + + - -<% ( $opt{labels} && exists $opt{labels}->{$pkey} ) - ? $opt{labels}->{$pkey} - : $pkey -%> - -#<% ( !$clone && $object->$pkey() ) || "(NEW)" %> + + <% ( $opt{labels} && exists $opt{labels}->{$pkey} ) + ? $opt{labels}->{$pkey} + : $pkey + %> + + #<% ( !$clone && $object->$pkey() ) || "(NEW)" %> + +% } % my $tablenum = 0; @@ -723,24 +747,28 @@ Example: : $opt{'html_bottom'} %> -
+% unless ($opt{'embed'}) { -" -> +
- + " + > -<% ref( $opt{'html_foot'} ) - ? &{ $opt{'html_foot'} }( $object ) - : $opt{'html_foot'} -%> + + + <% ref( $opt{'html_foot'} ) + ? &{ $opt{'html_foot'} }( $object ) + : $opt{'html_foot'} + %> + + <% include("/elements/footer.html") %> -<% include("/elements/footer.html") %> +% } <%init> my(%opt) = @_; @@ -756,116 +784,113 @@ my $fields = $opt{'fields'} || [ grep { $_ ne $pkey } fields($table) ]; #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields; -#$m->comp('/elements/handle_uri_query'); -if ( $cgi->param('redirect') ) { - my $session = $cgi->param('redirect'); - my $pref = $curuser->option("redirect$session"); - die "unknown redirect session $session\n" unless length($pref); - $cgi = new CGI($pref); -} - -&{$opt{'begin_callback'}}( $cgi, $fields, \%opt ) - if $opt{'begin_callback'}; - -my %qsearch = ( - 'table' => $table, - 'extra_sql' => ( $opt{'agent_virt'} - ? ' AND '. $curuser->agentnums_sql( - 'null_right' => $opt{'agent_null_right'} - ) - : '' - ), -); - -my $mode; -my $object; +my( $mode, $object); my $clone = ''; -if ( $cgi->param('error') ) { +if ( $opt{'embed'} ) { - $mode = 'error'; + $object = $opt{'embed'}; + $mode = $cgi->param('error') + ? 'error' + : $object->$pkey() + ? 'edit' + : 'new'; - $object = $class->new( { - map { $_ => scalar($cgi->param($_)) } fields($table) - }); +} else { - &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt ) - if $opt{'error_callback'}; + #$m->comp('/elements/handle_uri_query'); + if ( $cgi->param('redirect') ) { + my $session = $cgi->param('redirect'); + my $pref = $curuser->option("redirect$session"); + die "unknown redirect session $session\n" unless length($pref); + $cgi = new CGI($pref); + } -} elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) { + &{$opt{'begin_callback'}}( $cgi, $fields, \%opt ) + if $opt{'begin_callback'}; + + my %qsearch = ( + 'table' => $table, + 'extra_sql' => ( $opt{'agent_virt'} + ? ' AND '. $curuser->agentnums_sql( + 'null_right' => $opt{'agent_null_right'} + ) + : '' + ), + ); - $mode = 'clone'; + if ( $cgi->param('error') ) { - $clone = $1; + $mode = 'error'; - $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'} - if $opt{'agent_clone_extra_sql'}; + $object = $class->new( { + map { $_ => scalar($cgi->param($_)) } fields($table) + }); - $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } }) - or die "$pkey $clone not found in $table"; + &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'error_callback'}; - &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt ) - if $opt{'clone_callback'}; + } elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) { - #$object->$pkey(''); + $mode = 'clone'; - $opt{action} ||= 'Add'; + $clone = $1; -} elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing + $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'} + if $opt{'agent_clone_extra_sql'}; - $mode = 'edit'; + $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } }) + or die "$pkey $clone not found in $table"; - my $value; - if ( $cgi->param($pkey) ) { - $value = $cgi->param($pkey) - } else { - my( $query ) = $cgi->keywords; - $value = $query; - } - $value =~ /^(\d+)$/ or die "unparsable $pkey"; - $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } }) - or die "$pkey $1 not found in $table"; - - warn "$table $pkey => $1" - if $opt{'debug'}; + &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'clone_callback'}; - &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt ) - if $opt{'edit_callback'}; + #$object->$pkey(''); -} else { #adding + $opt{action} ||= 'Add'; - $mode = 'new'; + } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing - my $hashref = $opt{'new_hashref_callback'} - ? &{$opt{'new_hashref_callback'}} - : {}; + $mode = 'edit'; - $object = $opt{'new_object_callback'} - ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt ) - : $class->new( $hashref ); + my $value; + if ( $cgi->param($pkey) ) { + $value = $cgi->param($pkey) + } else { + my( $query ) = $cgi->keywords; + $value = $query; + } + $value =~ /^(\d+)$/ or die "unparsable $pkey"; + $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } }) + or die "$pkey $1 not found in $table"; - &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt ) - if $opt{'new_callback'}; + warn "$table $pkey => $1" + if $opt{'debug'}; -} + &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'edit_callback'}; -&{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt ) - if $opt{'end_callback'}; + } else { #adding -$opt{action} ||= $object->$pkey() ? 'Edit' : 'Add'; + $mode = 'new'; -my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} ); + my $hashref = $opt{'new_hashref_callback'} + ? &{$opt{'new_hashref_callback'}} + : {}; -my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html"; -$viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'}; + $object = $opt{'new_object_callback'} + ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt ) + : $class->new( $hashref ); + + &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'new_callback'}; + + } + + &{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt ) + if $opt{'end_callback'}; + + $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add'; -my @menubar = (); -if ( $opt{'menubar'} ) { - @menubar = @{ $opt{'menubar'} }; -} else { - my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'}); - @menubar = ( - "View all $items" => $viewall_url, - ); }