0ac0ed17e3a08872fba7ce6339733af157a56d92 tdreszer Mon Nov 21 14:08:32 2011 -0800 Fixed bug occurring on ddcl mdbVals that are beneath an added or removed line. diff --git src/hg/js/utils.js src/hg/js/utils.js index 6ac3d81..19f09fe 100644 --- src/hg/js/utils.js +++ src/hg/js/utils.js @@ -1861,53 +1861,45 @@ cmd: "hgt_mdbVal" + num, // NOTE must match METADATA_VALUE_PREFIX in hg/hgTracks/searchTracks.c num: num }); } // NOTE: with newJquery, the response is getting a new error (missing ; before statement) // There were also several XML parsing errors. // This error is fixed with the addition of "dataType: 'html'," above. }, handleNewMdbVals: function (response, status) { // Handle ajax response (repopulate a metadata val select) // This handles the currnet case when 2 vars have the same name (e.g. advanced, files tabs) var td = $('td#' + this.cmd ); if (td != undefined) { - var usesFilterBy = ($("select.mdbVar[name='hgt_mdbVar"+this.num+"']").hasClass('noMulti') == false); td.empty(); 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'))) { + } else if ($(inp).hasClass('wildList') || $(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) { ddcl.setup(this,'noneIsAll'); - } else { - $(this).attr("multiple",false); - $(this).removeClass('filterBy'); - $(this).show(); - } }); } findTracks.updateMdbHelp(this.num); }, mdbValChanged: function (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) findTracks.clearFound(); // 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]) { @@ -2139,122 +2131,130 @@ $(inp).appendTo('form#trackSearch'); $('form#trackSearch').attr('method','POST'); // Must be post to avoid url too long NOTE: probably needs to be post anyway } $('#searchSubmit').click(); return false; }, configSet: function (name) {// Called when configuring a composite or superTrack var thisForm = $('form#searchResults'); $(thisForm).attr('action',"../cgi-bin/hgTrackUi?hgt_tSearch=Search&g="+name); $(thisForm).find('input.viewBtn').click(); }, - mdbSelectPlusMinus: function (obj, rowNum) + mdbSelectPlusMinus: function (obj) { // 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! + var rowNum = objId.substring(objId.length - 1); + var val = $(obj).text(); + if (val == undefined || val.length == 0) + val = $(obj).val(); // Remove this when non-CSS buttons go away + if (val == '+') { + var buttons = $("#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]; var newTr = $(tr).clone(); var 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 ); element = $(newTr).find("select.mdbVar")[0]; if (element != undefined) $(element).attr('selectedIndex',-1); // chrome needs this after 'after' } }); if (table) findTracks.mdbSelectRowsNormalize(table); // magic is in this function return false; } } else { // == '-' - var buttons = $("input#minusButton"+rowNum); // Two tabs may have the exact same buttons! + var buttons = $("#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(); remaining = findTracks.mdbSelectRowsNormalize(table); // Must renormalize since 2nd of 3 rows may have been removed }); if (remaining > 0) { removeNum = remaining + 1; // Got to remove the cart vars, though it doesn't matter which as count must not be too many. setCartVars( [ "hgt_mdbVar"+removeNum, "hgt_mdbVal"+removeNum ], [ "[]","[]" ] ); } findTracks.clearFound(); // Changing values so abandon what has been found return false; } } return true; }, mdbSelectRowsNormalize: function (table) { // Called when [-][+] buttons changed the number of mdbSelects in findTracks\ // Will walk through each row and get the numberings of addressable elements correct. - //var table = $('table#'+tableId); if (table != undefined) { var mdbSelectRows = $(table).find('tr.mdbSelect'); var needMinus = (mdbSelectRows.length > 2); $(table).find('tr.mdbSelect').each( function (ix) { var rowNum = ix + 1; // Each [-][+] and mdb var=val pair of selects must be numbered // First the [-][+] buttons - var plusButton = $(this).find("input[value='+']")[0]; - if (plusButton != undefined) { + var plusButton = $(this).find("[id^='plusButton']")[0]; + if (plusButton != undefined) { // should always be a plus button + var oldNum = Number(plusButton.id.substring(plusButton.id.length - 1)); + if (oldNum == rowNum) + return; // that is continue with the next row + $(plusButton).attr('id',"plusButton"+rowNum); - // rebinding click appears to be not needed and screws up IE as well. - //$(plusButton).unbind('click') - //$(plusButton).click(function() { return findTracks.mdbSelectPlusMinus($(plusButton), rowNum); }); - var minusButton = $(this).find("input[value='-']")[0]; + var minusButton = $(this).find("[id^='minusButton']")[0]; if (needMinus) { if (minusButton == undefined) { - $(plusButton).before("<input type='button' id='minusButton"+rowNum+"' value='-' style='font-size:.7em;' title='delete this row' onclick='return findTracks.mdbSelectPlusMinus(this,"+rowNum+");'>"); - minusButton = $(this).find("input[value='-']")[0]; - } else { + if ($(plusButton).hasClass('pmButton')) + $(plusButton).before("<span class='pmButton' id='minusButton"+rowNum+"' title='delete this row' onclick='findTracks.mdbSelectPlusMinus(this);'>-</span>"); + else // Remove this else when non-CSS buttons go away + $(plusButton).before("<input type='button' id='minusButton"+rowNum+"' value='-' style='font-size:.7em;' title='delete this row' onclick='return findTracks.mdbSelectPlusMinus(this);'>"); + } else $(minusButton).attr('id',"minusButton"+rowNum); - $(minusButton).unbind('click'); - $(minusButton).click(function() { return findTracks.mdbSelectPlusMinus($(minusButton), rowNum); }); - } } else if (minusButton != undefined) $(minusButton).remove(); } + // Now the mdb var=val pair of selects - var element = $(this).find("select[name^='hgt_mdbVar']")[0]; + var element = $(this).find(".mdbVar")[0]; // select var if (element != undefined) $(element).attr('name','hgt_mdbVar' + rowNum); - element = $(this).find("select[name^='hgt_mdbVal']")[0]; - if (element != undefined) + element = $(this).find(".mdbVal")[0]; // select val + if (element != undefined) { // not there if new row $(element).attr('name','hgt_mdbVal' + rowNum); + if ($(element).hasClass('filterBy')) { + $(element).attr('id',''); // removing id ensures renumbering id + ddcl.reinit([ element ],true); + } + } // A couple more things element = $(this).find("td[id^='isLike']")[0]; if (element != undefined) $(element).attr('id','isLike' + rowNum); element = $(this).find("td[id^='hgt_mdbVal']")[0]; if (element != undefined) $(element).attr('id','hgt_mdbVal' + rowNum); }); return mdbSelectRows.length; } return 0; }, switchTabs: function (ui)