f059c823c500cb98784e9ab20ced74a2d0df3de7
tdreszer
  Wed Jan 11 14:03:48 2012 -0800
Adding an ectra column to subtrack list so that drag and drop works with subVis. 4665
diff --git src/hg/js/subCfg.js src/hg/js/subCfg.js
index f4ed693..8d5fddf 100644
--- src/hg/js/subCfg.js
+++ src/hg/js/subCfg.js
@@ -5,70 +5,41 @@
 // opened.  Composite and view level controls (parents) when updated override related
 // subtrack controls (children).  Subtrack controls, when updated overide parent controls
 // for the one subtrack.  Controls wil get class 'changed' added when changes are made.
 // When the form is submitted, all controls not marked as "changed" will be unnamed and will
 // therefore not make it into the cart.
 
 // Definitions as used here:
 // obj: an input or select style html control which may be marked as "changed"
 //   parentObj: composite or view level obj which has subtrack level childObjs associated
 //   childObj: subtrack level obj that has composite and or view level parentObjs
 // cfg: subtrack level embedded dialog which can be opened or closed (hidden) and isn't
 //      populated till first opened.  Can also be a viewCfg and maybe a compositeCfg
 // populate: act of filling a subtrack cfg with controls
 // fauxVis: fake control for subtrack visDD, which will be replaced with true vis when clicked.
 
-// TESTED:
-// OK  subCBs enable/disable subVis and subCfg
-// OK  subCBs set compVis to full
-// OK  subVis faux works
-// OK  subVis ajaxed on click
-// OK  subVis change is persistent (as seen in: hgTracks image, rightClick, return to hgTrackUi)
-// OK  subVis overridden by viewVis
-// OK  subVis overridden by compVis
-// -   subVis DOES NOT set compVis to full (when compVis set to hide, but subVis already populated) OK because this slips towords reshaping.
-// OK  subCfg wrench disabled
-// OK  subCfg wrench enable/disable by subCB
-// OK  subCfg wrench enable/disable by subVis
-// OK  subCfg populates (vias ajax) on click
-// OK  subCfg settings persist (as seen in hgTracks rightClick)
-// OK  subCfg open closes mdbArrow display
-// OK  subCfg closed by mdbArrow open
-// OK  subCfgs all closed on a table sort
-// OK  subCfg overridden by viewCfg
-//     STRANGE: clicking wrench to open does not leave viewCfg so viewCfg change isn't (yet) seen.
-// OK  subCfg overridden by compCfg
-// OK  matrix clicks enable/disable sub
-// OK  matrix clicks set compVis to full
-// OK  matrix [+][-] enable/disable subs
-// OK  matrix [+] set compVis to full
-// OK  viewVis changes set compVis to full
-// OK  subVis correct in hgTrackUi, hgTracks image, rightClick memnu, rightClick poCfg
-// OK  cart limited to minimum changed
-// -   sort of subtracks overides imgord - ONLY works if "priority" has changed!
-// OK  viewVis override fixed: viewSig:squish+sub:Full reshapes fine. viewSig->dense overrides all back to dense.
-
-// TODO:
-// - SOLVED: checkboxes: working with name = boolshad.{name}   FIXME: multishad?
+// Issues:
+// - SOLVED: checkboxes: working with name = boolshad.{name}   FIXME: multishad? [no problem currently]
 // - 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!  NO, I am against this as too disruptive.  We may want to end reshaping in CGIs as well!
-//  - Verify all composites work (hg19 hg18 mm9 mm8 panTro3 galGal3 braFlo1 dm3 ce10 homPan20 sacCer3 hg19Patch5 tested so far)
+// - Verified all composites work (hg19 hg18 mm9 mm8 panTro3 galGal3 braFlo1 dm3 ce10 homPan20 sacCer3 hg19Patch5 tested so far)
 //  - Speed up massive composites!  HAIB TFBS SYDH TFBS
-//  - Remove debug code when ready
+// - subVis DOES NOT set compVis to full (when compVis set to hide, but subVis already populated) OK because this slips towords reshaping.
 // NOTE:
 // Current implementation relies upon '.' delimiter in name and no '_-' in name.  Nothing breaks rule yet...
+// Can remove "DEBUG" messages when fully QA'd.  They are asserts.
 
 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: [],
 
     markChange: function (eventObj, obj)
     { // Marks a control as having been changed by the user.  Naming will send value to cart.
       // Note this is often called directly as the onchange event function
         if (obj == undefined || $.type(obj) === "string")
             obj = this;
         $(obj).addClass('changed');
@@ -566,31 +537,30 @@
         $(cfg).addClass('filled');
         var boxWithin = $(cfg).find('.blueBox');
         if (boxWithin.length > 1)
             $(boxWithin[1]).removeClass('blueBox');
 
         //$(cfg).html("<div style='font-size:.9em;'>" + cleanHtml + "</div>");
         var subObjs = $(cfg).find('input,select').filter("[name]");
         if (subObjs.length == 0) {
             warn('DEBUG: Did not find controls for cfg: ' + cfg.id);
             return;
         }
         $(subObjs).each(function (i) {
             if (this.name != undefined) { // The filter("[name]") above didn't do it!
                 if (this.type != 'hidden') {
                     subCfg.inheritSetting(this,false); // updates any values that have been changed on this page
-                    // if view vis do more than just name it on change
                     var suffix = subCfg.objSuffixGet(this);
                     if (suffix != undefined)
                         $(this).change( subCfg.markChange );
                     else
                         warn("DEBUG: couldn't find suffix for subtrack control: "+this.name);
                 }
             }
         });
         // 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 (subCfg.visIndependent) {
@@ -674,54 +644,54 @@
                         warn('DEBUG: Cant find subCB for ' + this.name);
                     }
                 } else {
                     subCfg.markChange(e,this);
                     // if just being made visible then composite to full?  NO (implications to other subs)
                     // Make view visible?  NO (subtrack override)
                     // reshape?  NO (much too complex)
                 }
             });
             $(newObj).focus();
         }
     },
 
     enableCfg: function (subCb,setTo)
     { // Enables or disables subVis and wrench
-        var td = normed($(subCb).parent('td'));
-        if (td == undefined) {
-            warn("DEBUG: subCfg.enableCfg() could not find TD for CB: "+subCb.name);
+        var tr = normed($(subCb).closest('tr'));
+        if (tr == undefined) {
+            warn("DEBUG: subCfg.enableCfg() could not find TR for CB: "+subCb.name);
             return false;
         }
-        var subFaux = normed($(td).find('div.subVisDD'));
+        var subFaux = normed($(tr).find('div.subVisDD'));
         if (subFaux != undefined) {
             if (setTo == true)
                 $(subFaux).removeClass('disabled');
             else
                 $(subFaux).addClass('disabled');
         } else {
-            var subVis = normed($(td).find('select.subVisDD'));
+            var subVis = normed($(tr).find('select.subVisDD'));
             if (subVis != undefined) {
                 $(subVis).attr('disabled',!setTo);
             }
         }
-        var wrench = normed($(td).find('span.clickable')); // TODO tighten this
+        var wrench = normed($(tr).find('span.clickable')); // TODO tighten this
         if (wrench != undefined) {
             if (setTo == true)
                 $(wrench).removeClass('disabled');
             else {
                 $(wrench).addClass('disabled');
-                var cfg = normed($(td).parent('tr').find('div.subCfg'));
+                var cfg = normed($(tr).find('div.subCfg'));
                 if (cfg != undefined)
                     $(cfg).hide();
             }
         }
     },
 
     cfgToggle: function (wrench,subtrack)
     { // Opens/closes subtrack cfg dialog, populating if empty
         var cfg = normed($("div#div_cfg_"+subtrack));
         if (cfg == undefined) {
             warn("DEBUG: Can't find div_cfg_"+subtrack);
             return false;
         }
 
         if ($(cfg).css('display') == 'none') {
@@ -740,88 +710,86 @@
                 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)
     { // 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;
         }
+        // iterate through all matching controls and setup for propgation and change flagging
         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);
                     });
                 }
             });
         }
 
         // Now vis control
         var viewVis = normed($("select.viewDD."+viewTag));
         if (viewVis == undefined) {
             warn('DEBUG: Did not find visibility control for view: ' + viewTag);
             return;
         }
         $(viewVis).bind('change',function (e) {
             subCfg.markChange(e,viewVis);
             subCfg.propagateVis(viewVis,viewTag);
         });
     },
 
     initialize: function ()
-    { // unnames all composite controls and then all view controls
-      // names will be added back in onchange events
-        // mySelf = this; // There is no need for a "mySelf" unless this object is being instantiated.
+    { // sets up all composite controls and then all view controls
+      // onchange gets set to mark controls as 'changed'.  Unchanged controls will
+      // be disabled on 'submit'.  Disabled controls will not get to the cart!
 
         var compVis = $('.visDD');
         if (compVis == undefined || compVis.length < 1) {
             warn('DEBUG: Did not find visibility control for composite.');
             return;
         }
         if (compVis.length > 1) {
             warn('DEBUG: Multiple visibility controls for composite???');
             return;
         }
 
         subCfg.compositeName = $(compVis).attr('name');
         subCfg.visIndependent = ($('.subVisDD').length > 0);  // Can subtracks have their own vis?
 
-        // Unname and set up vis propagation
+        // Set up vis propagation and change flagging
         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.
+        // SubCBs will may enable/diable vis/wrench and will be flagged on change
         var subCbs = $('input.subCB');
         $(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);
@@ -846,29 +814,28 @@
                         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);
                     });
                 }
             });
         }
 
         // Because of fauxDisabled subCBs, it is necessary to truly disable them before submitting.
         $("FORM").submit(function (i) {
             $('input.subCB.changed.disabled').attr('disabled',true);  // shadows will go to cart as they should
 
-            // Names will be removed for all controls that have not changed
+            // Unchanged controls will be disabled to avoid sending to the cart
             $('select,input').filter("[name]").not(".allOrOnly").not('.changed').each( function (i) {
                 if (this.type != 'hidden' || $(this).hasClass('trPos')
                 || $(this).hasClass('cbShadow') || $(this).hasClass('sortOrder')) {
                     // hiddens except priority and boolshad are all sent to the cart
                     // disable instead of unname because unname fills cart with a lot of garbage (Linux/FF)!
                     this.disabled = true;
                 }
             });
-            // to do: other hiddens?
         });
     }
 };