fix (hopefully last of the) customize package bogosity in 1.9, RT#4662
[freeside.git] / httemplate / edit / elements / edit.html
index 9347844..6178558 100644 (file)
@@ -36,7 +36,7 @@ Example:
                                        #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',
 
@@ -107,7 +107,10 @@ Example:
     '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 ) = @_; },
@@ -164,7 +167,7 @@ Example:
 <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} )
@@ -172,7 +175,7 @@ Example:
       : $pkey
 %>
 </B></FONT>
-#<% $object->$pkey() || "(NEW)" %>
+#<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
 
 % my $tablenum = 0;
 <TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
@@ -208,8 +211,9 @@ Example:
 %
 %     #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'},
 %
@@ -313,7 +317,7 @@ Example:
 %     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'};
@@ -527,7 +531,7 @@ Example:
 
 <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>
 
@@ -559,8 +563,19 @@ if ( $cgi->param('redirect') ) {
   $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';
@@ -572,6 +587,21 @@ if ( $cgi->param('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';
@@ -584,16 +614,8 @@ if ( $cgi->param('error') ) {
     $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'};