rt 4.2.15
[freeside.git] / rt / share / html / Elements / BulkLinks
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
6 %#                                          <sales@bestpractical.com>
7 %#
8 %# (Except where explicitly superseded by other copyright notices)
9 %#
10 %#
11 %# LICENSE:
12 %#
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %#
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %#
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %#
29 %#
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %#
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %#
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %#
47 %# END BPS TAGGED BLOCK }}}
48 <table width="100%">
49   <tr>
50     <td valign="top" width="50%">
51       <h3><&|/l&>Current Links</&></h3>
52 <table>
53   <tr>
54     <td class="labeltop"><&|/l&>Depends on</&>:</td>
55     <td class="value">
56 % if ( $hash{DependsOn} ) {
57 % for my $link ( values %{$hash{DependsOn}} ) {
58       <input type="checkbox" class="checkbox" id="DeleteLink--<%$link->Type%>-<%$link->Target%>" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" value="1" />
59       <label for="DeleteLink--<%$link->Type%>-<%$link->Target%>"><& /Elements/ShowLink, URI => $link->TargetURI &></label><br />
60 % } }
61     </td>
62   </tr>
63   <tr>
64     <td class="labeltop"><&|/l&>Depended on by</&>:</td>
65     <td class="value">
66 % if ( $hash{DependedOnBy} ) {
67 % for my $link ( values %{$hash{DependedOnBy}} ) {
68       <input type="checkbox" class="checkbox" id="DeleteLink-<%$link->Base%>-<%$link->Type%>-" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" value="1" />
69       <label for="DeleteLink-<%$link->Base%>-<%$link->Type%>-"><& /Elements/ShowLink, URI => $link->BaseURI &></label><br />
70 % } }
71     </td>
72   </tr>
73   <tr>
74     <td class="labeltop"><&|/l&>Parents</&>:</td>
75     <td class="value">
76 % if ( $hash{MemberOf} ) {
77 % for my $link ( values %{$hash{MemberOf}} ) {
78       <input type="checkbox" class="checkbox" id="DeleteLink--<%$link->Type%>-<%$link->Target%>" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" value="1" />
79       <label for="DeleteLink--<%$link->Type%>-<%$link->Target%>"><& /Elements/ShowLink, URI => $link->TargetURI &></label><br />
80 % } }
81     </td>
82   </tr>
83   <tr>
84     <td class="labeltop"><&|/l&>Children</&>:</td>
85     <td class="value">
86 % if ( $hash{Members} ) {
87 % for my $link ( values %{$hash{Members}} ) {
88       <input type="checkbox" class="checkbox" id="DeleteLink-<%$link->Base%>-<%$link->Type%>-" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" value="1" />
89       <label for="DeleteLink-<%$link->Base%>-<%$link->Type%>-"><& /Elements/ShowLink, URI => $link->BaseURI &></label><br />
90 % } }
91     </td>
92   </tr>
93   <tr>
94     <td class="labeltop"><&|/l&>Refers to</&>:</td>
95     <td class="value">
96 % if ( $hash{RefersTo} ) {
97 % for my $link ( values %{$hash{RefersTo}} ) {
98       <input type="checkbox" class="checkbox" id="DeleteLink--<%$link->Type%>-<%$link->Target%>" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" value="1" />
99       <label for="DeleteLink--<%$link->Type%>-<%$link->Target%>"><& /Elements/ShowLink, URI => $link->TargetURI &></label><br />
100 % } }
101     </td>
102   </tr>
103   <tr>
104     <td class="labeltop"><&|/l&>Referred to by</&>:</td>
105     <td class="value">
106 % if ( $hash{ReferredToBy} ) {
107 % for my $link ( values %{$hash{ReferredToBy}} ) {
108 % # Skip reminders
109 % next if (UNIVERSAL::isa($link->BaseObj, 'RT::Ticket')  && $link->BaseObj->__Value('Type') eq 'reminder');
110       <input type="checkbox" class="checkbox" id="DeleteLink-<%$link->Base%>-<%$link->Type%>-" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" value="1" />
111       <label for="DeleteLink-<%$link->Base%>-<%$link->Type%>-"><& /Elements/ShowLink, URI => $link->BaseURI &></label><br />
112 % } }
113     </td>
114   </tr>
115   <tr>
116     <td></td>
117     <td><i><&|/l&>(Check box to delete)</&></i></td>
118   </tr>
119 </table>
120 </td>
121 <td valign="top">
122 <h3><&|/l&>New Links</&></h3>
123 <em><&|/l&>Enter tickets or URIs to link to. Separate multiple entries with spaces.</&>
124 </em><br />
125 <table>
126   <tr>
127     <td class="label"><&|/l&>Depends on</&>:</td>
128     <td class="entry"><input name="<% $record_type %>-DependsOn" data-autocomplete="Tickets" data-autocomplete-multiple="1" value="<% $ARGS{ $record_type .'-DependsOn' } || '' %>" /></td>
129   </tr>
130   <tr>
131     <td class="label"><&|/l&>Depended on by</&>:</td>
132     <td class="entry"><input name="DependsOn-<% $record_type %>" data-autocomplete="Tickets" data-autocomplete-multiple="1" value="<% $ARGS{ 'DependsOn-'. $record_type } || '' %>" /></td>
133   </tr>
134   <tr>
135     <td class="label"><&|/l&>Parents</&>:</td>
136     <td class="entry"><input name="<% $record_type %>-MemberOf" data-autocomplete="Tickets" data-autocomplete-multiple="1" value="<% $ARGS{ $record_type .'-MemberOf'} || '' %>" /></td>
137   </tr>
138   <tr>
139     <td class="label"><&|/l&>Children</&>:</td>
140     <td class="entry"> <input name="MemberOf-<% $record_type %>" data-autocomplete="Tickets" data-autocomplete-multiple="1" value="<% $ARGS{ 'MemberOf-'. $record_type } || '' %>" /></td>
141   </tr>
142   <tr>
143     <td class="label"><&|/l&>Refers to</&>:</td>
144     <td class="entry"><input name="<% $record_type %>-RefersTo" data-autocomplete="Tickets" data-autocomplete-multiple="1" value="<% $ARGS{ $record_type .'-RefersTo'} || '' %>" /></td>
145   </tr>
146   <tr>
147     <td class="label"><&|/l&>Referred to by</&>:</td>
148     <td class="entry"> <input name="RefersTo-<% $record_type %>" data-autocomplete="Tickets" data-autocomplete-multiple="1" value="<% $ARGS{ 'RefersTo-'. $record_type } || '' %>" /></td>
149   </tr>
150 </table>
151 </td>
152 </tr>
153 </table>
154
155 <%ARGS>
156 $Collection
157 </%ARGS>
158
159 <%INIT>
160
161 my @types = qw/DependsOn DependedOnBy Members MemberOf RefersTo ReferredToBy/;
162
163 my $record_type = $Collection->RecordClass;
164 $record_type =~ s/^RT:://; $record_type =~ s/::/-/g;
165
166 my %hash;
167 if ( $Collection->Count ) {
168     my $first_record = $Collection->Next;
169     # we only show current links that exist on all the records
170     for my $type ( @types ) {
171         my $target_or_base =
172             $type =~ /DependsOn|MemberOf|RefersTo/ ? 'Target' : 'Base';
173         my $links = $first_record->$type;
174         while ( my $link = $links->Next ) {
175             $hash{$type}{$link->$target_or_base} = $link;
176         }
177     }
178
179     while ( my $record = $Collection->Next ) {
180         for my $type ( @types ) {
181             my $target_or_base =
182                 $type =~ /DependsOn|MemberOf|RefersTo/ ? 'Target' : 'Base';
183             # if $hash{$type} is empty, no need to check any more
184             next unless $hash{$type} && keys %{$hash{$type}};
185
186             my %exists;
187             while ( my $link = $record->$type->Next ) {
188                 $exists{$link->$target_or_base}++;
189             }
190
191             for ( keys %{$hash{$type}} ) {
192                 delete $hash{$type}{$_} unless $exists{$_};
193             }
194         }
195     }
196 }
197 </%INIT>