Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / share / html / Admin / Elements / EditRights
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2012 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 </%init>
70 %# Principals is an array of arrays, where the inner arrays are like:
71 %#      [ 'Category name' => $CollectionObj => 'DisplayColumn' => 1 ]
72 %# The last value is a boolen determining if the value of DisplayColumn
73 %# should be loc()-ed before display.
74
75 <script type="text/javascript">
76   jQuery(function() {
77       jQuery(".rights-editor").tabs({
78           select: function(ev, ui) {
79               window.location.hash = ui.tab.hash;
80           }
81       });
82       jQuery(".rights-editor .category-tabs").tabs();
83   });
84 </script>
85
86 <div class="rights-editor clearfix">
87   <ul>
88 <%perl>
89 for my $category (@$Principals) {
90     my ($name, $collection, $col, $loc) = @$category;
91 </%perl>
92 <li class="category"><% loc($name) %></li>
93 <%perl>
94     while ( my $obj = $collection->Next ) {
95         my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
96         my $id = "acl-$name-" . $obj->PrincipalId;
97         $id =~ s/[^a-zA-Z0-9\-]/_/g;
98 </%perl>
99 <li><a href="#<% $id %>"><% $loc ? loc($display) : $display %></a></li>
100 <%perl>
101     }
102 }
103 </%perl>
104 % if ( $AddPrincipal ) {
105     <li class="category"><&|/l, loc($AddPrincipal) &>Add [_1]</&></li>
106     <li class="addprincipal">
107       <a href="#acl-AddPrincipal">
108         <input type="text" value=""
109                name="AddPrincipalForRights-<% lc $AddPrincipal %>"
110                id="AddPrincipalForRights-<% lc $AddPrincipal %>" />
111         <script type="text/javascript">
112         jQuery(function() {
113             jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).keyup(function(){
114                 toggle_addprincipal_validity(this, true);
115             });
116
117 % if (lc $AddPrincipal eq 'group') {
118             jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).autocomplete({
119                 source: <% RT->Config->Get('WebPath') |n,j%>+"/Helpers/Autocomplete/Groups",
120                 select: addprincipal_onselect,
121                 change: addprincipal_onchange
122             });
123 % }
124         });
125         </script>
126 % my $type = lc $AddPrincipal eq 'user' ? loc('username') : loc($AddPrincipal);
127         <span class="warning"><&|/l, $type &>Invalid [_1]</&></span>
128       </a>
129     </li>
130 % }
131   </ul>
132
133 <%perl>
134 # Now generate our rights panels for each principal
135 for my $category (@$Principals) {
136     my ($name, $collection, $col, $loc) = @$category;
137     while ( my $obj = $collection->Next ) {
138         my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
139         my $id = "acl-$name-" . $obj->PrincipalId;
140         $id =~ s/[^a-zA-Z0-9\-]/_/g;
141 </%perl>
142
143   <div id="<% $id %>">
144     <h3>
145       <% $loc ? loc($display) : $display %>
146 <%perl>
147 if ($obj->isa('RT::Group') and $obj->Domain eq 'UserDefined') {
148     my $subgroups = $obj->GroupMembersObj( Recursively => 1 );
149     $subgroups->LimitToUserDefinedGroups;
150     $subgroups->Limit( FIELD => 'Name', OPERATOR => '!=', VALUE => $obj->Name );
151
152     if ( $subgroups->Count ) {
153         my $inc = join ", ", map $_->Name, @{$subgroups->ItemsArrayRef};
154 </%perl>
155       <span class="subgroups"><&|/l, $inc &>includes [_1]</&></span>\
156 <%perl>
157     }
158 }
159 </%perl>
160     </h3>
161     <& EditRightsCategoryTabs, Context => $Context, Principal => $obj, id => $id &>
162   </div>
163 <%perl>
164     }
165 }
166
167 if ( $AddPrincipal ) {
168 </%perl>
169   <div id="acl-AddPrincipal">
170     <h3><&|/l, loc($AddPrincipal) &>Add rights for this [_1]</&></h3>
171     <& EditRightsCategoryTabs, Context => $Context, id => 'acl-AddPrincipal' &>
172   </div>
173 % }
174
175 </div>