b5d779a494312fe4b7741fc08f780a75815a80cb
tdreszer
  Thu Jul 28 09:23:37 2011 -0700
More subCfg work.  Need to check in to switch branches cleanly.
diff --git src/hg/js/hui.js src/hg/js/hui.js
index 1b7ed13..4b3906c 100644
--- src/hg/js/hui.js
+++ src/hg/js/hui.js
@@ -1140,30 +1140,33 @@
     //      populated till first opened.  Can also be a viewCfg and maybe a compositeCfg
     // populate: act of filling a subtrack cfg with controls
     // named: control with a name attribute which means it has been updated by the user.
     //        Unfortunately radio buttons are an exception, since they must keep their names.
     // unnamed: control that has not been updated by the user.  Will not be sent to cart.
 
     // TODO:
     // 1) outside in: matrix and subtrack checkboxes to affect vis
     // 2) Non-configurable will need to show/change vis independently! (separate vis control instead of wrench?)
     // 3) SOLVED: Radio buttons work BUT they require name to keep unified set, so rely upon 'changed' class to detect changes.
     // 4) SOLVED: checkboxes: working with name = boolshad.{name}   FIXME: multishad?
     // 5) SOLVED: filterBy,filterComp working: they rely upon id, and id with '.' screwed it all up.  So replaced '.' with '_-'
     // 6) SOLVED: subCfg not matching parent: solved.
     // 7) SOLVED: OpenChromSynth: subtrack filterby needs to be updated by composite filterBy.
     // 8) Remove debug code when ready
+    // - check subtrack to enable/disable fauxVis and wrench
+    // - matCB should effect subCb including enable/disable fauxVis and wrench
+    // - composite/view vis should effect subVis and enable/disable fauxVis and wrench
     // NOTE:
     // Current implementation relies upon '.' delimiter in name and no '_-' in name.  Nothing breaks rule yet...
 
     //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
     compositeId: null,
     visIndependent: false,
     viewIds: [],
 
     markChange: function (obj)
     { // Marks a control as having been changed by the user.  Naming will send value to cart.
         $(obj).addClass('changed');
         if(obj.type.indexOf("radio") != 0) {   // radios must keep their names!
             var oldName = obj.id.replace(/\_\-/g,'.');   // sanitized id replaces '.' with '_-'
@@ -1624,30 +1627,31 @@
                 });
             } else {// selects and inputs are easy
                 $(myParents).each(function (i) {
                     if (scm.hasChanged(this)) {
                         $(childObj).val($(this).val());
                         count++;
                     }
                 });
             }
             if (count > 1) // if hasChanged() is working, there should never be more than one
                 warn('Both composite and view are seen as updated!  Named update is not working.');
         }
     },
 
     currentCfg: null, // keep track of cfg while ajaxing, man
+    currentSub: null, // keep track of subtrack while ajaxing, dude
 
     cfgFill: function (content, status)
     { // Finishes the population of a subtrack cfg.  Called by ajax return.
         var cfg = scm.currentCfg;
         scm.currentCfg = null;
         var cleanHtml = content;
         var shlurpPattern=/\<script type=\'text\/javascript\' SRC\=\'.*\'\>\<\/script\>/gi;
         // DEBUG -------------
             var jsFiles = cleanHtml.match(shlurpPattern);
             if (jsFiles && jsFiles.length > 0)
                 alert("jsFiles:'"+jsFiles+"'\n---------------\n"+cleanHtml); // warn() interprets html, etc.
         // DEBUG -------------
         cleanHtml = cleanHtml.replace(shlurpPattern,"");
         shlurpPattern=/\<script type=\'text\/javascript\'>.*\<\/script\>/gi;
         // DEBUG -------------
@@ -1722,105 +1726,161 @@
                     }
                 } else {//if (this.type == 'hidden') {
                     // Special for checkboixes with name = boolshad.{name}.
                     if ("boolshad." == this.name.substring(0,9)) {
                         scm.unnameIt(this,true);
                     }
                 }
             }
         });
         // finally show
         $(cfg).show();
         // Tricks to get this in the size and position I want
         $(cfg).css({ position: 'absolute'});
         var myWidth = $(cfg).width();
         var shiftLeft = -1;
-        if (scm.visIndependent)
+        if (scm.visIndependent) {
             shiftLeft *= ($(cfg).position().left - 125);
+            var subVis = $('div#' + scm.currentSub+'_faux');
+            if (subVis != undefined && subVis.length == 1) {
+                // SHOULD NOT NEED $(subVis[0]).removeClass('disabled');
+                scm.replaceWithVis(subVis[0],scm.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
         if (newJQuery) {
             $(cfg).find('.filterBy,.filterComp').each( function(i) {
                 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
         scm.currentCfg = cfg;
+        scm.currentSub = subtrack;
 
         $.ajax({
             type: "GET",
             url: "../cgi-bin/hgTrackUi?ajax=1&g=" + subtrack + "&hgsid=" + getHgsid() + "&db=" + getDb(),
             dataType: "html",
             trueSuccess: scm.cfgFill,
             success: catchErrorOrDispatch,
             error: errorHandler,
             cmd: "cfg",
             cache: false
         });
     },
 
     replaceWithVis: function (obj,subtrack,open)
     { // Replaces the current fauxVis object with a true visibility selector
 
+        if ($(obj).hasClass('disabled'))
+            return;
         var selectHtml = "<SELECT id='"+subtrack+"' class='normalText subVisDD' style='width: 70px'>";
         var selected = $(obj).text();
         if (selected == 'hide')
             selectHtml += "<OPTION SELECTED>hide</OPTION><OPTION>dense</OPTION><OPTION>squish</OPTION><OPTION>pack</OPTION><OPTION>full</OPTION>";
         else if (selected == 'dense')
             selectHtml += "<OPTION>hide</OPTION><OPTION SELECTED>dense</OPTION><OPTION>squish</OPTION><OPTION>pack</OPTION><OPTION>full</OPTION>";
         else if (selected == 'squish')
             selectHtml += "<OPTION>hide</OPTION><OPTION>dense</OPTION><OPTION SELECTED>squish</OPTION><OPTION>pack</OPTION><OPTION>full</OPTION>";
         else if (selected == 'full')
             selectHtml += "<OPTION>hide</OPTION><OPTION>dense</OPTION><OPTION>squish</OPTION><OPTION>pack</OPTION><OPTION SELECTED>full</OPTION>";
         else
             selectHtml += "<OPTION>hide</OPTION><OPTION>dense</OPTION><OPTION>squish</OPTION><OPTION>pack</OPTION><OPTION>full</OPTION>";
         selectHtml += "</SELECT>";
         $(obj).replaceWith(selectHtml);
         if (open) {
             var newObj = $('select#'+subtrack);
             $(newObj).attr('size',5)
             $(newObj).one('blur',function (e) {
                 $(this).attr('size',1);
                 $(this).unbind()
             });
             $(newObj).one('change',function (e) {
                 $(this).attr('size',1);
             });
+            // Doesn't work!
+            //$(newObj).parents('td').first().attr('valign','top');
             $(newObj).focus();
         }
     },
 
-    cfgToggle: function (subtrack)
+    enableCfg: function (cb,subtrack,setTo)
+    { // Enables or disables subVis and wrench
+        if (cb == null || cb == undefined) {
+            if (subtrack == null || subtrack.length == 0) {
+                warn("scm.enableCfg() called without CB or subtrack.");
+                return false;
+            }
+            cb = $("input[name='"++"'_sel]");
+            if (cb == undefined || cb.length == 0) {
+                warn("scm.enableCfg() could not find CB for subtrack: "+subtrack);
+                return false;
+            }
+        }
+        if (cb.length == 1)
+            cb = cb[0];
+
+        var td = $(cb).parent('td');
+        if (td == undefined || td.length == 0) {
+            warn("scm.enableCfg() could not TD for CB: "+cb.name);
+            return false;
+        }
+        if (td.length == 1)
+            td = td[0];
+        var subFaux = $(td).find('div.subVisDD');
+        if (subFaux != undefined && subFaux.length > 0) {
+            if (setTo == true)
+                $(subFaux).removeClass('disabled');
+            else
+                $(subFaux).addClass('disabled');
+        } else {
+            var subVis = $(td).find('select.subVisDD');
+            if (subVis != undefined && subVis.length > 0) {
+                $(subVis).attr('disable',!setTo);
+            }
+        }
+        var wrench = $(td).find('span.clickable'); // TODO tighten this
+        if (wrench != undefined && wrench.length > 0) {
+            if (setTo == true)
+                $(wrench).removeClass('halfVis');
+            else
+                $(wrench).addClass('halfVis');
+        }
+    },
+    cfgToggle: function (wrench,subtrack)
     { // Opens/closes subtrack cfg dialog, populating if empty
         var cfg = $("div#div_cfg_"+subtrack);
         if (cfg == undefined || cfg.length == 0) {
             warn("Can't find div_cfg_"+subtrack);
             return false;
         }
         if (cfg.length == 1)
             cfg = cfg[0];
 
         if ($(cfg).css('display') == 'none') {
+            if ($(wrench).hasClass('halfVis'))
+                return;
             // Don't allow if this composite is not enabled!
             // find the cb
             var tr = $(cfg).parents('tr').first();
             var subCb = $(tr).find("input[name='"+subtrack+"_sel']");
             if (subCb == undefined || subCb.length == 0) {
                 warn("Can't find subCB for "+subtrack);
                 return false;
             }
             if (subCb.length == 1)
                 subCb = subCb[0];
             if (subCb.disabled == true) // || subCb.checked == false)
                 return false;
 
             if(metadataIsVisible(subtrack))
                 metadataShowHide(subtrack,"","");