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