2010-01-26 20:54:14 +01:00
|
|
|
function DataTableView(div) {
|
|
|
|
this._div = div;
|
2010-01-29 01:46:15 +01:00
|
|
|
this._pageSize = 20;
|
2010-02-01 21:57:52 +01:00
|
|
|
this._showRecon = true;
|
2010-03-10 08:12:09 +01:00
|
|
|
this._collapsedColumnNames = {};
|
2010-03-08 07:48:12 +01:00
|
|
|
|
2010-01-29 01:46:15 +01:00
|
|
|
this._showRows(0);
|
2010-01-26 20:54:14 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
DataTableView.prototype.resize = function() {
|
|
|
|
var topHeight = this._div.find(".viewPanel-summary").outerHeight(true) + this._div.find(".viewPanel-pagingControls").outerHeight(true);
|
2010-03-08 07:48:12 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
this._div.find(".data-table-container")
|
|
|
|
.css("height", (this._div.innerHeight() - topHeight - 1) + "px")
|
|
|
|
.css("display", "block");
|
2010-03-08 07:48:12 +01:00
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
DataTableView.prototype.update = function(onDone) {
|
|
|
|
this._showRows(0, onDone);
|
2010-02-02 21:50:35 +01:00
|
|
|
};
|
|
|
|
|
2010-01-26 20:54:14 +01:00
|
|
|
DataTableView.prototype.render = function() {
|
|
|
|
var self = this;
|
2010-03-10 08:51:34 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
var oldTableDiv = this._div.find(".data-table-container");
|
|
|
|
var scrollLeft = (oldTableDiv.length > 0) ? oldTableDiv[0].scrollLeft : 0;
|
2010-03-10 08:51:34 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
var html = $(
|
|
|
|
'<div bind="summaryDiv" class="viewPanel-summary"></div>' +
|
|
|
|
'<table bind="pagingControls" width="100%" class="viewPanel-pagingControls"><tr><td align="right"></td><td align="right"></td></tr></table>' +
|
|
|
|
'<div bind="dataTableContainer" class="data-table-container" style="display: none;"><table bind="table" class="data-table" cellspacing="0"></table></div>'
|
|
|
|
);
|
|
|
|
var elmts = DOM.bind(html);
|
|
|
|
|
|
|
|
this._renderSummaryText(elmts.summaryDiv);
|
|
|
|
this._renderPagingControls(elmts.pagingControls[0]);
|
|
|
|
this._renderDataTable(elmts.table[0]);
|
2010-01-26 20:54:14 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
this._div.empty().append(html);
|
2010-02-23 20:18:25 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
this.resize();
|
|
|
|
|
|
|
|
elmts.dataTableContainer[0].scrollLeft = scrollLeft;
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.prototype._renderSummaryText = function(elmt) {
|
2010-02-23 20:18:25 +01:00
|
|
|
var summaryText;
|
|
|
|
|
|
|
|
var from = (theProject.rowModel.start + 1);
|
|
|
|
var to = Math.min(theProject.rowModel.filtered, theProject.rowModel.start + theProject.rowModel.limit);
|
|
|
|
if (theProject.rowModel.filtered == theProject.rowModel.total) {
|
|
|
|
summaryText = from + ' to ' + to + ' of <span class="viewPanel-summary-row-count">' + (theProject.rowModel.total) + '</span> rows';
|
|
|
|
} else {
|
|
|
|
summaryText = from + ' to ' + to + ' of <span class="viewPanel-summary-row-count">' +
|
|
|
|
(theProject.rowModel.filtered) + '</span> rows (filtered from ' + (theProject.rowModel.total) + ' rows total)';
|
|
|
|
}
|
2010-03-22 22:48:36 +01:00
|
|
|
$('<span>').html(summaryText).appendTo(elmt);
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.prototype._renderPagingControls = function(table) {
|
|
|
|
var self = this;
|
2010-02-02 19:43:19 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
var pagingControls0 = table.rows[0].cells[0];
|
|
|
|
var pagingControls1 = table.rows[0].cells[1];
|
2010-02-02 19:43:19 +01:00
|
|
|
|
|
|
|
var firstPage = $('<a href="javascript:{}">« first</a>').appendTo(pagingControls0);
|
|
|
|
var previousPage = $('<a href="javascript:{}">« previous</a>').appendTo(pagingControls0);
|
2010-01-26 20:54:14 +01:00
|
|
|
if (theProject.rowModel.start > 0) {
|
|
|
|
firstPage.addClass("action").click(function(evt) { self._onClickFirstPage(this, evt); });
|
|
|
|
previousPage.addClass("action").click(function(evt) { self._onClickPreviousPage(this, evt); });
|
|
|
|
} else {
|
|
|
|
firstPage.addClass("inaction");
|
|
|
|
previousPage.addClass("inaction");
|
|
|
|
}
|
2010-02-02 19:43:19 +01:00
|
|
|
$('<span> • </span>').appendTo(pagingControls0);
|
|
|
|
var nextPage = $('<a href="javascript:{}">next page »</a>').appendTo(pagingControls0);
|
|
|
|
var lastPage = $('<a href="javascript:{}">last »</a>').appendTo(pagingControls0);
|
2010-01-30 02:05:30 +01:00
|
|
|
if (theProject.rowModel.start + theProject.rowModel.limit < theProject.rowModel.filtered) {
|
2010-01-26 20:54:14 +01:00
|
|
|
nextPage.addClass("action").click(function(evt) { self._onClickNextPage(this, evt); });
|
|
|
|
lastPage.addClass("action").click(function(evt) { self._onClickLastPage(this, evt); });
|
|
|
|
} else {
|
|
|
|
nextPage.addClass("inaction");
|
|
|
|
lastPage.addClass("inaction");
|
|
|
|
}
|
|
|
|
|
2010-02-02 19:43:19 +01:00
|
|
|
$('<span>page size: </span>').appendTo(pagingControls1);
|
|
|
|
var sizes = [ 5, 10, 15, 20, 25, 50 ];
|
|
|
|
var renderPageSize = function(index) {
|
|
|
|
var pageSize = sizes[index];
|
|
|
|
var a = $('<a href="javascript:{}"></a>').appendTo(pagingControls1)
|
|
|
|
if (pageSize == self._pageSize) {
|
|
|
|
a.text("[" + pageSize + "]").addClass("inaction");
|
|
|
|
} else {
|
|
|
|
a.text(pageSize).addClass("action").click(function(evt) {
|
|
|
|
self._pageSize = pageSize;
|
2010-02-26 22:56:41 +01:00
|
|
|
self.update();
|
2010-02-02 19:43:19 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (var i = 0; i < sizes.length; i++) {
|
|
|
|
renderPageSize(i);
|
|
|
|
}
|
2010-03-22 22:48:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.prototype._renderDataTable = function(table) {
|
|
|
|
var self = this;
|
2010-01-26 20:54:14 +01:00
|
|
|
|
2010-02-05 02:27:14 +01:00
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
var columnGroups = theProject.columnModel.columnGroups;
|
|
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
|
|
* Column Group Headers
|
|
|
|
*------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
var renderColumnKeys = function(keys) {
|
|
|
|
if (keys.length > 0) {
|
|
|
|
var tr = table.insertRow(table.rows.length);
|
2010-02-23 08:45:12 +01:00
|
|
|
tr.insertCell(0); // star
|
|
|
|
tr.insertCell(1); // row index
|
2010-02-05 02:27:14 +01:00
|
|
|
|
|
|
|
for (var c = 0; c < columns.length; c++) {
|
|
|
|
var td = tr.insertCell(tr.cells.length);
|
|
|
|
|
|
|
|
for (var k = 0; k < keys.length; k++) {
|
|
|
|
if (c == keys[k]) {
|
|
|
|
$('<img />').attr("src", "images/down-arrow.png").appendTo(td);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var renderColumnGroups = function(groups, keys) {
|
|
|
|
var nextLayer = [];
|
|
|
|
|
|
|
|
if (groups.length > 0) {
|
|
|
|
var tr = table.insertRow(table.rows.length);
|
2010-02-23 08:45:12 +01:00
|
|
|
tr.insertCell(0); // star
|
|
|
|
tr.insertCell(1); // row index
|
2010-02-05 02:27:14 +01:00
|
|
|
|
|
|
|
for (var c = 0; c < columns.length; c++) {
|
|
|
|
var foundGroup = false;
|
|
|
|
|
|
|
|
for (var g = 0; g < groups.length; g++) {
|
|
|
|
var columnGroup = groups[g];
|
|
|
|
if (columnGroup.startColumnIndex == c) {
|
|
|
|
foundGroup = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var td = tr.insertCell(tr.cells.length);
|
|
|
|
if (foundGroup) {
|
|
|
|
td.setAttribute("colspan", columnGroup.columnSpan);
|
|
|
|
td.style.background = "blue";
|
|
|
|
|
|
|
|
if (columnGroup.keyColumnIndex >= 0) {
|
|
|
|
keys.push(columnGroup.keyColumnIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
c += (columnGroup.columnSpan - 1);
|
|
|
|
|
2010-03-27 06:23:09 +01:00
|
|
|
if ("subgroups" in columnGroup) {
|
|
|
|
nextLayer = nextLayer.concat(columnGroup.subgroups);
|
|
|
|
}
|
2010-02-05 02:27:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderColumnKeys(keys);
|
|
|
|
|
|
|
|
if (nextLayer.length > 0) {
|
|
|
|
renderColumnGroups(nextLayer, []);
|
|
|
|
}
|
|
|
|
};
|
2010-03-27 06:23:09 +01:00
|
|
|
|
|
|
|
if (columnGroups.length > 0) {
|
|
|
|
renderColumnGroups(
|
|
|
|
columnGroups,
|
|
|
|
[ theProject.columnModel.keyCellIndex ]
|
|
|
|
);
|
|
|
|
}
|
2010-02-05 02:27:14 +01:00
|
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
|
|
* Column Headers with Menus
|
|
|
|
*------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
var trHead = table.insertRow(table.rows.length);
|
2010-03-18 01:35:34 +01:00
|
|
|
DOM.bind(
|
|
|
|
$(trHead.insertCell(trHead.cells.length))
|
|
|
|
.attr("colspan", "2")
|
|
|
|
.addClass("column-header")
|
|
|
|
.html(
|
|
|
|
'<table class="column-header-layout"><tr><td> </td>' +
|
|
|
|
'<td width="1%">' +
|
|
|
|
'<a class="column-header-menu" bind="dropdownMenu"> </a>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr></table>'
|
|
|
|
)
|
|
|
|
).dropdownMenu.click(function() {
|
2010-01-26 20:54:14 +01:00
|
|
|
self._createMenuForAllColumns(this);
|
|
|
|
});
|
|
|
|
|
|
|
|
var createColumnHeader = function(column, index) {
|
|
|
|
var td = trHead.insertCell(trHead.cells.length);
|
|
|
|
$(td).addClass("column-header");
|
|
|
|
|
2010-03-10 08:12:09 +01:00
|
|
|
if (column.name in self._collapsedColumnNames) {
|
2010-03-06 08:43:45 +01:00
|
|
|
$(td).html(" ").attr("title", column.name).click(function(evt) {
|
2010-03-10 08:12:09 +01:00
|
|
|
delete self._collapsedColumnNames[column.name]
|
2010-01-26 20:54:14 +01:00
|
|
|
self.render();
|
|
|
|
});
|
|
|
|
} else {
|
2010-02-09 20:23:11 +01:00
|
|
|
new DataTableColumnHeaderUI(self, column, index, td);
|
2010-01-26 20:54:14 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
createColumnHeader(columns[i], i);
|
|
|
|
}
|
|
|
|
|
2010-02-05 02:27:14 +01:00
|
|
|
/*------------------------------------------------------------
|
|
|
|
* Data Cells
|
|
|
|
*------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2010-01-26 20:54:14 +01:00
|
|
|
var rows = theProject.rowModel.rows;
|
2010-02-23 08:45:12 +01:00
|
|
|
var renderRow = function(tr, r, row, even) {
|
2010-02-26 22:56:41 +01:00
|
|
|
$(tr).empty();
|
|
|
|
|
2010-01-26 20:54:14 +01:00
|
|
|
var cells = row.cells;
|
|
|
|
|
2010-02-23 08:45:12 +01:00
|
|
|
var tdStar = tr.insertCell(tr.cells.length);
|
|
|
|
var star = $('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass(row.starred ? "data-table-star-on" : "data-table-star-off")
|
|
|
|
.appendTo(tdStar)
|
|
|
|
.click(function() {
|
|
|
|
var newStarred = !row.starred;
|
2010-02-26 22:56:41 +01:00
|
|
|
|
|
|
|
Gridworks.postProcess(
|
|
|
|
"annotate-one-row",
|
|
|
|
{ row: row.i, starred: newStarred },
|
2010-02-23 08:45:12 +01:00
|
|
|
null,
|
2010-02-26 22:56:41 +01:00
|
|
|
{},
|
|
|
|
{ onDone: function(o) {
|
2010-02-23 08:45:12 +01:00
|
|
|
row.starred = newStarred;
|
|
|
|
renderRow(tr, r, row, even);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
});
|
2010-02-10 19:54:53 +01:00
|
|
|
|
2010-02-23 08:45:12 +01:00
|
|
|
var tdIndex = tr.insertCell(tr.cells.length);
|
2010-02-10 19:54:53 +01:00
|
|
|
if ("j" in row) {
|
|
|
|
$(tr).addClass("record");
|
2010-02-23 08:45:12 +01:00
|
|
|
$('<div></div>').html((row.j + 1) + ".").appendTo(tdIndex);
|
2010-02-10 19:54:53 +01:00
|
|
|
} else {
|
2010-02-23 08:45:12 +01:00
|
|
|
$('<div></div>').html(" ").appendTo(tdIndex);
|
2010-02-10 19:54:53 +01:00
|
|
|
}
|
2010-01-26 20:54:14 +01:00
|
|
|
|
2010-02-06 00:05:00 +01:00
|
|
|
if ("contextual" in row && row.contextual) {
|
|
|
|
$(tr).addClass("contextual");
|
|
|
|
}
|
|
|
|
|
2010-02-10 19:54:53 +01:00
|
|
|
$(tr).addClass(even ? "even" : "odd");
|
2010-01-26 20:54:14 +01:00
|
|
|
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
|
|
|
var td = tr.insertCell(tr.cells.length);
|
2010-03-10 08:12:09 +01:00
|
|
|
if (column.name in self._collapsedColumnNames) {
|
2010-01-26 20:54:14 +01:00
|
|
|
td.innerHTML = " ";
|
2010-02-09 20:23:11 +01:00
|
|
|
} else {
|
|
|
|
var cell = (column.cellIndex < cells.length) ? cells[column.cellIndex] : null;
|
2010-02-23 21:20:14 +01:00
|
|
|
new DataTableCellUI(self, cell, row.i, column.cellIndex, td);
|
2010-01-26 20:54:14 +01:00
|
|
|
}
|
|
|
|
}
|
2010-02-23 08:45:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
var even = true;
|
|
|
|
for (var r = 0; r < rows.length; r++) {
|
|
|
|
var row = rows[r];
|
|
|
|
var tr = table.insertRow(table.rows.length);
|
|
|
|
if ("j" in row) {
|
|
|
|
even = !even;
|
|
|
|
}
|
|
|
|
renderRow(tr, r, row, even);
|
2010-01-26 20:54:14 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.prototype._showRows = function(start, onDone) {
|
|
|
|
var self = this;
|
2010-02-26 22:56:41 +01:00
|
|
|
Gridworks.fetchRows(start, this._pageSize, function() {
|
|
|
|
self.render();
|
|
|
|
|
|
|
|
if (onDone) {
|
|
|
|
onDone();
|
|
|
|
}
|
|
|
|
});
|
2010-01-26 20:54:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.prototype._onClickPreviousPage = function(elmt, evt) {
|
2010-01-29 01:46:15 +01:00
|
|
|
this._showRows(theProject.rowModel.start - this._pageSize);
|
2010-01-26 20:54:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.prototype._onClickNextPage = function(elmt, evt) {
|
2010-01-29 01:46:15 +01:00
|
|
|
this._showRows(theProject.rowModel.start + this._pageSize);
|
2010-01-26 20:54:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.prototype._onClickFirstPage = function(elmt, evt) {
|
2010-01-29 01:46:15 +01:00
|
|
|
this._showRows(0);
|
2010-01-26 20:54:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.prototype._onClickLastPage = function(elmt, evt) {
|
2010-01-30 02:05:30 +01:00
|
|
|
this._showRows(Math.floor(theProject.rowModel.filtered / this._pageSize) * this._pageSize);
|
2010-01-26 20:54:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.prototype._createMenuForAllColumns = function(elmt) {
|
|
|
|
self = this;
|
|
|
|
MenuSystem.createAndShowStandardMenu([
|
2010-03-05 23:31:47 +01:00
|
|
|
{ label: "Edit",
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: "Star Rows",
|
|
|
|
click: function() {
|
|
|
|
Gridworks.postProcess("annotate-rows", { "starred" : "true" }, null, { rowMetadataChanged: true });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Unstar Rows",
|
|
|
|
click: function() {
|
|
|
|
Gridworks.postProcess("annotate-rows", { "starred" : "false" }, null, { rowMetadataChanged: true });
|
|
|
|
}
|
2010-01-26 20:54:14 +01:00
|
|
|
}
|
2010-03-05 23:31:47 +01:00
|
|
|
]
|
2010-01-26 20:54:14 +01:00
|
|
|
},
|
2010-03-05 23:31:47 +01:00
|
|
|
{ label: "Filter",
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: "By Star",
|
|
|
|
click: function() {
|
|
|
|
ui.browsingEngine.addFacet(
|
|
|
|
"list",
|
|
|
|
{
|
|
|
|
"name" : "Starred Rows",
|
|
|
|
"columnName" : "",
|
|
|
|
"expression" : "row.starred"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"scroll" : false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2010-01-26 20:54:14 +01:00
|
|
|
}
|
2010-03-05 23:31:47 +01:00
|
|
|
]
|
2010-02-23 08:45:12 +01:00
|
|
|
},
|
2010-03-05 23:31:47 +01:00
|
|
|
{ label: "View",
|
|
|
|
submenu: [
|
|
|
|
{
|
|
|
|
label: "Collapse All Columns",
|
|
|
|
click: function() {
|
|
|
|
for (var i = 0; i < theProject.columnModel.columns.length; i++) {
|
2010-04-06 08:18:43 +02:00
|
|
|
self._collapsedColumnNames[theProject.columnModel.columns[i].name] = true;
|
2010-03-05 23:31:47 +01:00
|
|
|
}
|
|
|
|
self.render();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Expand All Columns",
|
|
|
|
click: function() {
|
2010-04-06 08:18:43 +02:00
|
|
|
self._collapsedColumnNames = [];
|
2010-03-05 23:31:47 +01:00
|
|
|
self.render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2010-01-26 20:54:14 +01:00
|
|
|
}
|
2010-03-05 23:31:47 +01:00
|
|
|
], elmt, { width: "80px", horizontal: false });
|
2010-01-26 20:54:14 +01:00
|
|
|
};
|
|
|
|
|
2010-03-03 19:08:35 +01:00
|
|
|
DataTableView.sampleVisibleRows = function(column) {
|
2010-02-03 10:27:53 +01:00
|
|
|
var rowIndices = [];
|
|
|
|
var values = [];
|
|
|
|
|
|
|
|
var rows = theProject.rowModel.rows;
|
|
|
|
for (var r = 0; r < rows.length; r++) {
|
|
|
|
var row = rows[r];
|
|
|
|
|
|
|
|
rowIndices.push(row.i);
|
|
|
|
|
|
|
|
var v = null;
|
|
|
|
if (column.cellIndex < row.cells.length) {
|
|
|
|
var cell = row.cells[column.cellIndex];
|
|
|
|
if (cell != null) {
|
|
|
|
v = cell.v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
values.push(v);
|
|
|
|
}
|
|
|
|
|
2010-03-03 19:08:35 +01:00
|
|
|
return {
|
|
|
|
rowIndices: rowIndices,
|
|
|
|
values: values
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableView.promptExpressionOnVisibleRows = function(column, title, expression, onDone) {
|
|
|
|
var o = DataTableView.sampleVisibleRows(column);
|
|
|
|
|
2010-02-03 10:27:53 +01:00
|
|
|
var self = this;
|
|
|
|
new ExpressionPreviewDialog(
|
|
|
|
title,
|
|
|
|
column.cellIndex,
|
2010-03-03 19:08:35 +01:00
|
|
|
o.rowIndices,
|
|
|
|
o.values,
|
2010-02-03 10:27:53 +01:00
|
|
|
expression,
|
|
|
|
onDone
|
|
|
|
);
|
2010-01-30 02:05:30 +01:00
|
|
|
};
|
|
|
|
|
2010-02-05 00:38:40 +01:00
|
|
|
|