b56b616deec9a8b92b3abaf45b78e06d973a6517 max Mon Jan 13 10:24:56 2025 -0800 addressing various issues on the hgTrackUi config page that have to do with visibility interactions between composite parents and children, refs #4042 diff --git src/hg/js/subCfg.js src/hg/js/subCfg.js index 9682e54..1d6ab16 100644 --- src/hg/js/subCfg.js +++ src/hg/js/subCfg.js @@ -36,30 +36,42 @@ // There is one instance and these vars are page wide compositeName: undefined, canPack: true, // if composite vis is only hide,dense,full, then all children also restricted. 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 || $.type(obj) === "string") obj = this; $(obj).addClass('changed'); + // if the user checked a child checkbox that used to be unchecked, and the parent composite is on hide, + // then set the parent composite to pack + var compEl = $("[name='"+this.compositeName+"'"); + if (compEl.length!==0 && obj.type==="checkbox" && obj.checked && compEl.val()==="hide") + compEl.val("pack"); + + // if the user unchecked a child checkbox that used to be checked, and the parent composite is on pack, + // and no more child is checked, then set the parent composite to hide. + var subCfgs = $(".subCB:checked"); + if (subCfgs.length===0) + compEl.val("hide"); + // checkboxes have hidden boolshads which should be marked when unchecked if (obj.type === "checkbox") { var boolshad = normed($("input.cbShadow#boolshad\\."+obj.id)); if (boolshad) { $(boolshad).addClass('changed'); } else { boolshad = normed($("input.cbShadow[name='boolshad\\." + obj.name+"']")); if (boolshad) { $(boolshad).addClass('changed'); } } } }, clearChange: function (obj) @@ -431,38 +443,51 @@ } else { // No view so, simple var visText = 'hide'; if (parentVis === 1) visText = 'dense'; else if (parentVis === 2) { if (subCfg.canPack) visText = 'squish'; else visText = 'full'; } else if (parentVis === 3) visText = 'pack'; else if (parentVis === 4) visText = 'full'; var children = subCfg.visChildrenFind(parentObj); + + var checkedCount = 0; $(children).each(function (i) { + // the checkbox is in the right before the one of $(this) + if ($(this).parent().prev().find("[type='checkbox']")[0].checked) + checkedCount++; + + // apply the visibility to the subtrack if ($(this).hasClass('fauxInput')) { $(this).text(visText); } else { $(this).attr('selectedIndex',parentVis); subCfg.clearChange(this); } }); + + // when nothing is checked, the visibility has been applied but everything is still hidden. + // This is probably not what the user wanted, so in lack of a better idea, we select all checkboxes + if (checkedCount === 0) + // check all checkboxes + $(".subCB[type='checkbox']").prop("checked", true); } } else { // First get composite vis to limit with var compObj = subCfg.compositeObjFind(undefined); if (!compObj) { warn('DEBUG: Could not find composite vis object!'); return false; } subCfg.propagateViewVis(parentObj,compObj.selectedIndex); } }, inheritSetting: function (childObj,force) { // update value if parents values override child values. var myParents = subCfg.parentsFind(childObj);