further work on agents editing own packages: fix fallout on package customization...
[freeside.git] / httemplate / edit / elements / edit.html
index 33e4b0d..d18a37d 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',
 
@@ -91,31 +91,26 @@ Example:
     'menubar'     => '', #menubar arrayref
 
     #agent virtualization
-    'agent_virt'       => 1,
-    'agent_null_right' => 'Access Right Name',
-   
-    #run when re-displaying with an error
-    'error_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
-   
-    #run when editing
-    'edit_callback' => sub { my( $cgi, $object, $fields_listref ) = @_; },
-   
-    # returns a hashref for the new object
-    'new_hashref_callback'
+    'agent_virt'            => 1,
+    'agent_null_right'      => 'Access Right Name',
+    'agent_clone_extra_sql' => '', #if provided, this overrides the extra_sql
+                                   #implementing agent virt, for clone
+                                   #operations.  i.e. pass "1=1" to allow
+                                   #cloning anything
 
-    # returns the new object iself (otherwise, ->new is called)
-    'new_object_callback'
-   
-    #run when adding
-    'new_callback' => sub { my( $cgi, $object, $fields_listref ) = @_; },
-   
-    #run before display to return a different value
-    'value_callback' => sub { my( $columname, $value ) = @_; },
+    'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
 
-    #run before display to manipulate element of the 'fields' arrayref
-    'field_callback' => sub { my( $cgi, $object, $field_hashref ) = @_; },
+    # overrides default popurl(1)."process/$table.html"
+    'post_url' => popurl(1).'process/something', 
 
-    'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
+    #we're in a popup (no title/menu/searchboxes)
+    'popup' => 1,
+
+    ###
+    # HTML callbacks
+    ###
+
+    'body_etc' => '', # Additional BODY attributes, i.e. onLoad=""
 
     'html_init'   => '', #after the header/menubar
 
@@ -133,19 +128,58 @@ Example:
     #at the very bottom (well, as low as you can go from here)
     'html_foot'  => '',
 
-    # overrides default popurl(1)."process/$table.html"
-    'post_url' => popurl(1).'process/something', 
+    ###
+    # initialization callbacks
+    ###
 
-    #we're in a popup (no title/menu/searchboxes)
-    'popup' => 1,
+    ###global callbacks
+
+    #always run if provided, after decoding long CGI "redirect=" responses but
+    # before object creation/search
+    # (useful if you have a long form that might trigger redirect= and you need
+    #  to do things with $cgi params - they're not decoded in the calling
+    #  <%init> block yet)
+    'begin_callback' = sub { my( $cgi, $fields_listref, $opt_hashref ) = @_; },
+
+    #always run, after the mode-specific object creation/search
+    'end_callback' = sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
+
+    ###mode-specific callbacks
+   
+    #run when re-displaying with an error
+    'error_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
+   
+    #run when editing
+    'edit_callback' => sub { my( $cgi, $object, $fields_listref ) = @_; },
+   
+    # returns a hashref for the new object
+    'new_hashref_callback'
+
+    # returns the new object iself (otherwise, ->new is called)
+    'new_object_callback'
    
+    #run when adding
+    'new_callback' => sub { my( $cgi, $object, $fields_listref ) = @_; },
+
+    #run when cloning
+    'clone_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
+
+    ###display callbacks
+
+    #run before display to return a different value
+    'value_callback' => sub { my( $columname, $value ) = @_; },
+
+    #run before display to manipulate element of the 'fields' arrayref
+    'field_callback' => sub { my( $cgi, $object, $field_hashref ) = @_; },
+
   );
 
 </%doc>
 
 <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
               $title,
-              include( '/elements/menubar.html', @menubar )
+              include( '/elements/menubar.html', @menubar ),
+              $opt{'body_etc'},
            )
 %>
 
@@ -208,8 +242,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'},
 %
@@ -226,7 +261,7 @@ Example:
 %     'layer_values'  => $layer_values,
 %     'html_between'  => $f->{'html_between'},
 %
-%     #umm.
+%     #umm.  for select-agent_types at least
 %     'disabled'      => $f->{'disabled'},
 %   );
 %
@@ -559,6 +594,9 @@ if ( $cgi->param('redirect') ) {
   $cgi = new CGI($pref);
 }
 
+&{$opt{'begin_callback'}}( $cgi, $fields, \%opt )
+  if $opt{'begin_callback'};
+
 my %qsearch = (
     'table'     => $table,
     'extra_sql' => ( $opt{'agent_virt'}
@@ -589,10 +627,12 @@ if ( $cgi->param('error') ) {
 
   $clone = $1;
 
+  $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'}
+    if $opt{'agent_clone_extra_sql'};
+
   $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } });
 
-  #XXX document me
-  &{$opt{'clone_callback'}}($cgi, $object, $fields)
+  &{$opt{'clone_callback'}}($cgi, $object, $fields, \%opt )
     if $opt{'clone_callback'};
 
   #$object->$pkey('');
@@ -611,7 +651,8 @@ if ( $cgi->param('error') ) {
     $value = $query;
   }
   $value =~ /^(\d+)$/ or die "unparsable $pkey";
-  $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } });
+  $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } })
+    or die "$pkey $1 not found in $table";
   
   warn "$table $pkey => $1"
     if $opt{'debug'};
@@ -636,6 +677,9 @@ if ( $cgi->param('error') ) {
 
 }
 
+&{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt )
+  if $opt{'end_callback'};
+
 $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';
 
 my $title = $opt{action}. ' '. $opt{name};