ead784cdf9f0d7f79d1d505d8e450b3a220d5b1a
tdreszer
  Thu Jun 2 15:59:57 2011 -0700
Added rightClick 'hide highlihgted (green) set' and 'hide track (blue) set' options.
diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js
index 817ae73..3eb927c 100644
--- src/hg/js/hgTracks.js
+++ src/hg/js/hgTracks.js
@@ -740,30 +740,32 @@
                 $(sideImg).css( {'top': top.toString() + "px" });
                 $( center ).show();
             } else if(!show) {
                 $(btn).css('height',$(btn).height() - centerHeight);
                 $(side).css('height',$(side).height() - centerHeight);
                 top -= centerHeight; // top is a negative number
                 $(sideImg).css( {'top': top.toString() + "px" });
                 $( center ).hide();
             }
         }
     }
 }
 
 function imgTblContiguousRowSet(row)
 { // Returns the set of rows that are of the same class and contiguous
+    if(row == null)
+        return null;
     var btn = $( row ).find("p.btn");
     if( btn.length == 0)
         return null;
     var classList = $( btn ).attr("class").split(" ");
     var matchClass = classList[0];
     var table = $(row).parents('table#imgTbl')[0];
     var rows = $(table).find('tr');
 
     // Find start index
     var startIndex = $(row).attr('rowIndex');
     var endIndex = startIndex;
     for(var ix=startIndex-1;ix>=0;ix--) {
         btn = $( rows[ix] ).find("p.btn");
         if( btn.length == 0)
             break;
@@ -774,30 +776,43 @@
     }
 
     // Find end index
     for(var ix=endIndex;ix<rows.length;ix++) {
         btn = $( rows[ix] ).find("p.btn");
         if( btn.length == 0)
             break;
         classList = $( btn ).attr("class").split(" ");
         if (classList[0] != matchClass)
             break;
         endIndex = ix;
     }
     return rows.slice(startIndex,endIndex+1); // endIndex is 1 based!
 }
 
+function imgTblCompositeSet(row)
+{ // Returns the set of rows that are of the same class and contiguous
+    if(row == null)
+        return null;
+    var rowId = $(row).attr('id').substring('tr_'.length);
+    var rec = trackDbJson[rowId];
+    if (tdbIsSubtrack(rec) == false)
+        return null;
+
+    var rows = $('tr.trDraggable:has(p.' + rec.parentTrack+')');
+    return rows;
+}
+
 function imgTblZipButtons(table)
 {
 // Goes through the image and binds composite track buttons when adjacent
     var rows = $(table).find('tr');
     var lastClass="";
     var lastBtn;
     var lastMatchesLast=false;
     var lastBlue=true;
     var altColors=false;
     var count=0;
     var countN=0;
     for(var ix=0;ix<rows.length;ix++) {    // Need to have buttons in order
         var btn = $( rows[ix] ).find("p.btn");
         if( btn.length == 0)
             continue;
@@ -874,64 +889,66 @@
         $(handle).mouseleave( imgTblDragHandleMouseOut  );
     }
 }
 
 function imgTblDragHandleMouseOver()
 {
 // Highlights a single row when mouse over a dragHandle column (sideLabel and buttons)
     if(jQuery.tableDnD == undefined) {
         //var handle = $("td.dragHandle");
         //$(handle)
         //    .unbind('mouseenter')//, jQuery.tableDnD.mousemove);
         //    .unbind('mouseleave');//, jQuery.tableDnD.mouseup);
         return;
     }
     if (jQuery.tableDnD.dragObject == null) {
-        $( this ).parents("tr").addClass("trDrag");
+        $( this ).parents("tr.trDraggable").addClass("trDrag");
     }
 }
 
 function imgTblDragHandleMouseOut()
 {
 // Ends row highlighting by mouse over
-    $( this ).parents("tr").removeClass("trDrag");
+    $( this ).parents("tr.trDraggable").removeClass("trDrag");
 }
 
 function imgTblButtonMouseOver()
 {
 // Highlights a composite set of buttons, regarless of whether tracks are adjacent
     if(jQuery.tableDnD == undefined || jQuery.tableDnD.dragObject == null) {
         var classList = $( this ).attr("class").split(" ");
         var btns = $( "p." + classList[0] );
         $( btns ).removeClass('btnGrey');
         $( btns ).addClass('btnBlue');
         if (jQuery.tableDnD != undefined) {
-            var rows = imgTblContiguousRowSet($(this).parents('tr.trDraggable')[0])
+            var rows = imgTblContiguousRowSet($(this).parents('tr.trDraggable')[0]);
+            if (rows)
             $( rows ).addClass("trDrag");
         }
     }
 }
 
 function imgTblButtonMouseOut()
 {
 // Ends composite highlighting by mouse over
     var classList = $( this ).attr("class").split(" ");
     var btns = $( "p." + classList[0] );
     $( btns ).removeClass('btnBlue');
     $( btns ).addClass('btnGrey');
     if (jQuery.tableDnD != undefined) {
-        var rows = imgTblContiguousRowSet($(this).parents('tr.trDraggable')[0])
+        var rows = imgTblContiguousRowSet($(this).parents('tr.trDraggable')[0]);
+        if (rows)
         $( rows ).removeClass("trDrag");
     }
 }
 
 
 /////////////////////////////////////////////////////
 // Drag Scroll code
 jQuery.fn.panImages = function(imgOffset,imgBoxLeftOffset){
     // globals across all panImages
     var leftLimit   = imgBoxLeftOffset*-1;
     var rightLimit  = (imgBoxPortalWidth - imgBoxWidth + leftLimit);
     var prevX       = (imgOffset + imgBoxLeftOffset)*-1;
     var portalWidth = 0;
     panAdjustHeight(prevX);
 
@@ -1742,30 +1759,67 @@
     } else if (cmd == 'float') {
         if(floatingMenuItem && floatingMenuItem == id) {
             $.floatMgr.FOArray = new Array();
             floatingMenuItem = null;
         } else {
             if(floatingMenuItem) {
                 // This doesn't work.
                 $('#img_data_' + floatingMenuItem).parent().restartFloat();
                 // This does work
                 $.floatMgr.FOArray = new Array();
             }
             floatingMenuItem = id;
             reloadFloatingItem();
             updateTrackImg(id, "hgt.transparentImage=0", "");
         }
+    } else if (cmd == 'hideSet') {
+        var row = $( 'tr#tr_' + id );
+        var rows = imgTblContiguousRowSet(row);
+        if (rows && rows.length > 0) {
+            var vars = new Array();
+            var vals = new Array();
+            for (var ix=rows.length - 1; ix >= 0; ix--) { // from bottom, just in case remove screws with us
+                var rowId = $(rows[ix]).attr('id').substring('tr_'.length);
+                //if (tdbIsSubtrack(trackDbJson[rowId]) == false)
+                //    warn('What went wrong?');
+
+                vars.push(rowId, rowId+'_sel'); // Remove subtrack level vis and explicitly uncheck.
+                vals.push('[]', 0);
+                $(rows[ix]).remove();
+            }
+            if (vars.length > 0) {
+                setCartVars( vars, vals );
+                initImgTblButtons();
+                loadImgAreaSelect(false);
+            }
+        }
+    } else if (cmd == 'hideComposite') {
+        var rec = trackDbJson[id];
+        if (tdbIsSubtrack(rec)) {
+            var row = $( 'tr#tr_' + id );
+            var rows = imgTblCompositeSet(row);
+            if (rows && rows.length > 0) {
+                for (var ix=rows.length - 1; ix >= 0; ix--) { // from bottom, just in case remove screws with us
+                    $(rows[ix]).remove();
+                }
+            setCartVar(rec.parentTrack, 'hide' );
+            initImgTblButtons();
+            loadImgAreaSelect(false);
+            }
+        }
+        //else
+        //    warn('What went wrong?');
     } else {   // if( cmd in 'hide','dense','squish','pack','full','show' )
         // Change visibility settings:
         //
         // First change the select on our form:
         var rec = trackDbJson[id];
         var selectUpdated = updateVisibility(id, cmd);
 
         // Now change the track image
         if(imageV2 && cmd == 'hide')
         {
             // Hide local display of this track and update server side cart.
             // Subtracks controlled by 2 settings so del vis and set sel=0.  Others, just set vis hide.
             if(tdbIsSubtrack(rec))
                 setCartVars( [ id, id+"_sel" ], [ '[]', 0 ] ); // Remove subtrack level vis and explicitly uncheck.
             else if(tdbIsFolderContent(rec))
@@ -1837,30 +1891,65 @@
             popUpBoxCleanup();   // Popup box is not getting closed properly so must do it here
 
             var menu = [];
             var selectedImg = makeImgTag("greenChecksm.png");
             var blankImg    = makeImgTag("invisible16.png");
             var done = false;
             if(selectedMenuItem && selectedMenuItem.id != null) {
                 var href = selectedMenuItem.href;
                 var isHgc, isGene;
                 if(href) {
                     isGene = href.match("hgGene");
                     isHgc = href.match("hgc");
                 }
                 var id = selectedMenuItem.id;
                 var rec = trackDbJson[id];
+                var offerHideSet       = false;
+                var offerHideComposite = false;
+                var row = $( 'tr#tr_' + id );
+                if (row) {
+                    var btn = $(row).find('p.btnBlue');  // btnBlue means cursor over left button
+                    if (btn.length == 1) {
+                        var contiguousSet = imgTblContiguousRowSet(row);
+                        if (contiguousSet && contiguousSet.length > 1) {// There is a contiguous set
+                            offerHideSet = true;
+                            $( contiguousSet ).addClass("greenRows"); // green persists
+                        }
+                        var compositeSet = imgTblCompositeSet(row);
+                        if (compositeSet && compositeSet.length > 0) {  // There is a composite set
+                            offerHideComposite = true;
+                            $( compositeSet ).find('p.btn').addClass('blueButtons');  // blue persists
+                            if (contiguousSet && contiguousSet.length == compositeSet.length)
+                                offerHideSet = false; // no need to offer both
+                        }
+                    }
+                }
+
+                // First option is hide whole set
+                if (offerHideSet) {
+                    var o = new Object();
+                    o[blankImg + " hide highlighted (green) set"] = {onclick: makeContextMenuHitCallback('hideSet')};
+                    menu.push(o);
+                }
+                if (offerHideComposite) {
+                    var o = new Object();
+                    o[blankImg + " hide track (blue) set"] = {onclick: makeContextMenuHitCallback('hideComposite')};
+                    menu.push(o);
+                }
+                if (offerHideSet || offerHideComposite)
+                    menu.push($.contextMenu.separator);
+
                 // XXXX what if select is not available (b/c trackControlsOnMain is off)?
                 // Move functionality to a hidden variable?
                 var select = $("select[name=" + id + "]");
                 if (select.length > 1)  // Not really needed if $('#hgTrackUiDialog').html(""); has worked
                     select =  [ $(select)[0] ];
                 var cur = $(select).val();
                 if(cur) {
                     $(select).children().each(function(index, o) {
                                                var title = $(this).val();
                                                var str = blankImg + " " + title;
                                                if(title == cur)
                                                    str = selectedImg + " " + title;
                                                var o = new Object();
                                                o[str] = {onclick: function (menuItemClicked, menuObject) { contextMenuHit(menuItemClicked, menuObject, title); return true;}};
                                                menu.push(o);
@@ -2007,34 +2096,37 @@
             }
 
             // Add view image at end
             var o = new Object();
             o[makeImgTag("eye.png") + " View image"] = {onclick: function(menuItemClicked, menuObject) { contextMenuHit(menuItemClicked, menuObject, "viewImg"); return true; }};
             menu.push($.contextMenu.separator);
             menu.push(o);
 
             return menu;
         },
         {
             beforeShow: function(e) {
                 // console.log(mapItems[selectedMenuItem]);
                 selectedMenuItem = findMapItem(e);
                 // XXXX? blockUseMap = true;
+                return true;
             },
+            hideTransition:'hide', // hideCallback fails if these are not defined.
+            hideSpeed:10,
             hideCallback: function() {
-                // this doesn't work
-                warn("hideCallback");
+                $('p.btn.blueButtons').removeClass('blueButtons');
+                $('tr.trDraggable.greenRows').removeClass('greenRows');
             }
         });
     return;
 }
 
 function parseMap(ele, reset)
 {
 // Parse the jQuery <map> object into returned mapItems array (ele needn't be the element attached to current document).
         if(reset || !mapItems) {
             mapItems = new Array();
         }
         if(ele) {
                 var i = mapItems.length;
                 // src is necessary under msie
                 var src = ele.next().attr('src');