General Actions:
Log-in
Wiki:
CreativeIT
▼
:
Document Index
»
Space:
CreativityAndCogntion
▼
:
Document Index
»
Page:
BibliographyOverview
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Overview of Items Added
Wiki source code of
Overview of Items Added
Last modified by
Holger Dick
on 2010/07/15 14:50
Content
·
Comments
(1)
·
Attachments
(0)
·
History
·
Information
Show line numbers
## vars that can be sent: ## sortBy = accessed, title, creator, rating, comments. default=accessed ## accessedAfter = date default is earliest date. Any other value will cause only ojects added after date to display ## sortDir = up, down. default=up ## sortButtons = 0, 1 - 1 = allow sorting, 0 = don't allow sorting. default=1 ## rowsPerScreen = positive int. default=15. -1 (or any other neg number) means display all ## navButtons = 0, 1 - 1 = show "next", "prev" navigation buttons, 0 = don't show. default=1 ## displayCols = Array List - Order and number of columns where X=T(title col), C(creator col), D(date created), R(rating), M(comments). default=TCDRM ## addButton = 0,1 (false,true). Include a link to the add item form. default=1 <link rel="stylesheet" type="text/css" href="/xwiki/resources/js/xwiki/table/table.css"> <script type="text/javascript" src="/xwiki/resources/js/xwiki/table/tablefilterNsort.js"></script> #if(${request.navButtons}) #set($navButtons = ${request.navButtons}) #end #if(${request.sortButtons}) #set($sortButtons = ${request.sortButtons}) #end #if(${request.sortBy}) #set($sortBy = ${request.sortBy}) #end #if(${request.sortDir}) #set($sortDir = ${request.sortDir}) #end #if(${request.rowsPerScreen}) #set($rowsPerScreen = ${request.rowsPerScreen}) #end #if(${request.displayCols}) #set($displayCols = ${request.displayCols}) #end #if(${request.addButton}) #set($addButton = ${request.addButton}) #end #if(${request.accessedAfter}) #set($accessedAfter = ${request.addButton}) #end #if(!$displayCols) #set($displayCols = "TCDRM") #else #set($displayCols = $displayCols.toUpperCase()) #end #if(!$navButtons) #set($navButtons = 1) #end #if(!$sortButtons) #set($sortButtons = 1) #end #if(!$addButton) #set($addButton = 1) #end #if(!$sortBy) #set($sortBy = "accessed") #end #if(!$sortDir) #set($sortDir = "down") ##NOTE: sortDir up means sortDir should be down. non-intuitive #else #if($sortDir.toLowerCase() == "down") #set($sortDir = "up") #else #set($sortDir = "down") #end #end #set($numberOfRows = 0) #if(!$rowsPerScreen) #set($rowsPerScreen = 15) #elseif($rowsPerScreen == 0) #set($rowsPerScreen = 1) #end #if($addButton != 0) [Click here to add items to the wiki>${doc.getSpace()}.BibliographyForm] #end #set($bibClass = $xwiki.getClass("${doc.getSpace()}.BibliographyClass")) #set($dateFormat = $bibClass.get("accessed").getPropertyClass().getDateFormat()) #set($ratingsDoc = $xwiki.getDocument("XWiki.RatingStats")) #set ($sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='${doc.space}.BibliographyClass' and obj.name<>'${doc.space}.BibliographyClassTemplate'") <table id="bibitems" class="grid sortable"> <tbody> <tr id="sortableItems" class="sortHeader"> ##make sure same column isn't created twice #set($titleCounter = false) #set($creatorCounter = false) #set($accessedCounter = false) #set($ratingCounter = false) #set($commentsCounter = false) #foreach($colType in $displayCols.toCharArray()) #if($colType == "T" && !$titleCounter) <th id="titleCol">$bibClass.get("title").getPrettyName()</th> #set($titleCounter = true) #elseif($colType == "C" && !$creatorCounter) <th id="creatorCol">$bibClass.get("creator").getPrettyName()</th> #set($creatorCounter = true) #elseif($colType == "D" && !$accessedCounter) <th id="accessedCol">$bibClass.get("accessed").getPrettyName()</th> #set($accessedCounter = true) #elseif($colType == "R" && !$ratingCounter) <th id="ratingCol">Rating</th> #set($ratingCounter = true) #elseif($colType == "M" && !$commentsCounter) <th id="commentsCol" width="40">Number of Comments</th> #set($commentsCounter = true) #end #end </tr> #foreach ($item in $xwiki.searchDocuments($sql)) <tr> #set($bibObj = $xwiki.getDocument($item).getObject("${doc.getSpace()}.BibliographyClass")) #set($validEntry = true) #if($accessedAfter) #if($bibObj.getProperty("accessed").getValue().getTime() < $accessedAfter.getTime()) #set($validEntry = false) #end #end #if($validEntry) ##make sure same column isn't created twice #set($titleCounter = false) #set($creatorCounter = false) #set($accessedCounter = false) #set($ratingCounter = false) #set($commentsCounter = false) #foreach($colType in $displayCols.toCharArray()) #if($colType == "T" && !$titleCounter) <td>[$bibObj.getProperty("title").getValue()>$item]</td> #set($titleCounter = true) #elseif($colType == "C" && !$creatorCounter) <td>$xwiki.getUserName($bibObj.getProperty("creator").getValue())</td> #set($creatorCounter = true) #elseif($colType == "D" && !$accessedCounter) <td>$xwiki.formatDate($bibObj.getProperty("accessed").getValue())</td> #set($accessedCounter = true) #elseif($colType == "R" && !$ratingCounter) #if($ratingsDoc.getObject("XWiki.PerPageRatingsClass", "pagename", "$item")) #set($ratings = $ratingsDoc.getObject("XWiki.PerPageRatingsClass", "pagename", "$item")) #set($upcount = $ratings.upratings) #set($downcount = $ratings.downratings) #else #set($upcount = 0) #set($downcount = 0) #end <td> $upcount <img src="/bin/download/XWiki/Rater/Thumb%2Dup.png" alt="Thumb-up.png" title="Number of thumbs up"/> <br/>$downcount <img src="/bin/download/XWiki/Rater/Thumb%2Ddown.png" alt="Thumb-down.png" title="Number of thumbs down"/> </td> #set($ratingCounter = true) #elseif($colType == "M" && !$commentsCounter) <td> #set($numberOfComments = $xwiki.getDocument($item).getObjects("BBCode.PostClass").size()) $numberOfComments </td> #set($commentsCounter = true) #end #end #end </tr> #set($numberOfRows = $numberOfRows + 1) #end </tbody> </table> ##display all option #if($rowsPerScreen < 0) #set($rowsPerScreen = $numberOfRows) #end #set($fixButtons = false) #if($numberOfRows > $rowsPerScreen && $navButtons > 0) <p> <button id="bibitems_previous" onclick='navigateTable(0);return false;'>previous</button> <button id="bibitems_next" onclick='navigateTable(1);return false;'>next</button> <span id="bibitems_items_displayed"></span> </p> #set($fixButtons = true) #end {pre} <script type="text/javascript"> //<![CDATA[ //removeEvent(window, "load", init_sortnfilter); window.removeEventListener("load", init_sortnfilter, false); //image_path = "/xwiki/resources/"; image_down = "/xwiki/resources/js/xwiki/table/img/arrow-down.gif"; image_up = "/xwiki/resources/js/xwiki/table/img/arrow-up.gif"; image_none = "/xwiki/resources/js/xwiki/table/img/arrow-none.gif"; init_sortnfilter(); var currentRow = 0; var sortButtons = $sortButtons; fixTableNavigationButtons(); function navigateTable(dir) { var table = document.getElementById("bibitems"); if(dir == 1) { if(currentRow + $rowsPerScreen < $numberOfRows) { currentRow += $rowsPerScreen; } } else if(dir == 0) { if(currentRow - $rowsPerScreen >= 0) { currentRow -= $rowsPerScreen; } } var counter = 0; for (var j=getHeaderRow(table)+1;j<table.rows.length;j++) { if (!table.rows[j].className || (table.rows[j].className && (table.rows[j].className.indexOf('sortBottom') == -1))) { if(counter >= currentRow + $rowsPerScreen || counter < currentRow) { table.rows[j].style.display = 'none'; } else { table.rows[j].style.display = ''; } counter++; } } fixTableNavigationButtons(); } function fixTableNavigationButtons() { if($fixButtons) { var prev_button = document.getElementById("bibitems_previous"); var next_button = document.getElementById("bibitems_next"); var itemsDisplayed = document.getElementById("bibitems_items_displayed"); next_button.disabled = (currentRow + $rowsPerScreen >= $numberOfRows); prev_button.disabled = (currentRow - $rowsPerScreen < 0); var min=currentRow + 1; var max=currentRow + $rowsPerScreen; var total=$numberOfRows; if(max > total) { max = total; } if(max - min > 0) { itemsDisplayed.innerHTML = "Displaying items " + min + " to " + max + " out of " + numberOfRows; } else if(max - min == 0) { itemsDisplayed.innerHTML = "Displaying item " + min + " of " + numberOfRows; } else { itemsDisplayed.innerHTML = "Error displaying items"; } } } function ts_sort_rating(a,b) { var aup = parseFloat(a.cells[SORT_COLUMN_INDEX].childNodes[0].nodeValue); var bup = parseFloat(b.cells[SORT_COLUMN_INDEX].childNodes[0].nodeValue); var adown = parseFloat(a.cells[SORT_COLUMN_INDEX].childNodes[4].nodeValue); var bdown = parseFloat(b.cells[SORT_COLUMN_INDEX].childNodes[4].nodeValue); var atotal = aup + adown; var btotal = bup + bdown; var aratio = 0.5; var bratio = 0.5; if(atotal > 0) { aratio = aup / atotal; } if(btotal > 0) { bratio = bup / btotal; } var mult = 1; var comp = 0; if(aratio == bratio) { if(atotal > btotal) { comp = 1; } else if(atotal == btotal) { comp = 0; } else { comp = -1; } } else if(aratio > bratio) { comp = 1; } else { comp = -1; } return (comp); } function ts_resortTable_New(lnk, ratingSort) { // get the span var span, ARROW; for (var ci=0;ci<lnk.childNodes.length;ci++) { if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci]; } var spantext = ts_getInnerText(span); var td = lnk.parentNode; var column = td.cellIndex; var table = getParent(td,'TABLE'); // Work out a type for the column if (table.rows.length <= 1) return; var itm = ts_getInnerText(table.rows[getHeaderRow(table)+1].cells[column]); var nextRow = getHeaderRow(table)+2; // this loop will get the contents from the first line with actual content while (!itm){ itm = ts_getInnerText(table.rows[nextRow].cells[column]) ; nextRow++ ; } // Ensures for sorting and evaluation purposes that itm is never undefined if (!itm) { itm = ''; } var sortfn = ts_sort_caseinsensitive; if(ratingSort) { sortfn = ts_sort_rating; } else { if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date; if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date; if (itm.match(/^[�$�?��]/)) sortfn = ts_sort_currency; if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric; } SORT_COLUMN_INDEX = column; var firstRow = new Array(); var newRows = new Array(); SORT_COLUMN_INDEX = column; var firstRow = new Array(); var newRows = new Array(); var nonSortedRows = new Array(); // the new rows are added to the array to sort...get all rows from the "sortHeader" to the first sortBottom row. var firstNonSortedRow = null != getSortBottomRow(table) ? (getSortBottomRow(table)+1) : table.rows.length ; for (var j=firstNonSortedRow;j<table.rows.length;j++) { nonSortedRows[nonSortedRows.length] = table.rows[j]; } for (var j=getHeaderRow(table)+1;j<table.rows.length;j++) { newRows[newRows.length] = table.rows[j]; } newRows.sort(sortfn); if (span.getAttribute("sortdir") == 'down') { ARROW = '<img border="0" src="'+ image_path + image_up + '" alt="↑"/>'; newRows.reverse(); span.setAttribute('sortdir','up'); } else { ARROW = '<img border="0" src="'+ image_path + image_down + '" alt="↓"/>'; span.setAttribute('sortdir','down'); } // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones // don't do sortbottom rows currentRow = 0; for (var i=0; i<newRows.length; i++) { if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortBottom') == -1))) { table.tBodies[0].appendChild(newRows[i]); if(i >= $rowsPerScreen) { newRows[i].style.display = 'none'; } else { newRows[i].style.display = ''; } } } // do sortBottom rows only for (var i=0; i<newRows.length; i++) { if (newRows[i].className && (newRows[i].className.indexOf('sortBottom') != -1)) table.tBodies[0].appendChild(newRows[i]); } // ad the non sorted rows... for (var i=0; i<nonSortedRows.length; i++) { table.tBodies[0].appendChild(nonSortedRows[i]); } // Delete any other arrows there may be showing var allspans = document.getElementsByTagName("span"); for (var ci=0;ci<allspans.length;ci++) { if (allspans[ci].className == 'sortarrow') { if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us? allspans[ci].innerHTML = '<img border="0" src="'+ image_path + image_none + '" alt="↓"/>'; } } } span.innerHTML = ARROW; alternate(table); fixTableNavigationButtons(); } var table = document.getElementById('bibitems'); var row = getHeaderRow(table); var headerRow = table.rows[getHeaderRow(table)]; for(var cc = 0; cc < headerRow.cells.length; cc++) { var cell = headerRow.cells[cc]; if(cell.childNodes[0] && cell.childNodes[0].tagName && cell.id && cell.id.toLowerCase() == 'ratingcol' && cell.childNodes[0].tagName.toLowerCase() == 'a') { var txt = cell.childNodes[0].childNodes[0].nodeValue; cell.innerHTML = '<a href="#" class="sortHeader" onclick="ts_resortTable_New(this, true);return false;">'+txt+'<span sortdir="$sortDir" class="sortarrow"><img border="0" src="'+ image_path + image_none + '" alt="↓"/></span></a>'; } else { var txt = cell.childNodes[0].childNodes[0].nodeValue; cell.innerHTML = '<a href="#" class="sortHeader" onclick="ts_resortTable_New(this);return false;">'+txt+'<span sortdir="$sortDir" class="sortarrow"><img border="0" src="'+ image_path + image_none + '" alt="↓"/></span></a>'; } if(cell.childNodes[0] && cell.childNodes[0].tagName && cell.id && cell.id.toLowerCase() == '${sortBy}col' && cell.childNodes[0].tagName.toLowerCase() == 'a') { ts_resortTable_New(cell.childNodes[0]); } } //eliminate sorting function if(sortButtons == 0) { for(var cc = 0; cc < headerRow.cells.length; cc++) { var cell = headerRow.cells[cc]; if(cell.childNodes[0] && cell.childNodes[0].tagName && cell.id && cell.id.toLowerCase() == '${sortBy}col' && cell.childNodes[0].tagName.toLowerCase() == 'a') { var txt = cell.childNodes[0].childNodes[0].nodeValue; var allspans = cell.childNodes[0].getElementsByTagName("span"); var sortImage = image_up; for (var ci=0;ci<allspans.length;ci++) { if (allspans[ci].className == 'sortarrow') { if(allspans[ci].sortdir == 'up') { sortImage = image_up; } else { sortImage = image_down; } } } cell.innerHTML = txt+'<span sortdir="$sortDir" class="sortarrow"><img border="0" src="'+ image_path + sortImage + '" alt="↓"/></span>'; } else { var txt = cell.childNodes[0].childNodes[0].nodeValue; cell.innerHTML = txt+'<span sortdir="$sortDir" class="sortarrow"><img border="0" src="'+ image_path + image_none + '" alt="↓"/></span>'; } } } //]]> </script> {/pre}
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey