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<& /Elements/ListActions, actions => \@results &>
49
50<form action="<%RT->Config->Get('WebPath')%><% $m->request_comp->path |n %>" method="post" name="EditCustomRoles">
51<input type="hidden" class="hidden" name="id" value="<% $id %>" />
52
53<h2><&|/l&>Selected Custom Roles</&></h2>
54<& /Elements/CollectionList,
55    %ARGS,
56    Collection    => $added_crs,
57    Rows          => 0,
58    Page          => 1,
59    Format        => $format,
60    DisplayFormat => $display_format,
61    AllowSorting  => 0,
62    ShowEmpty     => 0,
63    PassArguments => [
64        qw(Page Order OrderBy id),
65    ],
66&>
67
68<h2><&|/l&>Unselected Custom Roles</&></h2>
69<& /Elements/CollectionList,
70    OrderBy       => 'Name',
71    Order         => 'ASC',
72    %ARGS,
73    Collection    => $not_added_crs,
74    Rows          => $rows,
75    Format        => $format,
76    DisplayFormat => "'__CheckBox.{AddCustomRole}__',". $format,
77    AllowSorting  => 1,
78    ShowEmpty     => 0,
79    PassArguments => [
80        qw(Page Order OrderBy id),
81    ],
82&>
83
84<& /Elements/Submit, Name => 'UpdateCRs' &>
85</form>
86
87
88<%INIT>
89my $id = $Object->Id or Abort( loc("Invalid object") );
90
91if ( !$Object->CurrentUserHasRight('AdminCustomRoles') ) {
92    $m->out( '<p><i>', loc('(No custom roles)'), '</i></p>' );
93    return;
94}
95
96my @results;
97
98## deal with moving sortorder of custom roles
99if ( $MoveCustomRoleUp ) {
100    my $record = RT::ObjectCustomRole->new( $session{'CurrentUser'} );
101    $record->LoadByCols( ObjectId => $id, CustomRole => $MoveCustomRoleUp );
102    unless ( $record->id ) {
103        push @results, loc("Custom role #[_1] is not applied to this object", $MoveCustomRoleUp);
104        last;
105    }
106
107    my ( $status, $msg ) = $record->MoveUp;
108    push @results, $msg;
109}
110if ( $MoveCustomRoleDown ) {
111    my $record = RT::ObjectCustomRole->new( $session{'CurrentUser'} );
112    $record->LoadByCols( ObjectId => $id, CustomRole => $MoveCustomRoleDown );
113    unless ( $record->id ) {
114        push @results, loc("Custom role #[_1] is not applied to this object", $MoveCustomRoleDown);
115        last;
116    }
117
118    my ( $status, $msg ) = $record->MoveDown;
119    push @results, $msg;
120}
121
122if ( $UpdateCRs ) {
123    for my $cr_id ( @AddCustomRole ) {
124        my $cr = RT::CustomRole->new( $session{'CurrentUser'} );
125        $cr->Load( $cr_id );
126        unless ( $cr->id ) {
127            push @results, loc("Couldn't load CustomRole #[_1]", $cr_id);
128            next;
129        }
130        my ( $status, $msg ) = $cr->AddToObject($id);
131        push @results, $msg;
132    }
133    for my $cr_id ( @RemoveCustomRole ) {
134        my $cr = RT::CustomRole->new( $session{'CurrentUser'} );
135        $cr->Load( $cr_id );
136        unless ( $cr->id ) {
137            push @results, loc("Couldn't load CustomRole #[_1]", $cr_id);
138            next;
139        }
140        my ( $status, $msg ) = $cr->RemoveFromObject($id);
141        push @results, $msg;
142    }
143}
144
145$m->callback( CallbackName => 'UpdateExtraFields', Results => \@results, Object => $Object, %ARGS );
146
147my $added_crs = RT::CustomRoles->new( $session{'CurrentUser'} );
148$added_crs->LimitToObjectId($id);
149$added_crs->ApplySortOrder;
150
151my $not_added_crs = RT::CustomRoles->new( $session{'CurrentUser'} );
152$not_added_crs->LimitToNotAdded( $id );
153
154my $format = RT->Config->Get('AdminSearchResultFormat')->{'CustomRoles'};
155my $rows = RT->Config->Get('AdminSearchResultRows')->{'CustomRoles'} || 50;
156
157my $display_format = $id
158            ? ("'__RemoveCheckBox.{$id}__',". $format .", '__MoveCR.{$id}__'")
159            : ("'__CheckBox.{RemoveCustomRole}__',". $format .", '__MoveCR.{$id}__'");
160$m->callback( CallbackName => 'EditDisplayFormat', DisplayFormat => \$display_format, id => $id );
161
162</%INIT>
163<%ARGS>
164$Object
165$UpdateCRs           => undef
166@RemoveCustomRole   => ()
167@AddCustomRole      => ()
168$MoveCustomRoleUp   => undef
169$MoveCustomRoleDown => undef
170</%ARGS>
171