[Rt-commit] rt branch, 4.6/tweak-elevator-themes, updated. rt-4.4.4-423-g2689af566

? sunnavy sunnavy at bestpractical.com
Fri Oct 18 18:38:59 EDT 2019


The branch, 4.6/tweak-elevator-themes has been updated
       via  2689af566fa3246e8ac75cee3a9e3f613848aa42 (commit)
      from  620a043b33e65f33024b69501a1283a8a516c538 (commit)

Summary of changes:
 lib/RT/Interface/Web.pm                  |  1 -
 share/html/Elements/HeaderJavascript     |  1 -
 share/html/Ticket/Elements/ShowAssets    | 13 ++------
 share/html/Ticket/Elements/ShowRequestor | 14 ++++-----
 share/static/js/titlebox-state.js        | 36 ----------------------
 share/static/js/util.js                  | 52 ++++++++++++++++++++++++++++++++
 6 files changed, 61 insertions(+), 56 deletions(-)
 delete mode 100644 share/static/js/titlebox-state.js

- Log -----------------------------------------------------------------
commit 2689af566fa3246e8ac75cee3a9e3f613848aa42
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Oct 19 06:07:22 2019 +0800

    Remember collapse status of accordion items in ShowRequestor and ShowAssets
    
    The logic is nearly identical to loadTitleBoxStates, so I directly
    updated the function, renamed it and moved it out of titlebox-state.js.
    
    Superfish menu in asset's accordion title will be broken if we show
    accordion before initializing the menu. Thus I put related js to the
    same jQuery block to assure the execute order.
    
    I also added prefix "accordion-" to related HTML ids in case of name
    collision in the future.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index e03710ac3..920745fc1 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -120,7 +120,6 @@ sub JSFiles {
         bootstrap.min.js
         bootstrap-select.min.js
         bootstrap-combobox.js
-        titlebox-state.js
         i18n.js
         util.js
         autocomplete.js
diff --git a/share/html/Elements/HeaderJavascript b/share/html/Elements/HeaderJavascript
index d58904d15..2e209a556 100644
--- a/share/html/Elements/HeaderJavascript
+++ b/share/html/Elements/HeaderJavascript
@@ -55,7 +55,6 @@ $onload => undef
 % }
 
 <script type="text/javascript"><!--
-jQuery( loadTitleBoxStates );
 % if ( $focus ) {
     jQuery(function () { jQuery(<% $focus |n,j%>).focus() });
 % }
diff --git a/share/html/Ticket/Elements/ShowAssets b/share/html/Ticket/Elements/ShowAssets
index 802e7a1cc..e7916bea9 100644
--- a/share/html/Ticket/Elements/ShowAssets
+++ b/share/html/Ticket/Elements/ShowAssets
@@ -118,18 +118,9 @@ $m->callback(
   <div id="assets-accordion" class="rt-accordion accordion">
 % my $display_path = $session{'CurrentUser'}->Privileged ? 'Asset' : 'SelfService/Asset';
 
-<script type="text/javascript">
-jQuery( function() {
-    jQuery('#assets-accordion span.collapsed').find('ul.toplevel:not(.sf-menu)').addClass('sf-menu sf-js-enabled sf-shadow').supersubs().superfish({ dropShadows: false, speed: 'fast', delay: 0 }).supposition().find('a').click(function(ev){
-      ev.stopPropagation();
-      return true;
-    });
-});
-</script>
-
 % while (my $asset = $assets->Next) {
     <div class="accordion-item">
-      <span class="accordion-title collapsed toggle" data-toggle="collapse" data-target="#asset-<% $asset->id %>" aria-expanded="false" aria-controls="asset-<% $asset->id %>" id="asset-<% $asset->id %>-title" >
+      <span class="accordion-title collapsed toggle" data-toggle="collapse" data-target="#accordion-asset-<% $asset->id %>" aria-expanded="false" aria-controls="accordion-asset-<% $asset->id %>" id="accordion-asset-<% $asset->id %>-title" >
         <a href="<% RT->Config->Get('WebPath') %>/<% $display_path %>/Display.html?id=<% $asset->id %>"><&|/l, $asset->id, $asset->Name &>#[_1]: [_2]</&></a>
 
 
@@ -171,7 +162,7 @@ if ($Ticket->CurrentUserHasRight("ModifyTicket")) {
 % }
 
       </span>
-      <div id="asset-<% $asset->id %>" class="accordion-content collapse" aria-labelledby="asset-<% $asset->id %>-title">
+      <div id="accordion-asset-<% $asset->id %>" class="accordion-content collapse" aria-labelledby="accordion-asset-<% $asset->id %>-title">
         <& /Elements/ShowRecord,
             Object      => $asset,
             Format      => $Format,
diff --git a/share/html/Ticket/Elements/ShowRequestor b/share/html/Ticket/Elements/ShowRequestor
index 1fd52c478..e23054923 100644
--- a/share/html/Ticket/Elements/ShowRequestor
+++ b/share/html/Ticket/Elements/ShowRequestor
@@ -66,17 +66,17 @@
     class => 'ticket-info-requestor fullwidth'
 &>
 
-<div id="requestor-accordion" class="user-accordion accordion">
+<div id="accordion-requestor-accordion" class="user-accordion accordion">
 
 % while ( my $requestor = $people->Next ) {
   <div class="accordion-item">
-    <span class="accordion-title collapsed toggle" data-toggle="collapse" data-target="#requestor-<% $requestor->id %>" aria-expanded="false" aria-controls="requestor-<% $requestor->id %>" id="requestor-<% $requestor->id %>-title" >
+    <span class="accordion-title collapsed toggle" data-toggle="collapse" data-target="#accordion-requestor-<% $requestor->id %>" aria-expanded="false" aria-controls="accordion-requestor-<% $requestor->id %>" id="accordion-requestor-<% $requestor->id %>-title" >
       <a class="user-summary" href="<%RT->Config->Get('WebPath')%>/User/Summary.html?id=<%$requestor->Id%>">
         <& /Elements/ShowUser, User => $requestor, Link => 0 &>
       </a>
     </span>
 
-    <div id="requestor-<% $requestor->id %>" class="accordion-content collapse" aria-labelledby="requestor-<% $requestor->id %>-title">
+    <div id="accordion-requestor-<% $requestor->id %>" class="accordion-content collapse" aria-labelledby="accordion-requestor-<% $requestor->id %>-title">
 
 %# Additional information about this user.  Empty by default.
 % $m->callback( requestor => $requestor, %ARGS, CallbackName => 'AboutThisUser' );
@@ -98,11 +98,11 @@
 % for my $status ( @$status_order ) {
           <li class="nav-item">
 % if ( $status eq $DefaultTicketsTab ) {
-            <a class="nav-link active" href="#requestor-<%$requestor->Id%>-ticket-default" id="requestor-<% $requestor->Id %>-ticket-default-tab" data-toggle="tab" role="tab" aria-controls="#requestor-<%$requestor->Id%>-ticket-default">\
+            <a class="nav-link active" href="#accordion-requestor-<%$requestor->Id%>-ticket-default" id="accordion-requestor-<% $requestor->Id %>-ticket-default-tab" data-toggle="tab" role="tab" aria-controls="#accordion-requestor-<%$requestor->Id%>-ticket-default">\
 % } else {
 %     my $url = RT->Config->Get('WebPath').'/Helpers/Toggle/ShowRequestor?'.
 %     $m->comp('/Elements/QueryString', Requestor => $requestor->Id , Status => $status);
-            <a class="nav-link" data-link="<% $url | n %>" href="#requestor-<%$requestor->Id%>-ticket-<% $index %>" id="requestor-<% $requestor->Id %>-ticket-<% $index %>-tab" data-toggle="tab" role="tab" aria-controls="#requestor-<%$requestor->Id%>-ticket-<% $index %>">\
+            <a class="nav-link" data-link="<% $url | n %>" href="#accordion-requestor-<%$requestor->Id%>-ticket-<% $index %>" id="accordion-requestor-<% $requestor->Id %>-ticket-<% $index %>-tab" data-toggle="tab" role="tab" aria-controls="#accordion-requestor-<%$requestor->Id%>-ticket-<% $index %>">\
 % $index++;
 % }
               <% $status_link_text->{$status} %></a>
@@ -113,10 +113,10 @@
         <div class="tab-content">
 % for my $status (@$status_order) {
 % if ( $status eq $DefaultTicketsTab ) {
-          <div id="requestor-<%$requestor->Id%>-ticket-default" class="tab-pane fade show active" role="tabpanel" aria-labelledby="requestor-<% $requestor->Id %>-ticket-default-tab">
+          <div id="accordion-requestor-<%$requestor->Id%>-ticket-default" class="tab-pane fade show active" role="tabpanel" aria-labelledby="accordion-requestor-<% $requestor->Id %>-ticket-default-tab">
             <& $TicketTemplate, Requestor => $requestor &>
 % } else {
-          <div id="requestor-<%$requestor->Id%>-ticket-<% $index %>" class="tab-pane fade" aria-labelledby="requestor-<% $requestor->Id %>-ticket-<% $index %>-tab">
+          <div id="accordion-requestor-<%$requestor->Id%>-ticket-<% $index %>" class="tab-pane fade" aria-labelledby="accordion-requestor-<% $requestor->Id %>-ticket-<% $index %>-tab">
 % $index++;
             <div class="label"><&|/l&>Loading...</&></div>
 % }
diff --git a/share/static/js/titlebox-state.js b/share/static/js/titlebox-state.js
deleted file mode 100644
index dd4607d8d..000000000
--- a/share/static/js/titlebox-state.js
+++ /dev/null
@@ -1,36 +0,0 @@
-function createCookie(name,value,days) {
-    var path = RT.Config.WebPath ? RT.Config.WebPath : "/";
-
-    if (days) {
-        var date = new Date();
-        date.setTime(date.getTime()+(days*24*60*60*1000));
-        var expires = "; expires="+date.toGMTString();
-    }
-    else
-        expires = "";
-    
-    document.cookie = name+"="+value+expires+"; path="+path;
-}
-
-function loadTitleBoxStates() {
-    var cookies = document.cookie.split(/;\s*/);
-    var len     = cookies.length;
-
-    for (var i = 0; i < len; i++) {
-        var c = cookies[i].split('=');
-        
-        if (c[0].match(/^TitleBox--/)) {
-            var e   = document.getElementById(c[0]);
-            if (e) {
-                var e2  = e.parentNode;
-    
-                if (c[1] != 0) {
-                    jQuery(e).collapse('show');
-                }
-                else {
-                    jQuery(e).collapse('hide');
-                }
-            }
-        }
-    }
-}
diff --git a/share/static/js/util.js b/share/static/js/util.js
index 28cb8a5ff..7cac45276 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -512,6 +512,40 @@ function escapeCssSelector(str) {
     return str.replace(/([^A-Za-z0-9_-])/g,'\\$1');
 }
 
+function createCookie(name,value,days) {
+    var path = RT.Config.WebPath ? RT.Config.WebPath : "/";
+
+    if (days) {
+        var date = new Date();
+        date.setTime(date.getTime()+(days*24*60*60*1000));
+        var expires = "; expires="+date.toGMTString();
+    }
+    else
+        expires = "";
+
+    document.cookie = name+"="+value+expires+"; path="+path;
+}
+
+function loadCollapseStates() {
+    var cookies = document.cookie.split(/;\s*/);
+    var len     = cookies.length;
+
+    for (var i = 0; i < len; i++) {
+        var c = cookies[i].split('=');
+
+        if (c[0].match(/^(TitleBox--|accordion-)/)) {
+            var e   = document.getElementById(c[0]);
+            if (e) {
+                if (c[1] != 0) {
+                    jQuery(e).collapse('show');
+                }
+                else {
+                    jQuery(e).collapse('hide');
+                }
+            }
+        }
+    }
+}
 
 jQuery(function() {
     ReplaceAllTextareas();
@@ -548,6 +582,17 @@ jQuery(function() {
             e.closest('div.titlebox').find('div.card-header span.right').removeClass('invisible');
         });
     });
+
+    jQuery(".card .accordion-item .toggle").each(function() {
+        var e = jQuery(jQuery(this).attr('data-target'));
+        e.on('hide.bs.collapse', function () {
+            createCookie(e.attr('id'),0,365);
+        });
+        e.on('show.bs.collapse', function () {
+            createCookie(e.attr('id'),1,365);
+        });
+    });
+
     jQuery(".card .card-body .toggle").each(function() {
         var e = jQuery(jQuery(this).attr('data-target'));
         e.on('hide.bs.collapse', function (event) {
@@ -569,6 +614,13 @@ jQuery(function() {
     jQuery('.custom-file input').change(function (e) {
         jQuery(this).next('.custom-file-label').html(e.target.files[0].name);
     });
+
+    jQuery('#assets-accordion span.collapsed').find('ul.toplevel:not(.sf-menu)').addClass('sf-menu sf-js-enabled sf-shadow').supersubs().superfish({ dropShadows: false, speed: 'fast', delay: 0 }).supposition().find('a').click(function(ev){
+      ev.stopPropagation();
+      return true;
+    });
+
+    loadCollapseStates();
 });
 
 // focus jquery object in window, only moving the screen when necessary

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


More information about the rt-commit mailing list