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 # optional link to delete this object; primary key will be appended
112 'delete_url' => $p.'misc/delete-something.html?',
114 #we're in a popup (no title/menu/searchboxes)
117 #we're embedded (rows only: no header at all, no html_init, no error
118 # display, no <FORM>, no hidden fields for table name or primary key, no
119 # display of primary key, no submit button, no html_foot, no footer)
120 'embed' => $object, #need to pass the object
122 #don't show the primary key label and value
123 'no_pkey_display' => 1,
129 'body_etc' => '', # Additional BODY attributes, i.e. onLoad=""
131 'html_init' => '', #after the header/menubar
133 #string or coderef of additional HTML to add before </TABLE>
134 'html_table_bottom' => '',
136 #after </TABLE> but before the submit
137 'html_bottom' => '', #string
138 'html_bottom' => sub {
144 #javascript function name, will be called with form name as arg
145 'onsubmit' => 'check_form_data',
147 #at the very bottom (well, as low as you can go from here)
151 # initialization callbacks
154 ###global callbacks, always run if provided
156 #after decoding long CGI "redirect=" responses but
157 # before object creation/search
158 # (useful if you have a long form that might trigger redirect= and you need
159 # to do things with $cgi params - they're not decoded in the calling
161 'begin_callback' = sub { my( $cgi, $fields_listref, $opt_hashref ) = @_; },
163 #after the mode-specific object creation/search
164 'end_callback' = sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
166 ###mode-specific callbacks. one (and only one) of these four is called
169 'new_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
172 'edit_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
174 #run when re-displaying with an error
175 'error_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
178 'clone_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
180 ###callbacks called in new mode only
182 # returns a hashref for the new object
183 'new_hashref_callback'
185 # returns the new object iself (otherwise, ->new is called)
186 'new_object_callback'
190 #run before display to return a different value
191 'value_callback' => sub { my( $columname, $value ) = @_; },
193 #run before display to manipulate element of the 'fields' arrayref
194 'field_callback' => sub { my( $cgi, $object, $field_hashref ) = @_; },
200 % unless ( $opt{embed} ) {
202 % my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} );
204 % my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
205 % $viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
208 % if ( $opt{'menubar'} ) {
209 % @menubar = @{ $opt{'menubar'} };
211 % my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'});
213 % "View all $items" => $viewall_url,
218 <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
220 include( '/elements/menubar.html', @menubar ),
225 <% defined($opt{'html_init'})
226 ? ( ref($opt{'html_init'})
227 ? &{$opt{'html_init'}}()
233 <% include('/elements/error.html') %>
235 % my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
237 <FORM NAME = "edit_topform"
239 ACTION = "<% $url %>"
240 <% $opt{onsubmit} ? 'onSubmit="return '.$opt{onsubmit}.'(this)"' : '' %>
243 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
244 <INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
246 % unless ( $opt{'no_pkey_display'} ) {
249 <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
250 ? $opt{labels}->{$pkey}
254 #<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
261 <TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
264 % my @g_row_stack = ();
265 % foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} }
269 % my $trash = &{ $opt{'field_callback'} }( $cgi, $object, $f )
270 % if $opt{'field_callback'};
272 % my $field = $f->{'field'};
273 % my $type = $f->{'type'} ||= 'text';
275 % my $label = ( $opt{labels} && exists $opt{labels}->{$field} )
276 % ? $opt{labels}->{$field}
279 % my $onchange = $f->{'onchange'};
281 % my $layer_values = {};
282 % $layer_values = &{ $f->{'layer_values_callback'} }( $cgi, $object )
283 % if $f->{'layer_values_callback'}
284 % && ! $f->{'m2name_table'}
285 % && ! $f->{'o2m_table'}
286 % && ! $f->{'m2m_method'};
288 % warn "layer values: ". Dumper($layer_values)
291 % my %include_common = (
293 % #text and derivitives
294 % 'size' => $f->{'size'},
295 % 'maxlength' => $f->{'maxlength'},
296 % 'prefix' => $f->{'prefix'},
297 % 'postfix' => $f->{'postfix'},
300 % 'rows' => $f->{'rows'},
301 % 'cols' => $f->{'cols'},
303 % #checkbox, title, fixed, hidden
304 % #& deprecated weird value hashref used only by reason.html
305 % 'value' => $f->{'value'},
308 % 'noescape' => $f->{'noescape'},
311 % 'options' => $f->{'options'},
312 % 'labels' => $f->{'labels'},
313 % 'multiple' => $f->{'multiple'},
314 % 'label_showkey' => $f->{'label_showkey'},
315 % 'disable_empty' => $f->{'disable_empty'},
317 % 'reason_class' => $f->{'reason_class'},
320 % 'layer_fields' => $f->{'layer_fields'},
321 % 'layer_values' => $layer_values,
322 % 'html_between' => $f->{'html_between'},
324 % #umm. for select-agent_types at least
325 % 'disabled' => $f->{'disabled'},
326 % 'fixed' => $f->{'fixed'},
328 % #umm. for select-agent_types at least
329 % 'label_callback'=> $f->{'label_callback'},
332 % 'colspan' => $f->{'colspan'},
333 % 'required' => $f->{'required'},
336 % $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
337 % qw( js_only html_only select_only layers_only cell_style ),#selectlayers,?
338 % qw( empty_label ), # select-*
339 % qw( value_col compare_sub order_by ), # select-table
340 % qw( table name_col ), #(select,checkboxes)-table
341 % qw( target_table link_table ), #checkboxes-table
342 % qw( hashref agent_virt agent_null agent_null_right ),#*-table
343 % qw( formatted_value ), #fixed
344 % qw( country ), #select-country
345 % qw( width height config ), #htmlarea
346 % qw( alt_format ), #select-cust_location
347 % qw( classnum ), # select-inventory_item
348 % qw( aligned ), # columnstart
352 % $include_common{$_} = ref( $f->{$_} ) eq 'CODE'
353 % ? &{ $f->{$_} }( $cgi, $object ) #, $f )
355 % foreach grep exists($f->{$_}), qw( extra_sql );
357 % if ( $type eq 'tablebreak-tr-title' ) {
358 % $include_common{'table_id'} = 'TableNumber'. $tablenum++;
360 % if ( $type eq 'tablebreak-tr-title' || $type eq 'title' ) {
361 % $include_common{'colspan'} = $f->{colspan} if $f->{colspan};
364 % if ( $f->{include_opt_callback} ) {
365 % %include_common = ( %include_common,
366 % &{ $f->{include_opt_callback} }( $object )
370 % my $layer_prefix_on = '';
372 % my $include_sub = sub {
375 % my $fieldnum = delete $opt{'fieldnum'};
377 % my $include = $type;
378 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
379 % $include = "tr-$include" unless $include =~ /^(hidden|tablebreak|column)/;
381 % $include_common{'layer_prefix'} = "$field$fieldnum."
382 % if $layer_prefix_on;
385 % ( "/elements/$include.html",
386 % 'field' => "$field$fieldnum",
387 % 'id' => "$field$fieldnum", #separate?
388 % 'label_id' => $field."_label$fieldnum", #don't want field0_label0...
393 % if ( $include eq 'tr-input-date-field' ) {
394 % # it's either hacking it here, or changing a lot more stuff
396 % "/elements/$include.html", {
398 % 'value' => $opt{curr_value},
400 % 'noinit' => $f->{noinit},
408 % my $column_sub = sub {
411 % my $column = delete($opt{field});
412 % my $fieldnum = delete($opt{fieldnum});
413 % my $include = delete($opt{type}) || 'text';
414 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
416 % ( "/elements/$include.html",
417 % 'field' => $field.'__'.$column.$fieldnum,
418 % 'id' => $field.'__'.$column.$fieldnum,
419 % 'layer_prefix' => $field.'__'.$column.$fieldnum.".",
421 % ? ('cell_style' => 'border-top:1px solid black')
429 % unless ( $type =~ /^column/ ) {
430 % $g_row = 1 if $type eq 'tablebreak-tr-title';
432 % $g_row++ if $type eq 'title';
433 % $g_row += scalar( @{ $f->{options} } )-1 if $type eq 'radio';
435 % if ( $type eq 'columnstart' ) {
436 % push @g_row_stack, $g_row;
438 % #} elsif ( $type eq 'columnnext' ) {
439 % } elsif ( $type eq 'columnend' ) {
440 % $g_row = pop @g_row_stack;
446 % my $curr_value = '';
447 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
450 % if ( $f->{'m2name_table'} ) {
451 % $table = $f->{'m2name_table'};
452 % $col = $f->{'m2name_namecol'};
453 % } elsif ( $f->{'o2m_table'} ) {
454 % $table = $f->{'o2m_table'};
455 % $col = dbdef->table($f->{'o2m_table'})->primary_key;
456 % } elsif ( $f->{'m2m_method'} ) {
457 % $table = $f->{'m2m_method'};
458 % $col = $f->{'m2m_dstcol'};
461 % $layer_prefix_on = 1;
462 % #print out the fields for the existing m2s
464 % if ( $mode eq 'error' ) {
465 % @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
466 % } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone'
467 % @existing = $object->$table();
468 % warn scalar(@existing). " from $object->$table: ". join('/', @existing)
470 % } elsif ( $f->{'m2_new_default'} ) { # && $mode eq 'new'
471 % @existing = @{ $f->{'m2_new_default'} };
473 % foreach my $name_obj ( @existing ) {
475 % my $ex_label = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this '.
476 % lc($f->{'m2_label'}).
477 % qq(" onClick="remove_$field($fieldnum);").
478 % ' STYLE="color:#ff0000;font-weight:bold;'.
479 % 'padding-left:2px;padding-right:2px"'.
480 % '> '. ($f->{'m2_label'} || $field ). ' ';
482 % if ( $f->{'layer_values_callback'} ) {
483 % my %switches = ( 'mode' => $mode );
485 % &{ $f->{'layer_values_callback'} }( $cgi, $name_obj, \%switches );
487 % warn "layer values: ". Dumper($layer_values)
490 % my @existing = &{ $include_sub }(
491 % 'label' => $ex_label,
492 % 'fieldnum' => $fieldnum,
493 % 'curr_value' => $name_obj->$col(),
494 % 'onchange' => $onchange,
495 % 'layer_values' => $layer_values,
496 % 'cell_style' => ( $fieldnum ? 'border-top:1px solid black' : '' ),
498 % $existing[0] =~ s(^/elements/tr-)(/elements/);
499 % my @label = @existing;
500 % $label[0] = '/elements/tr-td-label.html';
502 <% include( @label ) %>
503 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
504 <% include( @existing ) %>
507 % if ( $f->{'m2_fields'} ) {
508 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
509 % my $column = $c->{field};
510 % my @column = &{ $column_sub }( %$c,
511 % 'fieldnum' => $fieldnum,
512 % 'curr_value' => $name_obj->$column()
515 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
516 style='text-align:right;vertical-align:top;
517 border-top:1px solid black;padding-top:5px;'>
518 <% $c->{'label'} || '' %>
520 <TD style='border-top:1px solid black;padding-top:3px;'>
521 <% include( @column ) %>
531 % #$field .= $fieldnum;
532 % $onchange .= "\nspawn_$field(what);";
534 % if ( $f->{curr_value_callback} ) {
535 % $curr_value = &{ $f->{curr_value_callback} }( $cgi, $object, $field ),
537 % $curr_value = $object->$field() if $field;
539 % $curr_value = &{ $opt{'value_callback'} }( $f->{'field'}, $curr_value )
540 % if $opt{'value_callback'} && $mode ne 'error';
543 % my @include = &{ $include_sub }(
545 % 'fieldnum' => $fieldnum,
546 % 'curr_value' => $curr_value,
547 % 'object' => $object,
549 % 'onchange' => $onchange,
550 % ( $fieldnum ? ('cell_style' => 'border-top:1px solid black') : () ),
553 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
554 % $include[0] =~ s(^/elements/tr-)(/elements/);
555 % my @label = @include;
556 % $label[0] = '/elements/tr-td-label.html';
558 <% include( @label ) %>
559 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
560 <% include( @include ) %>
563 % if ( $f->{'m2_fields'} ) {
564 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
565 % my $column = $c->{field};
566 % my @column = &{ $column_sub }( %$c, 'fieldnum' => $fieldnum );
568 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
569 style='text-align:right;vertical-align:top;
570 border-top:1px solid black;padding-top:5px;'>
571 <% $c->{'label'} || '' %>
573 <TD style='border-top:1px solid black;padding-top:3px;'>
574 <% include( @column ) %>
583 <% include( @include ) %>
586 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
588 <SCRIPT TYPE="text/javascript">
590 var <%$field%>_rownum = <% $g_row %>;
591 var <%$field%>_fieldnum = <% $fieldnum %>;
593 function spawn_<%$field%>(what) {
595 // only spawn if we're the last element... return if not
597 var field_regex = /(\d+)(_[a-z_]+)?$/;
598 var match = field_regex.exec(what.name);
600 alert(what.name + " didn't match for " + what);
603 if ( match[1] != <%$field%>_fieldnum ) {
607 // change the label on the last entry & add a remove button
608 var prev_label = document.getElementById('<% $field %>_label' + <%$field%>_fieldnum );
609 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 %>';
611 <%$field%>_fieldnum++;
615 % $include[0] =~ s(^/elements/tr-)(/elements/);
616 % my @layer_opt = ( @include,
617 % 'field' => $field."MAGIC_NUMBER",
618 % 'id' => $field."MAGIC_NUMBER",
619 % 'layer_prefix' => $field."MAGIC_NUMBER.",
621 % warn @layer_opt if $opt{'debug'};
623 var newrow = <% include(@layer_opt, html_only=>1) |js_string %>;
625 % #until the rest have html/js_only
626 % if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ ) {
627 var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>;
632 // substitute in the new field name
633 var magic_regex = /MAGIC_NUMBER/g;
634 newrow = newrow.replace( magic_regex, <%$field%>_fieldnum );
635 newfunc = newfunc.replace( magic_regex, <%$field%>_fieldnum );
638 if (window.ActiveXObject) {
639 window.execScript(newfunc);
640 } else { /* (window.XMLHttpRequest) */
641 //window.eval(newfunc);
642 setTimeout(newfunc, 0);
647 //hmm, can't use selectlayers after a tablebreak-title for now
648 var table = document.getElementById('TableNumber<% $tablenum-1 %>');
650 var row = table.insertRow(<%$field%>_rownum++);
652 var label_cell = document.createElement('TD');
654 label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
656 label_cell.style.textAlign = "right";
657 label_cell.style.verticalAlign = "top";
658 label_cell.style.borderTop = "1px solid black";
659 label_cell.style.paddingTop = "5px";
661 label_cell.innerHTML = '<% $label %>';
663 row.appendChild(label_cell);
665 var widget_cell = document.createElement('TD');
667 widget_cell.style.borderTop = "1px solid black";
668 widget_cell.style.paddingTop = "3px";
669 widget_cell.colSpan = "<% $f->{'colspan'} || 1 %>";
671 widget_cell.innerHTML = newrow;
673 row.appendChild(widget_cell);
675 % if ( $f->{'m2_fields'} ) {
676 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
677 % my $column = $c->{field};
678 % my @column = &{ $column_sub }(%$c, 'fieldnum' => 'MAGIC_NUMBER');
680 var column = <% include(@column, html_only=>1) |js_string %>;
681 column = column.replace( magic_regex, <%$field%>_fieldnum );
683 var column_label = document.createElement('TD');
685 '<% $field %>__<% $column %>_label' + <%$field%>_fieldnum;
687 column_label.style.textAlign = "right";
688 column_label.style.verticalAlign = "top";
689 column_label.style.borderTop = "1px solid black";
690 column_label.style.paddingTop = "5px";
692 column_label.innerHTML = '<% $c->{'label'} || '' %>';
694 row.appendChild(column_label);
696 var column_widget = document.createElement('TD');
698 column_widget.style.borderTop = "1px solid black";
699 column_widget.style.paddingTop = "3px";
701 column_widget.innerHTML = column;
703 row.appendChild(column_widget);
708 % if ( $f->{'m2_new_js'} ) {
709 // take out items selected in previous dropdowns
710 var new_element = document.getElementById("<%$field%>" + <%$field%>_fieldnum );
711 <% $f->{'m2_new_js'} %>(new_element);
713 if ( new_element.length < 2 ) {
714 //just the ** Select new **, so don't display the row
715 row.style.display = 'none';
721 function remove_<%$field%>(remove_fieldnum) {
722 //alert("remove <%$field%> " + remove_fieldnum);
723 var select = document.getElementById('<%$field%>' + remove_fieldnum);
726 alert("can't find element <%$field%>" + remove_fieldnum);
730 % my $warnings = $f->{'m2_remove_warnings'};
732 var sel_value = select.options[select.selectedIndex].value;
733 % foreach my $value ( keys %$warnings ) {
734 if ( sel_value == '<% $value %>' ) {
735 if ( ! confirm( <% $warnings->{$value} |js_string %> ) ) {
742 select.disabled = 'disabled'; // this seems to prevent it from being submitted on tested browsers so far (IE, moz, konq at least)
743 var label_td = document.getElementById('<%$field%>_label' + remove_fieldnum );
744 label_td.parentNode.style.display = 'none';
746 % if ( $f->{m2_remove_js} ) {
747 var opt = select.options[select.selectedIndex];
748 <% $f->{m2_remove_js} %>( opt.value, opt.text, 'no_match');
759 <% ref( $opt{'html_table_bottom'} )
760 ? &{ $opt{'html_table_bottom'} }( $object )
761 : $opt{'html_table_bottom'}
766 <% ref( $opt{'html_bottom'} )
767 ? &{ $opt{'html_bottom'} }( $object )
768 : $opt{'html_bottom'}
771 % unless ($opt{'embed'}) {
775 % unless ($opt{'no_submit'}) {
776 <INPUT TYPE = "submit"
778 VALUE = "<% ( !$clone && $object->$pkey() )
780 : "Add ". ($opt{'name'} || $opt{'name_singular'})
783 % if ( $opt{'delete_url'} and $object->get($pkey) ) {
784 % my $delete_msg = 'Delete this '.
785 % ($opt{'name_singular'} || $opt{'name'});
786 % my $delete_url = $opt{'delete_url'};
787 % $delete_url .= '?' unless $delete_url =~ /\?/;
788 % $delete_url .= $object->get($pkey);
789 <SCRIPT TYPE="text/javascript">
790 function confirm_delete() {
791 if(confirm(<% $delete_msg . '?' |js_string %>)) {
792 window.location.href = <% $delete_url |js_string %>;
796 <INPUT TYPE = "button"
797 VALUE = "<% $delete_msg |h %>"
798 onclick = "confirm_delete()">
804 <% ref( $opt{'html_foot'} )
805 ? &{ $opt{'html_foot'} }( $object )
809 <% include("/elements/footer.html") %>
816 my $curuser = $FS::CurrentUser::CurrentUser;
818 #false laziness w/process.html
819 my $table = $opt{'table'};
820 my $class = "FS::$table";
821 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
822 my $fields = $opt{'fields'}
823 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
824 || [ grep { $_ ne $pkey } fields($table) ];
825 #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
829 if ( $opt{'embed'} ) {
831 $object = $opt{'embed'};
832 $mode = $cgi->param('error')
840 #$m->comp('/elements/handle_uri_query');
841 if ( $cgi->param('redirect') ) {
842 my $session = $cgi->param('redirect');
843 my $pref = $curuser->option("redirect$session");
844 die "unknown redirect session $session\n" unless length($pref);
845 $cgi = new CGI($pref);
848 &{$opt{'begin_callback'}}( $cgi, $fields, \%opt )
849 if $opt{'begin_callback'};
853 'extra_sql' => ( $opt{'agent_virt'}
854 ? ' AND '. $curuser->agentnums_sql(
855 'null_right' => $opt{'agent_null_right'}
861 if ( $cgi->param('error') ) {
865 $object = $class->new( {
866 map { $_ => scalar($cgi->param($_)) } fields($table)
869 &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt )
870 if $opt{'error_callback'};
872 } elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
878 $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'}
879 if $opt{'agent_clone_extra_sql'};
881 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } })
882 or die "$pkey $clone not found in $table";
884 &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt )
885 if $opt{'clone_callback'};
889 $opt{action} ||= 'Add';
891 } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
896 if ( $cgi->param($pkey) ) {
897 $value = $cgi->param($pkey)
899 my( $query ) = $cgi->keywords;
902 $value =~ /^(\d+)$/ or die "unparsable $pkey";
903 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } })
904 or die "$pkey $1 not found in $table";
906 warn "$table $pkey => $1"
909 &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt )
910 if $opt{'edit_callback'};
916 my $hashref = $opt{'new_hashref_callback'}
917 ? &{$opt{'new_hashref_callback'}}
920 $object = $opt{'new_object_callback'}
921 ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt )
922 : $class->new( $hashref );
924 &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt )
925 if $opt{'new_callback'};
929 &{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt )
930 if $opt{'end_callback'};
932 $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';