6 'name_singular' => #singular name for the record
7 # (preferred, will be pluralized automatically)
8 'name' => #name for the record
9 # (deprecated, will be pluralized simplistically)
12 #? 'primary_key' => #required when the dbdef doesn't know...???
17 #listref - each item is a literal column name (or method) or hashref
19 #if not specified all columns (except for the primary key) will be editable
22 { 'field' => 'another_columname',
23 'type' => 'text', #text
29 #selectlayers (can now use after a tablebreak-tr-title... but not inside columnstart/columnnext/columnend)
35 #hidden - hidden value from object
36 #fixed - display fixed value from object or here
39 'value' => 'Y', #for checkbox, title, fixed, hidden
41 'onchange' => 'javascript_function',
43 'include_opt_callback' => sub { my $object = @_;
44 ( 'option' => 'value', );
47 'm2name_table' => 'table_name',
48 'm2name_namecol' => 'name_column',
51 #'m2m_srccol' => #opt, if not the same as this table
52 'm2m_dstcol' => #required for now, eventuaully opt, if not the same as target table
56 'm2_label' => 'Label', #
57 'm2_new_default' => \@table_name_objects, #default
60 'm2_error_callback' => sub { my($cgi, $object) = @_; },
61 'm2_remove_warnings' => \%warnings, #hashref of warning
64 'm2_new_js' => 'function_name', #javascript function called
65 #on spawned rows (one arg:
67 'm2_remove_js' => 'function_name', #js function called when
68 #a row is deleted (three
71 #layer_fields & layer_values_callback only for selectlayer
73 'fieldname' => 'Label',
76 type =>'text', #text, money
79 'layer_values_callback' =>
81 my( $cgi, $object ) = @_;
82 { 'layer' => { 'fieldname' => 'current_value',
83 'fieldname2' => 'field2value',
86 'layer2' => { 'l2fieldname' => 'l2value',
95 'menubar' => '', #menubar arrayref
99 'agent_null' => 1, #if true, always allow no-agentnum globals
100 'agent_null_right' => 'Access Right Name',
101 'agent_clone_extra_sql' => '', #if provided, this overrides the extra_sql
102 #implementing agent virt, for clone
103 #operations. i.e. pass "1=1" to allow
106 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
108 # overrides default popurl(1)."process/$table.html"
109 'post_url' => popurl(1).'process/something',
111 #we're in a popup (no title/menu/searchboxes)
114 #we're embedded (rows only: no header at all, no html_init, no error
115 # display, no <FORM>, no hidden fields for table name or primary key, no
116 # display of primary key, no submit button, no html_foot, no footer)
117 'embed' => $object, #need to pass the object
123 'body_etc' => '', # Additional BODY attributes, i.e. onLoad=""
125 'html_init' => '', #after the header/menubar
127 #string or coderef of additional HTML to add before </TABLE>
128 'html_table_bottom' => '',
130 #after </TABLE> but before the submit
131 'html_bottom' => '', #string
132 'html_bottom' => sub {
138 #javascript function name, will be called with form name as arg
139 'onsubmit' => 'check_form_data',
141 #at the very bottom (well, as low as you can go from here)
145 # initialization callbacks
148 ###global callbacks, always run if provided
150 #after decoding long CGI "redirect=" responses but
151 # before object creation/search
152 # (useful if you have a long form that might trigger redirect= and you need
153 # to do things with $cgi params - they're not decoded in the calling
155 'begin_callback' = sub { my( $cgi, $fields_listref, $opt_hashref ) = @_; },
157 #after the mode-specific object creation/search
158 'end_callback' = sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
160 ###mode-specific callbacks. one (and only one) of these four is called
163 'new_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
166 'edit_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
168 #run when re-displaying with an error
169 'error_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
172 'clone_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
174 ###callbacks called in new mode only
176 # returns a hashref for the new object
177 'new_hashref_callback'
179 # returns the new object iself (otherwise, ->new is called)
180 'new_object_callback'
184 #run before display to return a different value
185 'value_callback' => sub { my( $columname, $value ) = @_; },
187 #run before display to manipulate element of the 'fields' arrayref
188 'field_callback' => sub { my( $cgi, $object, $field_hashref ) = @_; },
194 % unless ( $opt{embed} ) {
196 % my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} );
198 % my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
199 % $viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
202 % if ( $opt{'menubar'} ) {
203 % @menubar = @{ $opt{'menubar'} };
205 % my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'});
207 % "View all $items" => $viewall_url,
211 <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
213 include( '/elements/menubar.html', @menubar ),
218 <% defined($opt{'html_init'})
219 ? ( ref($opt{'html_init'})
220 ? &{$opt{'html_init'}}()
226 <% include('/elements/error.html') %>
228 % my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
230 <FORM NAME = "edit_topform"
232 ACTION = "<% $url %>"
233 <% $opt{onsubmit} ? 'onSubmit="return '.$opt{onsubmit}.'(this)"' : '' %>
236 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
237 <INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
240 <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
241 ? $opt{labels}->{$pkey}
245 #<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
250 <TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
253 % my @g_row_stack = ();
254 % foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} }
258 % my $trash = &{ $opt{'field_callback'} }( $cgi, $object, $f )
259 % if $opt{'field_callback'};
261 % my $field = $f->{'field'};
262 % my $type = $f->{'type'} ||= 'text';
264 % my $label = ( $opt{labels} && exists $opt{labels}->{$field} )
265 % ? $opt{labels}->{$field}
268 % my $onchange = $f->{'onchange'};
270 % my $layer_values = {};
271 % $layer_values = &{ $f->{'layer_values_callback'} }( $cgi, $object )
272 % if $f->{'layer_values_callback'}
273 % && ! $f->{'m2name_table'}
274 % && ! $f->{'o2m_table'}
275 % && ! $f->{'m2m_method'};
277 % warn "layer values: ". Dumper($layer_values)
280 % my %include_common = (
282 % #text and derivitives
283 % 'size' => $f->{'size'},
284 % 'maxlength' => $f->{'maxlength'},
285 % 'postfix' => $f->{'postfix'},
288 % 'rows' => $f->{'rows'},
289 % 'cols' => $f->{'cols'},
291 % #checkbox, title, fixed, hidden
292 % #& deprecated weird value hashref used only by reason.html
293 % 'value' => $f->{'value'},
296 % 'options' => $f->{'options'},
297 % 'labels' => $f->{'labels'},
298 % 'multiple' => $f->{'multiple'},
299 % 'label_showkey' => $f->{'label_showkey'},
300 % 'disable_empty' => $f->{'disable_empty'},
302 % 'reason_class' => $f->{'reason_class'},
305 % 'layer_fields' => $f->{'layer_fields'},
306 % 'layer_values' => $layer_values,
307 % 'html_between' => $f->{'html_between'},
309 % #umm. for select-agent_types at least
310 % 'disabled' => $f->{'disabled'},
313 % 'colspan' => $f->{'colspan'},
314 % 'required' => $f->{'required'},
317 % $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
318 % qw( js_only html_only select_only layers_only cell_style ),#selectlayers,?
319 % qw( empty_label ), # select-*
320 % qw( value_col compare_sub ), # select-table
321 % qw( table name_col ), #(select,checkboxes)-table
322 % qw( target_table link_table ), #checkboxes-table
323 % qw( hashref agent_virt agent_null agent_null_right ),#*-table
324 % qw( formatted_value ), #fixed
325 % qw( country ), #select-country
326 % qw( width height ), #htmlarea
327 % qw( alt_format ), #select-cust_location
331 % $include_common{$_} = ref( $f->{$_} ) eq 'CODE'
332 % ? &{ $f->{$_} }( $cgi, $object ) #, $f )
334 % foreach grep exists($f->{$_}), qw( extra_sql );
336 % if ( $type eq 'tablebreak-tr-title' ) {
337 % $include_common{'table_id'} = 'TableNumber'. $tablenum++;
339 % if ( $type eq 'tablebreak-tr-title' || $type eq 'title' ) {
340 % $include_common{'colspan'} = $f->{colspan} if $f->{colspan};
343 % if ( $f->{include_opt_callback} ) {
344 % %include_common = ( %include_common,
345 % &{ $f->{include_opt_callback} }( $object )
349 % my $layer_prefix_on = '';
351 % my $include_sub = sub {
354 % my $fieldnum = delete $opt{'fieldnum'};
356 % my $include = $type;
357 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
358 % $include = "tr-$include" unless $include =~ /^(hidden|tablebreak|column)/;
360 % $include_common{'layer_prefix'} = "$field$fieldnum."
361 % if $layer_prefix_on;
364 % ( "/elements/$include.html",
365 % 'field' => "$field$fieldnum",
366 % 'id' => "$field$fieldnum", #separate?
367 % 'label_id' => $field."_label$fieldnum", #don't want field0_label0...
372 % if ( $include eq 'tr-input-date-field' ) {
373 % # it's either hacking it here, or changing a lot more stuff
375 % "/elements/$include.html", {
377 % 'value' => $opt{curr_value},
379 % 'noinit' => $f->{noinit},
387 % my $column_sub = sub {
390 % my $column = delete($opt{field});
391 % my $fieldnum = delete($opt{fieldnum});
392 % my $include = delete($opt{type}) || 'text';
393 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
395 % ( "/elements/$include.html",
396 % 'field' => $field.'__'.$column.$fieldnum,
397 % 'id' => $field.'__'.$column.$fieldnum,
398 % 'layer_prefix' => $field.'__'.$column.$fieldnum.".",
400 % ? ('cell_style' => 'border-top:1px solid black')
408 % unless ( $type =~ /^column/ ) {
409 % $g_row = 1 if $type eq 'tablebreak-tr-title';
411 % $g_row++ if $type eq 'title';
412 % $g_row += scalar( @{ $f->{options} } )-1 if $type eq 'radio';
414 % if ( $type eq 'columnstart' ) {
415 % push @g_row_stack, $g_row;
417 % #} elsif ( $type eq 'columnnext' ) {
418 % } elsif ( $type eq 'columnend' ) {
419 % $g_row = pop @g_row_stack;
425 % my $curr_value = '';
426 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
429 % if ( $f->{'m2name_table'} ) {
430 % $table = $f->{'m2name_table'};
431 % $col = $f->{'m2name_namecol'};
432 % } elsif ( $f->{'o2m_table'} ) {
433 % $table = $f->{'o2m_table'};
434 % $col = dbdef->table($f->{'o2m_table'})->primary_key;
435 % } elsif ( $f->{'m2m_method'} ) {
436 % $table = $f->{'m2m_method'};
437 % $col = $f->{'m2m_dstcol'};
440 % $layer_prefix_on = 1;
441 % #print out the fields for the existing m2s
443 % if ( $mode eq 'error' ) {
444 % @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
445 % } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone'
446 % @existing = $object->$table();
447 % warn scalar(@existing). " from $object->$table: ". join('/', @existing)
449 % } elsif ( $f->{'m2_new_default'} ) { # && $mode eq 'new'
450 % @existing = @{ $f->{'m2_new_default'} };
452 % foreach my $name_obj ( @existing ) {
454 % my $ex_label = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this '.
455 % lc($f->{'m2_label'}).
456 % qq(" onClick="remove_$field($fieldnum);").
457 % ' STYLE="color:#ff0000;font-weight:bold;'.
458 % 'padding-left:2px;padding-right:2px"'.
459 % '> '. ($f->{'m2_label'} || $field ). ' ';
461 % if ( $f->{'layer_values_callback'} ) {
462 % my %switches = ( 'mode' => $mode );
464 % &{ $f->{'layer_values_callback'} }( $cgi, $name_obj, \%switches );
466 % warn "layer values: ". Dumper($layer_values)
469 % my @existing = &{ $include_sub }(
470 % 'label' => $ex_label,
471 % 'fieldnum' => $fieldnum,
472 % 'curr_value' => $name_obj->$col(),
473 % 'onchange' => $onchange,
474 % 'layer_values' => $layer_values,
475 % 'cell_style' => ( $fieldnum ? 'border-top:1px solid black' : '' ),
477 % $existing[0] =~ s(^/elements/tr-)(/elements/);
478 % my @label = @existing;
479 % $label[0] = '/elements/tr-td-label.html';
481 <% include( @label ) %>
482 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
483 <% include( @existing ) %>
486 % if ( $f->{'m2_fields'} ) {
487 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
488 % my $column = $c->{field};
489 % my @column = &{ $column_sub }( %$c,
490 % 'fieldnum' => $fieldnum,
491 % 'curr_value' => $name_obj->$column()
494 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
495 style='text-align:right;vertical-align:top;
496 border-top:1px solid black;padding-top:5px;'>
497 <% $c->{'label'} || '' %>
499 <TD style='border-top:1px solid black;padding-top:3px;'>
500 <% include( @column ) %>
510 % #$field .= $fieldnum;
511 % $onchange .= "\nspawn_$field(what);";
513 % if ( $f->{curr_value_callback} ) {
514 % $curr_value = &{ $f->{curr_value_callback} }( $cgi, $object, $field ),
516 % $curr_value = $object->$field();
518 % $curr_value = &{ $opt{'value_callback'} }( $f->{'field'}, $curr_value )
519 % if $opt{'value_callback'} && $mode ne 'error';
522 % my @include = &{ $include_sub }(
524 % 'fieldnum' => $fieldnum,
525 % 'curr_value' => $curr_value,
526 % 'object' => $object,
528 % 'onchange' => $onchange,
529 % ( $fieldnum ? ('cell_style' => 'border-top:1px solid black') : () ),
532 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
533 % $include[0] =~ s(^/elements/tr-)(/elements/);
534 % my @label = @include;
535 % $label[0] = '/elements/tr-td-label.html';
537 <% include( @label ) %>
538 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
539 <% include( @include ) %>
542 % if ( $f->{'m2_fields'} ) {
543 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
544 % my $column = $c->{field};
545 % my @column = &{ $column_sub }( %$c, 'fieldnum' => $fieldnum );
547 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
548 style='text-align:right;vertical-align:top;
549 border-top:1px solid black;padding-top:5px;'>
550 <% $c->{'label'} || '' %>
552 <TD style='border-top:1px solid black;padding-top:3px;'>
553 <% include( @column ) %>
562 <% include( @include ) %>
565 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
567 <SCRIPT TYPE="text/javascript">
569 var <%$field%>_rownum = <% $g_row %>;
570 var <%$field%>_fieldnum = <% $fieldnum %>;
572 function spawn_<%$field%>(what) {
574 // only spawn if we're the last element... return if not
576 var field_regex = /(\d+)(_[a-z_]+)?$/;
577 var match = field_regex.exec(what.name);
579 alert(what.name + " didn't match for " + what);
582 if ( match[1] != <%$field%>_fieldnum ) {
586 // change the label on the last entry & add a remove button
587 var prev_label = document.getElementById('<% $field %>_label' + <%$field%>_fieldnum );
588 prev_label.innerHTML = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this <% lc($f->{'m2_label'}) %>" onClick="remove_<% $field %>(' + <%$field%>_fieldnum + ');" STYLE="color:#ff0000;font-weight:bold;padding-left:2px;padding-right:2px" > <% $f->{'m2_label'} || $field %>';
590 <%$field%>_fieldnum++;
594 % $include[0] =~ s(^/elements/tr-)(/elements/);
595 % my @layer_opt = ( @include,
596 % 'field' => $field."MAGIC_NUMBER",
597 % 'id' => $field."MAGIC_NUMBER",
598 % 'layer_prefix' => $field."MAGIC_NUMBER.",
600 % warn @layer_opt if $opt{'debug'};
602 var newrow = <% include(@layer_opt, html_only=>1) |js_string %>;
604 % #until the rest have html/js_only
605 % if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ ) {
606 var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>;
611 // substitute in the new field name
612 var magic_regex = /MAGIC_NUMBER/g;
613 newrow = newrow.replace( magic_regex, <%$field%>_fieldnum );
614 newfunc = newfunc.replace( magic_regex, <%$field%>_fieldnum );
617 if (window.ActiveXObject) {
618 window.execScript(newfunc);
619 } else { /* (window.XMLHttpRequest) */
620 //window.eval(newfunc);
621 setTimeout(newfunc, 0);
626 //hmm, can't use selectlayers after a tablebreak-title for now
627 var table = document.getElementById('TableNumber<% $tablenum-1 %>');
629 var row = table.insertRow(<%$field%>_rownum++);
631 var label_cell = document.createElement('TD');
633 label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
635 label_cell.style.textAlign = "right";
636 label_cell.style.verticalAlign = "top";
637 label_cell.style.borderTop = "1px solid black";
638 label_cell.style.paddingTop = "5px";
640 label_cell.innerHTML = '<% $label %>';
642 row.appendChild(label_cell);
644 var widget_cell = document.createElement('TD');
646 widget_cell.style.borderTop = "1px solid black";
647 widget_cell.style.paddingTop = "3px";
648 widget_cell.colSpan = "<% $f->{'colspan'} || 1 %>"
650 widget_cell.innerHTML = newrow;
652 row.appendChild(widget_cell);
654 % if ( $f->{'m2_fields'} ) {
655 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
656 % my $column = $c->{field};
657 % my @column = &{ $column_sub }(%$c, 'fieldnum' => 'MAGIC_NUMBER');
659 var column = <% include(@column, html_only=>1) |js_string %>;
660 column = column.replace( magic_regex, <%$field%>_fieldnum );
662 var column_label = document.createElement('TD');
664 '<% $field %>__<% $column %>_label' + <%$field%>_fieldnum;
666 column_label.style.textAlign = "right";
667 column_label.style.verticalAlign = "top";
668 column_label.style.borderTop = "1px solid black";
669 column_label.style.paddingTop = "5px";
671 column_label.innerHTML = '<% $c->{'label'} || '' %>';
673 row.appendChild(column_label);
675 var column_widget = document.createElement('TD');
677 column_widget.style.borderTop = "1px solid black";
678 column_widget.style.paddingTop = "3px";
680 column_widget.innerHTML = column;
682 row.appendChild(column_widget);
687 % if ( $f->{'m2_new_js'} ) {
688 // take out items selected in previous dropdowns
689 var new_element = document.getElementById("<%$field%>" + <%$field%>_fieldnum );
690 <% $f->{'m2_new_js'} %>(new_element);
692 if ( new_element.length < 2 ) {
693 //just the ** Select new **, so don't display the row
694 row.style.display = 'none';
700 function remove_<%$field%>(remove_fieldnum) {
701 //alert("remove <%$field%> " + remove_fieldnum);
702 var select = document.getElementById('<%$field%>' + remove_fieldnum);
705 alert("can't find element <%$field%>" + remove_fieldnum);
709 % my $warnings = $f->{'m2_remove_warnings'};
711 var sel_value = select.options[select.selectedIndex].value;
712 % foreach my $value ( keys %$warnings ) {
713 if ( sel_value == '<% $value %>' ) {
714 if ( ! confirm( <% $warnings->{$value} |js_string %> ) ) {
721 select.disabled = 'disabled'; // this seems to prevent it from being submitted on tested browsers so far (IE, moz, konq at least)
722 var label_td = document.getElementById('<%$field%>_label' + remove_fieldnum );
723 label_td.parentNode.style.display = 'none';
725 % if ( $f->{m2_remove_js} ) {
726 var opt = select.options[select.selectedIndex];
727 <% $f->{m2_remove_js} %>( opt.value, opt.text, 'no_match');
738 <% ref( $opt{'html_table_bottom'} )
739 ? &{ $opt{'html_table_bottom'} }( $object )
740 : $opt{'html_table_bottom'}
745 <% ref( $opt{'html_bottom'} )
746 ? &{ $opt{'html_bottom'} }( $object )
747 : $opt{'html_bottom'}
750 % unless ($opt{'embed'}) {
754 <INPUT TYPE = "submit"
756 VALUE = "<% ( !$clone && $object->$pkey() )
758 : "Add ". ( $opt{'name'} || $opt{'name_singular'} )
764 <% ref( $opt{'html_foot'} )
765 ? &{ $opt{'html_foot'} }( $object )
769 <% include("/elements/footer.html") %>
776 my $curuser = $FS::CurrentUser::CurrentUser;
778 #false laziness w/process.html
779 my $table = $opt{'table'};
780 my $class = "FS::$table";
781 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
782 my $fields = $opt{'fields'}
783 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
784 || [ grep { $_ ne $pkey } fields($table) ];
785 #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
789 if ( $opt{'embed'} ) {
791 $object = $opt{'embed'};
792 $mode = $cgi->param('error')
800 #$m->comp('/elements/handle_uri_query');
801 if ( $cgi->param('redirect') ) {
802 my $session = $cgi->param('redirect');
803 my $pref = $curuser->option("redirect$session");
804 die "unknown redirect session $session\n" unless length($pref);
805 $cgi = new CGI($pref);
808 &{$opt{'begin_callback'}}( $cgi, $fields, \%opt )
809 if $opt{'begin_callback'};
813 'extra_sql' => ( $opt{'agent_virt'}
814 ? ' AND '. $curuser->agentnums_sql(
815 'null_right' => $opt{'agent_null_right'}
821 if ( $cgi->param('error') ) {
825 $object = $class->new( {
826 map { $_ => scalar($cgi->param($_)) } fields($table)
829 &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt )
830 if $opt{'error_callback'};
832 } elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
838 $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'}
839 if $opt{'agent_clone_extra_sql'};
841 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } })
842 or die "$pkey $clone not found in $table";
844 &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt )
845 if $opt{'clone_callback'};
849 $opt{action} ||= 'Add';
851 } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
856 if ( $cgi->param($pkey) ) {
857 $value = $cgi->param($pkey)
859 my( $query ) = $cgi->keywords;
862 $value =~ /^(\d+)$/ or die "unparsable $pkey";
863 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } })
864 or die "$pkey $1 not found in $table";
866 warn "$table $pkey => $1"
869 &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt )
870 if $opt{'edit_callback'};
876 my $hashref = $opt{'new_hashref_callback'}
877 ? &{$opt{'new_hashref_callback'}}
880 $object = $opt{'new_object_callback'}
881 ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt )
882 : $class->new( $hashref );
884 &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt )
885 if $opt{'new_callback'};
889 &{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt )
890 if $opt{'end_callback'};
892 $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';