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)
10 'table' => #database table
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 'html_table_class' => '', #HTML <TABLE CLASS=
140 #string or coderef of additional HTML to add before </TABLE>
141 'html_table_bottom' => '',
143 #after </TABLE> but before the submit
144 'html_bottom' => '', #string
145 'html_bottom' => sub {
151 #javascript function name, will be called with form name as arg
152 'onsubmit' => 'check_form_data',
154 #at the very bottom (well, as low as you can go from here)
158 # initialization callbacks
161 ###global callbacks, always run if provided
163 #after decoding long CGI "redirect=" responses but
164 # before object creation/search
165 # (useful if you have a long form that might trigger redirect= and you need
166 # to do things with $cgi params - they're not decoded in the calling
168 'begin_callback' = sub { my( $cgi, $fields_listref, $opt_hashref ) = @_; },
170 #after the mode-specific object creation/search
171 'end_callback' = sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
173 ###mode-specific callbacks. one (and only one) of these four is called
176 'new_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
179 'edit_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
181 #run when re-displaying with an error
182 'error_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
185 'clone_callback' => sub { my( $cgi, $object, $fields_listref, $opt_hashref ) = @_; },
187 ###callbacks called in new mode only
189 # returns a hashref for the new object
190 'new_hashref_callback'
192 # returns the new object iself (otherwise, ->new is called)
193 'new_object_callback'
197 #run before display to return a different value
198 'value_callback' => sub { my( $columname, $value ) = @_; },
200 #run before display to manipulate element of the 'fields' arrayref
201 'field_callback' => sub { my( $cgi, $object, $field_hashref ) = @_; },
207 % unless ( $opt{embed} ) {
209 % my $title = $opt{action}. ' '. ( $opt{name} || $opt{'name_singular'} );
211 % my $viewall_url = $p . ( $opt{'viewall_dir'} || 'search' ) . "/$table.html";
212 % $viewall_url = $opt{'viewall_url'} if $opt{'viewall_url'};
215 % if ( $opt{'menubar'} ) {
216 % @menubar = @{ $opt{'menubar'} };
218 % my $items = $opt{'name'} ? $opt{'name'}.'s' : PL($opt{'name_singular'});
220 % "View all $items" => $viewall_url,
224 <% include('/elements/header'. ( $opt{popup} ? '-popup' : '' ). '.html',
226 include( '/elements/menubar.html', @menubar ),
231 <% defined($opt{'html_init'})
232 ? ( ref($opt{'html_init'})
233 ? &{$opt{'html_init'}}()
239 <% include('/elements/error.html') %>
241 % my $url = $opt{'post_url'} || popurl(1)."process/$table.html";
243 % $js_form_validate = { 'edit_topform' => { 'name' => 'edit_topform' } };
244 <FORM NAME = "edit_topform"
246 ACTION = "<% $url %>"
247 <% $opt{onsubmit} ? 'onSubmit="return '.$opt{onsubmit}.'(this)"' : '' %>
250 <INPUT TYPE="hidden" NAME="svcdb" VALUE="<% $table %>">
251 <INPUT TYPE="hidden" ID="<% $pkey %>" NAME="<% $pkey %>" VALUE="<% $clone ? '' : $object->$pkey() %>">
253 <% defined($opt{'form_init'})
254 ? ( ref($opt{'form_init'})
255 ? &{$opt{'form_init'}}()
261 % unless ( $opt{'no_pkey_display'} ) {
264 <% ( $opt{labels} && exists $opt{labels}->{$pkey} )
265 ? $opt{labels}->{$pkey}
269 #<% ( !$clone && $object->$pkey() ) || "(NEW)" %>
275 % my $tablenum = $opt{'tablenum'} || 0;
276 <TABLE ID="TableNumber<% $tablenum++ %>"
277 <% $opt{html_table_class} ? 'CLASS="'. $opt{html_table_class}. '"'
278 : 'BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0'
283 % my @g_row_stack = ();
284 % foreach my $f ( map { ref($_) ? $_ : {'field'=>$_} }
288 % my $trash = &{ $opt{'field_callback'} }( $cgi, $object, $f )
289 % if $opt{'field_callback'};
291 % my $field = $f->{'field'};
292 % my $type = $f->{'type'} ||= 'text';
294 % my $label = ( $opt{labels} && exists $opt{labels}->{$field} )
295 % ? $opt{labels}->{$field}
298 % my $onchange = $f->{'onchange'};
300 % my $layer_values = {};
301 % $layer_values = &{ $f->{'layer_values_callback'} }( $cgi, $object )
302 % if $f->{'layer_values_callback'}
303 % && ! $f->{'m2name_table'}
304 % && ! $f->{'o2m_table'}
305 % && ! $f->{'m2m_method'};
307 % warn "layer values: ". Dumper($layer_values)
310 % my %include_common = (
312 % #text and derivitives
313 % 'size' => $f->{'size'},
314 % 'maxlength' => $f->{'maxlength'},
315 % 'prefix' => $f->{'prefix'},
316 % 'postfix' => $f->{'postfix'},
319 % 'rows' => $f->{'rows'},
320 % 'cols' => $f->{'cols'},
322 % #checkbox, title, fixed, hidden
323 % #& deprecated weird value hashref used only by reason.html
324 % 'value' => $f->{'value'},
327 % 'noescape' => $f->{'noescape'},
330 % 'options' => $f->{'options'},
331 % 'labels' => $f->{'labels'},
332 % 'multiple' => $f->{'multiple'},
333 % 'label_showkey' => $f->{'label_showkey'},
334 % 'disable_empty' => $f->{'disable_empty'},
336 % 'reason_class' => $f->{'reason_class'},
338 % 'viewall_right' => $f->{'viewall_right'},
341 % 'layer_fields' => $f->{'layer_fields'},
342 % 'layer_values' => $layer_values,
343 % 'html_between' => $f->{'html_between'},
345 % #umm. for select-agent_type at least
346 % 'disabled' => $f->{'disabled'},
347 % 'fixed' => $f->{'fixed'},
348 % 'label_callback'=> $f->{'label_callback'},
349 % 'element_etc' => $f->{'element_etc'},
351 % #for select-ticketing_queueid at least
352 % 'post_options' => $f->{'post_options'},
355 % 'colspan' => $f->{'colspan'},
356 % 'required' => $f->{'required'},
359 % 'custnum' => $f->{'custnum'},
360 % 'prospectnum' => $f->{'prospectnum'},
364 % $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
365 % qw( js_only html_only select_only layers_only cell_style ),#selectlayers,?
366 % qw( empty_label ), # select-*
367 % qw( value_col compare_sub order_by addl_from ), # select-table
368 % qw( table name_col ), #(select,checkboxes)-table
369 % qw( target_table link_table ), #checkboxes-table
370 % qw( hashref agent_virt agent_null agent_null_right ),#*-table
371 % qw( formatted_value ), #fixed
372 % qw( country ), #select-country
373 % qw( width height config ), #htmlarea
374 % qw( is_optional alt_format ), #select-cust_location
375 % qw( classnum ), # select-inventory_item
376 % qw( aligned ), # columnstart
377 % qw( debug ), # select-table
381 % $include_common{$_} = ref( $f->{$_} ) eq 'CODE'
382 % ? &{ $f->{$_} }( $cgi, $object ) #, $f )
384 % foreach grep exists($f->{$_}), qw( extra_sql );
386 % if ( $type eq 'tablebreak-tr-title' ) {
387 % $include_common{'table_id'} = 'TableNumber'. $tablenum++;
389 % if ( $type eq 'tablebreak-tr-title' || $type eq 'title' ) {
390 % $include_common{'colspan'} = $f->{colspan} if $f->{colspan};
393 % if ( $f->{include_opt_callback} ) {
394 % %include_common = ( %include_common,
395 % &{ $f->{include_opt_callback} }( $object )
399 % my $layer_prefix_on = '';
401 % my $include_sub = sub {
404 % my $fieldnum = delete $opt{'fieldnum'};
406 % my $include = $type;
407 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
408 % $include = "tr-$include" unless $include =~ /^(hidden|tablebreak|column)/;
410 % $include_common{'layer_prefix'} = "$field$fieldnum."
411 % if $layer_prefix_on;
413 % ## set conditionname field values for validation.
414 % if ($field eq 'conditionname') {
415 % my $validate_field = $field . $fieldnum . '.after_event.run_delay';
416 % $js_form_validate->{edit_topform}->{validate_fields}{$validate_field} = 'digits: true';
417 % $js_form_validate->{edit_topform}->{error_message}{$validate_field} = 'Please only enter numbers here.';
421 % ( "/elements/$include.html",
422 % 'field' => "$field$fieldnum",
423 % 'id' => "$field$fieldnum", #separate?
424 % 'label_id' => $field."_label$fieldnum", #don't want field0_label0...
429 % if ( $include eq 'tr-input-date-field' ) {
430 % # it's either hacking it here, or changing a lot more stuff
432 % "/elements/$include.html", {
434 % 'value' => $opt{curr_value},
436 % 'noinit' => $f->{noinit},
437 % 'required' => $f->{'required'},
445 % my $column_sub = sub {
448 % my $column = delete($opt{field});
449 % my $fieldnum = delete($opt{fieldnum});
450 % my $include = delete($opt{type}) || 'text';
451 % $include = "input-$include" if $include =~ /^(text|money|percentage)$/;
453 % ( "/elements/$include.html",
454 % 'field' => $field.'__'.$column.$fieldnum,
455 % 'id' => $field.'__'.$column.$fieldnum,
456 % 'layer_prefix' => $field.'__'.$column.$fieldnum.".",
458 % ? ('cell_style' => 'border-top:1px solid black')
466 % unless ( $type =~ /^column/ ) {
467 % $g_row = 1 if $type eq 'tablebreak-tr-title';
469 % $g_row++ if $type eq 'title';
470 % $g_row += scalar( @{ $f->{options} } )-1 if $type eq 'radio';
472 % if ( $type eq 'columnstart' ) {
473 % push @g_row_stack, $g_row;
475 % #} elsif ( $type eq 'columnnext' ) {
476 % } elsif ( $type eq 'columnend' ) {
477 % $g_row = pop @g_row_stack;
483 % my $curr_value = '';
484 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
487 % if ( $f->{'m2name_table'} ) {
488 % $table = $f->{'m2name_table'};
489 % $col = $f->{'m2name_namecol'};
490 % } elsif ( $f->{'o2m_table'} ) {
491 % $table = $f->{'o2m_table'};
492 % $col = dbdef->table($f->{'o2m_table'})->primary_key;
493 % } elsif ( $f->{'m2m_method'} ) {
494 % $table = $f->{'m2m_method'};
495 % $col = $f->{'m2m_dstcol'};
498 % $layer_prefix_on = 1;
499 % #print out the fields for the existing m2s
501 % if ( $mode eq 'error' ) {
502 % @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
503 % } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone'
504 % @existing = $object->$table();
505 % warn scalar(@existing). " from $object->$table: ". join('/', @existing)
507 % } elsif ( $f->{'m2_new_default'} ) { # && $mode eq 'new'
508 % @existing = @{ $f->{'m2_new_default'} };
510 % foreach my $name_obj ( @existing ) {
512 % my $ex_label = '<INPUT TYPE="button" VALUE="X" TITLE="Remove this '.
513 % lc($f->{'m2_label'}).
514 % qq(" onClick="remove_$field($fieldnum);").
515 % ' STYLE="color:#ff0000;font-weight:bold;'.
516 % 'padding-left:2px;padding-right:2px"'.
517 % '> '. ($f->{'m2_label'} || $field ). ' ';
519 % if ( $f->{'layer_values_callback'} ) {
520 % my %switches = ( 'mode' => $mode );
522 % &{ $f->{'layer_values_callback'} }( $cgi, $name_obj, \%switches );
524 % warn "layer values: ". Dumper($layer_values)
527 % my @existing = &{ $include_sub }(
528 % 'label' => $ex_label,
529 % 'fieldnum' => $fieldnum,
530 % 'curr_value' => $name_obj->$col(),
531 % 'onchange' => $onchange,
532 % 'layer_values' => $layer_values,
533 % 'cell_style' => ( $fieldnum ? 'border-top:1px solid black' : '' ),
535 % $existing[0] =~ s(^/elements/tr-)(/elements/);
536 % my @label = @existing;
537 % $label[0] = '/elements/tr-td-label.html';
539 <% include( @label ) %>
540 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
541 <% include( @existing ) %>
544 % if ( $f->{'m2_fields'} ) {
545 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
546 % my $column = $c->{field};
547 % my @column = &{ $column_sub }( %$c,
548 % 'fieldnum' => $fieldnum,
549 % 'curr_value' => $name_obj->$column()
552 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
553 style='text-align:right;vertical-align:top;
554 border-top:1px solid black;padding-top:5px;'>
555 <% $c->{'label'} || '' %>
557 <TD style='border-top:1px solid black;padding-top:3px;'>
558 <% include( @column ) %>
568 % #$field .= $fieldnum;
569 % $onchange .= "\nspawn_$field(what);";
571 % if ( $f->{curr_value_callback} ) {
572 % $curr_value = &{ $f->{curr_value_callback} }( $cgi, $object, $field ),
574 % $curr_value = $object->$field() if $field;
576 % $curr_value = &{ $opt{'value_callback'} }( $f->{'field'}, $curr_value )
577 % if $opt{'value_callback'} && $mode ne 'error';
580 % my @include = &{ $include_sub }(
582 % 'fieldnum' => $fieldnum,
583 % 'curr_value' => $curr_value,
584 % 'object' => $object,
586 % 'onchange' => $onchange,
587 % ( $fieldnum ? ('cell_style' => 'border-top:1px solid black') : () ),
590 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
591 % $include[0] =~ s(^/elements/tr-)(/elements/);
592 % my @label = @include;
593 % $label[0] = '/elements/tr-td-label.html';
595 <% include( @label ) %>
596 <TD COLSPAN="<% $f->{'colspan'} || 1 %>">
597 <% include( @include ) %>
600 % if ( $f->{'m2_fields'} ) {
601 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
602 % my $column = $c->{field};
603 % my @column = &{ $column_sub }( %$c, 'fieldnum' => $fieldnum );
605 <TD id='<% $field %>__<% $column %>_label<% $fieldnum %>'
606 style='text-align:right;vertical-align:top;
607 border-top:1px solid black;padding-top:5px;'>
608 <% $c->{'label'} || '' %>
610 <TD style='border-top:1px solid black;padding-top:3px;'>
611 <% include( @column ) %>
620 <% include( @include ) %>
623 % if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
625 <SCRIPT TYPE="text/javascript">
627 var <%$field%>_rownum = <% $g_row %>;
628 var <%$field%>_fieldnum = <% $fieldnum %>;
630 function spawn_<%$field%>(what) {
632 // only spawn if we're the last element... return if not
634 var field_regex = /(\d+)(_[a-z_]+)?$/;
635 var match = field_regex.exec(what.name);
637 alert(what.name + " didn't match for " + what);
640 if ( match[1] != <%$field%>_fieldnum ) {
644 % if ( exists( $f->{'js_spawn_test'} ) ) {
645 // XXX check a passed-in hook here and optionall return
646 if ( <% $f->{'js_spawn_test'} %> ) {
647 // then go ahead and spawn
653 // change the label on the last entry & add a remove button
654 var prev_label = document.getElementById('<% $field %>_label' + <%$field%>_fieldnum );
655 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 %>';
657 <%$field%>_fieldnum++;
661 % $include[0] =~ s(^/elements/tr-)(/elements/);
662 % my @layer_opt = ( @include,
663 % 'field' => $field."MAGIC_NUMBER",
664 % 'id' => $field."MAGIC_NUMBER",
665 % 'layer_prefix' => $field."MAGIC_NUMBER.",
667 % warn @layer_opt if $opt{'debug'};
669 var newrow = <% include(@layer_opt, html_only=>1) |js_string %>;
671 % #until the rest have html/js_only
672 % if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ ) {
673 var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>;
678 // substitute in the new field name
679 var magic_regex = /MAGIC_NUMBER/g;
680 newrow = newrow.replace( magic_regex, <%$field%>_fieldnum );
681 newfunc = newfunc.replace( magic_regex, <%$field%>_fieldnum );
684 if (window.ActiveXObject) {
685 window.execScript(newfunc);
686 } else { /* (window.XMLHttpRequest) */
687 //window.eval(newfunc);
688 setTimeout(newfunc, 0);
693 //hmm, can't use selectlayers after a tablebreak-title for now
694 var table = document.getElementById('TableNumber<% $tablenum-1 %>');
696 var row = table.insertRow(<%$field%>_rownum++);
698 var label_cell = document.createElement('TD');
700 label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
702 label_cell.style.textAlign = "right";
703 label_cell.style.verticalAlign = "top";
704 label_cell.style.borderTop = "1px solid black";
705 label_cell.style.paddingTop = "5px";
707 label_cell.innerHTML = '<% $label %>';
709 row.appendChild(label_cell);
711 var widget_cell = document.createElement('TD');
713 widget_cell.style.borderTop = "1px solid black";
714 widget_cell.style.paddingTop = "3px";
715 widget_cell.colSpan = "<% $f->{'colspan'} || 1 %>";
717 widget_cell.innerHTML = newrow;
719 row.appendChild(widget_cell);
721 % if ( $f->{'m2_fields'} ) {
722 % foreach my $c ( @{ $f->{'m2_fields'} } ) {
723 % my $column = $c->{field};
724 % my @column = &{ $column_sub }(%$c, 'fieldnum' => 'MAGIC_NUMBER');
726 var column = <% include(@column, html_only=>1) |js_string %>;
727 column = column.replace( magic_regex, <%$field%>_fieldnum );
729 var column_label = document.createElement('TD');
731 '<% $field %>__<% $column %>_label' + <%$field%>_fieldnum;
733 column_label.style.textAlign = "right";
734 column_label.style.verticalAlign = "top";
735 column_label.style.borderTop = "1px solid black";
736 column_label.style.paddingTop = "5px";
738 column_label.innerHTML = '<% $c->{'label'} || '' %>';
740 row.appendChild(column_label);
742 var column_widget = document.createElement('TD');
744 column_widget.style.borderTop = "1px solid black";
745 column_widget.style.paddingTop = "3px";
747 column_widget.innerHTML = column;
749 row.appendChild(column_widget);
754 % if ( $f->{'m2_new_js'} ) {
755 // take out items selected in previous dropdowns
756 var new_element = document.getElementById("<%$field%>" + <%$field%>_fieldnum );
757 <% $f->{'m2_new_js'} %>(new_element);
759 if ( new_element.length < 2 ) {
760 //just the ** Select new **, so don't display the row
761 row.style.display = 'none';
767 function remove_<%$field%>(remove_fieldnum) {
768 //alert("remove <%$field%> " + remove_fieldnum);
769 var select = document.getElementById('<%$field%>' + remove_fieldnum);
772 alert("can't find element <%$field%>" + remove_fieldnum);
776 % my $warnings = $f->{'m2_remove_warnings'};
778 var sel_value = select.options[select.selectedIndex].value;
779 % foreach my $value ( keys %$warnings ) {
780 if ( sel_value == '<% $value %>' ) {
781 if ( ! confirm( <% $warnings->{$value} |js_string %> ) ) {
788 select.disabled = 'disabled'; // this seems to prevent it from being submitted on tested browsers so far (IE, moz, konq at least)
789 var label_td = document.getElementById('<%$field%>_label' + remove_fieldnum );
790 label_td.parentNode.style.display = 'none';
792 % if ( $f->{m2_remove_js} ) {
793 var opt = select.options[select.selectedIndex];
794 <% $f->{m2_remove_js} %>( opt.value, opt.text, 'no_match');
805 <% ref( $opt{'html_table_bottom'} )
806 ? &{ $opt{'html_table_bottom'} }( $object )
807 : $opt{'html_table_bottom'}
812 <% ref( $opt{'html_bottom'} )
813 ? &{ $opt{'html_bottom'} }( $object )
814 : $opt{'html_bottom'}
817 % unless ($opt{'embed'}) {
821 % unless ($opt{'no_submit'}) {
822 <INPUT TYPE = "submit"
824 VALUE = "<% ( !$clone && $object->$pkey() )
826 : "Add ". ($opt{'name'} || $opt{'name_singular'})
829 % if ( $opt{'delete_url'} and $object->get($pkey) ) {
830 % my $delete_msg = 'Delete this '.
831 % ($opt{'name_singular'} || $opt{'name'});
832 % my $delete_url = $opt{'delete_url'};
833 % $delete_url .= '?' unless $delete_url =~ /\?/;
834 % $delete_url .= $object->get($pkey);
835 <SCRIPT TYPE="text/javascript">
836 function confirm_delete() {
837 if(confirm(<% $delete_msg . '?' |js_string %>)) {
838 window.location.href = <% $delete_url |js_string %>;
842 <INPUT TYPE = "button"
843 VALUE = "<% $delete_msg |h %>"
844 onclick = "confirm_delete()">
850 <% ref( $opt{'html_foot'} )
851 ? &{ $opt{'html_foot'} }( $object )
856 % 'formvalidation' => $js_form_validate,
859 <% include("/elements/footer.html", %footerdata) %>
866 my $curuser = $FS::CurrentUser::CurrentUser;
868 #false laziness w/process.html
869 my $table = $opt{'table'};
870 my $class = "FS::$table";
871 my $pkey = dbdef->table($table)->primary_key; #? $opt{'primary_key'} ||
872 my $fields = $opt{'fields'}
873 #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
874 || [ grep { $_ ne $pkey } fields($table) ];
875 my @actualfields = map { ref($_) ? $_->{'field'} : $_ } @$fields;
877 push @actualfields, $pkey;
879 my $js_form_validate = {};
883 if ( $opt{'embed'} ) {
885 $object = $opt{'embed'};
886 $mode = $cgi->param('error')
894 #$m->comp('/elements/handle_uri_query');
895 if ( $cgi->param('redirect') ) {
896 my $session = $cgi->param('redirect');
897 my $pref = $curuser->option("redirect$session");
898 die "unknown redirect session $session\n" unless length($pref);
899 $cgi = new CGI($pref);
902 &{$opt{'begin_callback'}}( $cgi, $fields, \%opt )
903 if $opt{'begin_callback'};
907 'extra_sql' => ( $opt{'agent_virt'}
908 ? ' AND '. $curuser->agentnums_sql(
909 'null_right' => $opt{'agent_null_right'}
915 if ( $cgi->param('error') ) {
919 $object = $class->new( {
920 map { $_ => scalar($cgi->param($_)) } @actualfields
923 &{$opt{'error_callback'}}( $cgi, $object, $fields, \%opt )
924 if $opt{'error_callback'};
926 } elsif ( $cgi->param('clone') =~ /^(\d+)$/ ) {
932 $qsearch{'extra_sql'} = ' AND '. $opt{'agent_clone_extra_sql'}
933 if $opt{'agent_clone_extra_sql'};
935 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $clone } })
936 or die "$pkey $clone not found in $table";
938 &{$opt{'clone_callback'}}( $cgi, $object, $fields, \%opt )
939 if $opt{'clone_callback'};
943 $opt{action} ||= 'Add';
945 } elsif ( $cgi->keywords || $cgi->param($pkey) ) { #editing
950 if ( $cgi->param($pkey) ) {
951 $value = $cgi->param($pkey)
953 my( $query ) = $cgi->keywords;
956 $value =~ /^(\d+)$/ or die "unparsable $pkey";
957 $object = qsearchs({ %qsearch, 'hashref' => { $pkey => $1 } })
958 or die "$pkey $1 not found in $table";
960 warn "$table $pkey => $1"
963 &{$opt{'edit_callback'}}( $cgi, $object, $fields, \%opt )
964 if $opt{'edit_callback'};
970 my $hashref = $opt{'new_hashref_callback'}
971 ? &{$opt{'new_hashref_callback'}}
974 $object = $opt{'new_object_callback'}
975 ? &{$opt{'new_object_callback'}}( $cgi, $hashref, $fields, \%opt )
976 : $class->new( $hashref );
978 &{$opt{'new_callback'}}( $cgi, $object, $fields, \%opt )
979 if $opt{'new_callback'};
983 &{$opt{'end_callback'}}( $cgi, $object, $fields, \%opt )
984 if $opt{'end_callback'};
986 $opt{action} ||= $object->$pkey() ? 'Edit' : 'Add';