summaryrefslogtreecommitdiff
path: root/httemplate/edit
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-03-24 18:47:07 -0700
committerIvan Kohler <ivan@freeside.biz>2012-03-24 18:47:07 -0700
commit83f70978574fef3401020cb11cf651d12c139b3b (patch)
tree327059675499bfa2be0ccbfd8918b37a29312b5e /httemplate/edit
parent798cf217a0d14520c5648560ef8a3095ffcfad27 (diff)
better display/edit of contacts on customer view, RT#16819
Diffstat (limited to 'httemplate/edit')
-rw-r--r--httemplate/edit/cust_main-contacts.html100
-rw-r--r--httemplate/edit/process/cust_main-contacts.html20
-rw-r--r--httemplate/edit/process/elements/process.html96
3 files changed, 174 insertions, 42 deletions
diff --git a/httemplate/edit/cust_main-contacts.html b/httemplate/edit/cust_main-contacts.html
new file mode 100644
index 000000000..bae58bd33
--- /dev/null
+++ b/httemplate/edit/cust_main-contacts.html
@@ -0,0 +1,100 @@
+<% include('elements/edit.html',
+ 'name_singular' => 'customer contacts', #yes, we're editing all of them
+ 'table' => 'cust_main',
+ 'post_url' => popurl(1). 'process/cust_main-contacts.html',
+ 'labels' => { 'custnum' => ' ', #XXX supress this line entirely, its being redundant
+ 'contactnum' => 'Contact',
+ #'locationnum' => '&nbsp;',
+ },
+ 'fields' => [
+ { 'field' => 'contactnum',
+ 'type' => 'contact',
+ 'colspan' => 6,
+ 'm2m_method' => 'cust_contact',
+ 'm2m_dstcol' => 'contactnum',
+ 'm2_label' => 'Contact',
+ 'm2_error_callback' => $m2_error_callback,
+ },
+ ],
+ #'new_callback' => $new_callback,
+ #'edit_callback' => $edit_callback,
+ #'error_callback' => $error_callback,
+ 'agent_virt' => 1,
+ 'menubar' => [], #remove "view all" link
+
+ #XXX it would be nice if this could instead be after the error but before
+ # the table
+ 'html_init' => include('/elements/small_custview.html',
+ $custnum,
+ $conf->config('countrydefault') || 'US',
+ 1, #no balance
+ ),
+ )
+%>
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $conf = new FS::Conf;
+
+my $custnum;
+if ( $cgi->param('error') ) {
+ $custnum = scalar($cgi->param('custnum'));
+
+ die "access denied"
+ unless $curuser->access_right(($custnum ? 'Edit' : 'New'). ' customer'); #contacts?
+
+} elsif ( $cgi->keywords ) { #editing
+ $custnum = ($cgi->keywords)[0];
+
+ die "access denied"
+ unless $curuser->access_right('Edit customer');
+
+} else { #new customer
+
+ #this doesn't really work here, we're an edit only
+ die "guru meditation #32";
+
+ die "access denied"
+ unless $curuser->access_right('New customer');
+
+}
+
+#my $new_callback = sub {
+# my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
+#};
+
+#my $edit_callback = sub {
+# my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
+#};
+
+#my $error_callback = sub {
+# my( $cgi, $prospect_main, $fields_listref, $opt_hashref ) = @_;
+#};
+
+my $m2_error_callback = sub {
+ my($cgi, $object) = @_;
+
+ #process_o2m fields in process/cust_main-contacts.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' => scalar($cgi->param("contactnum$num")),
+ map { $_ => scalar($cgi->param("contactnum${num}_$_")) } @fields,
+ };
+ $x;
+ } else {
+ ();
+ }
+ } else {
+ ();
+ }
+ }
+ $cgi->param;
+};
+
+</%init>
diff --git a/httemplate/edit/process/cust_main-contacts.html b/httemplate/edit/process/cust_main-contacts.html
new file mode 100644
index 000000000..ed874a55e
--- /dev/null
+++ b/httemplate/edit/process/cust_main-contacts.html
@@ -0,0 +1,20 @@
+<% include('elements/process.html',
+ 'table' => 'cust_main',
+ 'error_redirect' => popurl(3). 'edit/cust_main-contacts.html?',
+ 'agent_virt' => 1,
+ 'skip_process' => 1, #we don't want to make any changes to cust_main
+ 'process_o2m' => {
+ 'table' => 'contact',
+ 'fields' => \@contact_fields,
+ },
+ 'redirect' => popurl(3). 'view/cust_main.cgi?',
+ )
+%>
+<%init>
+
+my @contact_fields = qw( classnum first last title comment emailaddress );
+foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
+ push @contact_fields, 'phonetypenum'.$phone_type->phonetypenum;
+}
+
+</%init>
diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html
index 636bae0ce..12b3bd94b 100644
--- a/httemplate/edit/process/elements/process.html
+++ b/httemplate/edit/process/elements/process.html
@@ -62,6 +62,10 @@ Example:
'fields' => [qw( fieldname fieldname2 )],
},
+ 'skip_process' => 0, #boolean, if set true, will skip the main table
+ #add/edit processing and only run any linked table
+ #process_ items
+
#checks CGI params and whatever else before much else runs
#return an error string or empty for no error
'precheck_callback' => sub { my( $cgi ) = @_; },
@@ -204,62 +208,71 @@ my $new;
my $new_pkey = '';
foreach my $value ( @values ) {
- $new = $class->new( \%hash );
+ if ($opt{'skip_process'}) {
+
+ $new = $old;
+ $new_pkey = $old_pkey;
+
+ } else {
+
+ $new = $class->new( \%hash );
- $new->$bfield($value) if $bfield;
+ $new->$bfield($value) if $bfield;
- if ($old && exists($opt{'copy_on_empty'})) {
- foreach my $field (@{$opt{'copy_on_empty'}}) {
- $new->set($field, $old->get($field))
- unless scalar($cgi->param($field));
+ if ($old && exists($opt{'copy_on_empty'})) {
+ foreach my $field (@{$opt{'copy_on_empty'}}) {
+ $new->set($field, $old->get($field))
+ unless scalar($cgi->param($field));
+ }
}
- }
- if ( $opt{'agent_virt'} ) {
+ if ( $opt{'agent_virt'} ) {
- if ( ! $new->agentnum
- && ( ! $opt{'agent_null_right'}
- || ! $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';
+ $error ||= 'Select an agent';
- } else {
+ } else {
- die "illegal agentnum"
- unless $curuser->agentnums_href->{$new->agentnum}
- or $curuser->access_right('View customers of all agents')
- or $opt{'agent_null_right'}
- && ! $new->agentnum
- && $curuser->access_right($opt{'agent_null_right'});
+ die "illegal agentnum"
+ unless $curuser->agentnums_href->{$new->agentnum}
+ or $curuser->access_right('View customers of all agents')
+ or $opt{'agent_null_right'}
+ && ! $new->agentnum
+ && $curuser->access_right($opt{'agent_null_right'});
- }
+ }
- }
+ }
- $error ||= $new->check;
+ $error ||= $new->check;
- my @args = ();
- if ( !$error && $opt{'args_callback'} ) {
- @args = &{ $opt{'args_callback'} }( $cgi, $new );
- }
+ my @args = ();
+ if ( !$error && $opt{'args_callback'} ) {
+ @args = &{ $opt{'args_callback'} }( $cgi, $new );
+ }
- if ( !$error && $opt{'debug'} ) {
- warn "$me updating record in $table table using $class class\n";
- warn Dumper(\%hash);
- warn "with args: \n". Dumper(\@args) if @args;
- }
+ if ( !$error && $opt{'debug'} ) {
+ warn "$me updating record in $table table using $class class\n";
+ warn Dumper(\%hash);
+ warn "with args: \n". Dumper(\@args) if @args;
+ }
- if ( !$error ) {
- if ( $old_pkey ) {
- $error = $new->replace($old, @args);
- } else {
- $error = $new->insert(@args);
+ if ( !$error ) {
+ if ( $old_pkey ) {
+ $error = $new->replace($old, @args);
+ } else {
+ $error = $new->insert(@args);
+ }
+ $new_pkey = $new->getfield($pkey);
}
- $new_pkey = $new->getfield($pkey);
- }
+
+ } #unless $opt{'skip_process'}
if ( !$error && $opt{'process_m2m'} ) {
@@ -344,5 +357,4 @@ foreach my $value ( @values ) {
last if $error;
}
-
</%init>