Example:
include( 'elements/edit.html',
- 'name' =>
- 'table' =>
+ 'name_singular' => #singular name for the record
+ # (preferred, will be pluralized automatically)
+ 'name' => #name for the record
+ # (deprecated, will be pluralized simplistically)
+ 'table' =>
+
#? 'primary_key' => #required when the dbdef doesn't know...???
'labels' => {
'column' => 'Label',
'new_callback' => sub { my( $cgi, $object, $fields_listref ) = @_; },
#run before display to return a different value
- 'value_callback' => sub { my( $columname, $value } ) = @_; },
+ 'value_callback' => sub { my( $columname, $value ) = @_; },
- #XXX describe
- 'field_callback' => sub { },
+ #run before display to manipulate element of the 'fields' arrayref
+ 'field_callback' => sub { my( $cgi, $object, $field_hashref ) = @_; },
'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
<FORM ACTION="<% $url %>" METHOD=POST NAME="edit_topform">
<INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
-<INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $object->$pkey() %>">
+<INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
<FONT SIZE="+1"><B>
<% ( $opt{labels} && exists $opt{labels}->{$pkey} )
: $pkey
%>
</B></FONT>
-#<% $object->$pkey() || "(NEW)" %>
+#<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
% my $tablenum = 0;
<TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
% @$fields
% ) {
%
-% &{ $opt{'field_callback'} }( $f )
+% my $trash = &{ $opt{'field_callback'} }( $cgi, $object, $f )
% if $opt{'field_callback'};
%
% my $field = $f->{'field'};
% 'disabled' => $f->{'disabled'},
% );
%
-% #select-table
+% #selectlayers, others?
+% $include_common{$_} = $f->{$_}
+% foreach grep exists($f->{$_}),
+% qw( js_only html_only select_only layers_only cell_style);
+%
+% #select-*
+% $include_common{$_} = $f->{$_}
+% foreach grep exists($f->{$_}), qw( empty_label );
+%
+% #select-table, checkboxes-table
% $include_common{$_} = $f->{$_}
% foreach grep exists($f->{$_}), qw( table name_col );
%
+% #checkboxes-table
+% $include_common{$_} = $f->{$_}
+% foreach grep exists($f->{$_}), qw( target_table link_table );
+%
+% #*-table
+% $include_common{$_} = $f->{$_}
+% foreach grep exists($f->{$_}), qw( hashref agent_virt agent_null_right );
+%
% if ( $type eq 'tablebreak-tr-title' ) {
% $include_common{'table_id'} = 'TableNumber'. $tablenum++
% }
% $g_row++ if $type eq 'title';
% } else {
% if ( $type eq 'columnstart' ) {
-% push @g_row_stack, $g_row++;
+% push @g_row_stack, $g_row;
% $g_row = 0;
% #} elsif ( $type eq 'columnnext' ) {
% } elsif ( $type eq 'columnend' ) {
% my @existing = ();
% if ( $mode eq 'error' ) {
% @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
-% } elsif ( $object->$pkey() ) { # $mode eq 'edit'
+% } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone'
% @existing = $object->$table();
% warn scalar(@existing). " from $object->$table: ". join('/', @existing)
% if $opt{'debug'};
% 'object' => $object,
% 'cgi' => $cgi,
% 'onchange' => $onchange,
-% 'cell_style' => ( $fieldnum ? 'border-top:1px solid black' : '' ),
+% ( $fieldnum ? ('cell_style' => 'border-top:1px solid black') : () ),
% );
<% include( @include ) %>
<BR>
-<INPUT TYPE="submit" ID="submit" VALUE="<% $object->$pkey() ? "Apply changes" : "Add $opt{'name'}" %>">
+<INPUT TYPE="submit" ID="submit" VALUE="<% ( !$clone && $object->$pkey() ) ? "Apply changes" : "Add $opt{'name'}" %>">
</FORM>
$cgi = new CGI($pref);
}
-my $object;
+my %qsearch = (
+ 'table' => $table,
+ 'extra_sql' => ( $opt{'agent_virt'}
+ ? ' AND '. $curuser->agentnums_sql(
+ 'null_right' => $opt{'agent_null_right'}
+ )
+ : ''
+ ),
+);
+
my $mode;
+my $object;
+my $clone = '';
if ( $cgi->param('error') ) {
$mode = 'error';
&{$opt{'error_callback'}}($cgi, $object, $fields, \%opt )
if $opt{'error_callback'};
+} elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
+
+ $mode = 'clone';
+
+ $clone = $1;
+
+ $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } });
+
+ #XXX document me
+ &{$opt{'clone_callback'}}($cgi, $object, $fields)
+ if $opt{'clone_callback'};
+
+ #$object->$pkey('');
+
+ $opt{action} ||= 'Add';
+
} elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
$mode = 'edit';
$value = $query;
}
$value =~ /^(\d+)$/ or die "unparsable $pkey";
- $object = qsearchs({
- 'table' => $table,
- 'hashref' => { $pkey => $1 },
- 'extra_sql' => ( $opt{'agent_virt'}
- ? ' AND '. $curuser->agentnums_sql(
- 'null_right' => $opt{'agent_null_right'}
- )
- : ''
- ),
- });
+ $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } });
+
warn "$table $pkey => $1"
if $opt{'debug'};
if ( $opt{'menubar'} ) {
@menubar = @{ $opt{'menubar'} };
} else {
+ my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'});
@menubar = (
- #eventually use Lingua::bs to pluralize
- "View all $opt{'name'}s" => $viewall_url,
+ "View all $items" => $viewall_url,
);
}