b51260d4c45fa3d35cecead29ac260c64904a316 tdreszer Fri May 2 15:20:38 2014 -0700 Updates to handle case when both vis changes AND chrom change occurs, making certain queued updates get sent along. Redmine 13164. diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js index 2ba14d1..1174e25 100644 --- src/hg/js/hgTracks.js +++ src/hg/js/hgTracks.js @@ -441,31 +441,31 @@ if ($(obj).hasClass('noLink')) // TITLE_BUT_NO_LINK return false; if (obj.href.match('#') || obj.target.length > 0) { //alert("Matched # ["+obj.href+"] or has target:"+obj.target); return true; } var thisForm=$(obj).parents('form'); if(thisForm == undefined || $(thisForm).length == 0) thisForm=$("FORM"); if($(thisForm).length > 1 ) thisForm=$(thisForm)[0]; if(thisForm != undefined && $(thisForm).length == 1) { //alert("posting form:"+$(thisForm).attr('name')); - var href = obj.href + vis.cartUpdatesGet(); + var href = vis.cartUpdatesAddToUrl(obj.href); return postTheForm($(thisForm).attr('name'),href); } return true; } } /////////////////////////////////////////////// //// visibility (mixed with group toggle) ///// /////////////////////////////////////////////// var vis = { enumOrder: new Array("hide", "dense", "full", "pack", "squish"), // map cgi enum visibility codes to strings cartUpdateQueue: {}, update: function (track, visibility) @@ -515,45 +515,55 @@ return setTableRowVisibility(button, prefix, "hgtgroup", "group",false,arguments[2]); else return setTableRowVisibility(button, prefix, "hgtgroup", "group",false); }, expandAllGroups: function (newState) { // Set visibility of all track groups to newState (true means expanded). // This code also modifies the corresponding hidden fields and the gif's of the +/- img tag. imageV2.markAsDirtyPage(); $(".toggleButton[id$='_button']").each( function (i) { // works for old img type AND new BUTTONS_BY_CSS vis.toggleForGroup(this,this.id.substring(0,this.id.length - 7),newState); // clip '_button' suffix }); return false; }, - cartUpdatesGet: function () - { // returns any outstanding cart updates as a string, and clears the queue + cartUpdatesWaiting: function () + { // returns TRUE if updates are waiting. + return (Object.keys(vis.cartUpdateQueue).length !== 0); + }, + + cartUpdatesAddToUrl: function (url) + { // adds any outstanding cart updates to the url, then clears the queue var updates = ""; for (var track in vis.cartUpdateQueue) { updates += "&" + track + "=" + vis.cartUpdateQueue[track]; } - + if (updates.length > 0) { + if(url.length > 0 && url.lastIndexOf("?") == -1 && url.lastIndexOf("&") == -1) + url += "?" + updates.substring(1); + else + url += updates + } vis.cartUpdateQueue = {}; - return updates; + return url; }, // NOTE: could update in background, however, failing to hit "refresh" is a user choice // cartUpdatesViaAjax: function () // { // Called via timer: updates the cart via setVars. - // if (Object.keys(vis.cartUpdateQueue).length === 0) + // if (!vis.cartUpdatesWaiting()) // return; // // var tracks = []; // var newVis = []; // for (var track in vis.cartUpdateQueue) { // tracks.push(track) // newVis.push(vis.cartUpdateQueue[track]); // } // if (tracks.length === 0) // return; // vis.cartUpdateQueue = {}; // setCartVars(tracks,newVis,async=false); // sync to avoid another race condition mess // }, cartUpdateAddToQueue: function (track,newVis) @@ -3245,32 +3255,33 @@ if(keepCurrentTrackVisible) { var item = rightClick.currentMapItem || imageV2.lastTrack; if(item) { var top = $(document.getElementById("tr_" + item.id)).position().top; if(top >= $(window).scrollTop() || top < $(window).scrollTop() + $(window).height()) { // don't bother if the item is not currently visible. currentId = item.id; currentIdYOffset = top - $(window).scrollTop(); } } } $.ajax({ type: "GET", url: "../cgi-bin/hgTracks", - data: params + "&hgt.trackImgOnly=1&hgt.ideogramToo=1&hgsid=" + - getHgsid() + vis.cartUpdatesGet(), + data: vis.cartUpdatesAddToUrl(params + + "&hgt.trackImgOnly=1&hgt.ideogramToo=1&hgsid=" + + getHgsid()), dataType: "html", trueSuccess: imageV2.updateImgAndMap, success: catchErrorOrDispatch, error: errorHandler, cmd: 'wholeImage', loadingId: showLoadingImage("imgTbl"), disabledEle: disabledEle, currentId: currentId, currentIdYOffset: currentIdYOffset, cache: false }); }, highlightRegion: function() // highlight vertical region in imgTbl based on hgTracks.highlight (#709). @@ -3359,30 +3370,39 @@ }); // TODO: move elsewhere? // With history support it is best that most position changes will ajax-update the image // This ensures that the 'go' and 'refresh' button will do so unless the chrom changes. $("input[value='go'],input[value='refresh']").click(function () { var newPos = genomePos.get().replace(/,/g,''); var newChrom = newPos.split(':')[0]; var oldChrom = genomePos.getOriginalPos().split(':')[0]; if (newChrom == oldChrom) { imageV2.markAsDirtyPage(); imageV2.navigateInPlace("position="+encodeURIComponent(newPos), null, false); window.scrollTo(0,0); return false; } + + // If chrom changed AND there are vis updates waiting... + if (vis.cartUpdatesWaiting()) { + var url = "hgTracks?db=" + getDb() + "&position=" + newPos + "&hgsid="+getHgsid(); + url = vis.cartUpdatesAddToUrl(url) + window.location.assign(url) + return false; + } + return true; }); // Have vis box changes update cart through ajax. This helps keep page/cart in sync. vis.initForAjax(); // We reach here from these possible paths: // A) Forward: Full page retrieval: hgTracks is first navigated to (or chrom change) // B) Back-button past a full retrieval (B in: ->A,->b,->c(full page),->d,<-c,<-B(again)) // B1) Dirty page: at least one non-position change (e.g. 1 track vis changed in b) // B2) Clean page: only position changes from A->b->| var curPos = encodeURIComponent(genomePos.get().replace(/,/g,'')); var cachedPos = imageV2.history.getState().data.position; // A) Forward: Full page retrieval: hgTracks is first navigated to (or chrom change) if (cachedPos == undefined) { // Not a back-button operation // set the current position into history outright (will replace). No img update needed