diff options
Diffstat (limited to 'httemplate/edit')
| -rw-r--r-- | httemplate/edit/elements/edit.html | 7 | ||||
| -rw-r--r-- | httemplate/edit/process/elements/process.html | 28 | ||||
| -rw-r--r-- | httemplate/edit/process/prospect_main.html | 34 | ||||
| -rw-r--r-- | httemplate/edit/prospect_main.html | 83 | 
4 files changed, 148 insertions, 4 deletions
| diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index fd73e031e..4935ddc1a 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -409,7 +409,7 @@ Example:  %       $label[0] = '/elements/tr-td-label.html';          <% include( @label ) %> -        <TD> +        <TD COLSPAN="<% $f->{'colspan'} || 1 %>">          <% include( @existing ) %>          </TD> @@ -465,7 +465,7 @@ Example:  %     $label[0] = '/elements/tr-td-label.html';        <% include( @label ) %> -      <TD> +      <TD COLSPAN="<% $f->{'colspan'} || 1 %>">        <% include( @include ) %>        </TD> @@ -503,7 +503,7 @@ Example:            // only spawn if we're the last element... return if not -          var field_regex = /(\d+)$/; +          var field_regex = /(\d+)(_[a-z]+)?$/;            var match = field_regex.exec(what.name);            if ( !match ) {              alert(what.name + " didn't match?!"); @@ -574,6 +574,7 @@ Example:            widget_cell.style.borderTop = "1px solid black";            widget_cell.style.paddingTop = "3px"; +          widget_cell.colSpan = "<% $f->{'colspan'} || 1 %>"            widget_cell.innerHTML = newrow; diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html index 5befdd337..e24f3f681 100644 --- a/httemplate/edit/process/elements/process.html +++ b/httemplate/edit/process/elements/process.html @@ -56,13 +56,17 @@ Example:                         }, +   'process_o2m' => { 'table' => table_name', +                      'num_col' => 'column', #if column name is different in +                                             #link_table than source_table  +                    },     #checks CGI params and whatever else before much else runs     #return an error string or empty for no error     'precheck_callback' => sub { my( $cgi ) = @_; },     #supplies arguments to insert() and replace() -   # for use with tables that are FS::option_Common +   # for use with tables that are FS::option_Common (among other things)     'args_callback' => sub { my( $cgi, $object ) = @_; },     'debug' => 1, #turns on debugging output @@ -255,6 +259,28 @@ if ( !$error && $opt{'process_m2name'} ) {  } +if ( !$error && $opt{'process_o2m'} ) { + +  my @process_o2m = ref($opt{'process_o2m'}) eq 'ARRAY' +                         ? @{ $opt{'process_o2m'} } +                         :  ( $opt{'process_o2m'} ); + + +  foreach my $process_o2m (@process_o2m) { + +    if ( $opt{'debug'} ) { +      warn "$me processing o2m:\n". Dumper( %{ $process_o2m }, +                                               'params' => scalar($cgi->Vars), +                                             ); +    } + +    $error = $new->process_o2m( %{ $process_o2m }, +                                   'params' => scalar($cgi->Vars), +                                 ); +  } + +} +  if ( $error ) {    $cgi->param('error', $error); diff --git a/httemplate/edit/process/prospect_main.html b/httemplate/edit/process/prospect_main.html new file mode 100644 index 000000000..34d26421b --- /dev/null +++ b/httemplate/edit/process/prospect_main.html @@ -0,0 +1,34 @@ +<% include('elements/process.html', +     'table'          => 'prospect_main', +     'args_callback'  => $args_callback, +     'agent_virt'     => 1, +     'process_o2m' => { +       'table'  => 'contact', +       'fields' => [qw( first last title comment )], +     }, +     'redirect' => popurl(3). 'view/prospect_main.html?', +   ) +%> +<%init> + +my $args_callback = sub { +  my( $cgi, $object ) = @_; + +  $cgi->param('locationnum') =~ /^(\-?\d*)$/ +    or die 'illegal locationnum '. $cgi->param('locationnum'); +  my $locationnum = $1; + +  return ( 'cust_location' => '' ) unless $locationnum; + +  my $cust_location = new FS::cust_location { +    map { $_ => scalar($cgi->param($_)) } +        qw( address1 address2 city county state zip country ) +  }; + +  $cust_location->locationnum($locationnum) unless $locationnum == -1; + +  ( 'cust_location' => $cust_location ); + +}; + +</%init> diff --git a/httemplate/edit/prospect_main.html b/httemplate/edit/prospect_main.html new file mode 100644 index 000000000..c4123a078 --- /dev/null +++ b/httemplate/edit/prospect_main.html @@ -0,0 +1,83 @@ +<% include('elements/edit.html', +     'name_singular'   => 'prospect', +     'table'           => 'prospect_main', +     'labels'          => { 'prospectnum' => 'Prospect', +                            'agentnum'    => 'Agent', +                            'company'     => 'Company', +                            'contactnum'  => 'Contact', +                          }, +     'fields'          => [ +       { 'field'       => 'agentnum', +         'type'        => 'select-agent', +         'empty_label' => 'Select agent', +       }, +       { 'field'   => 'company', +         'type'   => 'text', +         'size'    => 50, +       }, +       { 'field'             => 'contactnum', +         'type'              => 'contact', +         'colspan'           => 6, +         #actually o2m, but this seems to be working for edit so far +         'm2name_table'      => 'contact', +         'm2name_namecol'    => 'contactnum', +         'm2_label'          => 'Contact', +         'm2_error_callback' => sub { my($cgi, $object) = @_; (); }, #XXX +       }, +       { 'field'       => 'locationnum', +         'type'        => 'select-cust_location', +         'empty_label' => 'No address', +       }, +     ], +     'edit_callback'   => $edit_callback, +     'error_callbacck' => $error_callback, +     'agent_virt'      => 1, +   ) +%> +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; + +my $prospectnum; +if ( $cgi->param('error') ) { +  $prospectnum = scalar($cgi->param('prospectnum')); + +  die "access denied" +    unless $curuser->access_right(($prospectnum ? 'Edit' : 'New'). ' prospect'); + +} elsif ( $cgi->keywords ) { #editing + +  die "access denied" +    unless $curuser->access_right('Edit prospect'); + +} else { #new prospect  + +  die "access denied" +    unless $curuser->access_right('New prospect'); + +} + +my $edit_callback = sub { +  #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_; +  my( $cgi, $prospect_main ) = @_; +  my @cust_location = +    qsearch('cust_location', { 'prospectnum' => $prospect_main->prospectnum } ); +  die 'multiple locations for prospect '. $prospect_main->prospectnum +    if scalar(@cust_location) > 1; +  $prospect_main->set('locationnum', $cust_location[0]->locationnum) +    if scalar(@cust_location); +  #warn 'prospect_main.locationnum '.$prospect_main->get('locationnum'); +}; + +my $error_callback = sub { +  #my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_; +  my( $cgi, $prospect_main ) = @_; +  $cgi->param('locationnum') =~ /^(\-?\d*)$/ +    or die 'illegal locationnum '. $cgi->param('locationnum'); +  my $locationnum = $1; +  $prospect_main->set('locationnum', $locationnum); +}; + +my @agentnums = $FS::CurrentUser::CurrentUser->agentnums; + +</%init> | 
