aba9ee18d932daaa659dc3298c0ea4db250fc704
tdreszer
  Tue Aug 24 15:47:41 2010 -0700
Added clear button and fixed bombing simple search, among other things
diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js
index 5b85e16..8f2efe1 100644
--- src/hg/js/hgTracks.js
+++ src/hg/js/hgTracks.js
@@ -1992,8 +1992,35 @@
     return true;
 }
 
-function metadataSelectChanged(obj)
+function remoteTrackCallback(rec)
+// jsonp callback to load a remote track.
 {
+    if(rec.error) {
+        alert("retrieval from remote site failed with error: " + rec.error)
+    } else {
+        var track = rec.track;
+        $('#img_data_' + track).attr('style', '');
+        $('#img_data_' + track).attr('height', rec.height);
+        $('#img_data_' + track).attr('width', rec.width);
+        $('#img_data_' + track).attr('src', rec.img);
+        $('#td_data_' + track + ' > div').each(function(index) {
+                                                   if(index == 1) {
+                                                       var style = $(this).attr('style');
+                                                       style = style.replace(/height:\s*\d+/i, "height:" + rec.height);
+                                                       $(this).attr('style', style);
+                                                   }
+                                               });
+        var style = $('#p_btn_' + track).attr('style');
+        style = style.replace(/height:\s*\d+/i, "height:" + rec.height);
+        $('#p_btn_' + track).attr('style', style);
+    }
+}
+
+/////////////////////////////////////////////////////
+// findTracks functions
+
+function findTracksMdbVarChanged(obj)
+{ // Ajax call to repopulate a metadata vals select when mdb var changes
     var newVar = $(obj).val();
     var a = /metadataName(\d+)/.exec(obj.name)
     if(newVar != undefined && a && a[1]) {
@@ -2002,16 +2029,17 @@
                    type: "GET",
                    url: "../cgi-bin/hgApi",
                    data: "db=" + getDb() +  "&cmd=metaDb&var=" + newVar,
-                   trueSuccess: handleNewMetadataVar,
+                   trueSuccess: findTracksHandleNewMdbVals,
                    success: catchErrorOrDispatch,
                    cache: true,
                    cmd: "hgt.metadataValue" + num
                });
     }
+    findTracksSearchButtonsEnable(false);
 }
 
-function handleNewMetadataVar(response, status)
-// Handle ajax response (repopulate a metadata select)
+function findTracksHandleNewMdbVals(response, status)
+// Handle ajax response (repopulate a metadata val select)
 {
     var list = eval(response);
     var ele = $('select[name=' + this.cmd + ']');
@@ -2031,41 +2059,14 @@
     }
 }
 
-function remoteTrackCallback(rec)
-// jsonp callback to load a remote track.
-{
-    if(rec.error) {
-        alert("retrieval from remote site failed with error: " + rec.error)
-    } else {
-        var track = rec.track;
-        $('#img_data_' + track).attr('style', '');
-        $('#img_data_' + track).attr('height', rec.height);
-        $('#img_data_' + track).attr('width', rec.width);
-        $('#img_data_' + track).attr('src', rec.img);
-        $('#td_data_' + track + ' > div').each(function(index) {
-                                                   if(index == 1) {
-                                                       var style = $(this).attr('style');
-                                                       style = style.replace(/height:\s*\d+/i, "height:" + rec.height);
-                                                       $(this).attr('style', style);
-                                                   }
-                                               });
-        var style = $('#p_btn_' + track).attr('style');
-        style = style.replace(/height:\s*\d+/i, "height:" + rec.height);
-        $('#p_btn_' + track).attr('style', style);
-    }
-}
-
 function changeSearchVisibilityPopups(cmd)
-{
+{  // ??? Larry?
     $("#searchResultsForm select").each(function(i) {
                                                                  $(this).val(cmd);
                                                              });
     return false;
 }
 
-/////////////////////////////////////////////////////
-// findTracks functions
-
 function findTracksChangeVis(seenVis)
 {
     var trackName = $(seenVis).attr('id');
@@ -2099,8 +2100,10 @@
     } else
         $(seenVis).attr('disabled', true );
 
-    if(justClicked) {
         // Deal with hiddenSel so that submit does the right thing
+    // Setting these requires justClicked OR seen vs. hidden to be different
+    var setHiddenInputs = (justClicked || (checked != ($(hiddenSel).val() == '1')));
+    if(setHiddenInputs) {
         if(subtrack) {
             $(hiddenSel).attr('disabled',false);
             if(checked)
@@ -2133,6 +2136,7 @@
 
 function findTracksNormalize()
 { // Normalize the page based upon current state of all found tracks
+    $('#foundTracks').show()
     var selCbs = $('input.selCb');
 
     // All should have their vis enabled/disabled appropriately (false means don't update cart)
@@ -2200,6 +2204,34 @@
     }
 }
 
+function findTracksSearchButtonsEnable(enable)
+{
+// Displays visible and checked track count
+    var searchButton = $('input[name="hgt_searchTracks"]');
+    var clearButton  = $('input.clear');
+    if(enable) {
+        $(searchButton).attr('disabled',false);
+        $(clearButton).attr('disabled',false);
+    } else {
+        $(searchButton).attr('disabled',true);
+        $(clearButton).attr('disabled',true);
+    }
+}
+
+function findTracksClear()
+{// Clear found tracks and all input controls
+    var foundTracks = $('#foundTracks');
+    if(foundTracks != undefined)
+        $(foundTracks).remove();
+    $('input[type="text"]').val(''); // This will always be found
+    //$('select.mdbVar').attr('selectedIndex',0); // Do we want to set the first two to cell/antibody?
+    $('select.mdbVal').attr('selectedIndex',0); // Should be 'Any'
+    $('select.groupSearch').attr('selectedIndex',0);
+    findTracksSearchButtonsEnable(false);
+    return false;
+}
+/////////////////////////////////////////////////////
+
 function delSearchSelect(obj, rowNum)
 {
     obj = $(obj);
