General Actions:
Log-in
Wiki:
CreativeIT
▼
:
Document Index
»
Space:
CreativityAndCogntion
▼
:
Document Index
»
Page:
BibliographyOverviewTest
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
BibliographyOverviewTest
Wiki source code of
BibliographyOverviewTest
Last modified by
Holger Dick
on 2009/07/22 13:21
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: 2: <link rel="stylesheet" type="text/css" href="/xwiki/resources/js/xwiki/table/table.css"> 3: <script type="text/javascript" src="/xwiki/resources/js/xwiki/table/tablefilterNsort.js"></script> 4: 5: #set($numberOfRows = 0) 6: #set($rowsPerScreen = 4) 7: 8: #set($bibClass = $xwiki.getClass("${doc.getSpace()}.BibliographyClass")) 9: #set($dateFormat = $bibClass.get("accessed").getPropertyClass().getDateFormat()) 10: #set($ratingsDoc = $xwiki.getDocument("XWiki.RatingStats")) 11: 12: 13: 14: #set ($sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='${doc.space}.BibliographyClass' and obj.name<>'${doc.space}.BibliographyClassTemplate'") 15: 16: 17: <table id="bibitems" class="grid sortable"> 18: <tbody> 19: <tr id="sortableItems" class="sortHeader"> 20: <th id="titleCol">$bibClass.get("title").getPrettyName()</th> 21: <th id="creatorCol">$bibClass.get("creator").getPrettyName()</th> 22: <th id="accessedCol">$bibClass.get("accessed").getPrettyName()</th> 23: <th id="ratingCol">Rating</th> 24: </tr> 25: 26: #foreach ($item in $xwiki.searchDocuments($sql)) 27: <tr> 28: #set($bibObj = $xwiki.getDocument($item).getObject("${doc.getSpace()}.BibliographyClass")) 29: <td>[$bibObj.getProperty("title").getValue()>$item]</td> 30: #set($docthing = $xwiki.getDocument($item)) 31: <td>$xwiki.getUserName($bibObj.getProperty("creator").getValue())</td> 32: <td>$xwiki.formatDate($bibObj.getProperty("accessed").getValue())</td> 33: #if($ratingsDoc.getObject("XWiki.PerPageRatingsClass", "pagename", "$item")) 34: #set($ratings = $ratingsDoc.getObject("XWiki.PerPageRatingsClass", "pagename", "$item")) 35: #set($upcount = $ratings.upratings) 36: #set($downcount = $ratings.downratings) 37: #else 38: #set($upcount = 0) 39: #set($downcount = 0) 40: #end 41: <td> $upcount <img src="/bin/download/XWiki/Rater/Thumb%2Dup.png" alt="Thumb-up.png" title="Number of thumbs up"/> 42: <br/>$downcount <img src="/bin/download/XWiki/Rater/Thumb%2Ddown.png" alt="Thumb-down.png" title="Number of thumbs down"/> 43: </td> 44: </tr> 45: #set($numberOfRows = $numberOfRows + 1) 46: #end 47: </tbody> 48: </table> 49: 50: #set($fixButtons = false) 51: #if($numberOfRows > $rowsPerScreen) 52: <p> 53: <button id="bibitems_previous" onclick='navigateTable(0);return false;'>previous</button> 54: <button id="bibitems_next" onclick='navigateTable(1);return false;'>next</button> 55: <span id="bibitems_items_displayed"></span> 56: </p> 57: #set($fixButtons = true) 58: #end 59: 60: 61: 62: {pre} 63: <script type="text/javascript"> 64: //<![CDATA[ 65: //removeEvent(window, "load", init_sortnfilter); 66: window.removeEventListener("load", init_sortnfilter, false); 67: //image_path = "/xwiki/resources/"; 68: image_down = "/xwiki/resources/js/xwiki/table/img/arrow-down.gif"; 69: image_up = "/xwiki/resources/js/xwiki/table/img/arrow-up.gif"; 70: image_none = "/xwiki/resources/js/xwiki/table/img/arrow-none.gif"; 71: 72: init_sortnfilter(); 73: var currentRow = 0; 74: var numberOfRows = $numberOfRows; 75: var rowsPerScreen = $rowsPerScreen; 76: var fixButtons = $fixButtons; 77: fixTableNavigationButtons(); 78: 79: function navigateTable(dir) { 80: var table = document.getElementById("bibitems"); 81: 82: if(dir == 1) { 83: if(currentRow + rowsPerScreen < numberOfRows) { 84: currentRow += rowsPerScreen; 85: } 86: } 87: else if(dir == 0) { 88: if(currentRow - rowsPerScreen >= 0) { 89: currentRow -= rowsPerScreen; 90: } 91: } 92: 93: var counter = 0; 94: for (var j=getHeaderRow(table)+1;j<table.rows.length;j++) { 95: if (!table.rows[j].className || (table.rows[j].className && (table.rows[j].className.indexOf('sortBottom') == -1))) { 96: if(counter >= currentRow + rowsPerScreen || counter < currentRow) { 97: table.rows[j].style.display = 'none'; 98: } 99: else { 100: table.rows[j].style.display = ''; 101: } 102: counter++; 103: } 104: } 105: fixTableNavigationButtons(); 106: } 107: 108: function fixTableNavigationButtons() { 109: if(fixButtons) { 110: var prev_button = document.getElementById("bibitems_previous"); 111: var next_button = document.getElementById("bibitems_next"); 112: var itemsDisplayed = document.getElementById("bibitems_items_displayed"); 113: 114: next_button.disabled = (currentRow + rowsPerScreen >= numberOfRows); 115: prev_button.disabled = (currentRow - rowsPerScreen < 0); 116: 117: var min=currentRow + 1; 118: var max=currentRow + rowsPerScreen; 119: if(max > numberOfRows) { 120: max = numberOfRows; 121: } 122: if(max - min > 0) { 123: itemsDisplayed.innerHTML = "Displaying items " + min + " to " + max + " out of " + numberOfRows; 124: } 125: else if(max - min == 0) { 126: itemsDisplayed.innerHTML = "Displaying item " + min + " of " + numberOfRows; 127: } 128: else { 129: itemsDisplayed.innerHTML = "Error displaying items"; 130: } 131: } 132: } 133: 134: function ts_sort_rating(a,b) { 135: var aup = parseFloat(a.cells[SORT_COLUMN_INDEX].childNodes[0].nodeValue); 136: var bup = parseFloat(b.cells[SORT_COLUMN_INDEX].childNodes[0].nodeValue); 137: var adown = parseFloat(a.cells[SORT_COLUMN_INDEX].childNodes[4].nodeValue); 138: var bdown = parseFloat(b.cells[SORT_COLUMN_INDEX].childNodes[4].nodeValue); 139: var atotal = aup + adown; 140: var btotal = bup + bdown; 141: var aratio = 0.5; 142: var bratio = 0.5; 143: if(atotal > 0) { 144: aratio = aup / atotal; 145: } 146: if(btotal > 0) { 147: bratio = bup / btotal; 148: } 149: 150: var mult = 1; 151: var comp = 0; 152: 153: if(aratio == bratio) { 154: if(atotal > btotal) { 155: comp = 1; 156: } 157: else if(atotal == btotal) { 158: comp = 0; 159: } 160: else { 161: comp = -1; 162: } 163: } 164: else if(aratio > bratio) { 165: comp = 1; 166: } 167: else { 168: comp = -1; 169: } 170: 171: return (comp); 172: 173: } 174: 175: 176: 177: function ts_resortTable_New(lnk, ratingSort) { 178: // get the span 179: var span, ARROW; 180: for (var ci=0;ci<lnk.childNodes.length;ci++) { 181: if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci]; 182: } 183: var spantext = ts_getInnerText(span); 184: var td = lnk.parentNode; 185: var column = td.cellIndex; 186: var table = getParent(td,'TABLE'); 187: 188: // Work out a type for the column 189: if (table.rows.length <= 1) return; 190: var itm = ts_getInnerText(table.rows[getHeaderRow(table)+1].cells[column]); 191: var nextRow = getHeaderRow(table)+2; 192: // this loop will get the contents from the first line with actual content 193: while (!itm){ 194: itm = ts_getInnerText(table.rows[nextRow].cells[column]) ; 195: nextRow++ ; 196: } 197: // Ensures for sorting and evaluation purposes that itm is never undefined 198: if (!itm) { 199: itm = ''; 200: } 201: var sortfn = ts_sort_caseinsensitive; 202: if(ratingSort) { 203: sortfn = ts_sort_rating; 204: } 205: else { 206: if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date; 207: if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date; 208: if (itm.match(/^[�$�?��]/)) sortfn = ts_sort_currency; 209: if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric; 210: } 211: SORT_COLUMN_INDEX = column; 212: var firstRow = new Array(); 213: var newRows = new Array(); 214: 215: 216: SORT_COLUMN_INDEX = column; 217: var firstRow = new Array(); 218: var newRows = new Array(); 219: var nonSortedRows = new Array(); 220: // the new rows are added to the array to sort...get all rows from the "sortHeader" to the first sortBottom row. 221: var firstNonSortedRow = null != getSortBottomRow(table) ? (getSortBottomRow(table)+1) : table.rows.length ; 222: 223: for (var j=firstNonSortedRow;j<table.rows.length;j++) { 224: nonSortedRows[nonSortedRows.length] = table.rows[j]; 225: } 226: 227: for (var j=getHeaderRow(table)+1;j<table.rows.length;j++) { 228: newRows[newRows.length] = table.rows[j]; 229: } 230: newRows.sort(sortfn); 231: 232: if (span.getAttribute("sortdir") == 'down') { 233: ARROW = '<img border="0" src="'+ image_path + image_up + '" alt="↑"/>'; 234: newRows.reverse(); 235: span.setAttribute('sortdir','up'); 236: } else { 237: ARROW = '<img border="0" src="'+ image_path + image_down + '" alt="↓"/>'; 238: span.setAttribute('sortdir','down'); 239: } 240: 241: // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones 242: // don't do sortbottom rows 243: currentRow = 0; 244: for (var i=0; i<newRows.length; i++) { 245: if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortBottom') == -1))) { 246: table.tBodies[0].appendChild(newRows[i]); 247: if(i >= rowsPerScreen) { 248: newRows[i].style.display = 'none'; 249: } 250: else { 251: newRows[i].style.display = ''; 252: } 253: } 254: } 255: // do sortBottom rows only 256: for (var i=0; i<newRows.length; i++) { 257: if (newRows[i].className && (newRows[i].className.indexOf('sortBottom') != -1)) 258: table.tBodies[0].appendChild(newRows[i]); 259: } 260: // ad the non sorted rows... 261: for (var i=0; i<nonSortedRows.length; i++) { 262: table.tBodies[0].appendChild(nonSortedRows[i]); 263: } 264: 265: // Delete any other arrows there may be showing 266: var allspans = document.getElementsByTagName("span"); 267: for (var ci=0;ci<allspans.length;ci++) { 268: if (allspans[ci].className == 'sortarrow') { 269: if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us? 270: allspans[ci].innerHTML = '<img border="0" src="'+ image_path + image_none + '" alt="↓"/>'; 271: } 272: } 273: } 274: 275: span.innerHTML = ARROW; 276: alternate(table); 277: 278: 279: fixTableNavigationButtons(); 280: } 281: 282: 283: 284: 285: var table = document.getElementById('bibitems'); 286: var row = getHeaderRow(table); 287: var headerRow = table.rows[getHeaderRow(table)]; 288: 289: for(var cc = 0; cc < headerRow.cells.length; cc++) { 290: var cell = headerRow.cells[cc]; 291: if(cell.childNodes[0] && cell.childNodes[0].tagName && cell.id && cell.id.toLowerCase() == 'accessedcol' && cell.childNodes[0].tagName.toLowerCase() == 'a') { 292: var txt = cell.childNodes[0].childNodes[0].nodeValue; 293: cell.innerHTML = '<a href="#" class="sortHeader" onclick="ts_resortTable_New(this);return false;">'+txt+'<span sortdir="down" class="sortarrow"><img border="0" src="'+ image_path + image_none + '" alt="↓"/></span></a>'; 294: ts_resortTable_New(cell.childNodes[0]); 295: } 296: else if(cell.childNodes[0] && cell.childNodes[0].tagName && cell.id && cell.id.toLowerCase() == 'ratingcol' && cell.childNodes[0].tagName.toLowerCase() == 'a') { 297: //cell.childNodes[0].onclick = "ts_resortTableRating(this);return false;"; 298: var txt = cell.childNodes[0].childNodes[0].nodeValue; 299: cell.innerHTML = '<a href="#" class="sortHeader" onclick="ts_resortTable_New(this, true);return false;">'+txt+'<span sortdir="up" class="sortarrow"><img border="0" src="'+ image_path + image_none + '" alt="↓"/></span></a>'; 300: 301: 302: // ts_resortTableRating(cell.childNodes[0]); 303: } 304: else { 305: var txt = cell.childNodes[0].childNodes[0].nodeValue; 306: cell.innerHTML = '<a href="#" class="sortHeader" onclick="ts_resortTable_New(this);return false;">'+txt+'<span sortdir="up" class="sortarrow"><img border="0" src="'+ image_path + image_none + '" alt="↓"/></span></a>'; 307: } 308: } 309: 310: //]]> 311: </script> 312: {/pre}
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey