8885686b3723a1a256cb1ff0677ca8a07927bed4 chmalee Thu Apr 4 13:24:20 2024 -0700 Make the hprc table stuff work in an hgc popup, make any javascript that would execute on document ready execute when the pop up is ready, refs #33216 diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js index 02ecf90..72896e0 100644 --- src/hg/js/hgTracks.js +++ src/hg/js/hgTracks.js @@ -3435,79 +3435,126 @@ error: errorHandler, loadingId: loadingId, cache: true }); }, hgc: function (table, url) { // Launches the popup but shields the ajax with a waitOnFunction if (typeof doHgcInPopUp !== 'undefined' && doHgcInPopUp === true) { waitOnFunction(popUpHgcOrHgGene._uiDialogRequest, table, url); } else { window.location = cart.addUpdatesToUrl(url); } }, - uiDialogOk: function (popObj) - { // When popup closes with ok + uiDialogOk: function (trackName) + { + // See popUp.uiDialogOk for a detailed explanation of the below vis-setting + // code + var rec = hgTracks.trackDb[trackName]; + var subtrack = tdbIsSubtrack(rec) ? trackName : undefined; // subtrack vis rules differ + var allVars = getAllVars($('#hgcDialog'), subtrack ); + var changedVars = varHashChanges(allVars,popUpHgcOrHgGene.saveAllVars); + // special case thses hprc tracks that allow you to turn on different tracks + if (trackName.startsWith("hprcDeletions") || trackName.startsWith("hprcInserts") || + trackName.startsWith("hprcArr") || trackName.startsWith("hprcDouble")) { + trackName = "chainHprc"; + } + var newVis = changedVars[trackName]; + // subtracks do not have "hide", thus '[]' + var hide = (newVis && (newVis === 'hide' || newVis === '[]')); + if ( ! normed($('#imgTbl')) ) { // On findTracks or config page + if (objNotEmpty(changedVars)) + cart.setVarsObj(changedVars); + } + else { // On image page + if (hide) { + if (objNotEmpty(changedVars)) + cart.setVarsObj(changedVars); + $(document.getElementById('tr_' + trackName)).remove(); + imageV2.afterImgChange(true); + cart.updateSessionPanel(); + } else { + // Keep local state in sync if user changed visibility + if (newVis) { + vis.update(trackName, newVis); + } + if (objNotEmpty(changedVars)) { + var urlData = cart.varsToUrlData(changedVars); + if (imageV2.mapIsUpdateable) { + imageV2.requestImgUpdate(trackName,urlData,"fake"); + } else { + window.location = "../cgi-bin/hgTracks?" + urlData + "&hgsid=" + getHgsid(); + } + } + } + } }, uiDialog: function (response, status) { // Take html from hgc/hgGene and put it up as a modal dialog. // make sure all links (e.g. help links) open up in a new window //response = response.replace(/"+ cleanHtml +""); appendNonceJsToPage(nonceJs); + // if there is anything on the hgc page that would normally run + // on document.ready, run it now + hgc.initPage(); + let subtrack = tdbIsSubtrack(hgTracks.trackDb[popUpHgcOrHgGene.table]) ? popUpHgcOrHgGene.table : ""; + popUpHgcOrHgGene.saveAllVars = getAllVars( $('#hgcDialog'), subtrack ); // Strategy for popups with js: // - jsFiles and CSS should not be included in html. Here they are shluped out. // - The resulting files ought to be loadable dynamically (with getScript()), // but this was not working nicely with the modal dialog // Therefore include files must be included with hgc CGI ! // - embedded js should not be in the popup box. // - Somethings should be in a popup.ready() function, and this is emulated below, // as soon as the cleanHtml is added // Since there are many possible popup cfg dialogs, the ready should be all inclusive. // -- popup.ready() -- Here is the place to do things that might otherwise go // into a $('#pop').ready() routine! // Searching for some semblance of size suitability var popMaxHeight = (window.innerHeight - (window.innerHeight * 0.15)); // make 15% of the bottom of the screen still visible var popMaxWidth = (window.innerWidth - (window.innerWidth * 0.1)); // take up 90% of the window // Create dialog buttons for UI popup - var uiDialogButtons = {}; // this could be more buttons later + var uiDialogButtons = {}; uiDialogButtons.OK = function() { + // if there was a form to submit, submit it: + popUpHgcOrHgGene.uiDialogOk(popUpHgcOrHgGene.table); $(this).dialog("close"); }; $('#hgcDialog').dialog({ resizable: true, // Let scroll vertically height: popMaxHeight, width: popMaxWidth, minHeight: 200, minWidth: 400, modal: true, closeOnEscape: true, autoOpen: false, buttons: uiDialogButtons, open: function (event) {