General Actions:
Log-in
Wiki:
CC09
▼
:
Document Index
»
Space:
Main
▼
:
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
Kenneth Latimer
on 2009/10/02 13:21
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: 2: 3: ## vars that can be sent: 4: ## sortBy = accessed, title, creator, rating, comments. default=accessed 5: ## accessedAfter = date default is earliest date. Any other value will cause only ojects added after date to display 6: ## sortDir = up, down. default=up 7: ## sortButtons = 0, 1 - 1 = allow sorting, 0 = don't allow sorting. default=1 8: ## rowsPerScreen = positive int. default=15. -1 (or any other neg number) means display all 9: ## navButtons = 0, 1 - 1 = show "next", "prev" navigation buttons, 0 = don't show. default=1 10: ## 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 11: ## addButton = 0,1 (false,true). Include a link to the add item form. default=1 12: 13: <link rel="stylesheet" type="text/css" href="/xwiki/resources/js/xwiki/table/table.css"> 14: <script type="text/javascript" src="/xwiki/resources/js/xwiki/table/tablefilterNsort.js"></script> 15: 16: #if(${request.navButtons}) 17: #set($navButtons = ${request.navButtons}) 18: #end 19: #if(${request.sortButtons}) 20: #set($sortButtons = ${request.sortButtons}) 21: #end 22: #if(${request.sortBy}) 23: #set($sortBy = ${request.sortBy}) 24: #end 25: #if(${request.sortDir}) 26: #set($sortDir = ${request.sortDir}) 27: #end 28: #if(${request.rowsPerScreen}) 29: #set($rowsPerScreen = ${request.rowsPerScreen}) 30: #end 31: #if(${request.displayCols}) 32: #set($displayCols = ${request.displayCols}) 33: #end 34: #if(${request.addButton}) 35: #set($addButton = ${request.addButton}) 36: #end 37: #if(${request.accessedAfter}) 38: #set($accessedAfter = ${request.addButton}) 39: #end 40: 41: #if(!$displayCols) 42: #set($displayCols = "TCDRM") 43: #else 44: #set($displayCols = $displayCols.toUpperCase()) 45: #end 46: 47: #if(!$navButtons) 48: #set($navButtons = 1) 49: #end 50: 51: #if(!$sortButtons) 52: #set($sortButtons = 1) 53: #end 54: 55: 56: #if(!$addButton) 57: #set($addButton = 1) 58: #end 59: 60: #if(!$sortBy) 61: #set($sortBy = "accessed") 62: #end 63: #if(!$sortDir) 64: #set($sortDir = "down") 65: ##NOTE: sortDir up means sortDir should be down. non-intuitive 66: #else 67: #if($sortDir.toLowerCase() == "down") 68: #set($sortDir = "up") 69: #else 70: #set($sortDir = "down") 71: #end 72: #end 73: 74: #set($numberOfRows = 0) 75: #if(!$rowsPerScreen) 76: #set($rowsPerScreen = 15) 77: #elseif($rowsPerScreen == 0) 78: #set($rowsPerScreen = 1) 79: #end 80: 81: 82: #if($addButton != 0) 83: [Click here to add items to the wiki>${doc.getSpace()}.BibliographyForm] 84: #end 85: 86: #set($bibClass = $xwiki.getClass("${doc.getSpace()}.BibliographyClass")) 87: #set($dateFormat = $bibClass.get("accessed").getPropertyClass().getDateFormat()) 88: #set($ratingsDoc = $xwiki.getDocument("XWiki.RatingStats")) 89: 90: 91: 92: #set ($sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='${doc.space}.BibliographyClass' and obj.name<>'${doc.space}.BibliographyClassTemplate'") 93: 94: 95: <table id="bibitems" class="grid sortable"> 96: <tbody> 97: <tr id="sortableItems" class="sortHeader"> 98: ##make sure same column isn't created twice 99: #set($titleCounter = false) 100: #set($creatorCounter = false) 101: #set($accessedCounter = false) 102: #set($ratingCounter = false) 103: #set($commentsCounter = false) 104: 105: #foreach($colType in $displayCols.toCharArray()) 106: #if($colType == "T" && !$titleCounter) 107: <th id="titleCol">$bibClass.get("title").getPrettyName()</th> 108: #set($titleCounter = true) 109: #elseif($colType == "C" && !$creatorCounter) 110: <th id="creatorCol">$bibClass.get("creator").getPrettyName()</th> 111: #set($creatorCounter = true) 112: #elseif($colType == "D" && !$accessedCounter) 113: <th id="accessedCol">$bibClass.get("accessed").getPrettyName()</th> 114: #set($accessedCounter = true) 115: #elseif($colType == "R" && !$ratingCounter) 116: <th id="ratingCol">Rating</th> 117: #set($ratingCounter = true) 118: #elseif($colType == "M" && !$commentsCounter) 119: <th id="commentsCol" width="40">Number of Comments</th> 120: #set($commentsCounter = true) 121: #end 122: #end 123: </tr> 124: 125: #foreach ($item in $xwiki.searchDocuments($sql)) 126: <tr> 127: #set($bibObj = $xwiki.getDocument($item).getObject("${doc.getSpace()}.BibliographyClass")) 128: #set($validEntry = true) 129: #if($accessedAfter) 130: #if($bibObj.getProperty("accessed").getValue().getTime() < $accessedAfter.getTime()) 131: #set($validEntry = false) 132: #end 133: #end 134: 135: #if($validEntry) 136: ##make sure same column isn't created twice 137: #set($titleCounter = false) 138: #set($creatorCounter = false) 139: #set($accessedCounter = false) 140: #set($ratingCounter = false) 141: #set($commentsCounter = false) 142: 143: #foreach($colType in $displayCols.toCharArray()) 144: #if($colType == "T" && !$titleCounter) 145: <td>[$bibObj.getProperty("title").getValue()>$item]</td> 146: #set($titleCounter = true) 147: #elseif($colType == "C" && !$creatorCounter) 148: <td>$xwiki.getUserName($bibObj.getProperty("creator").getValue())</td> 149: #set($creatorCounter = true) 150: #elseif($colType == "D" && !$accessedCounter) 151: <td>$xwiki.formatDate($bibObj.getProperty("accessed").getValue())</td> 152: #set($accessedCounter = true) 153: #elseif($colType == "R" && !$ratingCounter) 154: #if($ratingsDoc.getObject("XWiki.PerPageRatingsClass", "pagename", "$item")) 155: #set($ratings = $ratingsDoc.getObject("XWiki.PerPageRatingsClass", "pagename", "$item")) 156: #set($upcount = $ratings.upratings) 157: #set($downcount = $ratings.downratings) 158: #else 159: #set($upcount = 0) 160: #set($downcount = 0) 161: #end 162: <td> $upcount <img src="/bin/download/XWiki/Rater/Thumb%2Dup.png" alt="Thumb-up.png" title="Number of thumbs up"/> 163: <br/>$downcount <img src="/bin/download/XWiki/Rater/Thumb%2Ddown.png" alt="Thumb-down.png" title="Number of thumbs down"/> 164: </td> 165: #set($ratingCounter = true) 166: #elseif($colType == "M" && !$commentsCounter) 167: <td> 168: #set($numberOfComments = $xwiki.getDocument($item).getObjects("BBCode.PostClass").size()) 169: $numberOfComments 170: </td> 171: #set($commentsCounter = true) 172: #end 173: 174: #end 175: #end 176: </tr> 177: #set($numberOfRows = $numberOfRows + 1) 178: #end 179: </tbody> 180: </table> 181: 182: ##display all option 183: #if($rowsPerScreen < 0) 184: #set($rowsPerScreen = $numberOfRows) 185: #end 186: 187: #set($fixButtons = false) 188: #if($numberOfRows > $rowsPerScreen && $navButtons > 0) 189: <p> 190: <button id="bibitems_previous" onclick='navigateTable(0);return false;'>previous</button> 191: <button id="bibitems_next" onclick='navigateTable(1);return false;'>next</button> 192: <span id="bibitems_items_displayed"></span> 193: </p> 194: #set($fixButtons = true) 195: #end 196: 197: 198: 199: {pre} 200: <script type="text/javascript"> 201: //<![CDATA[ 202: //removeEvent(window, "load", init_sortnfilter); 203: window.removeEventListener("load", init_sortnfilter, false); 204: //image_path = "/xwiki/resources/"; 205: image_down = "/xwiki/resources/js/xwiki/table/img/arrow-down.gif"; 206: image_up = "/xwiki/resources/js/xwiki/table/img/arrow-up.gif"; 207: image_none = "/xwiki/resources/js/xwiki/table/img/arrow-none.gif"; 208: 209: init_sortnfilter(); 210: var currentRow = 0; 211: var sortButtons = $sortButtons; 212: fixTableNavigationButtons(); 213: 214: function navigateTable(dir) { 215: var table = document.getElementById("bibitems"); 216: 217: if(dir == 1) { 218: if(currentRow + $rowsPerScreen < $numberOfRows) { 219: currentRow += $rowsPerScreen; 220: } 221: } 222: else if(dir == 0) { 223: if(currentRow - $rowsPerScreen >= 0) { 224: currentRow -= $rowsPerScreen; 225: } 226: } 227: 228: var counter = 0; 229: for (var j=getHeaderRow(table)+1;j<table.rows.length;j++) { 230: if (!table.rows[j].className || (table.rows[j].className && (table.rows[j].className.indexOf('sortBottom') == -1))) { 231: if(counter >= currentRow + $rowsPerScreen || counter < currentRow) { 232: table.rows[j].style.display = 'none'; 233: } 234: else { 235: table.rows[j].style.display = ''; 236: } 237: counter++; 238: } 239: } 240: fixTableNavigationButtons(); 241: } 242: 243: function fixTableNavigationButtons() { 244: if($fixButtons) { 245: var prev_button = document.getElementById("bibitems_previous"); 246: var next_button = document.getElementById("bibitems_next"); 247: var itemsDisplayed = document.getElementById("bibitems_items_displayed"); 248: 249: next_button.disabled = (currentRow + $rowsPerScreen >= $numberOfRows); 250: prev_button.disabled = (currentRow - $rowsPerScreen < 0); 251: 252: var min=currentRow + 1; 253: var max=currentRow + $rowsPerScreen; 254: var total=$numberOfRows; 255: if(max > total) { 256: max = total; 257: } 258: if(max - min > 0) { 259: itemsDisplayed.innerHTML = "Displaying items " + min + " to " + max + " out of " + numberOfRows; 260: } 261: else if(max - min == 0) { 262: itemsDisplayed.innerHTML = "Displaying item " + min + " of " + numberOfRows; 263: } 264: else { 265: itemsDisplayed.innerHTML = "Error displaying items"; 266: } 267: } 268: } 269: 270: function ts_sort_rating(a,b) { 271: var aup = parseFloat(a.cells[SORT_COLUMN_INDEX].childNodes[0].nodeValue); 272: var bup = parseFloat(b.cells[SORT_COLUMN_INDEX].childNodes[0].nodeValue); 273: var adown = parseFloat(a.cells[SORT_COLUMN_INDEX].childNodes[4].nodeValue); 274: var bdown = parseFloat(b.cells[SORT_COLUMN_INDEX].childNodes[4].nodeValue); 275: var atotal = aup + adown; 276: var btotal = bup + bdown; 277: var aratio = 0.5; 278: var bratio = 0.5; 279: if(atotal > 0) { 280: aratio = aup / atotal; 281: } 282: if(btotal > 0) { 283: bratio = bup / btotal; 284: } 285: 286: var mult = 1; 287: var comp = 0; 288: 289: if(aratio == bratio) { 290: if(atotal > btotal) { 291: comp = 1; 292: } 293: else if(atotal == btotal) { 294: comp = 0; 295: } 296: else { 297: comp = -1; 298: } 299: } 300: else if(aratio > bratio) { 301: comp = 1; 302: } 303: else { 304: comp = -1; 305: } 306: 307: return (comp); 308: 309: } 310: 311: 312: 313: function ts_resortTable_New(lnk, ratingSort) { 314: // get the span 315: var span, ARROW; 316: for (var ci=0;ci<lnk.childNodes.length;ci++) { 317: if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci]; 318: } 319: var spantext = ts_getInnerText(span); 320: var td = lnk.parentNode; 321: var column = td.cellIndex; 322: var table = getParent(td,'TABLE'); 323: 324: // Work out a type for the column 325: if (table.rows.length <= 1) return; 326: var itm = ts_getInnerText(table.rows[getHeaderRow(table)+1].cells[column]); 327: var nextRow = getHeaderRow(table)+2; 328: // this loop will get the contents from the first line with actual content 329: while (!itm){ 330: itm = ts_getInnerText(table.rows[nextRow].cells[column]) ; 331: nextRow++ ; 332: } 333: // Ensures for sorting and evaluation purposes that itm is never undefined 334: if (!itm) { 335: itm = ''; 336: } 337: var sortfn = ts_sort_caseinsensitive; 338: if(ratingSort) { 339: sortfn = ts_sort_rating; 340: } 341: else { 342: if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date; 343: if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date; 344: if (itm.match(/^[�$�?��]/)) sortfn = ts_sort_currency; 345: if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric; 346: } 347: SORT_COLUMN_INDEX = column; 348: var firstRow = new Array(); 349: var newRows = new Array(); 350: 351: 352: SORT_COLUMN_INDEX = column; 353: var firstRow = new Array(); 354: var newRows = new Array(); 355: var nonSortedRows = new Array(); 356: // the new rows are added to the array to sort...get all rows from the "sortHeader" to the first sortBottom row. 357: var firstNonSortedRow = null != getSortBottomRow(table) ? (getSortBottomRow(table)+1) : table.rows.length ; 358: 359: for (var j=firstNonSortedRow;j<table.rows.length;j++) { 360: nonSortedRows[nonSortedRows.length] = table.rows[j]; 361: } 362: 363: for (var j=getHeaderRow(table)+1;j<table.rows.length;j++) { 364: newRows[newRows.length] = table.rows[j]; 365: } 366: newRows.sort(sortfn); 367: 368: if (span.getAttribute("sortdir") == 'down') { 369: ARROW = '<img border="0" src="'+ image_path + image_up + '" alt="↑"/>'; 370: newRows.reverse(); 371: span.setAttribute('sortdir','up'); 372: } else { 373: ARROW = '<img border="0" src="'+ image_path + image_down + '" alt="↓"/>'; 374: span.setAttribute('sortdir','down'); 375: } 376: 377: // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones 378: // don't do sortbottom rows 379: currentRow = 0; 380: for (var i=0; i<newRows.length; i++) { 381: if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortBottom') == -1))) { 382: table.tBodies[0].appendChild(newRows[i]); 383: if(i >= $rowsPerScreen) { 384: newRows[i].style.display = 'none'; 385: } 386: else { 387: newRows[i].style.display = ''; 388: } 389: } 390: } 391: // do sortBottom rows only 392: for (var i=0; i<newRows.length; i++) { 393: if (newRows[i].className && (newRows[i].className.indexOf('sortBottom') != -1)) 394: table.tBodies[0].appendChild(newRows[i]); 395: } 396: // ad the non sorted rows... 397: for (var i=0; i<nonSortedRows.length; i++) { 398: table.tBodies[0].appendChild(nonSortedRows[i]); 399: } 400: 401: // Delete any other arrows there may be showing 402: var allspans = document.getElementsByTagName("span"); 403: for (var ci=0;ci<allspans.length;ci++) { 404: if (allspans[ci].className == 'sortarrow') { 405: if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us? 406: allspans[ci].innerHTML = '<img border="0" src="'+ image_path + image_none + '" alt="↓"/>'; 407: } 408: } 409: } 410: 411: span.innerHTML = ARROW; 412: alternate(table); 413: 414: 415: fixTableNavigationButtons(); 416: } 417: 418: 419: 420: 421: var table = document.getElementById('bibitems'); 422: var row = getHeaderRow(table); 423: var headerRow = table.rows[getHeaderRow(table)]; 424: 425: for(var cc = 0; cc < headerRow.cells.length; cc++) { 426: var cell = headerRow.cells[cc]; 427: if(cell.childNodes[0] && cell.childNodes[0].tagName && cell.id && cell.id.toLowerCase() == 'ratingcol' && cell.childNodes[0].tagName.toLowerCase() == 'a') { 428: var txt = cell.childNodes[0].childNodes[0].nodeValue; 429: 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>'; 430: } 431: else { 432: var txt = cell.childNodes[0].childNodes[0].nodeValue; 433: 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>'; 434: } 435: 436: if(cell.childNodes[0] && cell.childNodes[0].tagName && cell.id && cell.id.toLowerCase() == '${sortBy}col' && cell.childNodes[0].tagName.toLowerCase() == 'a') { 437: ts_resortTable_New(cell.childNodes[0]); 438: } 439: } 440: 441: 442: //eliminate sorting function 443: if(sortButtons == 0) { 444: 445: for(var cc = 0; cc < headerRow.cells.length; cc++) { 446: var cell = headerRow.cells[cc]; 447: if(cell.childNodes[0] && cell.childNodes[0].tagName && cell.id && cell.id.toLowerCase() == '${sortBy}col' && cell.childNodes[0].tagName.toLowerCase() == 'a') { 448: var txt = cell.childNodes[0].childNodes[0].nodeValue; 449: var allspans = cell.childNodes[0].getElementsByTagName("span"); 450: var sortImage = image_up; 451: for (var ci=0;ci<allspans.length;ci++) { 452: if (allspans[ci].className == 'sortarrow') { 453: if(allspans[ci].sortdir == 'up') { 454: sortImage = image_up; 455: } 456: else { 457: sortImage = image_down; 458: } 459: } 460: } 461: 462: cell.innerHTML = txt+'<span sortdir="$sortDir" class="sortarrow"><img border="0" src="'+ image_path + sortImage + '" alt="↓"/></span>'; 463: } 464: else { 465: var txt = cell.childNodes[0].childNodes[0].nodeValue; 466: cell.innerHTML = txt+'<span sortdir="$sortDir" class="sortarrow"><img border="0" src="'+ image_path + image_none + '" alt="↓"/></span>'; 467: } 468: } 469: } 470: //]]> 471: </script> 472: {/pre} 473:
Quick Links
Wiki Dashboard
Document Index
Blog
Sandbox
My Recent Modifications
recentComments