summaryrefslogtreecommitdiff
path: root/httemplate/edit
diff options
context:
space:
mode:
authorivan <ivan>2009-12-31 02:20:33 +0000
committerivan <ivan>2009-12-31 02:20:33 +0000
commit2e928dafa3cf6383ea9e97f48af61af05e5a292a (patch)
tree107c9908948a9c5463ffcb80add9323245d6fa54 /httemplate/edit
parent0d2d8c0b11b715fa7ba1d889e04637194d97e275 (diff)
prospecting: proper contact error handling when you add a prospect
Diffstat (limited to 'httemplate/edit')
-rw-r--r--httemplate/edit/elements/edit.html20
-rw-r--r--httemplate/edit/process/elements/process.html25
-rw-r--r--httemplate/edit/prospect_main.html42
3 files changed, 69 insertions, 18 deletions
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html
index 4935ddc1a..43b7afe11 100644
--- a/httemplate/edit/elements/edit.html
+++ b/httemplate/edit/elements/edit.html
@@ -40,14 +40,14 @@ Example:
'disabled' => 0,
'onchange' => 'javascript_function',
- #m2 stuff only tested w/selectlayers so far
- #might work w/select too, dunno others
'm2name_table' => 'table_name',
'm2name_namecol' => 'name_column',
#OR#
'm2m_method' =>
#'m2m_srccol' => #opt, if not the same as this table
'm2m_dstcol' => #required for now, eventuaully opt, if not the same as target table
+ #OR#
+ 'o2m_table' =>
'm2_label' => 'Label', #
'm2_new_default' => \@table_name_objects, #default
@@ -235,6 +235,7 @@ Example:
% $layer_values = &{ $f->{'layer_values_callback'} }( $cgi, $object )
% if $f->{'layer_values_callback'}
% && ! $f->{'m2name_table'}
+% && ! $f->{'o2m_table'}
% && ! $f->{'m2m_method'};
%
% warn "layer values: ". Dumper($layer_values)
@@ -356,12 +357,15 @@ Example:
%
% my $fieldnum = '';
% my $curr_value = '';
-% if ( $f->{'m2name_table'} || $f->{'m2m_method'} ) { #XXX test this for all
-% #types of fields
+% if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
+%
% my($table, $col);
% if ( $f->{'m2name_table'} ) {
% $table = $f->{'m2name_table'};
% $col = $f->{'m2name_namecol'};
+% } elsif ( $f->{'o2m_table'} ) {
+% $table = $f->{'o2m_table'};
+% $col = dbdef->table($f->{'o2m_table'})->primary_key;
% } elsif ( $f->{'m2m_method'} ) {
% $table = $f->{'m2m_method'};
% $col = $f->{'m2m_dstcol'};
@@ -374,8 +378,8 @@ Example:
% @existing = &{ $f->{'m2_error_callback'} }( $cgi, $object );
% } elsif ( $object->$pkey() ) { # $mode eq 'edit'||'clone'
% @existing = $object->$table();
-% warn scalar(@existing). " from $object->$table: ". join('/', @existing)
-% if $opt{'debug'};
+% warn scalar(@existing). " from $object->$table: ". join('/', @existing)
+% if $opt{'debug'};
% } elsif ( $f->{'m2_new_default'} ) { # && $mode eq 'new'
% @existing = @{ $f->{'m2_new_default'} };
% }
@@ -459,7 +463,7 @@ Example:
% ( $fieldnum ? ('cell_style' => 'border-top:1px solid black') : () ),
% );
%
-% if ( $f->{'m2name_table'} || $f->{'m2m_method'} ) {
+% if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
% $include[0] =~ s(^/elements/tr-)(/elements/);
% my @label = @include;
% $label[0] = '/elements/tr-td-label.html';
@@ -492,7 +496,7 @@ Example:
<% include( @include ) %>
% }
-% if ( $f->{'m2name_table'} || $f->{'m2m_method'} ) {
+% if ( $f->{'m2name_table'} || $f->{'o2m_table'} || $f->{'m2m_method'} ) {
<SCRIPT TYPE="text/javascript">
diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html
index e24f3f681..87cadb774 100644
--- a/httemplate/edit/process/elements/process.html
+++ b/httemplate/edit/process/elements/process.html
@@ -190,11 +190,26 @@ if ($old && exists($opt{'copy_on_empty'})) {
}
if ( $opt{'agent_virt'} ) {
- die "illegal agentnum"
- unless $curuser->agentnums_href->{$new->agentnum}
- or $opt{'agent_null_right'}
- && ! $new->agentnum
- && $curuser->access_right($opt{'agent_null_right'});
+
+ if ( ! $new->agentnum
+ && ( ! $opt{'agent_null_right'}
+ || ! $curuser->access_right($opt{'agent_null_right'})
+ )
+ )
+ {
+
+ $error ||= 'Select an agent';
+
+ } else {
+
+ die "illegal agentnum"
+ unless $curuser->agentnums_href->{$new->agentnum}
+ or $opt{'agent_null_right'}
+ && ! $new->agentnum
+ && $curuser->access_right($opt{'agent_null_right'});
+
+ }
+
}
$error ||= $new->check;
diff --git a/httemplate/edit/prospect_main.html b/httemplate/edit/prospect_main.html
index c4123a078..8ae76a9a1 100644
--- a/httemplate/edit/prospect_main.html
+++ b/httemplate/edit/prospect_main.html
@@ -18,11 +18,16 @@
{ '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
+ ##actually o2m, but this seems to be working for edit so far
+ #'m2name_table' => 'contact',
+ #'m2name_namecol' => 'contactnum',
+ #'m2_label' => 'Contact',
+ #'m2_error_callback' => $m2_error_callback,
+
+ 'o2m_table' => 'contact',
+ 'm2_label' => 'Contact',
+ 'm2_error_callback' => $m2_error_callback,
+
},
{ 'field' => 'locationnum',
'type' => 'select-cust_location',
@@ -78,6 +83,33 @@ my $error_callback = sub {
$prospect_main->set('locationnum', $locationnum);
};
+my $m2_error_callback = sub {
+ my($cgi, $object) = @_;
+
+ #process_o2m fields in process/prospect_main.html
+ my @fields = qw( first last title comment );
+ my @gfields = ( '', map "_$_", @fields );
+
+ map {
+ if ( /^contactnum(\d+)$/ ) {
+ my $num = $1;
+ if ( grep $cgi->param("contactnum$num$_"), @gfields ) {
+ my $x = new FS::contact {
+ 'contactnum' => $cgi->param("contactnum$num"),
+ map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
+ };
+ use Data::Dumper; warn Dumper $x;
+ $x;
+ } else {
+ ();
+ }
+ } else {
+ ();
+ }
+ }
+ $cgi->param;
+};
+
my @agentnums = $FS::CurrentUser::CurrentUser->agentnums;
</%init>