Mercurial > hg > STI-GWT
view war/scripts/sti/DynamicTable.js @ 41:90b7bbc9962f default
Merged the bugfixes
author | Sebastian Kruse <skruse@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 06 Dec 2012 18:09:00 +0100 |
parents | cf06b77a8bbd |
children | 20eb7596d466 |
line wrap: on
line source
/** * @author stjaenicke */ function DynamicTable(core, dataSet, index){ this.core = core; this.dataSet = dataSet; this.chunks = []; this.index = index; this.tableDiv; this.tableHeader; this.tableBody; this.tableFooter; this.chunkSelect; this.actualChunk; this.rows; this.initialize(); } DynamicTable.prototype = { initialize: function(){ this.chunks.push([]); for (var i = 0; i < this.dataSet.objects.length; i++) { if (this.chunks[this.chunks.length - 1].length == tableElements) this.chunks.push([]); this.chunks[this.chunks.length - 1].push(this.dataSet.objects[i]); } this.rows = []; var base = this; this.tableDiv = document.createElement("div"); this.tableDiv.id = "dataTable"; var table = document.createElement("table"); table.onselectstart = function(){ return false; }; this.tableDiv.appendChild(table); // Initialisation of the table header this.tableHeader = document.createElement("thead"); var headerRow = document.createElement("tr"); this.tableHeader.appendChild(headerRow); var visibilityLink = document.createElement("a"); visibilityLink.id = "visibilityLink" + this.index; if (this.dataSet.hidden) visibilityLink.innerHTML = "show"; else visibilityLink.innerHTML = "hide"; visibilityLink.onclick = function(){ if (base.core.changeVisibilityStatus(base.index)) document.getElementById("visibilityLink" + base.index).innerHTML = "show"; else document.getElementById("visibilityLink" + base.index).innerHTML = "hide"; } var cell1 = document.createElement("th"); cell1.appendChild(visibilityLink); headerRow.appendChild(cell1); var thead = document.createElement("th"); if (this.dataSet.type == 0) thead.innerHTML = "Hits for: \"" + this.dataSet.termIdentifier + "\""; else if (this.dataSet.type == 1) thead.innerHTML = "Individual Data"; headerRow.appendChild(thead); var colorBox = document.createElement("th"); var canvas = document.createElement("canvas"); canvas.width = 15; canvas.height = 15; if (!canvas.getContext && G_vmlCanvasManager) canvas = G_vmlCanvasManager.initElement(canvas); var ctx = canvas.getContext("2d"); ctx.fillStyle = 'rgb(' + colors[this.index].rt + ',' + colors[this.index].gt + ',' + colors[this.index].bt + ')'; ctx.fillRect (0, 0, 15, 15); colorBox.appendChild(canvas); headerRow.appendChild(colorBox); var deleteLink = document.createElement("a"); deleteLink.innerHTML = "delete"; deleteLink.onclick = function(){ base.core.deleteSearch(base.index); } var cell2 = document.createElement("th"); cell2.appendChild(deleteLink); headerRow.appendChild(cell2); table.appendChild(this.tableHeader); // Initialisation of the table footer this.tableBody = document.createElement("tbody"); table.appendChild(this.tableBody); // Initialisation of the table footer this.tableFooter = document.createElement("tfoot"); var footerRow = document.createElement("tr"); this.tableFooter.appendChild(footerRow); var previousLink = document.createElement("a"); previousLink.innerHTML = "<<<"; previousLink.onclick = function(){ if (base.actualChunk > 0) { base.chunkSelect.value = base.actualChunk; base.createTableBody(); } } var nextLink = document.createElement("a"); nextLink.innerHTML = ">>>"; nextLink.onclick = function(){ if (base.actualChunk + 1 < base.chunks.length) { base.chunkSelect.value = base.actualChunk + 2; base.createTableBody(); } } var tfoot = document.createElement("th"); tfoot.colSpan = "4"; this.chunkSelect = document.createElement("input"); this.chunkSelect.type = "text"; this.chunkSelect.setAttribute( 'size', this.chunks.length.toString().length-1 ); this.chunkSelect.setAttribute( 'maxlength', this.chunks.length.toString().length ); this.chunkSelect.value = 1; this.chunkSelect.onkeypress = function handleEnter(event){ var charCode; if (event && event.which) { charCode = event.which; } else if (window.event) { event = window.event; charCode = event.keyCode; } if (charCode == 13) base.createTableBody(); } var maxChunks = document.createElement("label"); maxChunks.innerHTML = "/" + this.chunks.length; tfoot.appendChild(previousLink); tfoot.appendChild(this.chunkSelect); tfoot.appendChild(maxChunks); tfoot.appendChild(nextLink); footerRow.appendChild(tfoot); table.appendChild(this.tableFooter); this.createTableBody(); }, createRow: function(object, index){ var base = this; var dataRow = document.createElement("tr"); var indexCell = document.createElement("td"); indexCell.innerHTML = index + 1; dataRow.appendChild(indexCell); var objectCell = document.createElement("td"); if (object.link != null) { var linkElement = document.createElement("a"); linkElement.href = object.link; linkElement.target = "_blank"; linkElement.innerHTML = object.name; objectCell.appendChild(linkElement); } else { objectCell.innerHTML = object.name; } dataRow.appendChild(objectCell); var placeCell = document.createElement("td"); placeCell.innerHTML = object.place; dataRow.appendChild(placeCell); var timeCell = document.createElement("td"); timeCell.innerHTML = base.core.getTimeString(object.time,object.granularity); dataRow.appendChild(timeCell); var mouseover = function(){ dataRow.lastColor = dataRow.style.backgroundColor; dataRow.style.backgroundColor = "rgb(" + cellColor.ro + "," + cellColor.go + "," + cellColor.bo + ")"; if( object.percentage != 1 ){ object.hoverSelect = true; base.core.timeplot.removePoles(); base.core.updateTimeAndMap(); } } var mouseout = function(){ dataRow.style.backgroundColor = dataRow.lastColor; object.hoverSelect = false; base.core.timeplot.removePoles(); base.core.updateTimeAndMap(); } var mouseclick = function(){ base.core.resetCore(); object.hoverSelect = false; var c = colors[base.index]; dataRow.style.background = 'rgb(' + c.rt + ',' + c.gt + ',' + c.bt + ')'; dataRow.lastColor = dataRow.style.background; object.setPercentage(1); base.core.updateTimeAndMap(); } if (document.addEventListener) { dataRow.addEventListener("mouseover", mouseover, false); dataRow.addEventListener("mouseout", mouseout, false); dataRow.addEventListener("click", mouseclick, false); } else if (document.attachEvent) { dataRow.attachEvent("onmouseover", mouseover); dataRow.attachEvent("onmouseout", mouseout); dataRow.attachEvent("onclick", mouseclick); } if (index % 20 == 0) { indexCell.style.borderTop = "none"; objectCell.style.borderTop = "none"; placeCell.style.borderTop = "none"; timeCell.style.borderTop = "none"; } return dataRow; }, createTableBody: function(){ try { var selectedChunk = parseInt(this.chunkSelect.value); if (selectedChunk > this.chunks.length) { throw "Exception"; } this.actualChunk = selectedChunk - 1; } catch (exception) { this.chunkSelect.value = this.actualChunk + 1; return; } this.tableBody.innerHTML = ""; this.rows = []; for (var i = 0; i < this.chunks[this.actualChunk].length; i++) { var index = this.actualChunk * tableElements + i; var row = this.createRow(this.chunks[this.actualChunk][i], index); this.tableBody.appendChild(row); this.rows.push(row); } this.update(); }, update: function(){ for (var i = 0; i < this.chunks[this.actualChunk].length; i++) { var object = this.chunks[this.actualChunk][i]; var p = object.percentage; if (object.hoverSelect) { p = 1; } var r = cellColor.r + Math.round(p * (colors[this.index].rt - cellColor.r)); var g = cellColor.g + Math.round(p * (colors[this.index].gt - cellColor.g)); var b = cellColor.b + Math.round(p * (colors[this.index].bt - cellColor.b)); this.rows[i].style.background = 'rgb(' + r + ',' + g + ',' + b + ')'; } } }