rt 4.0.23
[freeside.git] / rt / share / html / Admin / Elements / EditRights
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2015 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 <%args>
49 $Context
50 $Principals
51 $AddPrincipal => undef
52 </%args>
53 <%init>
54 use Scalar::Util qw(blessed);
55
56 # Let callbacks get at principals and context before we do anything with them
57 $m->callback( Principals => $Principals, Context => $Context );
58
59 # Try to detect if we want to include an add user/group box
60 unless ( $AddPrincipal ) {
61     my $last = $Principals->[-1];
62     if ( $last->[0] =~ /Groups/i ) {
63         $AddPrincipal = 'group'; # loc
64     }
65     elsif ( $last->[0] =~ /Users/i ) {
66         $AddPrincipal = 'user'; # loc
67     }
68 }
69
70 my $anchor = $DECODED_ARGS->{Anchor} || '';
71 if ($anchor =~ /AddPrincipal/) {
72     for my $type ("group", "user") {
73         my $record = _ParseACLNewPrincipal($DECODED_ARGS, $type)
74             or next;
75         if ($record->PrincipalId) {
76             $anchor = "#acl-" . $record->PrincipalId;
77             last;
78         }
79     }
80 }
81 </%init>
82 %# Principals is an array of arrays, where the inner arrays are like:
83 %#      [ 'Category name' => $CollectionObj => 'DisplayColumn' => 1 ]
84 %# The last value is a boolen determining if the value of DisplayColumn
85 %# should be loc()-ed before display.
86
87 <script type="text/javascript">
88   jQuery(function() {
89       function sync_anchor(hash) {
90           if (!hash.length) return;
91           window.location.hash = hash;
92           jQuery(".rights-editor input[name=Anchor]").val(hash);
93       }
94       sync_anchor(<% $anchor |n,j %>);
95
96       jQuery(".rights-editor").tabs({
97           select: function(ev, ui) {
98               sync_anchor(ui.tab.hash);
99               if ( jQuery(ui.tab).find('input[type=text]').size() > 0 ) {
100                   jQuery(ui.tab).find('input[type=text]:first').focus();
101               }
102           }
103       });
104
105       jQuery(".rights-editor .category-tabs").tabs({
106           cookie: { name: "rights-category-tab" /* saves current tab in cookie */ },
107           show: function(ev, ui) {
108               jQuery(".rights-editor .category-tabs").not(this).each(function() {
109                   var item     = jQuery(this);
110                   var selected = item.tabs("option", "selected") || 0;
111                   if (selected != ui.index)
112                       item.tabs("select", ui.index);
113               });
114           }
115       });
116   });
117 </script>
118
119 <div class="rights-editor clearfix">
120   <input type="hidden" value="" name="Anchor" />
121
122   <ul>
123 <%perl>
124 for my $category (@$Principals) {
125     my ($name, $collection, $col, $loc) = @$category;
126 </%perl>
127 <li class="category"><% loc($name) %></li>
128 <%perl>
129     while ( my $obj = $collection->Next ) {
130         my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
131         my $id = "acl-" . $obj->PrincipalId;
132 </%perl>
133 <li><a href="#<% $id %>"><% $loc ? loc($display) : $display %></a></li>
134 <%perl>
135     }
136 }
137 </%perl>
138 % if ( $AddPrincipal ) {
139     <li class="category"><&|/l, loc($AddPrincipal) &>Add [_1]</&></li>
140     <li class="addprincipal">
141       <a href="#acl-AddPrincipal">
142         <input type="text" value=""
143                name="AddPrincipalForRights-<% lc $AddPrincipal %>"
144                id="AddPrincipalForRights-<% lc $AddPrincipal %>" />
145         <script type="text/javascript">
146         jQuery(function() {
147             jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).keyup(function(){
148                 toggle_addprincipal_validity(this, true);
149             });
150
151 % if (lc $AddPrincipal eq 'group') {
152             jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).autocomplete({
153                 source: <% RT->Config->Get('WebPath') |n,j%>+"/Helpers/Autocomplete/Groups",
154                 select: addprincipal_onselect,
155                 change: addprincipal_onchange
156             });
157 % }
158         });
159         </script>
160 % my $type = lc $AddPrincipal eq 'user' ? loc('username') : loc($AddPrincipal);
161         <span class="warning"><&|/l, $type &>Invalid [_1]</&></span>
162       </a>
163     </li>
164 % }
165   </ul>
166
167 <%perl>
168 # Now generate our rights panels for each principal
169 for my $category (@$Principals) {
170     my ($name, $collection, $col, $loc) = @$category;
171     while ( my $obj = $collection->Next ) {
172         my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
173         my $id = "acl-" . $obj->PrincipalId;
174 </%perl>
175
176   <div id="<% $id %>">
177     <h3>
178       <% $loc ? loc($display) : $display %>
179 <%perl>
180 if ($obj->isa('RT::Group') and $obj->Domain eq 'UserDefined') {
181     my $subgroups = $obj->GroupMembersObj( Recursively => 1 );
182     $subgroups->LimitToUserDefinedGroups;
183     $subgroups->Limit( FIELD => 'Name', OPERATOR => '!=', VALUE => $obj->Name );
184
185     if ( $subgroups->Count ) {
186         my $inc = join ", ", map $_->Name, @{$subgroups->ItemsArrayRef};
187 </%perl>
188       <span class="subgroups"><&|/l, $inc &>includes [_1]</&></span>\
189 <%perl>
190     }
191 }
192 </%perl>
193     </h3>
194     <& EditRightsCategoryTabs, Context => $Context, Principal => $obj, id => $id &>
195   </div>
196 <%perl>
197     }
198 }
199
200 if ( $AddPrincipal ) {
201 </%perl>
202   <div id="acl-AddPrincipal">
203     <h3><&|/l, loc($AddPrincipal) &>Add rights for this [_1]</&></h3>
204     <& EditRightsCategoryTabs, Context => $Context, id => 'acl-AddPrincipal' &>
205   </div>
206 % }
207
208 </div>