rt 4.2.13 ticket#13852
[freeside.git] / rt / share / html / Admin / Elements / EditRights
index e5b9908..ece8d9e 100644 (file)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
@@ -51,8 +51,6 @@ $Principals
 $AddPrincipal => undef
 </%args>
 <%init>
-use Scalar::Util qw(blessed);
-
 # Let callbacks get at principals and context before we do anything with them
 $m->callback( Principals => $Principals, Context => $Context );
 
@@ -66,6 +64,18 @@ unless ( $AddPrincipal ) {
         $AddPrincipal = 'user'; # loc
     }
 }
+
+my $anchor = $DECODED_ARGS->{Anchor} || '';
+if ($anchor =~ /AddPrincipal/) {
+    for my $type ("group", "user") {
+        my $record = _ParseACLNewPrincipal($DECODED_ARGS, $type)
+            or next;
+        if ($record->PrincipalId) {
+            $anchor = "#acl-" . $record->PrincipalId;
+            last;
+        }
+    }
+}
 </%init>
 %# Principals is an array of arrays, where the inner arrays are like:
 %#      [ 'Category name' => $CollectionObj => 'DisplayColumn' => 1 ]
@@ -74,16 +84,40 @@ unless ( $AddPrincipal ) {
 
 <script type="text/javascript">
   jQuery(function() {
+      function sync_anchor(hash) {
+          if (!hash.length) return;
+          window.location.hash = hash;
+          jQuery(".rights-editor input[name=Anchor]").val(hash);
+      }
+      sync_anchor(<% $anchor |n,j %>);
+
       jQuery(".rights-editor").tabs({
-          select: function(ev, ui) {
-              window.location.hash = ui.tab.hash;
+          beforeActivate: function(ev, ui) {
+              sync_anchor(ui.newPanel.selector);
+              if ( ui.newTab.find('input[type=text]').size() > 0 ) {
+                  ui.newTab.find('input[type=text]:first').focus();
+              }
+          }
+      });
+
+      jQuery(".rights-editor .category-tabs").tabs({
+          active: jQuery.cookie('rights-category-tab') || 0,
+          activate: function(ev, ui) {
+              jQuery.cookie('rights-category-tab', ui.newTab.index());
+              jQuery(".rights-editor .category-tabs").not(this).each(function() {
+                  var item     = jQuery(this);
+                  var selected = item.tabs("option", "active") || 0;
+                  if (selected != ui.newTab.index())
+                      item.tabs("option", "active", ui.newTab.index());
+              });
           }
       });
-      jQuery(".rights-editor .category-tabs").tabs();
   });
 </script>
 
 <div class="rights-editor clearfix">
+  <input type="hidden" value="" name="Anchor" />
+
   <ul>
 <%perl>
 for my $category (@$Principals) {
@@ -93,8 +127,7 @@ for my $category (@$Principals) {
 <%perl>
     while ( my $obj = $collection->Next ) {
         my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
-        my $id = "acl-$name-" . $obj->PrincipalId;
-        $id =~ s/[^a-zA-Z0-9\-]/_/g;
+        my $id = "acl-" . $obj->PrincipalId;
 </%perl>
 <li><a href="#<% $id %>"><% $loc ? loc($display) : $display %></a></li>
 <%perl>
@@ -106,21 +139,23 @@ for my $category (@$Principals) {
     <li class="addprincipal">
       <a href="#acl-AddPrincipal">
         <input type="text" value=""
+            data-autocomplete="<% lc $AddPrincipal eq 'user' ? 'Users' : 'Groups' %>"
+% if ( lc $AddPrincipal eq 'user' ) {
+            data-autocomplete-return="Name"
+            data-autocomplete-privileged="1"
+% }
                name="AddPrincipalForRights-<% lc $AddPrincipal %>"
                id="AddPrincipalForRights-<% lc $AddPrincipal %>" />
         <script type="text/javascript">
         jQuery(function() {
-            jQuery("#AddPrincipalForRights-<% lc $AddPrincipal %>").keyup(function(){
+            jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).keyup(function(){
                 toggle_addprincipal_validity(this, true);
+            }).keydown(function(event){
+                event.stopPropagation() // Disable tabs keyboard nav
             });
 
-% if (lc $AddPrincipal eq 'group') {
-            jQuery("#AddPrincipalForRights-<% lc $AddPrincipal %>").autocomplete({
-                source: "<% RT->Config->Get('WebPath')%>/Helpers/Autocomplete/Groups",
-                select: addprincipal_onselect,
-                change: addprincipal_onchange
-            });
-% }
+            jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).on("autocompleteselect", addprincipal_onselect);
+            jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).on("autocompletechange", addprincipal_onchange);
         });
         </script>
 % my $type = lc $AddPrincipal eq 'user' ? loc('username') : loc($AddPrincipal);
@@ -136,8 +171,7 @@ for my $category (@$Principals) {
     my ($name, $collection, $col, $loc) = @$category;
     while ( my $obj = $collection->Next ) {
         my $display = ref $col eq 'CODE' ? $col->($obj) : $obj->$col;
-        my $id = "acl-$name-" . $obj->PrincipalId;
-        $id =~ s/[^a-zA-Z0-9\-]/_/g;
+        my $id = "acl-" . $obj->PrincipalId;
 </%perl>
 
   <div id="<% $id %>">
@@ -147,7 +181,7 @@ for my $category (@$Principals) {
 if ($obj->isa('RT::Group') and $obj->Domain eq 'UserDefined') {
     my $subgroups = $obj->GroupMembersObj( Recursively => 1 );
     $subgroups->LimitToUserDefinedGroups;
-    $subgroups->Limit( FIELD => 'Name', OPERATOR => '!=', VALUE => $obj->Name );
+    $subgroups->Limit( FIELD => 'Name', OPERATOR => '!=', VALUE => $obj->Name, CASESENSITIVE => 0 );
 
     if ( $subgroups->Count ) {
         my $inc = join ", ", map $_->Name, @{$subgroups->ItemsArrayRef};