952399f2eae3acbca7dc79b7b311a0fe1e936d03
tdreszer
  Wed Sep 1 12:37:49 2010 -0700
Made getAllVars understand subtrack vis. Redid cfg popup OK with subtrack vis understanding in mind
diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js
index 05bc9e4..169fb10 100644
--- src/hg/js/hgTracks.js
+++ src/hg/js/hgTracks.js
@@ -1780,7 +1780,7 @@
             });
 }
 
-var popUpTrackName;
+var popUpTrackName = "";
 var popUpTrackDescriptionOnly = false;
 function _hgTrackUiPopUp(trackName,descriptionOnly)
 { // popup cfg dialog
@@ -1806,6 +1806,44 @@
     waitOnFunction( _hgTrackUiPopUp, trackName, descriptionOnly );  // Launches the popup but shields the ajax with a waitOnFunction
 }
 
+function hgTrackUiPopCfgOk(popObj, trackName)
+{ // When hgTrackUi Cfg popup closes with ok, then update cart and refresh parts of page
+    var rec = trackDbJson[trackName];
+    var subtrack = rec.isSubtrack ? trackName :"";  // If subtrack then vis rules differ
+
+    var allVars = getAllVars($('#pop'), subtrack );
+    var newVis = allVars[subtrack];
+    var hide = (newVis == null || newVis == 'hide' || newVis == '[]');  // subtracks do not have "hide"
+    if($('#imgTbl') == undefined) { // On findTracks or config page
+        setAllVars(popObj, subtrack );
+        //if(hide) // Need to set checkbox here
+    }
+    else {  // On image page
+        if(hide) {
+            setAllVars(popObj, subtrack );
+            $('#tr_' + trackName).remove();
+            initImgTblButtons();
+            loadImgAreaSelect(false);
+        } else {
+            // Keep local state in sync if user changed visibility
+            if(newVis != null) {
+                $("select[name=" + trackName + "]").each(function(t) {
+                    $(this).val(newVis);
+                });
+                if(rec) {
+                    rec.localVisibility = newVis;
+                }
+            }
+            var urlData = objectToQueryString(allVars);
+            if(mapIsUpdateable) {
+                updateTrackImg(trackName,urlData,"");
+            } else {
+                window.location = "../cgi-bin/hgTracks?" + urlData + "&hgsid=" + getHgsid();
+            }
+        }
+    }
+}
+
 function handleTrackUi(response, status)
 {
 // Take html from hgTrackUi and put it up as a modal dialog.
@@ -1824,50 +1862,14 @@
                                closeOnEscape: true,
                                autoOpen: false,
                                buttons: { "Ok": function() {
-                                    var hide = false; // need to handle special case of vis going to hide!
-                                    var vis = $('#pop').find('select[name="'+popUpTrackName+'"]');
-                                    if(vis != undefined)
-                                        hide = ($(vis).val() == 'hide');
-                                    if(popUpTrackDescriptionOnly == false) {
-                                        if($('#imgTbl') != undefined) {
-                                            if(hide) {
-                                                if(trackDbJson[popUpTrackName].parentTrack)
-                                                    setAllVars($('#pop'),popUpTrackName);
-                                                else
-                                                    setAllVars($('#pop'));
-                                                $('#tr_' + popUpTrackName).remove();
-                                                initImgTblButtons();
-                                                loadImgAreaSelect(false);
-                                            } else {
-                                                var o = getAllVars($('#pop'));
-                                                // Keep local state in sync if user changed visibility
-                                                var newVisibility = o[popUpTrackName];
-                                                if(newVisibility != null) {
-                                                    $("select[name=" + popUpTrackName + "]").each(function(t) {
-                                                        $(this).val(newVisibility);
-                                                    });
-                                                    var rec = trackDbJson[popUpTrackName];
-                                                    if(rec) {
-                                                        rec.localVisibility = newVisibility;
-                                            }
-                                                }
-                                                var urlData = objectToQueryString(o);
-                                                if(mapIsUpdateable) {
-                                                updateTrackImg(popUpTrackName,urlData,"");
-                                                } else {
-                                                    window.location = "../cgi-bin/hgTracks?" + urlData + "&hgsid=" + getHgsid();
-                                                }
-                                            }
-                                        } else {
-                                            setAllVars($('#pop'));
-                                            //if(hide) // Need to set checkbox here
-                                        }
-                                    }
+                                    if( ! popUpTrackDescriptionOnly )
+                                        hgTrackUiPopCfgOk($('#pop'), popUpTrackName);
                                     $(this).dialog("close");
                                }},
                                close: function() {
-                                   // clear out html after close to prevent problems caused by duplicate html elements
-                                   $('#hgTrackUiDialog').html("");
+                                   $('#hgTrackUiDialog').html("");  // clear out html after close to prevent problems caused by duplicate html elements
+                                popUpTrackName = ""; //set to defaults
+                                popUpTrackDescriptionOnly = false;
                                }
                            });
     if(popUpTrackDescriptionOnly) {