diff --git a/share/html/Elements/AddLinks b/share/html/Elements/AddLinks
index 4fd52791688..32cbf9c8fe7 100644
--- a/share/html/Elements/AddLinks
+++ b/share/html/Elements/AddLinks
@@ -55,8 +55,52 @@ my $id = ($Object and $Object->id)
? $Object->id
: "new";
-my $exclude = qq| data-autocomplete="Tickets" data-autocomplete-multiple="1"|;
-$exclude .= qq| data-autocomplete-exclude="$id"| if $Object->id;
+my $exclude = qq| data-autocomplete="LinkTargets" data-autocomplete-multiple="1"|;
+my @excludes;
+push @excludes, ( $Object->isa('RT::Asset') ? 'asset:' : '' ) . $id
+ if $id ne 'new';
+
+my %exclude_links = (
+ Depend => [ qw( DependsOn DependedOnBy ) ],
+ Member => [ qw( MemberOf Members ) ],
+ Refer => [ qw( RefersTo ReferredToBy ) ],
+);
+foreach my $exclude_type ( keys %exclude_links ) {
+ my @ids;
+ if ( $id ne 'new' ) {
+ foreach my $link_type ( @{ $exclude_links{$exclude_type} } ) {
+ my $links = $Object->$link_type;
+ while ( my $link = $links->Next ) {
+ my $LinkedObj = $link->TargetObj;
+ # if $LinkedObj is same as $Object we want the BaseObj
+ $LinkedObj = $link->BaseObj
+ if (
+ ( ref($Object) eq ref($LinkedObj) )
+ &&
+ ( $id == $LinkedObj->id )
+ );
+ if ( $LinkedObj ) {
+ my $prefix = '';
+ if ( $LinkedObj->isa('RT::Asset') ) {
+ $prefix = 'asset:';
+ }
+ elsif ( $LinkedObj->isa('RT::Article') ) {
+ $prefix = 'a:';
+ }
+ elsif ( $LinkedObj->isa('RT::Group') ) {
+ $prefix = 'group:';
+ }
+ elsif ( $LinkedObj->isa('RT::User') ) {
+ $prefix = 'user:';
+ }
+ push @ids, $prefix . $LinkedObj->id;
+ }
+ }
+ }
+ }
+ $exclude_links{$exclude_type} = $exclude . ' data-autocomplete-exclude="' . join( ' ', @excludes, @ids ) . '"'
+ if @excludes || @ids;
+}
%init>
% if (ref($Object) eq 'RT::Ticket') {
<&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.&>
@@ -76,24 +120,24 @@ $exclude .= qq| data-autocomplete-exclude="$id"| if $Object->id;
<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Depends on'), Relation => 'DependsOn') &>
- " <% $exclude |n%>/>
+ " <% $exclude_links{Depend} |n%>/>
&>
<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Depended on by'), Relation => 'DependedOnBy') &>
- " <% $exclude |n%>/>
+ " <% $exclude_links{Depend} |n%>/>
&>
<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Parents'), Relation => 'Parents') &>
- " <% $exclude |n%>/>
+ " <% $exclude_links{Member} |n%>/>
&>
<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Children'), Relation => 'Children') &>
- " <% $exclude |n%>/>
+ " <% $exclude_links{Member} |n%>/>
&>
<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Refers to'), Relation => 'RefersTo') &>
- " <% $exclude |n%>/>
+ " <% $exclude_links{Refer} |n%>/>
&>
<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Referred to by'), Relation => 'ReferredToBy') &>
- " <% $exclude |n%>/>
+ " <% $exclude_links{Refer} |n%>/>
&>
<& /Elements/EditCustomFields,