[Rt-commit] rt branch, 4.4/admin-rights-unselected, created. rt-4.4.1-125-g19230bd

Shawn Moore shawn at bestpractical.com
Thu Nov 10 18:43:28 EST 2016


The branch, 4.4/admin-rights-unselected has been created
        at  19230bdf5908bff688334af03a3a80c38c4d09f9 (commit)

- Log -----------------------------------------------------------------
commit 10aff1ecd1acb21e28edf019532bb20da38c4fcb
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Nov 10 23:36:06 2016 +0000

    Factor out an "input" variable
    
    jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>)
    
    is rather verbose and confusing to repeat three times

diff --git a/share/html/Admin/Elements/EditRights b/share/html/Admin/Elements/EditRights
index 57dc2fb..c48e497 100644
--- a/share/html/Admin/Elements/EditRights
+++ b/share/html/Admin/Elements/EditRights
@@ -205,14 +205,15 @@ for my $category (@$Principals) {
                id="AddPrincipalForRights-<% lc $AddPrincipal %>" />
         <script type="text/javascript">
         jQuery(function() {
-            jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).keyup(function(){
+            var input = jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>);
+            input.keyup(function(){
                 toggle_addprincipal_validity(this, true);
             }).keydown(function(event){
                 event.stopPropagation() // Disable tabs keyboard nav
             });
 
-            jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).on("autocompleteselect", addprincipal_onselect);
-            jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>).on("autocompletechange", addprincipal_onchange);
+            input.on("autocompleteselect", addprincipal_onselect);
+            input.on("autocompletechange", addprincipal_onchange);
         });
         </script>
 % my $type = lc $AddPrincipal eq 'user' ? loc('username') : loc($AddPrincipal);

commit 7dd7e512581442143ed715dfad1bb52b1f36cbb3
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Nov 10 23:37:11 2016 +0000

    Factor out an addprincipal_test_validity function
    
    This lets us reuse it in multiple places

diff --git a/share/static/js/util.js b/share/static/js/util.js
index 5cd61dd..8bc1b76 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -493,27 +493,31 @@ function addprincipal_onselect(ev, ui) {
     toggle_addprincipal_validity(this, true, ui.item.value);
 }
 
+function addprincipal_test_validity(input) {
+    // Check using the same autocomplete source if the value typed would
+    // have been autocompleted and is therefore valid
+    jQuery.ajax({
+        url: input.autocomplete("option", "source"),
+        data: {
+            op: "=",
+            term: input.val()
+        },
+        dataType: "json",
+        success: function(data) {
+            if (data)
+                toggle_addprincipal_validity(input, data.length ? true : false );
+            else
+                toggle_addprincipal_validity(input, true);
+        }
+    });
+}
+
 // when the input is actually changed, through typing or autocomplete
 function addprincipal_onchange(ev, ui) {
     // if we have a ui.item, then they selected from autocomplete and it's good
     if (!ui.item) {
         var input = jQuery(this);
-        // Check using the same autocomplete source if the value typed would
-        // have been autocompleted and is therefore valid
-        jQuery.ajax({
-            url: input.autocomplete("option", "source"),
-            data: {
-                op: "=",
-                term: input.val()
-            },
-            dataType: "json",
-            success: function(data) {
-                if (data)
-                    toggle_addprincipal_validity(input, data.length ? true : false );
-                else
-                    toggle_addprincipal_validity(input, true);
-            }
-        });
+        addprincipal_test_validity(input);
     } else {
         toggle_addprincipal_validity(this, true);
     }

commit 19230bdf5908bff688334af03a3a80c38c4d09f9
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Nov 10 23:39:10 2016 +0000

    Improve hiding/showing of rights UI for unselected principal
    
    If you're assigning rights to a user or group and you're using the "Add
    Group" or "Add User" text field but have not yet typed in a valid group
    or user name, RT will still display the three-tab list of checkboxes UI
    on the right-hand side of the page. This is confusing to administrators
    since they should not be selecting rights, as there is no principal
    selected yet, but we show the UI anyway.
    
    This re-engineering hides and shows the panel itself based on whether
    there is a valid principal selected. This also improves the
    responsiveness of the "no user/group selected" warning which previously
    required you to blur the autocomplete field to render. Now, it provides
    more instantaneous feedback.

diff --git a/share/html/Admin/Elements/EditRights b/share/html/Admin/Elements/EditRights
index c48e497..9a8de28 100644
--- a/share/html/Admin/Elements/EditRights
+++ b/share/html/Admin/Elements/EditRights
@@ -207,7 +207,7 @@ for my $category (@$Principals) {
         jQuery(function() {
             var input = jQuery("#AddPrincipalForRights-"+<% lc $AddPrincipal |n,j%>);
             input.keyup(function(){
-                toggle_addprincipal_validity(this, true);
+                addprincipal_test_validity(input);
             }).keydown(function(event){
                 event.stopPropagation() // Disable tabs keyboard nav
             });
@@ -216,8 +216,6 @@ for my $category (@$Principals) {
             input.on("autocompletechange", addprincipal_onchange);
         });
         </script>
-% my $type = lc $AddPrincipal eq 'user' ? loc('username') : loc($AddPrincipal);
-        <span class="warning"><&|/l, $type &>Invalid [_1]</&></span>
       </a>
     </li>
 % }
@@ -259,8 +257,13 @@ if ($obj->isa('RT::Group') and $obj->Domain eq 'UserDefined') {
 if ( $AddPrincipal ) {
 </%perl>
   <div id="acl-AddPrincipal">
-    <h3><&|/l, loc($AddPrincipal) &>Add rights for this [_1]</&></h3>
-    <& EditRightsCategoryTabs, Context => $Context, id => 'acl-AddPrincipal' &>
+    <div class="valid-group hidden">
+      <h3><&|/l, loc($AddPrincipal) &>Add rights for this [_1]</&></h3>
+      <& EditRightsCategoryTabs, Context => $Context, id => 'acl-AddPrincipal' &>
+    </div>
+    <div class="invalid-group">
+      <p><&|/l, loc($AddPrincipal)&>Please select a [_1]</&></p>
+    </div>
   </div>
 % }
 
diff --git a/share/static/css/base/rights-editor.css b/share/static/css/base/rights-editor.css
index 6236b5f..ac42202 100644
--- a/share/static/css/base/rights-editor.css
+++ b/share/static/css/base/rights-editor.css
@@ -38,11 +38,6 @@ li.category ~ li.category {
     margin-top: 1em;
 }
 
-.rights-editor li.addprincipal .warning {
-    color: #a00;
-    display: none;
-}
-
 /* Position the outer-most panel */
 .rights-editor > .ui-tabs-panel {
     position: static;
@@ -144,3 +139,8 @@ span.rights-editor-label {
 .category-tabs.ui-tabs .ui-tabs-nav .ui-tabs-anchor {
     padding: .5em 0.5em;
 }
+
+.rights-editor #acl-AddPrincipal .invalid-group p {
+    color: gray;
+    text-align: center;
+}
diff --git a/share/static/js/util.js b/share/static/js/util.js
index 8bc1b76..99aa6c2 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -458,11 +458,11 @@ function AddAttachmentWarning() {
 
 function toggle_addprincipal_validity(input, good, title) {
     if (good) {
-        jQuery(input).nextAll(".warning").hide();
-        jQuery("#acl-AddPrincipal input[type=checkbox]").removeAttr("disabled");
+        jQuery("#acl-AddPrincipal .valid-group").removeClass("hidden");
+        jQuery("#acl-AddPrincipal .invalid-group").addClass("hidden");
     } else {
-        jQuery(input).nextAll(".warning").css("display", "block");
-        jQuery("#acl-AddPrincipal input[type=checkbox]").attr("disabled", "disabled");
+        jQuery("#acl-AddPrincipal .invalid-group").removeClass("hidden");
+        jQuery("#acl-AddPrincipal .valid-group").addClass("hidden");
     }
 
     if (title == null)
@@ -472,7 +472,7 @@ function toggle_addprincipal_validity(input, good, title) {
 }
 
 function update_addprincipal_title(title) {
-    var h3 = jQuery("#acl-AddPrincipal h3");
+    var h3 = jQuery("#acl-AddPrincipal .valid-group h3");
     h3.text( h3.text().replace(/: .*$/,'') + ": " + title );
 }
 
@@ -494,6 +494,13 @@ function addprincipal_onselect(ev, ui) {
 }
 
 function addprincipal_test_validity(input) {
+    // autocomplete won't run if the input field is empty
+    // and we know that an empty input field should hide the panel
+    if (input.val() == "") {
+        toggle_addprincipal_validity(input, false);
+        return;
+    }
+
     // Check using the same autocomplete source if the value typed would
     // have been autocompleted and is therefore valid
     jQuery.ajax({

-----------------------------------------------------------------------


More information about the rt-commit mailing list