...
Here’s where we start the script. We get going by finding the row in the report table where the Custom Reports live.
Code Block | ||
---|---|---|
| ||
// get references to the bits we want to twiddle var customReportsTable = jQuery("h3:contains('Custom Reports')").parent().parent(); var reportsToMove = jQuery("[id*='MGMT']"); |
...
Next up is to create our new column and “push” all the links that meet our criteria above into that new column. To match the existing formatting of the page we’ll also inject a line break after each report.
Code Block | ||
---|---|---|
| ||
// create a new column in the reports table to house the reports we're moving var newColumn = jQuery(" "); newColumn.append('<h3><img src="/boss/images/Custom Reports.gif"/> Management Reports</h3>'); // add each report to the new column reportsToMove.each(function(el){ newColumn.append(this); newColumn.append(jQuery("<br/>")); }); // add the column to the custom reports table customReportsRow.append(newColumn); |
...
Finally, the work we did above left some gaps in our custom report list.
Code Block | ||
---|---|---|
| ||
// remove the superflous BR elements customReportsRow.find('br').each(function(){ if(jQuery(this).next().is('br')){ jQuery(this).next().remove(); } if(jQuery(this).prev().is('h3')){ jQuery(this).remove(); } }); |
...
Here is the completed script:
Code Block | ||
---|---|---|
| ||
// get references to the bits we want to twiddle var customReportsTable = jQuery("h3:contains('Custom Reports')").parent().parent(); var reportsToMove = jQuery("[id*='MGMT']"); // create a new column in the reports table to house the reports we're moving var newColumn = jQuery(" "); newColumn.append('<h3><img src="/boss/images/Custom Reports.gif"/> Management Reports</h3>'); // add each report to the new column reportsToMove.each(function(el){ newColumn.append(this); newColumn.append(jQuery("<br/>")); }); // add the column to the custom reports table customReportsRow.append(newColumn); // remove the superflous BR elements customReportsRow.find('br').each(function(){ if(jQuery(this).next().is('br')){ jQuery(this).next().remove(); } if(jQuery(this).prev().is('h3')){ jQuery(this).remove(); } }); |