improve display of ticket service links, #17067
authorMark Wells <mark@freeside.biz>
Thu, 20 Dec 2012 19:50:46 +0000 (11:50 -0800)
committerMark Wells <mark@freeside.biz>
Thu, 20 Dec 2012 19:50:46 +0000 (11:50 -0800)
FS/FS/UI/Web/small_custview.pm
rt/lib/RT/URI/freeside/Internal.pm
rt/share/html/Ticket/Elements/AddCustomers
rt/share/html/Ticket/Elements/Customers [new file with mode: 0644]
rt/share/html/Ticket/Elements/EditCustomers
rt/share/html/Ticket/Elements/ShowCustomers

index e4b5421..ae0a421 100644 (file)
@@ -29,7 +29,7 @@ sub small_custview {
                   : qsearchs('cust_main', { 'custnum' => $arg } )
     or die "unknown custnum $arg";
 
                   : qsearchs('cust_main', { 'custnum' => $arg } )
     or die "unknown custnum $arg";
 
-  my $html = '<DIV ID="fs_small_custview">';
+  my $html = '<DIV ID="fs_small_custview" CLASS="small_custview">';
   
   $html = qq!View <A HREF="$url?! . $cust_main->custnum . '">'
     if $url;
   
   $html = qq!View <A HREF="$url?! . $cust_main->custnum . '">'
     if $url;
index b5e56ee..61b256e 100644 (file)
@@ -161,12 +161,12 @@ sub _FreesideURILabelLong {
   } elsif ( $table eq 'cust_svc' ) {
 
     my $string = '';
   } elsif ( $table eq 'cust_svc' ) {
 
     my $string = '';
-    my $cust = $self->CustomerResolver;
-    if ( $cust ) {
-      $string = $cust->AsStringLong;
-    }
-    $string .= '<B><A HREF="' . $self->HREF . '">' . 
-        $self->AsString . '</A></B>';
+    # we now do this within the UI
+    #my $cust = $self->CustomerResolver;
+    #if ( $cust ) {
+    #  $string = $cust->AsStringLong;
+    #}
+    $string .= $self->AsString;
     return $string;
 
   } else {
     return $string;
 
   } else {
@@ -177,6 +177,16 @@ sub _FreesideURILabelLong {
 
 }
 
 
 }
 
+sub AsString {
+  my $self = shift;
+  if ( $self->{'fstable'} eq 'cust_svc' ) {
+    return '<B><A HREF="' . $self->HREF . '">' . 
+          $self->_FreesideURILabel . '</A></B>';
+  } else {
+    $self->SUPER::AsString;
+  }
+}
+
 sub CustomerResolver {
   my $self = shift;
   if ( $self->{fstable} eq 'cust_main' ) {
 sub CustomerResolver {
   my $self = shift;
   if ( $self->{fstable} eq 'cust_main' ) {
index 13fb2f0..0ae4f9e 100644 (file)
@@ -21,6 +21,8 @@
 <tr>
   <td>
     <input type="checkbox" name="Ticket-AddCustomer-<% $customer->{'custnum'} %>" VALUE="1" <% scalar(@Customers) == 1 ? 'CHECKED' : '' %>>
 <tr>
   <td>
     <input type="checkbox" name="Ticket-AddCustomer-<% $customer->{'custnum'} %>" VALUE="1" <% scalar(@Customers) == 1 ? 'CHECKED' : '' %>>
+  </td>
+  <td>
     <& .small_custview, $customer &>
   </td>
 </tr>
     <& .small_custview, $customer &>
   </td>
 </tr>
@@ -30,6 +32,8 @@
 <tr>
   <td>
     <input type="checkbox" name="Ticket-AddService-<% $service->{'svcnum'} %>" VALUE="1" <% scalar(@Services) == 1 ? 'CHECKED' : '' %>>
 <tr>
   <td>
     <input type="checkbox" name="Ticket-AddService-<% $service->{'svcnum'} %>" VALUE="1" <% scalar(@Services) == 1 ? 'CHECKED' : '' %>>
+  </td>
+  <td>
     <& .small_custview, $service &>
     <& .small_svcview,  $service &>
   </td>
     <& .small_custview, $service &>
     <& .small_svcview,  $service &>
   </td>
diff --git a/rt/share/html/Ticket/Elements/Customers b/rt/share/html/Ticket/Elements/Customers
new file mode 100644 (file)
index 0000000..d90ef1c
--- /dev/null
@@ -0,0 +1,62 @@
+%# Copyright (c) 2004 Ivan Kohler <ivan-rt@420.am>
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%# 
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+<%doc>
+Provides resolver objects (RT::URI::freeside) for customer/service links 
+to a specified ticket.
+
+Do this:
+%hash = $m->comp('Customers', Ticket => $ticket);
+
+%hash contains four elements:
+- "custnums", an arrayref of customer numbers that are linked to the ticket,
+  in order.
+- "cust_main", a hashref of custnum => customer object, for each custnum.
+- "cust_linked", a hashref of custnum => boolean flag.  If the flag is true,
+  then the customer is _explicitly_ linked (i.e. there is a 
+  'freeside://freeside/cust_main/' record in the Links table).  Otherwise,
+  the customer link is implied by a service link but doesn't exist in its
+  own right.
+- "cust_svc", a hashref of custnum => an arrayref of service objects that 
+  are linked to the ticket and belong to that customer.
+</%doc>
+<%init>
+my @custnums;
+my %cust_main;
+my %cust_svc;
+my %cust_linked;
+my $customers = $Ticket->Customers;
+# ensure each customer is displayed only once
+while (my $link = $customers->Next) {
+  my $uri = $link->Target;
+  if ( $uri =~ /cust_main\/(\d+)/ ) {
+    $cust_main{$1} = $link->TargetURI->Resolver;
+    $cust_linked{$1} = 1;
+  } elsif ( $uri =~ /cust_svc\/(\d+)/ ) {
+    my $svc = $link->TargetURI->Resolver;
+    my $cust = $svc->CustomerResolver;
+    my $custnum = $cust->{fspkey};
+    $cust_main{$custnum} ||= $cust;
+    $cust_svc{$custnum} ||= [];
+    push @{$cust_svc{$custnum}}, $svc;
+  }
+}
+@custnums = sort { $a <=> $b } keys %cust_main;
+return (
+  'custnums'    => \@custnums,
+  'cust_main'   => \%cust_main,
+  'cust_svc'    => \%cust_svc,
+  'cust_linked' => \%cust_linked,
+);
+</%init>
+<%ARGS>
+$Ticket => undef
+</%ARGS>
index 96207f4..e8aa69e 100644 (file)
     <TD VALIGN=TOP WIDTH=50% ROWSPAN=3>
       <h3><&|/l&>Current Customers</&></h3>
 
     <TD VALIGN=TOP WIDTH=50% ROWSPAN=3>
       <h3><&|/l&>Current Customers</&></h3>
 
+% my %data = $m->comp('Customers', Ticket => $Ticket);
+% if ( @{ $data{custnums} } ) {
+<style>
+.small_custview {
+  padding-top: 1em;
+}
+</style>
 <table>
   <tr>
 <table>
   <tr>
-    <td><i><&|/l&>(Check box to disassociate)</&></i></td>
+    <td colspan=2><i><&|/l&>(Check box to disassociate)</&></i></td>
   </tr>
   </tr>
+%   foreach my $custnum ( @{ $data{custnums} } ) {
+%     foreach my $resolver
+%       ( $data{cust_main}{$custnum}, @{ $data{cust_svc}{$custnum} } )
+%     {
   <tr>
     <td class="value">
   <tr>
     <td class="value">
-% foreach my $link ( @{ $Ticket->Customers->ItemsArrayRef } ) {
-
-      <INPUT TYPE=CHECKBOX NAME="DeleteLink--<%$link->Type%>-<%$link->Target%>">
-%#        <& ShowLink, URI => $link->TargetURI &><br>
-        <% $link->TargetURI->Resolver->AsStringLong |n %></A>
-      <BR><BR>
-% }
+%       if ( $resolver->URI !~ /cust_main/ or $data{cust_linked}{$custnum} ) {
+%   # don't show a checkbox for implicit cust_main links
+      <input type="checkbox" name="DeleteLink--MemberOf-<% $resolver->URI %>">
+%       }
+    </td>
+    <td>
+      <% $resolver->AsStringLong |n %>
     </td>
   </tr>
     </td>
   </tr>
+%     }
+%   }
 </table>
 </table>
+% }
 
 </TD>
 
 
 </TD>
 
 <h3><&|/l&>New Customer Links</&></h3>
 </TD>
 </TR>
 <h3><&|/l&>New Customer Links</&></h3>
 </TD>
 </TR>
-<TR VALIGN="top">
+<TR>
 %# rowspan
 %# rowspan
-  <td width=25%>
+  <td width=25% style="vertical-align:top">
     <&|/l&>Find customer</&><br>
     <input name="CustomerString">
     <input type=submit name="OnlySearchForCustomers" value="<&|/l&>Go!</&>">
     <br><i>cust #, name, company or phone</i>
   </td>
     <&|/l&>Find customer</&><br>
     <input name="CustomerString">
     <input type=submit name="OnlySearchForCustomers" value="<&|/l&>Go!</&>">
     <br><i>cust #, name, company or phone</i>
   </td>
-  <td width=25%>
+  <td width=25% style="vertical-align:top">
     <&|/l&>Find service</&><br>
     <input name="ServiceString">
     <input type=submit name="OnlySearchForServices" value="<&|/l&>Go!</&>">
     <&|/l&>Find service</&><br>
     <input name="ServiceString">
     <input type=submit name="OnlySearchForServices" value="<&|/l&>Go!</&>">
index add5624..175822f 100644 (file)
@@ -9,20 +9,29 @@
 %# WITHOUT ANY WARRANTY; without even the implied warranty of
 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 %# General Public License for more details.
 %# WITHOUT ANY WARRANTY; without even the implied warranty of
 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 %# General Public License for more details.
+<%init>
+my %data = $m->comp('Customers', Ticket => $Ticket);
+</%init>
+<style>
+.small_custview {
+  padding-top: 1em;
+}
+</style>
 <table>
 <table>
-% my @cust = map { $_->TargetURI->Resolver } 
-%                   @{ $Ticket->Customers->ItemsArrayRef };
-%
-% foreach my $custResolver ( @cust ) {
+% foreach my $custnum (@{ $data{custnums} }) {
+%   my $cust = $data{cust_main}{$custnum};
   <tr>
     <td class="value">
   <tr>
     <td class="value">
-      <% $custResolver->AsStringLong |n %>
-%# includes service label and view/svc_ link for cust_svc links
+      <% $cust->AsStringLong |n %>
+%   foreach my $svc ( @{ $data{cust_svc}{$custnum} || [] } ) {
+      <% $svc->AsString |n %>
+      <br>
+%   }
     </td>
   </tr>
 % }
 
     </td>
   </tr>
 % }
 
-% unless ( @cust ) {
+% unless ( @{ $data{custnums} } ) {
   <tr>
     <td class="labeltop">
       <i>(none)<i>
   <tr>
     <td class="labeltop">
       <i>(none)<i>