#fixed - display fixed value from object or here
#fixed-country
#fixed-state
- 'value' => 'Y', #for checkbox, title, fixed, fixedhidden
+ 'value' => 'Y', #for checkbox, title, fixed, hidden
'disabled' => 0,
'onchange' => 'javascript_function',
'new_object_callback'
#run when adding
- 'new_callback' => sub { my( $cgi, $object, $fields_listref ) = @_; },
+ 'new_callback' => sub { my( $cgi, $object, $fields_listref, $optref ) = @_; },
+
+ #run when cloning
+ 'clone_callback' => sub { my( $cgi, $object, $fields_listref, $optref ) = @_; },
#run before display to return a different value
'value_callback' => sub { my( $columname, $value ) = @_; },
<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>
%
% #text and derivitives
% 'size' => $f->{'size'},
+% 'maxlength' => $f->{'maxlength'},
%
-% #checkbox, title, fixed, fixedhidden
+% #checkbox, title, fixed, hidden
% #& deprecated weird value hashref used only by reason.html
% 'value' => $f->{'value'},
%
% 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'};
<SCRIPT TYPE="text/javascript">
var <%$field%>_rownum = <% $g_row %>;
-% warn "g_row $g_row\n";
var <%$field%>_fieldnum = <% $fieldnum %>;
function spawn_<%$field%>(what) {
<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 } });
+
+ &{$opt{'clone_callback'}}($cgi, $object, $fields, \%opt )
+ 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'};