b4ac25c5138fbad826427cdade2bdd627dc10745
tdreszer
  Wed Sep 28 15:07:50 2011 -0700
A few nice bug catches due to walking through code in firebug.
diff --git src/hg/js/subCfg.js src/hg/js/subCfg.js
index c080de9..02a62e6 100644
--- src/hg/js/subCfg.js
+++ src/hg/js/subCfg.js
@@ -22,30 +22,31 @@
 // - SOLVED: filterBy,filterComp working: they rely upon a unique id, and id with '.' screwed it all up.  So replaced '.' with '_-'
 // - SOLVED: OpenChromSynth: subtrack filterby needs to be updated by composite filterBy.
 // - SOLVED: check subtrack to enable/disable fauxVis and wrench
 // - SOLVED: matCB should effect subCb including enable/disable fauxVis and wrench
 // - SOLVED: composite/view vis should effect subVis and enable/disable fauxVis and wrench
 // - SOLVED: inside out: changing subtrack vis should affect subCB and matCB
 // - SOLVED: Loosing checked tracks!!!  Setting vis clears checkboxes?
 // - TESTED: hui.c #ifdef SUBTRACK_CFG should switch full functionality on/off
 // - SOLVED: Make "disabled" subCB clickable!
 // - SOLVED: PROBLEM is fauxDisabled.  SOLUTION is convert fauxDisabled to true disabled on form.submit()
 // - DECIDED: When parent vis makes subs hidden, should they go to unchecked?   No, disabled!
 // - DECIDED: Should user be able to click on disabled vis to check the CB?  No, not important.
 // - DECIDED: Make vis changes "reshape" composite!  NOTE: Do we want to do this???   I am against this as too disruptive.  We may want to end reshaping in CGIs as well!
 // - DECIDED: Decide on a name (scm, subCfg, ? ) and then make a module file like ddcl.js.
 // - SOLVED: subtrack selected count is wrong!
+// - SOLVED: matCb unclick leaves vis/wrench enabled.  Vis/Wrench is usually only enabled for checked and visible.
 //  - Non-configurable will need to show/change vis independently! (separate vis control but no wrench)
 //  - Speed up massive composites!  HAIB TFBS SYDH TFBS
 //  - Verify all composites work (conservation and SNPs are likely failures)
 //  - Remove debug code when ready
 // NOTE:
 // Current implementation relies upon '.' delimiter in name and no '_-' in name.  Nothing breaks rule yet...
 
 var subCfg = { // subtrack config module.
     //mySelf: null, // There is no need for a "mySelf" unless this object is being instantiated.
 
     // There is one instance and these vars are page wide
     compositeName: undefined,
     visIndependent: false,
     viewTags: [],
 
@@ -352,55 +353,55 @@
                 return [];
             }
             return $(subVis).filter('.' + classList[0]);
         }
     },
 
     checkOneSubtrack: function (subCb,check,enable)
     { // Handle a single check of a single subCb
       // called by changing subVis to/from 'hide'
         subCb.checked = check;
         if (enable)
             fauxDisable(subCb,false,"");
         else
             fauxDisable(subCb,true, "View is hidden");
         subCfg.markChange(null,subCb);
-        subCfg.enableCfg(subCb,undefined,check);
+        subCfg.enableCfg(subCb,check);
         matSubCbClick(subCb); // needed to mark matCBs, shadow and show/hide
     },
 
     propagateSetting: function (parentObj)
     { // propagate composite/view level setting to subtrack children
         var children = subCfg.childrenFind(parentObj);
         if(parentObj.type === "checkbox") {
             var parentChecked = parentObj.checked;
             $(children).each(function (i) {
                 if (this.type != 'hidden')
                     this.checked = parentObj.checked;
                 subCfg.clearChange(this);
             });
         //} else if(parentObj.type.indexOf("radio") == 0) {
         } else if(parentObj.type === "radio") {
             var parentVal = $(parentObj).val();
             $(children).each(function (i) {
                 this.checked = ($(this).val() == parentVal);
                 subCfg.clearChange(this);
             });
         } else {// selects and inputs are easy
             var parentVal = $(parentObj).val();
-            var updateDdcl = ($(parentObj).hasClass('filterBy') || $(parentObj).hasClass('filterComp'));
-            $(children).each(function (i) {
+            var updateDdcl = ($(parentObj).hasClass('filterBy'));// || $(parentObj).hasClass('filterComp'));
+            $(children).each(function (i) {                      // Should never be filterComp
                 $(this).val(parentVal);
                 subCfg.clearChange(this);
                 if (updateDdcl)
                     ddcl.onComplete(this);
             });
         }
     },
 
     propagateViewVis: function (viewObj,compositeVis)
     { // propagate vis from a view limiting with compositeVis
         var limitedVis = Math.min(compositeVis,viewObj.selectedIndex);
         var visText = 'hide';
         if (limitedVis == 1)
             visText = 'dense';
         else if (limitedVis == 2)
@@ -601,35 +602,32 @@
         // Tricks to get this in the size and position I want
         $(cfg).css({ position: 'absolute'});
         var myWidth = $(cfg).width();
         var shiftLeft = -1;
         if (subCfg.visIndependent) {
             shiftLeft *= ($(cfg).position().left - 125);
             var subVis = normed($('div#' + subCfg.currentSub+'_faux'));
             if (subVis != undefined)
                 subCfg.replaceWithVis(subVis,subCfg.currentSub,false);
         }
         else
             shiftLeft *= ($(cfg).position().left - 40);
         $(cfg).css({ width: myWidth+'px',position: 'relative', left: shiftLeft + 'px' });
 
         // Setting up filterBys must follow show because sizing requires visibility
-        $(cfg).find('.filterBy,.filterComp').each( function(i) {
+        $(cfg).find('.filterBy').each( function(i) { // Should never be filterComp
             this.id = this.name.replace(/\./g,'_-'); // Must have id unique to page!
-            if ($(this).hasClass('filterComp'))
-                ddcl.setup(this);
-            else
                 ddcl.setup(this, 'noneIsAll');
         });
     },
 
     cfgPopulate: function (cfg,subtrack)
     { // Populates a subtrack cfg dialog via ajax and update from composite/view parents
         subCfg.currentCfg = cfg;
         subCfg.currentSub = subtrack;
 
         $.ajax({
             type: "GET",
             url: "../cgi-bin/hgTrackUi?ajax=1&g=" + subtrack + "&hgsid=" + getHgsid() + "&db=" + getDb(),
             dataType: "html",
             trueSuccess: subCfg.cfgFill,
             success: catchErrorOrDispatch,
@@ -679,44 +677,32 @@
                     //    so that the reverse action makes sense
                     var subCb = normed($("input[name='" + this.name + "_sel']"));
                     if (subCb != undefined) {
                         subCfg.checkOneSubtrack(subCb,false,true);
                         subCfg.inheritSetting(this,true);
                     } else {
                         warn('DEBUG: Cant find subCB for ' + this.name);
                     }
                 } else
                     subCfg.markChange(e,this);
             });
             $(newObj).focus();
         }
     },
 
-    enableCfg: function (subCb,subtrack,setTo)
+    enableCfg: function (subCb,setTo)
     { // Enables or disables subVis and wrench
-        if (subCb == undefined) {
-            if (subtrack == undefined || subtrack.length == 0) {
-                warn("DEBUG: subCfg.enableCfg() called without CB or subtrack.");
-                return false;
-            }
-            subCb = normed($("input[name='"+subtrack+"'_sel]"));
-            if (subCb == undefined) {
-                warn("DEBUG: subCfg.enableCfg() could not find CB for subtrack: "+subtrack);
-                return false;
-            }
-        }
-
         var td = normed($(subCb).parent('td'));
         if (td == undefined) {
             warn("DEBUG: subCfg.enableCfg() could not find TD for CB: "+subCb.name);
             return false;
         }
         var subFaux = normed($(td).find('div.subVisDD'));
         if (subFaux != undefined) {
             if (setTo == true)
                 $(subFaux).removeClass('disabled');
             else
                 $(subFaux).addClass('disabled');
         } else {
             var subVis = normed($(td).find('select.subVisDD'));
             if (subVis != undefined) {
                 $(subVis).attr('disabled',!setTo);
@@ -754,31 +740,31 @@
             if (isFauxDisabled(subCb,true))
                 return false;
 
             if(metadataIsVisible(subtrack))
                 metadataShowHide(subtrack,"","");
             if ($(cfg).hasClass('filled'))
                 $(cfg).show();
             else
                 waitOnFunction( subCfg.cfgPopulate, cfg, subtrack );
         } else
             $(cfg).hide();
         return false; // called by link!
     },
 
     viewInit: function (viewTag)
-    { // unnames all view controls
+    { // sets up view controls for propagation
         // iterate through all matching controls and unname
         var tr = normed($('tr#tr_cfg_'+viewTag));
         if (tr == undefined) {
             warn('DEBUG: Did not find view: ' + viewTag);
             return;
         }
         var viewObjs = $(tr).find('input,select');
         if (viewObjs.length > 0) {
             $(viewObjs).each(function (i) {
                 if (this.type != 'hidden') {
                     $(this).bind('change',function (e) {
                         subCfg.markChange(e,this);
                         subCfg.propagateSetting(this);
                     });
                 }
@@ -814,51 +800,54 @@
 
         subCfg.compositeName = $(compVis).attr('name');
         subCfg.visIndependent = ($('.subVisDD').length > 0);  // Can subtracks have their own vis?
 
         // Unname and set up vis propagation
         compVis = compVis[0];
         $(compVis).bind('change',function (e) {
             subCfg.markChange(e,compVis);
             subCfg.propagateVis(compVis,undefined);
         });
 
         // Find all appropriate controls and unname
 
         // SubCBs will get renamed and on change will name them back.
         var subCbs = $('input.subCB');
-        $(subCbs).change( subCfg.markChange );
+        $(subCbs).change( function (e) {
+            subCfg.enableCfg(this, (this.checked && !isFauxDisabled(this, true)));
+            subCfg.markChange(e,this);
+        });
 
         // iterate through views
         var viewVis = $('select.viewDD');
         $(viewVis).each(function (i) {
             var classList = $( this ).attr("class").split(" ");
             classList = aryRemove(classList,["viewDD","normalText","changed"]);
             if (classList.length == 0)
                 warn('DEBUG: View classlist is missing view class.');
             else if (classList.length > 1)
                 warn('DEBUG: View classlist contains unexpected classes:' + classList);
             else {
                 subCfg.viewTags[i] = classList[0];
                 subCfg.viewInit(subCfg.viewTags[i]);
             }
         });
 
         // Tricky for composite level controls.  Could wrap cfg controls in new div.
         // DO THIS AFTER Views
         // NOTE: excluding sortOrder and showCfg which are special cases we don't care about in subCfg
-        var compObjs = $('select,input').filter("[name^='"+subCfg.compositeName+"\\.'],[name^='"+subCfg.compositeName+"_']").not(".allOrOnly");
+        var compObjs = $('select,input').filter("[name^='"+subCfg.compositeName+"\\.'],[name^='"+subCfg.compositeName+"_']").not(".viewDD");
         if (compObjs.length > 0) {
             $(compObjs).each(function (i) {
                 if (this.type != 'hidden') {
                     // DEBUG -------------
                     if (this.id != undefined
                     && this.id.length > 0
                     && $(this).hasClass('filterBy') == false
                     && $(this).hasClass('filterComp') == false)
                         warn('DEBUG: Not expected control with name ['+this.name + '], and id #'+this.id);
                     // DEBUG -------------
 
                     $(this).change(function (e) {
                         subCfg.markChange(e,this);
                         subCfg.propagateSetting(this);
                     });