5b8fdca0d6014f4b2f363724ee91f096ef62eae5
chmalee
  Thu Sep 30 12:21:57 2021 -0700
Get hub track selection box and hgTrackUi links working on track search

diff --git src/hg/js/utils.js src/hg/js/utils.js
index d441498..e221c4d 100644
--- src/hg/js/utils.js
+++ src/hg/js/utils.js
@@ -2845,30 +2845,32 @@
         }
         $(hiddenVis).attr('disabled',false);
 
         $('input.viewBtn').val('View in Browser');
     },
 
     clickedOne: function (selCb,justClicked)
     {   // called by on click of CB and findTracks.checkAll()
         var selName = $(selCb).attr('id');
         var trackName = selName.substring(0,selName.length - "_sel_id".length);
         var hiddenSel = $("input[name='"+trackName+"_sel']");
         var seenVis = $('select#' + trackName + "_id");
         var hiddenVis = $("input[name='"+trackName+"']");
         var tr = $(selCb).parents('tr.found');
         var tdb = tdbGetJsonRecord(trackName);
+        var isHub = trackName.slice(0,4) === "hub_";
+        var hubUrl = isHub ? tdb.hubUrl : "";
         var needSel = (typeof(tdb.parentTrack) === 'string' && tdb.parentTrack !== '');
         var shouldPack = tdb.canPack && tdb.kindOfParent === 0; // If parent then not pack but full
         if (shouldPack
         &&  tdb.shouldPack !== undefined && tdb.shouldPack !== null && !tdb.shouldPack)
             shouldPack = false;
         var checked = $(selCb).attr('checked');
 
         // First deal with seenVis control
         if (checked) {
             $(seenVis).attr('disabled', false);
             if ($(seenVis).attr('selectedIndex') === 0) {
                 if (shouldPack)
                     $(seenVis).attr('selectedIndex',3);  // packed
                 else
                     $(seenVis).attr('selectedIndex',$(seenVis).attr('length') - 1);
@@ -2895,30 +2897,54 @@
             else if (tdbIsSubtrack(tdb))
                 $(hiddenVis).val("[]");
             else
                 $(hiddenVis).val("hide");
             $(hiddenVis).attr('disabled',false);
 
             if (needSel) {
                 if (checked)
                     $(hiddenSel).val('1');
                 else
                     $(hiddenSel).val('0');  // Can't set it to [] because it means default is used.
                 $(hiddenSel).attr('disabled',false);
             }
         }
 
+        // if we selected a track in a public hub that is unconnected, we need to get the
+        // hubUrl into the form so the genome browser knows to load that hub. If the hub
+        // was already a connected hub, then we don't need to specify anything because it
+        // will already be in the cart and we handle the visibility settings like normal.
+        // The hubUrl field present in the json indicates this is an unconnected hub
+        if (justClicked && hubUrl !== undefined) {
+            var form = $("form[id='searchResults'");
+            var newHubInput = document.createElement("input");
+            // if we are a subtrack we need to explicitly hide the parent
+            // track so ALL subtracks of the parent don't show up unexpectedly
+            if (needSel) {
+                var parentTrack = tdb.parentTrack;
+                var parentTrackInput = document.createElement("input");
+                parentTrackInput.setAttribute("type", "hidden");
+                parentTrackInput.setAttribute("name", parentTrack);
+                parentTrackInput.setAttribute("value", "hide");
+                form.append(parentTrackInput);
+            }
+            newHubInput.setAttribute("type", "hidden");
+            newHubInput.setAttribute("name", "hubUrl");
+            newHubInput.setAttribute("value", hubUrl);
+            form.append(newHubInput);
+        }
+
         // The "view in browser" button should be enabled/disabled
         if (justClicked) {
             $('input.viewBtn').val('View in Browser');
             findTracks.counts();
         }
     },
 
 
     normalize: function ()
     {   // Normalize the page based upon current state of all found tracks
         $('div#found').show();
         var selCbs = $('input.selCb');
 
         // All should have their vis enabled/disabled appropriately (false means don't update cart)
         $(selCbs).each( function(i) { findTracks.clickedOne(this,false); });