1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
5%# This software is Copyright (c) 1996-2021 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% if ($ShowLabel) {
49<br />
50<br />
51
52<&|/l&>Add new watchers</&>:<br />
53% }
54
55% if ($Users and $Users->Count) {
56  <div class="form-row">
57    <div class="col-3">
58      <&|/l&>Type</&>
59    </div>
60    <div class="col-9">
61      <&|/l&>Username</&>
62    </div>
63  </div>
64% while (my $u = $Users->Next ) {
65  <div class="form-row">
66    <div class="col-3">
67      <&/Elements/SelectWatcherType,
68        Name  => "Ticket-AddWatcher-Principal-". $u->PrincipalId,
69        Queue => $Ticket->QueueObj,
70      &>
71    </div>
72    <div class="col-9">
73      <span class="form-control current-value">
74        <& '/Elements/ShowUser', User => $u, style=>'verbose' &>
75      </span>
76    </div>
77  </div>
78% }
79% }
80
81% if ($Groups and $Groups->Count) {
82  <div class="form-row">
83    <div class="col-3">
84      <&|/l&>Type</&>
85    </div>
86    <div class="col-9">
87      <&|/l&>Group</&>
88    </div>
89  </div>
90% while (my $g = $Groups->Next ) {
91  <div class="form-row">
92    <div class="col-3">
93      <& /Elements/SelectWatcherType,
94        Name  => "Ticket-AddWatcher-Principal-".$g->PrincipalId,
95        Queue => $Ticket->QueueObj,
96      &>
97    </div>
98    <div class="col-9">
99      <span class="form-control current-value">
100        <%$g->Name%> (<%$g->Description%>)
101      </span>
102    </div>
103  </div>
104% }
105% }
106
107  <div class="form-row">
108    <div class="col-3">
109      <&|/l&>Type</&>
110    </div>
111    <div class="col-9">
112      <&|/l&>User or Group</&>
113    </div>
114  </div>
115% my $counter = 4;
116% for my $email (@extras) {
117% $counter++;
118  <div class="form-row">
119    <div class="col-3">
120      <&/Elements/SelectWatcherType, Name => "WatcherTypeEmail".$counter, Queue => $Ticket->QueueObj &>
121    </div>
122    <div class="col-9">
123      <input type="hidden" name="WatcherAddressEmail<%$counter%>" value="<%$email->format%>">
124      <span class="form-control current-value">
125        <%$email->format%>
126      </span>
127    </div>
128  </div>
129% }
130% for my $i (1 .. 3) {
131  <div class="form-row">
132    <div class="col-3">
133      <&/Elements/SelectWatcherType, Name => "WatcherTypeEmail" . $i, Queue => $Ticket->QueueObj &>
134    </div>
135    <div class="col-6">
136      <& /Elements/EmailInput, Name => 'WatcherAddressEmail' . $i, Size => '20', AutocompleteType => 'Principals' &>
137    </div>
138  </div>
139% }
140
141<%INIT>
142my ($Users, $Groups);
143
144if ($UserString) {
145    $Users = RT::Users->new($session{'CurrentUser'});
146    $Users->Limit(FIELD => $UserField, VALUE => $UserString, OPERATOR => $UserOp, CASESENSITIVE => 0);
147    $Users->LimitToPrivileged if $PrivilegedOnly;
148}
149
150if ($GroupString) {
151    $Groups = RT::Groups->new($session{'CurrentUser'});
152    $Groups->LimitToUserDefinedGroups;
153    $Groups->Limit(FIELD => $GroupField, VALUE => $GroupString, OPERATOR => $GroupOp, CASESENSITIVE => 0);
154}
155
156my @extras;
157for my $addr ( values %{$Ticket->TransactionAddresses} ) {
158    my $is_watcher;
159    for my $type ( qw/Owner Requestor Cc AdminCc/ ) {
160        if ($Ticket->IsWatcher( Email => $addr->address, Type => $type )) {
161            $is_watcher = 1;
162            last;
163        }
164    }
165    push @extras, $addr unless $is_watcher;
166}
167
168
169</%INIT>
170
171<%ARGS>
172$ShowLabel => 1
173$UserField => 'Name'
174$UserOp => '='
175$UserString => undef
176$GroupField => 'Name'
177$GroupOp => '='
178$GroupString => undef
179$PrivilegedOnly => undef
180$Ticket => undef
181</%ARGS>
182