1a89c8e587e4cdbdb94430448caaa19247871cb8 tdreszer Thu Sep 22 13:01:11 2011 -0700 Big load of changes for subCfg. diff --git src/hg/js/utils.js src/hg/js/utils.js index a4ab8ce..fe86c46 100644 --- src/hg/js/utils.js +++ src/hg/js/utils.js @@ -96,30 +96,39 @@ // while checkbox id must have 'cb_' prefix (ie: 'tr_cb_checkThis' & 'cb_checkThis') var trs = $('table.subtracks').children('tbody').children('tr'); if(!onlySelected) $(trs).show(); else { $(trs).each(function (ix) { var subCB = $(this).find('input.subCB'); if (subCB.length > 0 && subCB[0].checked && subCB[0].disabled == false) $(this).show(); else $(this).hide(); }); } } +function normed(obj) +{ // returns undefined, the obj or the obj normalized from one member array + if (obj == undefined || obj == null || obj.length == 0) + return undefined; + if (obj.length == 1) + return obj[0]; + return obj; // (obj.length > 1) +} + function hideOrShowSubtrack(obj) { // This can show/hide a tablerow that contains a specific object // Containing <tr>'s must be id'd with 'tr_' + obj.id // Also, this relies upon the "displaySubtracks" radio button control var tr = $(obj).parents('tr#tr_'+obj.id); if (tr != undefined && tr.length == 1) { tr = tr[0]; if(!obj.checked || obj.disabled) { var radio = $('input.allOrOnly'); for (var ix=0;ix<radio.length;ix++) { if(radio[ix].checked && radio[ix].value == "selected") { $(tr).hide(); return; @@ -788,62 +797,92 @@ function startTiming() { var now = new Date(); return now.getTime(); } function showTiming(start,whatTookSoLong) { var now = new Date(); var end = (now.getTime() - start); warn(whatTookSoLong+" took "+end+" msecs."); return end; } function getHgsid() -{ -// return current session id - var hgsid; - var list = document.getElementsByName("hgsid"); - if(list.length) { - var ele = list[0]; - hgsid = ele.value; - } - if(!hgsid) { +{// return current session id + + // .first() because hgTracks turned up 3 of these! + var hgsid = normed($("input[name='hgsid']").first()); + if(hgsid != undefined) + return hgsid.value; + hgsid = getURLParam(window.location.href, "hgsid"); - } + if (hgsid.length > 0) return hgsid; + + // This may be moved to 1st position as the most likely source + if (typeof(common) !== "undefined" && common.hgsid !== undefined) + return common.hgsid; + + hgsid = normed($("input#hgsid").first()); + if(hgsid != undefined) + return hgsid.value; + + return ""; } function getDb() { - var db = document.getElementsByName("db"); - if(db == undefined || db.length == 0) - { - db = $("#db"); - if(db == undefined || db.length == 0) - return ""; // default? - } - return db[0].value; + var db = normed($("input[name='db']").first()); + if(db != undefined) + return db.value; + + db = getURLParam(window.location.href, "db"); + if (db.length > 0) + return db; + + // This may be moved to 1st position as the most likely source + if (typeof(common) !== "undefined" && common.db !== undefined) + return common.db; + + db = normed($("input#db").first()); + if(db != undefined) + return db.value; + + return ""; } function getTrack() { - var track = $("#track"); - if(track == undefined || track.length == 0) - return ""; // default? - return track[0].value; + var track = normed($("input[name='g']").first()); + if (track != undefined) + return track.value; + + track = getURLParam(window.location.href, "g"); + if (track.length > 0) + return track; + + // This may be moved to 1st position as the most likely source + if (typeof(common) !== "undefined" && common.track !== undefined) + return common.track; + + var track = normed($("input#g").first()); + if (track != undefined) + return track.value; + + return ""; } function Rectangle() { // Rectangle object constructor: // calling syntax: // // new Rectangle(startX, endX, startY, endY) // new Rectangle(coords) <-- coordinate string from an area item if(arguments.length == 4) { this.startX = arguments[0]; this.endX = arguments[1]; this.startY = arguments[2]; this.endY = arguments[3]; } else if(arguments.length > 0) { @@ -1833,64 +1872,58 @@ td.append(response); var inp = $(td).find('.mdbVal'); var tdIsLike = $('td#isLike'+this.num); if (inp != undefined && tdIsLike != undefined) { if ($(inp).hasClass('freeText')) { $(tdIsLike).text('contains'); } else if ($(inp).hasClass('wildList') || (usesFilterBy && $(inp).hasClass('filterBy'))) { $(tdIsLike).text('is among'); } else { $(tdIsLike).text('is'); } } $(td).find('.filterBy').each( function(i) { // Do this by 'each' to set noneIsAll individually if (usesFilterBy) { - if (newJQuery) ddcl.setup(this,'noneIsAll'); - else - $(this).dropdownchecklist({ firstItemChecksAll: true, noneIsAll: true, maxDropHeight: filterByMaxHeight(this) }); } else { $(this).attr("multiple",false); $(this).removeClass('filterBy'); $(this).show(); } }); } updateMetaDataHelpLinks(this.num); } function findTracksMdbValChanged(obj) { // Keep all tabs with same selects in sync TODO: Change from name to id based identification and only have one set of inputs in form // This handles the currnet case when 2 vars have the same name (e.g. advanced, files tabs) findTracksClearFound(); // Changing values so abandon what has been found if ($('#advancedTab').length == 1 && $('#filesTab').length == 1) { var newVal = $(obj).val(); var a = /hgt_mdbVal(\d+)/.exec(obj.name); // NOTE must match METADATA_NAME_PREFIX in hg/hgTracks/searchTracks.c if(newVal != undefined && a && a[1]) { var num = a[1]; $("input.mdbVal[name='hgt_mdbVal"+num+"'][value!='"+newVal+"']").val(newVal); $("select.mdbVal[name='hgt_mdbVal"+num+"'][value!='"+newVal+"']").each( function (i) { $(this).val(newVal); if ($(this).hasClass('filterBy')) { $(this).dropdownchecklist("destroy"); - if (newJQuery) ddcl.setup(this,'noneIsAll'); - else - $(this).dropdownchecklist({ firstItemChecksAll: true, noneIsAll: true, maxDropHeight: filterByMaxHeight(this) }); } }); } } //findTracksSearchButtonsEnable(true); } function findTracksChangeVis(seenVis) { // called by onchange of vis var visName = $(seenVis).attr('id'); var trackName = visName.substring(0,visName.length - "_id".length) var hiddenVis = $("input[name='"+trackName+"']"); var tdb = tdbGetJsonRecord(trackName); if($(seenVis).val() != "hide") $(hiddenVis).val($(seenVis).val()); @@ -2072,34 +2105,31 @@ // maxHeight = 500; // Seems to be solved by disbling DDCL's window.resize event for IE return maxHeight; } function findTracksClear() {// Clear found tracks and all input controls findTracksClearFound(); $('input[type="text"]').val(''); // This will always be found //$('select.mdbVar').attr('selectedIndex',0); // Do we want to set the first two to cell/antibody? $('select.mdbVal').attr('selectedIndex',0); // Should be 'Any' $('select.filterBy').each( function(i) { // Do this by 'each' to set noneIsAll individually //$(this).dropdownchecklist("refresh"); // requires v1.1 $(this).dropdownchecklist("destroy"); $(this).show(); - if (newJQuery) ddcl.setup(this,'noneIsAll'); - else - $(this).dropdownchecklist({ firstItemChecksAll: true, noneIsAll: true, maxDropHeight: filterByMaxHeight(this) }); }); $('select.groupSearch').attr('selectedIndex',0); $('select.typeSearch').attr('selectedIndex',0); //findTracksSearchButtonsEnable(false); return false; } function findTracksSortNow(obj) {// Called by radio button to sort tracks if( $('#sortIt').length == 0 ) $('form#trackSearch').append("<input TYPE=HIDDEN id='sortIt' name='"+$(obj).attr('name')+"' value='"+$(obj).val()+"'>"); else $('#sortIt').val($(obj).val()); @@ -2142,45 +2172,42 @@ function findTracksMdbSelectPlusMinus(obj, rowNum) { // Now [+][-] mdb var rows with javascript rather than cgi roundtrip // Will remove row or clone new one. Complication is that 'advanced' and 'files' tab duplicate the tables! var objId = $(obj).attr('id'); rowNum = objId.substring(objId.length - 1); if ($(obj).val() == '+') { var buttons = $("input#plusButton"+rowNum); // Two tabs may have the exact same buttons! if (buttons.length > 0) { var table = null; $(buttons).each(function (i) { var tr = $(this).parents('tr.mdbSelect')[0]; if (tr != undefined) { table = $(tr).parents('table')[0]; - if(newJQuery) { var newTr = $(tr).clone(); var element = $(newTr).find("select.mdbVar")[0]; if (element != undefined) $(element).attr('selectedIndex',-1); element = $(newTr).find("td[id^='hgt_mdbVal']")[0]; if (element != undefined) $(element).empty(); element = $(newTr).find("td[id^='isLike']")[0]; if (element != undefined) $(element).empty(); $(tr).after( newTr ); - } else - $(tr).after( $(tr).clone() ); } }); if (table) findTracksMdbSelectRowsNormalize(table); // magic is in this function return false; } } else { // == '-' var buttons = $("input#minusButton"+rowNum); // Two tabs may have the exact same buttons! if (buttons.length > 0) { var remaining = 0; $(buttons).each(function (i) { var tr = $(this).parents('tr')[0]; var table = $(tr).parents('table')[0]; if (tr != undefined) $(tr).remove();