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
121 'tablenum' => 4, #need to specify a table number when using multiple
122 #embedded edits on a page (and m2 stuff)
124 #don't show the primary key label and value
125 'no_pkey_display' => 1,
131 'body_etc' => '', # Additional BODY attributes, i.e. onLoad=""
133 'html_init' => '', #after the header/menubar
135 'form_init' => '', #after html_init, error and the opening <FORM>, but
136 #before any other form contents
138 #string or coderef of additional HTML to add before </TABLE>
139 'html_table_bottom' => '',
141 #after </TABLE> but before the submit
142 'html_bottom' => '', #string
143 'html_bottom' => sub {
149 #javascript function name, will be called with form name as arg
150 'onsubmit' => 'check_form_data',
152 #at the very bottom (well, as low as you can go from here)
156 # initialization callbacks
159 ###global callbacks, always run if provided
161 #after decoding long CGI "redirect=" responses but
162 # before object creation/search
163 # (useful if you have a long form that might trigger redirect= and you need
164 # to do things with $cgi params - they're not decoded in the calling
166 'begin_callback' = sub { my( $cgi, $fields_listref, $opt_hashref ) = @_; },
168 #after the mode-specific object creation/search
169 'end_callback' = sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
171 ###mode-specific callbacks. one (and only one) of these four is called
174 'new_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
177 'edit_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
179 #run when re-displaying with an error
180 'error_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
183 'clone_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
185 ###callbacks called in new mode only
187 # returns a hashref for the new object
188 'new_hashref_callback'
190 # returns the new object iself (otherwise, ->new is called)
191 'new_object_callback'
195 #run before display to return a different value
196 'value_callback' => sub { my( $columname, $value ) = @_; },
198 #run before display to manipulate element of the 'fields' arrayref
199 'field_callback' => sub { my( $cgi, $object, $field_hashref ) = @_; },
205 % unless ( $opt{embed} ) {
207 % my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} );
209 % my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
210 % $viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
213 % if ( $opt{'menubar'} ) {
214 % @menubar = @{ $opt{'menubar'} };
216 % my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'});
218 % "View all $items" => $viewall_url,
222 <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
224 include( '/elements/menubar.html', @menubar ),
229 <% defined($opt{'html_init'})
230 ? ( ref($opt{'html_init'})
231 ? &{$opt{'html_init'}}()
237 <% include('/elements/error.html') %>
239 % my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
241 <FORM NAME = "edit_topform"
243 ACTION = "<% $url %>"
244 <% $opt{onsubmit} ? 'onSubmit="return '.$opt{onsubmit}.'(this)"' : '' %>
247 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
248 <INPUT TYPE="hidden" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
250 <% defined($opt{'form_init'})
251 ? ( ref($opt{'form_init'})
252 ? &{$opt{'form_init'}}()
258 % unless ( $opt{'no_pkey_display'} ) {
261 <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
262 ? $opt{labels}->{$pkey}
266 #<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
272 % my $tablenum = $opt{'tablenum'} || 0;
273 <TABLE ID="TableNumber<% $tablenum++ %>" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
276 % my @g_row_stack = ();
277 % foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} }
281 % my $trash = &{ $opt{'field_callback'} }( $cgi, $object, $f )
282 % if $opt{'field_callback'};
284 % my $field = $f->{'field'};
285 % my $type = $f->{'type'} ||= 'text';
287 % my $label = ( $opt{labels} && exists $opt{labels}->{$field} )
288 % ? $opt{labels}->{$field}
291 % my $onchange = $f->{'onchange'};
293 % my $layer_values = {};
294 % $layer_values = &{ $f->{'layer_values_callback'} }( $cgi, $object )
295 % if $f->{'layer_values_callback'}
296 % && ! $f->{'m2name_table'}
297 % && ! $f->{'o2m_table'}
298 % && ! $f->{'m2m_method'};
300 % warn "layer values: ". Dumper($layer_values)
303 % my %include_common = (
305 % #text and derivitives
306 % 'size' => $f->{'size'},
307 % 'maxlength' => $f->{'maxlength'},
308 % 'prefix' => $f->{'prefix'},
309 % 'postfix' => $f->{'postfix'},
312 % 'rows' => $f->{'rows'},
313 % 'cols' => $f->{'cols'},
315 % #checkbox, title, fixed, hidden
316 % #& deprecated weird value hashref used only by reason.html
317 % 'value' => $f->{'value'},
320 % 'noescape' => $f->{'noescape'},
323 % 'options' => $f->{'options'},
324 % 'labels' => $f->{'labels'},
325 % 'multiple' => $f->{'multiple'},
326 % 'label_showkey' => $f->{'label_showkey'},
327 % 'disable_empty' => $f->{'disable_empty'},
329 % 'reason_class' => $f->{'reason_class'},
331 % 'viewall_right' => $f->{'viewall_right'},
334 % 'layer_fields' => $f->{'layer_fields'},
335 % 'layer_values' => $layer_values,
336 % 'html_between' => $f->{'html_between'},
338 % #umm. for select-agent_type at least
339 % 'disabled' => $f->{'disabled'},
340 % 'fixed' => $f->{'fixed'},
341 % 'label_callback'=> $f->{'label_callback'},
342 % 'element_etc' => $f->{'element_etc'},
344 % #for select-ticketing_queueid at least
345 % 'post_options' => $f->{'post_options'},
348 % 'colspan' => $f->{'colspan'},
349 % 'required' => $f->{'required'},
352 % 'custnum' => $f->{'custnum'},
353 % 'prospectnum' => $f->{'prospectnum'},
356 % $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
357 % qw( js_only html_only select_only layers_only cell_style ),#selectlayers,?
358 % qw( empty_label ), # select-*
359 % qw( value_col compare_sub order_by ), # select-table
360 % qw( table name_col ), #(select,checkboxes)-table
361 % qw( target_table link_table ), #checkboxes-table
362 % qw( hashref agent_virt agent_null agent_null_right ),#*-table
363 % qw( formatted_value ), #fixed
364 % qw( country ), #select-country
365 % qw( width height config ), #htmlarea
366 % qw( alt_format ), #select-cust_location
367 % qw( classnum ), # select-inventory_item
368 % qw( aligned ), # columnstart
372 % $include_common{$_} = ref( $f->{$_} ) eq 'CODE'
373 % ? &{ $f->{$_} }( $cgi, $object ) #, $f )
375 % foreach grep exists($f->{$_}), qw( extra_sql );
377 % if ( $type eq 'tablebreak-tr-title' ) {
378 % $include_common{'table_id'} = 'TableNumber'. $tablenum++;
380 % if ( $type eq 'tablebreak-tr-title' || $type eq 'title' ) {
381 % $include_common{'colspan'} = $f->{colspan} if $f->{colspan};
384 % if ( $f->{include_opt_callback} ) {
385 % %include_common = ( %include_common,
386 % &{ $f->{include_opt_callback} }( $object )
390 % my $layer_prefix_on = '';
392 % my $include_sub = sub {
395 % my $fieldnum = delete $opt{'fieldnum'};
397 % my $include = $type;
398 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
399 % $include = "tr-$include" unless $include =~ /^(hidden|tablebreak|column)/;
401 % $include_common{'layer_prefix'} = "$field$fieldnum."
402 % if $layer_prefix_on;
405 % ( "/elements/$include.html",
406 % 'field' => "$field$fieldnum",
407 % 'id' => "$field$fieldnum", #separate?
408 % 'label_id' => $field."_label$fieldnum", #don't want field0_label0...
413 % if ( $include eq 'tr-input-date-field' ) {
414 % # it's either hacking it here, or changing a lot more stuff
416 % "/elements/$include.html", {
418 % 'value' => $opt{curr_value},
420 % 'noinit' => $f->{noinit},
428 % my $column_sub = sub {
431 % my $column = delete($opt{field});
432 % my $fieldnum = delete($opt{fieldnum});
433 % my $include = delete($opt{type}) || 'text';
434 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
436 % ( "/elements/$include.html",
437 % 'field' => $field.'__'.$column.$fieldnum,
438 % 'id' => $field.'__'.$column.$fieldnum,
439 % 'layer_prefix' => $field.'__'.$column.$fieldnum.".",
441 % ? ('cell_style' => 'border-top:1px solid black')
449 % unless ( $type =~ /^column/ ) {
450 % $g_row = 1 if $type eq 'tablebreak-tr-title';
452 % $g_row++ if $type eq 'title';
453 % $g_row += scalar( @{ $f->{options} } )-1 if $type eq 'radio';
455 % if ( $type eq 'columnstart' ) {
456 % push @g_row_stack, $g_row;
458 % #} elsif ( $type eq 'columnnext' ) {
459 % } elsif ( $type eq 'columnend' ) {
460 % $g_row = pop @g_row_stack;
466 % my $curr_value = '';
467 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
470 % if ( $f->{'m2name_table'} ) {
471 % $table = $f->{'m2name_table'};
472 % $col = $f->{'m2name_namecol'};
473 % } elsif ( $f->{'o2m_table'} ) {
474 % $table = $f->{'o2m_table'};
475 % $col = dbdef->table($f->{'o2m_table'})->primary_key;
476 % } elsif ( $f->{'m2m_method'} ) {
477 % $table = $f->{'m2m_method'};
478 % $col = $f->{'m2m_dstcol'};
481 % $layer_prefix_on = 1;
482 % #print out the fields for the existing m2s
484 % if ( $mode eq 'error' ) {
485 % @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
486 % } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone'
487 % @existing = $object->$table();
488 % warn scalar(@existing). " from $object->$table: ". join('/', @existing)
490 % } elsif ( $f->{'m2_new_default'} ) { # && $mode eq 'new'
491 % @existing = @{ $f->{'m2_new_default'} };
493 % foreach my $name_obj ( @existing ) {
495 % my $ex_label = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this '.
496 % lc($f->{'m2_label'}).
497 % qq(" onClick="remove_$field($fieldnum);").
498 % ' STYLE="color:#ff0000;font-weight:bold;'.
499 % 'padding-left:2px;padding-right:2px"'.
500 % '> '. ($f->{'m2_label'} || $field ). ' ';
502 % if ( $f->{'layer_values_callback'} ) {
503 % my %switches = ( 'mode' => $mode );
505 % &{ $f->{'layer_values_callback'} }( $cgi, $name_obj, \%switches );
507 % warn "layer values: ". Dumper($layer_values)
510 % my @existing = &{ $include_sub }(
511 % 'label' => $ex_label,
512 % 'fieldnum' => $fieldnum,
513 % 'curr_value' => $name_obj->$col(),
514 % 'onchange' => $onchange,
515 % 'layer_values' => $layer_values,
516 % 'cell_style' => ( $fieldnum ? 'border-top:1px solid black' : '' ),
518 % $existing[0] =~ s(^/elements/tr-)(/elements/);
519 % my @label = @existing;
520 % $label[0] = '/elements/tr-td-label.html';
522 <% include( @label ) %>
523 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
524 <% include( @existing ) %>
527 % if ( $f->{'m2_fields'} ) {
528 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
529 % my $column = $c->{field};
530 % my @column = &{ $column_sub }( %$c,
531 % 'fieldnum' => $fieldnum,
532 % 'curr_value' => $name_obj->$column()
535 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
536 style='text-align:right;vertical-align:top;
537 border-top:1px solid black;padding-top:5px;'>
538 <% $c->{'label'} || '' %>
540 <TD style='border-top:1px solid black;padding-top:3px;'>
541 <% include( @column ) %>
551 % #$field .= $fieldnum;
552 % $onchange .= "\nspawn_$field(what);";
554 % if ( $f->{curr_value_callback} ) {
555 % $curr_value = &{ $f->{curr_value_callback} }( $cgi, $object, $field ),
557 % $curr_value = $object->$field() if $field;
559 % $curr_value = &{ $opt{'value_callback'} }( $f->{'field'}, $curr_value )
560 % if $opt{'value_callback'} && $mode ne 'error';
563 % my @include = &{ $include_sub }(
565 % 'fieldnum' => $fieldnum,
566 % 'curr_value' => $curr_value,
567 % 'object' => $object,
569 % 'onchange' => $onchange,
570 % ( $fieldnum ? ('cell_style' => 'border-top:1px solid black') : () ),
573 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
574 % $include[0] =~ s(^/elements/tr-)(/elements/);
575 % my @label = @include;
576 % $label[0] = '/elements/tr-td-label.html';
578 <% include( @label ) %>
579 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
580 <% include( @include ) %>
583 % if ( $f->{'m2_fields'} ) {
584 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
585 % my $column = $c->{field};
586 % my @column = &{ $column_sub }( %$c, 'fieldnum' => $fieldnum );
588 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
589 style='text-align:right;vertical-align:top;
590 border-top:1px solid black;padding-top:5px;'>
591 <% $c->{'label'} || '' %>
593 <TD style='border-top:1px solid black;padding-top:3px;'>
594 <% include( @column ) %>
603 <% include( @include ) %>
606 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
608 <SCRIPT TYPE="text/javascript">
610 var <%$field%>_rownum = <% $g_row %>;
611 var <%$field%>_fieldnum = <% $fieldnum %>;
613 function spawn_<%$field%>(what) {
615 // only spawn if we're the last element... return if not
617 var field_regex = /(\d+)(_[a-z_]+)?$/;
618 var match = field_regex.exec(what.name);
620 alert(what.name + " didn't match for " + what);
623 if ( match[1] != <%$field%>_fieldnum ) {
627 // change the label on the last entry & add a remove button
628 var prev_label = document.getElementById('<% $field %>_label' + <%$field%>_fieldnum );
629 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 %>';
631 <%$field%>_fieldnum++;
635 % $include[0] =~ s(^/elements/tr-)(/elements/);
636 % my @layer_opt = ( @include,
637 % 'field' => $field."MAGIC_NUMBER",
638 % 'id' => $field."MAGIC_NUMBER",
639 % 'layer_prefix' => $field."MAGIC_NUMBER.",
641 % warn @layer_opt if $opt{'debug'};
643 var newrow = <% include(@layer_opt, html_only=>1) |js_string %>;
645 % #until the rest have html/js_only
646 % if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ ) {
647 var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>;
652 // substitute in the new field name
653 var magic_regex = /MAGIC_NUMBER/g;
654 newrow = newrow.replace( magic_regex, <%$field%>_fieldnum );
655 newfunc = newfunc.replace( magic_regex, <%$field%>_fieldnum );
658 if (window.ActiveXObject) {
659 window.execScript(newfunc);
660 } else { /* (window.XMLHttpRequest) */
661 //window.eval(newfunc);
662 setTimeout(newfunc, 0);
667 //hmm, can't use selectlayers after a tablebreak-title for now
668 var table = document.getElementById('TableNumber<% $tablenum-1 %>');
670 var row = table.insertRow(<%$field%>_rownum++);
672 var label_cell = document.createElement('TD');
674 label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
676 label_cell.style.textAlign = "right";
677 label_cell.style.verticalAlign = "top";
678 label_cell.style.borderTop = "1px solid black";
679 label_cell.style.paddingTop = "5px";
681 label_cell.innerHTML = '<% $label %>';
683 row.appendChild(label_cell);
685 var widget_cell = document.createElement('TD');
687 widget_cell.style.borderTop = "1px solid black";
688 widget_cell.style.paddingTop = "3px";
689 widget_cell.colSpan = "<% $f->{'colspan'} || 1 %>";
691 widget_cell.innerHTML = newrow;
693 row.appendChild(widget_cell);
695 % if ( $f->{'m2_fields'} ) {
696 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
697 % my $column = $c->{field};
698 % my @column = &{ $column_sub }(%$c, 'fieldnum' => 'MAGIC_NUMBER');
700 var column = <% include(@column, html_only=>1) |js_string %>;
701 column = column.replace( magic_regex, <%$field%>_fieldnum );
703 var column_label = document.createElement('TD');
705 '<% $field %>__<% $column %>_label' + <%$field%>_fieldnum;
707 column_label.style.textAlign = "right";
708 column_label.style.verticalAlign = "top";
709 column_label.style.borderTop = "1px solid black";
710 column_label.style.paddingTop = "5px";
712 column_label.innerHTML = '<% $c->{'label'} || '' %>';
714 row.appendChild(column_label);
716 var column_widget = document.createElement('TD');
718 column_widget.style.borderTop = "1px solid black";
719 column_widget.style.paddingTop = "3px";
721 column_widget.innerHTML = column;
723 row.appendChild(column_widget);
728 % if ( $f->{'m2_new_js'} ) {
729 // take out items selected in previous dropdowns
730 var new_element = document.getElementById("<%$field%>" + <%$field%>_fieldnum );
731 <% $f->{'m2_new_js'} %>(new_element);
733 if ( new_element.length < 2 ) {
734 //just the ** Select new **, so don't display the row
735 row.style.display = 'none';
741 function remove_<%$field%>(remove_fieldnum) {
742 //alert("remove <%$field%> " + remove_fieldnum);
743 var select = document.getElementById('<%$field%>' + remove_fieldnum);
746 alert("can't find element <%$field%>" + remove_fieldnum);
750 % my $warnings = $f->{'m2_remove_warnings'};
752 var sel_value = select.options[select.selectedIndex].value;
753 % foreach my $value ( keys %$warnings ) {
754 if ( sel_value == '<% $value %>' ) {
755 if ( ! confirm( <% $warnings->{$value} |js_string %> ) ) {
762 select.disabled = 'disabled'; // this seems to prevent it from being submitted on tested browsers so far (IE, moz, konq at least)
763 var label_td = document.getElementById('<%$field%>_label' + remove_fieldnum );
764 label_td.parentNode.style.display = 'none';
766 % if ( $f->{m2_remove_js} ) {
767 var opt = select.options[select.selectedIndex];
768 <% $f->{m2_remove_js} %>( opt.value, opt.text, 'no_match');
779 <% ref( $opt{'html_table_bottom'} )
780 ? &{ $opt{'html_table_bottom'} }( $object )
781 : $opt{'html_table_bottom'}
786 <% ref( $opt{'html_bottom'} )
787 ? &{ $opt{'html_bottom'} }( $object )
788 : $opt{'html_bottom'}
791 % unless ($opt{'embed'}) {
795 % unless ($opt{'no_submit'}) {
796 <INPUT TYPE = "submit"
798 VALUE = "<% ( !$clone && $object->$pkey() )
800 : "Add ". ($opt{'name'} || $opt{'name_singular'})
803 % if ( $opt{'delete_url'} and $object->get($pkey) ) {
804 % my $delete_msg = 'Delete this '.
805 % ($opt{'name_singular'} || $opt{'name'});
806 % my $delete_url = $opt{'delete_url'};
807 % $delete_url .= '?' unless $delete_url =~ /\?/;
808 % $delete_url .= $object->get($pkey);
809 <SCRIPT TYPE="text/javascript">
810 function confirm_delete() {
811 if(confirm(<% $delete_msg . '?' |js_string %>)) {
812 window.location.href = <% $delete_url |js_string %>;
816 <INPUT TYPE = "button"
817 VALUE = "<% $delete_msg |h %>"
818 onclick = "confirm_delete()">
824 <% ref( $opt{'html_foot'} )
825 ? &{ $opt{'html_foot'} }( $object )
829 <% include("/elements/footer.html") %>
836 my $curuser = $FS::CurrentUser::CurrentUser;
838 #false laziness w/process.html
839 my $table = $opt{'table'};
840 my $class = "FS::$table";
841 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
842 my $fields = $opt{'fields'}
843 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
844 || [ grep { $_ ne $pkey } fields($table) ];
845 #my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
849 if ( $opt{'embed'} ) {
851 $object = $opt{'embed'};
852 $mode = $cgi->param('error')
860 #$m->comp('/elements/handle_uri_query');
861 if ( $cgi->param('redirect') ) {
862 my $session = $cgi->param('redirect');
863 my $pref = $curuser->option("redirect$session");
864 die "unknown redirect session $session\n" unless length($pref);
865 $cgi = new CGI($pref);
868 &{$opt{'begin_callback'}}( $cgi, $fields, \%opt )
869 if $opt{'begin_callback'};
873 'extra_sql' => ( $opt{'agent_virt'}
874 ? ' AND '. $curuser->agentnums_sql(
875 'null_right' => $opt{'agent_null_right'}
881 if ( $cgi->param('error') ) {
885 $object = $class->new( {
886 map { $_ => scalar($cgi->param($_)) } fields($table)
889 &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt )
890 if $opt{'error_callback'};
892 } elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
898 $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'}
899 if $opt{'agent_clone_extra_sql'};
901 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } })
902 or die "$pkey $clone not found in $table";
904 &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt )
905 if $opt{'clone_callback'};
909 $opt{action} ||= 'Add';
911 } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
916 if ( $cgi->param($pkey) ) {
917 $value = $cgi->param($pkey)
919 my( $query ) = $cgi->keywords;
922 $value =~ /^(\d+)$/ or die "unparsable $pkey";
923 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } })
924 or die "$pkey $1 not found in $table";
926 warn "$table $pkey => $1"
929 &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt )
930 if $opt{'edit_callback'};
936 my $hashref = $opt{'new_hashref_callback'}
937 ? &{$opt{'new_hashref_callback'}}
940 $object = $opt{'new_object_callback'}
941 ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt )
942 : $class->new( $hashref );
944 &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt )
945 if $opt{'new_callback'};
949 &{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt )
950 if $opt{'end_callback'};
952 $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';