18cb96eaa4c57791cf9df208edd326df2aafca5b tdreszer Thu Dec 16 14:55:35 2010 -0800 Move drag and drop registration to utils because this needs to be reregistered after a sort. diff --git src/hg/js/utils.js src/hg/js/utils.js index 0f8474d..20d154f 100644 --- src/hg/js/utils.js +++ src/hg/js/utils.js @@ -947,30 +947,51 @@ } function hideLoadingImage(id) { $('#' + id).remove(); } function codonColoringChanged(name) { // Updated disabled state of codonNumbering checkbox based on current value of track coloring select. var val = $("select[name='" + name + ".baseColorDrawOpt'] option:selected").text(); $("input[name='" + name + ".codonNumbering']").attr('disabled', val == "OFF"); } +//////////// Drag and Drop //////////// +function tableDragAndDropRegister(thisTable) +{// Initialize a table with tableWithDragAndDrop + if ($(thisTable).hasClass("tableWithDragAndDrop") == false) + return; + + $(thisTable).tableDnD({ + onDragClass: "trDrag", + dragHandle: "dragHandle", + onDrop: function(table, row, dragStartIndex) { + if(tableSetPositions) { + tableSetPositions(table); + } + } + }); + $(thisTable).find("td.dragHandle").hover( + function(){ $(this).closest('tr').addClass('trDrag'); }, + function(){ $(this).closest('tr').removeClass('trDrag'); } + ); +} + //////////// Sorting //////////// // Sorting a table by columns relies upon the sortColumns structure // The sortColumns structure looks like: //{ // char * tags[]; // a list of field names in sort order (e.g. 'cell', 'shortLabel') // boolean reverse[]; // the sort direction for each sort field // int cellIxs[]; // The indexes of the columns in the table to be sorted // boolean useAbbr[]; // Compare on Abbr or on innerHtml? //} // These 2 globals are used by setTimeout, so that rows can be hidden while sorting and javascript timeout is less likely var gSortColumns; var gTbody function sortField(value,index) @@ -1047,42 +1068,45 @@ for(var cIx=0;cIx<cols.length;cIx++) { $(tbody.rows[cIx]).replaceWith(cols[cIx].row); } gTbody=tbody; gSortColumns=sortColumns; setTimeout('tableSortFinish(gTbody,gSortColumns)',5); // Avoid javascript timeouts! } function tableSortFinish(tbody,sortColumns) {// Additional sort cleanup. // This is in a separate function to allow calling with setTimeout() which will prevent javascript timeouts (I hope) tableSetPositions(tbody); if ($(tbody).hasClass('altColors')) sortedTableAlternateColors(tbody,sortColumns); + $(tbody).parents("table.tableWithDragAndDrop").each(function (ix) { + tableDragAndDropRegister(this); + }); //$(tbody).show(); $(tbody).removeClass('sorting'); } function tableSortByColumns(tbody,sortColumns) {// Will sort the table based on the abbr values on a set of <TH> colIds // Expects tbody to not sort thead, but could take table //$(tbody).hide(); $(tbody).addClass('sorting'); gTbody=tbody; gSortColumns=sortColumns; - setTimeout('tableSort(gTbody,gSortColumns)',5); // This allows hiding the rows while sorting! + setTimeout('tableSort(gTbody,gSortColumns)',50); // This allows hiding the rows while sorting! } function trAlternateColors(tbody,rowGroup,cellIx) {// Will alternate colors for visible table rows. // If cellIx(s) provided then color changes when the column(s) abbr or els innerHtml changes // If no cellIx is provided then alternates on rowGroup (5= change color 5,10,15,...) // Expects tbody to not color thead, but could take table var darker = false; // == false will trigger first row to be change color = darker if (arguments.length<3) { // No columns to check so alternate on rowGroup if (rowGroup == undefined || rowGroup == 0) rowGroup = 1; var curCount = 0; // Always start with a change $(tbody).children('tr:visible').each( function(i) { @@ -1523,29 +1547,35 @@ //warn("Added class='sortable sort"+(ix+1)+"' to th:"+this.innerHTML); }); sortColumns = new sortColumnsGetFromTr(tr,"silent"); if (sortColumns == undefined || sortColumns.cellIxs.length == 0) { warn("sortable table's header row contains no sort columns."); return; } } // Can wrap all columnn headers with link $(tr).find("th.sortable").each(function (ix) { //if ( $(this).queue('click').length == 0 ) { if ( $(this).attr('onclick') == undefined ) { $(this).click( function () { tableSortOnButtonPress(this);} ); } if ( $(this).attr('title').length == 0) { - $(this).attr('title',"Sort list on '" + $(this).text() + "'." ); + var title = $(this).text().replace(/[^a-z0-9 ]/ig,''); + if (title.length > 0 && $(this).find('sup')) + title = title.replace(/[0-9]$/g,''); + if (title.length > 0) + $(this).attr('title',"Sort list on '" + title + "'." ); + else + $(this).attr('title',"Sort list on column." ); } }) // Now update all of those cells sortOrderUpdate(table,sortColumns,addSuperscript); // Alternate colors if requested if(altColors != undefined) sortedTableAlternateColors(tbody); // Finally, make visible $(tbody).show(); }