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