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 % 'noescape' => $f->{'noescape'},
299 % 'options' => $f->{'options'},
300 % 'labels' => $f->{'labels'},
301 % 'multiple' => $f->{'multiple'},
302 % 'label_showkey' => $f->{'label_showkey'},
303 % 'disable_empty' => $f->{'disable_empty'},
305 % 'reason_class' => $f->{'reason_class'},
308 % 'layer_fields' => $f->{'layer_fields'},
309 % 'layer_values' => $layer_values,
310 % 'html_between' => $f->{'html_between'},
312 % #umm. for select-agent_types at least
313 % 'disabled' => $f->{'disabled'},
314 % 'fixed' => $f->{'fixed'},
317 % 'colspan' => $f->{'colspan'},
318 % 'required' => $f->{'required'},
321 % $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
322 % qw( js_only html_only select_only layers_only cell_style ),#selectlayers,?
323 % qw( empty_label ), # select-*
324 % qw( value_col compare_sub ), # select-table
325 % qw( table name_col ), #(select,checkboxes)-table
326 % qw( target_table link_table ), #checkboxes-table
327 % qw( hashref agent_virt agent_null agent_null_right ),#*-table
328 % qw( formatted_value ), #fixed
329 % qw( country ), #select-country
330 % qw( width height ), #htmlarea
331 % qw( alt_format ), #select-cust_location
335 % $include_common{$_} = ref( $f->{$_} ) eq 'CODE'
336 % ? &{ $f->{$_} }( $cgi, $object ) #, $f )
338 % foreach grep exists($f->{$_}), qw( extra_sql );
340 % if ( $type eq 'tablebreak-tr-title' ) {
341 % $include_common{'table_id'} = 'TableNumber'. $tablenum++;
343 % if ( $type eq 'tablebreak-tr-title' || $type eq 'title' ) {
344 % $include_common{'colspan'} = $f->{colspan} if $f->{colspan};
347 % if ( $f->{include_opt_callback} ) {
348 % %include_common = ( %include_common,
349 % &{ $f->{include_opt_callback} }( $object )
353 % my $layer_prefix_on = '';
355 % my $include_sub = sub {
358 % my $fieldnum = delete $opt{'fieldnum'};
360 % my $include = $type;
361 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
362 % $include = "tr-$include" unless $include =~ /^(hidden|tablebreak|column)/;
364 % $include_common{'layer_prefix'} = "$field$fieldnum."
365 % if $layer_prefix_on;
368 % ( "/elements/$include.html",
369 % 'field' => "$field$fieldnum",
370 % 'id' => "$field$fieldnum", #separate?
371 % 'label_id' => $field."_label$fieldnum", #don't want field0_label0...
376 % if ( $include eq 'tr-input-date-field' ) {
377 % # it's either hacking it here, or changing a lot more stuff
379 % "/elements/$include.html", {
381 % 'value' => $opt{curr_value},
383 % 'noinit' => $f->{noinit},
391 % my $column_sub = sub {
394 % my $column = delete($opt{field});
395 % my $fieldnum = delete($opt{fieldnum});
396 % my $include = delete($opt{type}) || 'text';
397 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
399 % ( "/elements/$include.html",
400 % 'field' => $field.'__'.$column.$fieldnum,
401 % 'id' => $field.'__'.$column.$fieldnum,
402 % 'layer_prefix' => $field.'__'.$column.$fieldnum.".",
404 % ? ('cell_style' => 'border-top:1px solid black')
412 % unless ( $type =~ /^column/ ) {
413 % $g_row = 1 if $type eq 'tablebreak-tr-title';
415 % $g_row++ if $type eq 'title';
416 % $g_row += scalar( @{ $f->{options} } )-1 if $type eq 'radio';
418 % if ( $type eq 'columnstart' ) {
419 % push @g_row_stack, $g_row;
421 % #} elsif ( $type eq 'columnnext' ) {
422 % } elsif ( $type eq 'columnend' ) {
423 % $g_row = pop @g_row_stack;
429 % my $curr_value = '';
430 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
433 % if ( $f->{'m2name_table'} ) {
434 % $table = $f->{'m2name_table'};
435 % $col = $f->{'m2name_namecol'};
436 % } elsif ( $f->{'o2m_table'} ) {
437 % $table = $f->{'o2m_table'};
438 % $col = dbdef->table($f->{'o2m_table'})->primary_key;
439 % } elsif ( $f->{'m2m_method'} ) {
440 % $table = $f->{'m2m_method'};
441 % $col = $f->{'m2m_dstcol'};
444 % $layer_prefix_on = 1;
445 % #print out the fields for the existing m2s
447 % if ( $mode eq 'error' ) {
448 % @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
449 % } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone'
450 % @existing = $object->$table();
451 % warn scalar(@existing). " from $object->$table: ". join('/', @existing)
453 % } elsif ( $f->{'m2_new_default'} ) { # && $mode eq 'new'
454 % @existing = @{ $f->{'m2_new_default'} };
456 % foreach my $name_obj ( @existing ) {
458 % my $ex_label = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this '.
459 % lc($f->{'m2_label'}).
460 % qq(" onClick="remove_$field($fieldnum);").
461 % ' STYLE="color:#ff0000;font-weight:bold;'.
462 % 'padding-left:2px;padding-right:2px"'.
463 % '> '. ($f->{'m2_label'} || $field ). ' ';
465 % if ( $f->{'layer_values_callback'} ) {
466 % my %switches = ( 'mode' => $mode );
468 % &{ $f->{'layer_values_callback'} }( $cgi, $name_obj, \%switches );
470 % warn "layer values: ". Dumper($layer_values)
473 % my @existing = &{ $include_sub }(
474 % 'label' => $ex_label,
475 % 'fieldnum' => $fieldnum,
476 % 'curr_value' => $name_obj->$col(),
477 % 'onchange' => $onchange,
478 % 'layer_values' => $layer_values,
479 % 'cell_style' => ( $fieldnum ? 'border-top:1px solid black' : '' ),
481 % $existing[0] =~ s(^/elements/tr-)(/elements/);
482 % my @label = @existing;
483 % $label[0] = '/elements/tr-td-label.html';
485 <% include( @label ) %>
486 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
487 <% include( @existing ) %>
490 % if ( $f->{'m2_fields'} ) {
491 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
492 % my $column = $c->{field};
493 % my @column = &{ $column_sub }( %$c,
494 % 'fieldnum' => $fieldnum,
495 % 'curr_value' => $name_obj->$column()
498 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
499 style='text-align:right;vertical-align:top;
500 border-top:1px solid black;padding-top:5px;'>
501 <% $c->{'label'} || '' %>
503 <TD style='border-top:1px solid black;padding-top:3px;'>
504 <% include( @column ) %>
514 % #$field .= $fieldnum;
515 % $onchange .= "\nspawn_$field(what);";
517 % if ( $f->{curr_value_callback} ) {
518 % $curr_value = &{ $f->{curr_value_callback} }( $cgi, $object, $field ),
520 % $curr_value = $object->$field();
522 % $curr_value = &{ $opt{'value_callback'} }( $f->{'field'}, $curr_value )
523 % if $opt{'value_callback'} && $mode ne 'error';
526 % my @include = &{ $include_sub }(
528 % 'fieldnum' => $fieldnum,
529 % 'curr_value' => $curr_value,
530 % 'object' => $object,
532 % 'onchange' => $onchange,
533 % ( $fieldnum ? ('cell_style' => 'border-top:1px solid black') : () ),
536 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
537 % $include[0] =~ s(^/elements/tr-)(/elements/);
538 % my @label = @include;
539 % $label[0] = '/elements/tr-td-label.html';
541 <% include( @label ) %>
542 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
543 <% include( @include ) %>
546 % if ( $f->{'m2_fields'} ) {
547 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
548 % my $column = $c->{field};
549 % my @column = &{ $column_sub }( %$c, 'fieldnum' => $fieldnum );
551 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
552 style='text-align:right;vertical-align:top;
553 border-top:1px solid black;padding-top:5px;'>
554 <% $c->{'label'} || '' %>
556 <TD style='border-top:1px solid black;padding-top:3px;'>
557 <% include( @column ) %>
566 <% include( @include ) %>
569 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
571 <SCRIPT TYPE="text/javascript">
573 var <%$field%>_rownum = <% $g_row %>;
574 var <%$field%>_fieldnum = <% $fieldnum %>;
576 function spawn_<%$field%>(what) {
578 // only spawn if we're the last element... return if not
580 var field_regex = /(\d+)(_[a-z_]+)?$/;
581 var match = field_regex.exec(what.name);
583 alert(what.name + " didn't match for " + what);
586 if ( match[1] != <%$field%>_fieldnum ) {
590 // change the label on the last entry & add a remove button
591 var prev_label = document.getElementById('<% $field %>_label' + <%$field%>_fieldnum );
592 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 %>';
594 <%$field%>_fieldnum++;
598 % $include[0] =~ s(^/elements/tr-)(/elements/);
599 % my @layer_opt = ( @include,
600 % 'field' => $field."MAGIC_NUMBER",
601 % 'id' => $field."MAGIC_NUMBER",
602 % 'layer_prefix' => $field."MAGIC_NUMBER.",
604 % warn @layer_opt if $opt{'debug'};
606 var newrow = <% include(@layer_opt, html_only=>1) |js_string %>;
608 % #until the rest have html/js_only
609 % if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ ) {
610 var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>;
615 // substitute in the new field name
616 var magic_regex = /MAGIC_NUMBER/g;
617 newrow = newrow.replace( magic_regex, <%$field%>_fieldnum );
618 newfunc = newfunc.replace( magic_regex, <%$field%>_fieldnum );
621 if (window.ActiveXObject) {
622 window.execScript(newfunc);
623 } else { /* (window.XMLHttpRequest) */
624 //window.eval(newfunc);
625 setTimeout(newfunc, 0);
630 //hmm, can't use selectlayers after a tablebreak-title for now
631 var table = document.getElementById('TableNumber<% $tablenum-1 %>');
633 var row = table.insertRow(<%$field%>_rownum++);
635 var label_cell = document.createElement('TD');
637 label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
639 label_cell.style.textAlign = "right";
640 label_cell.style.verticalAlign = "top";
641 label_cell.style.borderTop = "1px solid black";
642 label_cell.style.paddingTop = "5px";
644 label_cell.innerHTML = '<% $label %>';
646 row.appendChild(label_cell);
648 var widget_cell = document.createElement('TD');
650 widget_cell.style.borderTop = "1px solid black";
651 widget_cell.style.paddingTop = "3px";
652 widget_cell.colSpan = "<% $f->{'colspan'} || 1 %>"
654 widget_cell.innerHTML = newrow;
656 row.appendChild(widget_cell);
658 % if ( $f->{'m2_fields'} ) {
659 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
660 % my $column = $c->{field};
661 % my @column = &{ $column_sub }(%$c, 'fieldnum' => 'MAGIC_NUMBER');
663 var column = <% include(@column, html_only=>1) |js_string %>;
664 column = column.replace( magic_regex, <%$field%>_fieldnum );
666 var column_label = document.createElement('TD');
668 '<% $field %>__<% $column %>_label' + <%$field%>_fieldnum;
670 column_label.style.textAlign = "right";
671 column_label.style.verticalAlign = "top";
672 column_label.style.borderTop = "1px solid black";
673 column_label.style.paddingTop = "5px";
675 column_label.innerHTML = '<% $c->{'label'} || '' %>';
677 row.appendChild(column_label);
679 var column_widget = document.createElement('TD');
681 column_widget.style.borderTop = "1px solid black";
682 column_widget.style.paddingTop = "3px";
684 column_widget.innerHTML = column;
686 row.appendChild(column_widget);
691 % if ( $f->{'m2_new_js'} ) {
692 // take out items selected in previous dropdowns
693 var new_element = document.getElementById("<%$field%>" + <%$field%>_fieldnum );
694 <% $f->{'m2_new_js'} %>(new_element);
696 if ( new_element.length < 2 ) {
697 //just the ** Select new **, so don't display the row
698 row.style.display = 'none';
704 function remove_<%$field%>(remove_fieldnum) {
705 //alert("remove <%$field%> " + remove_fieldnum);
706 var select = document.getElementById('<%$field%>' + remove_fieldnum);
709 alert("can't find element <%$field%>" + remove_fieldnum);
713 % my $warnings = $f->{'m2_remove_warnings'};
715 var sel_value = select.options[select.selectedIndex].value;
716 % foreach my $value ( keys %$warnings ) {
717 if ( sel_value == '<% $value %>' ) {
718 if ( ! confirm( <% $warnings->{$value} |js_string %> ) ) {
725 select.disabled = 'disabled'; // this seems to prevent it from being submitted on tested browsers so far (IE, moz, konq at least)
726 var label_td = document.getElementById('<%$field%>_label' + remove_fieldnum );
727 label_td.parentNode.style.display = 'none';
729 % if ( $f->{m2_remove_js} ) {
730 var opt = select.options[select.selectedIndex];
731 <% $f->{m2_remove_js} %>( opt.value, opt.text, 'no_match');
742 <% ref( $opt{'html_table_bottom'} )
743 ? &{ $opt{'html_table_bottom'} }( $object )
744 : $opt{'html_table_bottom'}
749 <% ref( $opt{'html_bottom'} )
750 ? &{ $opt{'html_bottom'} }( $object )
751 : $opt{'html_bottom'}
754 % unless ($opt{'embed'}) {
758 % unless ($opt{'no_submit'}) {
759 <INPUT TYPE = "submit"
761 VALUE = "<% ( !$clone && $object->$pkey() )
763 : "Add ". ($opt{'name'} || $opt{'name_singular'})
770 <% ref( $opt{'html_foot'} )
771 ? &{ $opt{'html_foot'} }( $object )
775 <% include("/elements/footer.html") %>
782 my $curuser = $FS::CurrentUser::CurrentUser;
784 #false laziness w/process.html
785 my $table = $opt{'table'};
786 my $class = "FS::$table";
787 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
788 my $fields = $opt{'fields'}
789 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
790 || [ grep { $_ ne $pkey } fields($table) ];
791 #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
795 if ( $opt{'embed'} ) {
797 $object = $opt{'embed'};
798 $mode = $cgi->param('error')
806 #$m->comp('/elements/handle_uri_query');
807 if ( $cgi->param('redirect') ) {
808 my $session = $cgi->param('redirect');
809 my $pref = $curuser->option("redirect$session");
810 die "unknown redirect session $session\n" unless length($pref);
811 $cgi = new CGI($pref);
814 &{$opt{'begin_callback'}}( $cgi, $fields, \%opt )
815 if $opt{'begin_callback'};
819 'extra_sql' => ( $opt{'agent_virt'}
820 ? ' AND '. $curuser->agentnums_sql(
821 'null_right' => $opt{'agent_null_right'}
827 if ( $cgi->param('error') ) {
831 $object = $class->new( {
832 map { $_ => scalar($cgi->param($_)) } fields($table)
835 &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt )
836 if $opt{'error_callback'};
838 } elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
844 $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'}
845 if $opt{'agent_clone_extra_sql'};
847 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } })
848 or die "$pkey $clone not found in $table";
850 &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt )
851 if $opt{'clone_callback'};
855 $opt{action} ||= 'Add';
857 } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
862 if ( $cgi->param($pkey) ) {
863 $value = $cgi->param($pkey)
865 my( $query ) = $cgi->keywords;
868 $value =~ /^(\d+)$/ or die "unparsable $pkey";
869 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } })
870 or die "$pkey $1 not found in $table";
872 warn "$table $pkey => $1"
875 &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt )
876 if $opt{'edit_callback'};
882 my $hashref = $opt{'new_hashref_callback'}
883 ? &{$opt{'new_hashref_callback'}}
886 $object = $opt{'new_object_callback'}
887 ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt )
888 : $class->new( $hashref );
890 &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt )
891 if $opt{'new_callback'};
895 &{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt )
896 if $opt{'end_callback'};
898 $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';