2010-02-09 20:23:11 +01:00
|
|
|
function DataTableCellUI(dataTableView, cell, rowIndex, cellIndex, td) {
|
|
|
|
this._dataTableView = dataTableView;
|
|
|
|
this._cell = cell;
|
|
|
|
this._rowIndex = rowIndex;
|
|
|
|
this._cellIndex = cellIndex;
|
|
|
|
this._td = td;
|
|
|
|
|
|
|
|
this._render();
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableCellUI.prototype._render = function() {
|
2010-02-09 21:04:43 +01:00
|
|
|
var self = this;
|
2010-02-09 20:23:11 +01:00
|
|
|
var cell = this._cell;
|
|
|
|
|
2010-02-10 19:54:53 +01:00
|
|
|
$(this._td).empty();
|
|
|
|
var divContent = $('<div></div>').appendTo(this._td);
|
2010-02-09 21:04:43 +01:00
|
|
|
|
2010-02-09 20:23:11 +01:00
|
|
|
if (cell == null || cell.v == null) {
|
2010-02-10 19:54:53 +01:00
|
|
|
$(divContent).html(" ");
|
2010-02-09 21:04:43 +01:00
|
|
|
// TODO: content editing UI
|
2010-02-09 20:23:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!("r" in cell) || cell.r == null) {
|
2010-02-10 19:54:53 +01:00
|
|
|
$(divContent).html(cell.v);
|
2010-02-09 20:23:11 +01:00
|
|
|
} else {
|
|
|
|
var r = cell.r;
|
|
|
|
if (r.j == "new") {
|
2010-02-10 19:54:53 +01:00
|
|
|
$(divContent).html(cell.v + " (new topic)");
|
2010-02-09 21:04:43 +01:00
|
|
|
|
2010-02-10 19:54:53 +01:00
|
|
|
$('<span> </span>').appendTo(divContent);
|
2010-02-09 21:04:43 +01:00
|
|
|
$('<a href="javascript:{}">re-match</a>')
|
|
|
|
.addClass("data-table-recon-action")
|
2010-02-10 19:54:53 +01:00
|
|
|
.appendTo(divContent).click(function(evt) {
|
2010-02-09 21:04:43 +01:00
|
|
|
self._doRematch();
|
|
|
|
});
|
|
|
|
} else if (r.j == "matched" && "m" in r && r.m != null) {
|
2010-02-09 20:23:11 +01:00
|
|
|
var match = cell.r.m;
|
|
|
|
$('<a></a>')
|
|
|
|
.attr("href", "http://www.freebase.com/view" + match.id)
|
|
|
|
.attr("target", "_blank")
|
|
|
|
.text(match.name)
|
2010-02-10 19:54:53 +01:00
|
|
|
.appendTo(divContent);
|
2010-02-09 21:04:43 +01:00
|
|
|
|
2010-02-10 19:54:53 +01:00
|
|
|
$('<span> </span>').appendTo(divContent);
|
2010-02-09 21:04:43 +01:00
|
|
|
$('<a href="javascript:{}">re-match</a>')
|
|
|
|
.addClass("data-table-recon-action")
|
2010-02-10 19:54:53 +01:00
|
|
|
.appendTo(divContent).click(function(evt) {
|
2010-02-09 21:04:43 +01:00
|
|
|
self._doRematch();
|
|
|
|
});
|
2010-02-09 20:23:11 +01:00
|
|
|
} else {
|
2010-02-10 19:54:53 +01:00
|
|
|
$(divContent).html(cell.v);
|
2010-02-09 21:04:43 +01:00
|
|
|
|
2010-02-23 21:20:14 +01:00
|
|
|
if (this._dataTableView._showRecon) {
|
|
|
|
var ul = $('<div></div>').addClass("data-table-recon-candidates").appendTo(divContent);
|
|
|
|
if ("c" in r && r.c.length > 0) {
|
|
|
|
var candidates = r.c;
|
|
|
|
var renderCandidate = function(candidate, index) {
|
|
|
|
var li = $('<div></div>').addClass("data-table-recon-candidate").appendTo(ul);
|
2010-02-09 21:04:43 +01:00
|
|
|
|
2010-02-23 21:20:14 +01:00
|
|
|
$('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass("data-table-recon-match-similar")
|
|
|
|
.attr("title", "Match this topic to this cell and other cells with the same content")
|
|
|
|
.appendTo(li).click(function(evt) {
|
|
|
|
self._doMatchTopicToSimilarCells(candidate);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass("data-table-recon-match")
|
|
|
|
.attr("title", "Match this topic to this cell")
|
|
|
|
.appendTo(li).click(function(evt) {
|
|
|
|
self._doMatchTopicToOneCell(candidate);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<a></a>')
|
|
|
|
.addClass("data-table-recon-topic")
|
|
|
|
.attr("href", "http://www.freebase.com/view" + candidate.id)
|
|
|
|
.attr("target", "_blank")
|
|
|
|
.click(function(evt) {
|
|
|
|
self._previewCandidateTopic(candidate.id, this);
|
|
|
|
evt.preventDefault();
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
.text(candidate.name)
|
|
|
|
.appendTo(li);
|
|
|
|
|
|
|
|
$('<span></span>').addClass("data-table-recon-score").text("(" + Math.round(candidate.score) + ")").appendTo(li);
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < candidates.length; i++) {
|
|
|
|
renderCandidate(candidates[i], i);
|
|
|
|
}
|
2010-02-09 20:23:11 +01:00
|
|
|
}
|
2010-02-22 02:28:13 +01:00
|
|
|
|
2010-02-23 21:20:14 +01:00
|
|
|
var liNew = $('<div></div>').addClass("data-table-recon-candidate").appendTo(ul);
|
|
|
|
$('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass("data-table-recon-match-similar")
|
|
|
|
.attr("title", "Create a new topic for this cell and other cells with the same content")
|
|
|
|
.appendTo(liNew).click(function(evt) {
|
|
|
|
self._doMatchNewTopicToSimilarCells();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass("data-table-recon-match")
|
|
|
|
.attr("title", "Create a new topic for this cell")
|
|
|
|
.appendTo(liNew).click(function(evt) {
|
|
|
|
self._doMatchNewTopicToOneCell();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<span>').text("(New topic)").appendTo(liNew);
|
2010-02-22 02:28:13 +01:00
|
|
|
|
2010-02-23 21:20:14 +01:00
|
|
|
$('<a href="javascript:{}"></a>')
|
|
|
|
.addClass("data-table-recon-search")
|
|
|
|
.click(function(evt) {
|
|
|
|
self._searchForMatch();
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
.text("search for match")
|
|
|
|
.appendTo($('<div>').appendTo(divContent));
|
|
|
|
}
|
2010-02-09 20:23:11 +01:00
|
|
|
}
|
|
|
|
}
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableCellUI.prototype._doRematch = function() {
|
2010-02-22 21:25:45 +01:00
|
|
|
this._doJudgment("none");
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
2010-02-22 02:28:13 +01:00
|
|
|
DataTableCellUI.prototype._doMatchNewTopicToOneCell = function() {
|
2010-02-09 21:04:43 +01:00
|
|
|
this._doJudgment("new");
|
|
|
|
};
|
|
|
|
|
2010-02-22 02:28:13 +01:00
|
|
|
DataTableCellUI.prototype._doMatchNewTopicToSimilarCells = function() {
|
2010-02-22 23:15:48 +01:00
|
|
|
this._doJudgmentForSimilarCells("new", { shareNewTopics: true });
|
2010-02-22 02:28:13 +01:00
|
|
|
};
|
|
|
|
|
2010-02-22 21:25:45 +01:00
|
|
|
DataTableCellUI.prototype._doMatchTopicToOneCell = function(candidate) {
|
|
|
|
this._doJudgment("matched", {
|
|
|
|
topicID : candidate.id,
|
|
|
|
topicGUID: candidate.guid,
|
|
|
|
topicName: candidate.name,
|
|
|
|
score: candidate.score,
|
|
|
|
types: candidate.types.join(",")
|
|
|
|
});
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
2010-02-22 21:25:45 +01:00
|
|
|
DataTableCellUI.prototype._doMatchTopicToSimilarCells = function(candidate) {
|
|
|
|
this._doJudgmentForSimilarCells("matched", {
|
|
|
|
topicID : candidate.id,
|
|
|
|
topicGUID: candidate.guid,
|
|
|
|
topicName: candidate.name,
|
|
|
|
score: candidate.score,
|
|
|
|
types: candidate.types.join(",")
|
|
|
|
});
|
2010-02-22 02:28:13 +01:00
|
|
|
};
|
|
|
|
|
2010-02-09 21:04:43 +01:00
|
|
|
DataTableCellUI.prototype._doJudgment = function(judgment, params) {
|
|
|
|
params = params || {};
|
|
|
|
params.row = this._rowIndex;
|
|
|
|
params.cell = this._cellIndex;
|
|
|
|
params.judgment = judgment;
|
2010-02-26 22:56:41 +01:00
|
|
|
this._postProcessOneCell("recon-judge-one-cell", params);
|
2010-02-20 01:47:08 +01:00
|
|
|
};
|
|
|
|
|
2010-02-22 02:28:13 +01:00
|
|
|
DataTableCellUI.prototype._doJudgmentForSimilarCells = function(judgment, params) {
|
|
|
|
params = params || {};
|
2010-02-26 22:56:41 +01:00
|
|
|
params.columnName = Gridworks.cellIndexToColumn(this._cellIndex).headerLabel;
|
2010-02-22 21:25:45 +01:00
|
|
|
params.similarValue = this._cell.v;
|
2010-02-22 02:28:13 +01:00
|
|
|
params.judgment = judgment;
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
this._postProcessSeveralCells("recon-judge-similar-cells", params);
|
2010-02-22 02:28:13 +01:00
|
|
|
};
|
|
|
|
|
2010-02-20 01:47:08 +01:00
|
|
|
DataTableCellUI.prototype._searchForMatch = function() {
|
|
|
|
var self = this;
|
|
|
|
var frame = DialogSystem.createDialog();
|
2010-02-22 02:28:13 +01:00
|
|
|
frame.width("400px");
|
2010-02-20 01:47:08 +01:00
|
|
|
|
|
|
|
var header = $('<div></div>').addClass("dialog-header").text("Search for Match").appendTo(frame);
|
|
|
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
|
|
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
|
|
|
|
|
|
|
$('<p></p>').text("Search Freebase for topic to match " + this._cell.v).appendTo(body);
|
|
|
|
|
|
|
|
var input = $('<input />').attr("value", this._cell.v).appendTo($('<p></p>').appendTo(body));
|
2010-02-22 02:28:13 +01:00
|
|
|
var match = null;
|
2010-02-20 01:47:08 +01:00
|
|
|
input.suggest({}).bind("fb-select", function(e, data) {
|
2010-02-22 02:28:13 +01:00
|
|
|
match = data;
|
2010-02-20 01:47:08 +01:00
|
|
|
});
|
|
|
|
|
2010-02-22 02:28:13 +01:00
|
|
|
var pSimilar = $('<p></p>').appendTo(body);
|
|
|
|
var checkSimilar = $('<input type="checkbox" checked="true" />').appendTo(pSimilar);
|
|
|
|
$('<span>').text(" Match other cells with the same content as well").appendTo(pSimilar);
|
|
|
|
|
|
|
|
$('<button></button>').text("Match").click(function() {
|
|
|
|
if (match != null) {
|
|
|
|
var params = {
|
2010-02-22 21:25:45 +01:00
|
|
|
judgment: "matched",
|
2010-02-22 02:28:13 +01:00
|
|
|
topicID: match.id,
|
|
|
|
topicGUID: match.guid,
|
|
|
|
topicName: match.name,
|
|
|
|
types: $.map(match.type, function(elmt) { return elmt.id; }).join(",")
|
|
|
|
};
|
|
|
|
if (checkSimilar[0].checked) {
|
2010-02-22 21:25:45 +01:00
|
|
|
params.similarValue = self._cell.v;
|
2010-02-26 22:56:41 +01:00
|
|
|
params.columnName = Gridworks.cellIndexToColumn(self._cellIndex).headerLabel;
|
2010-02-22 21:25:45 +01:00
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
self._postProcessSeveralCells("recon-judge-similar-cells", params);
|
2010-02-22 02:28:13 +01:00
|
|
|
} else {
|
2010-02-22 21:25:45 +01:00
|
|
|
params.row = self._rowIndex;
|
|
|
|
params.cell = self._cellIndex;
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
self._postProcessOneCell("recon-judge-one-cell", params);
|
2010-02-22 02:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
}
|
|
|
|
}).appendTo(footer);
|
|
|
|
|
2010-02-20 01:47:08 +01:00
|
|
|
$('<button></button>').text("Cancel").click(function() {
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
}).appendTo(footer);
|
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
2010-02-22 02:28:13 +01:00
|
|
|
input.focus().data("suggest").textchange();
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
DataTableCellUI.prototype._postProcessOneCell = function(command, params) {
|
2010-02-09 21:04:43 +01:00
|
|
|
var self = this;
|
2010-02-26 22:56:41 +01:00
|
|
|
|
|
|
|
Gridworks.postProcess(
|
|
|
|
command,
|
|
|
|
params,
|
|
|
|
null,
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
onDone: function(o) {
|
2010-02-09 21:04:43 +01:00
|
|
|
self._cell = data.cell;
|
|
|
|
self._render();
|
|
|
|
}
|
|
|
|
}
|
2010-02-26 22:56:41 +01:00
|
|
|
);
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
DataTableCellUI.prototype._postProcessSeveralCells = function(command, params) {
|
|
|
|
Gridworks.postProcess(
|
|
|
|
command,
|
|
|
|
params,
|
2010-02-09 21:04:43 +01:00
|
|
|
null,
|
2010-02-26 22:56:41 +01:00
|
|
|
{ cellsChanged: true }
|
2010-02-09 21:04:43 +01:00
|
|
|
);
|
|
|
|
};
|
2010-02-09 21:36:47 +01:00
|
|
|
|
|
|
|
DataTableCellUI.prototype._previewCandidateTopic = function(id, elmt) {
|
|
|
|
var url = "http://www.freebase.com/widget/topic" + id + '?mode=content&blocks=[{"block"%3A"image"}%2C{"block"%3A"full_info"}%2C{"block"%3A"article_props"}]';
|
|
|
|
|
|
|
|
var fakeMenu = MenuSystem.createMenu();
|
|
|
|
fakeMenu
|
|
|
|
.width(700)
|
|
|
|
.height(300)
|
|
|
|
.css("background", "none")
|
|
|
|
.css("border", "none");
|
|
|
|
|
|
|
|
var iframe = $('<iframe></iframe>')
|
|
|
|
.attr("width", "100%")
|
|
|
|
.attr("height", "100%")
|
|
|
|
.css("background", "none")
|
|
|
|
.css("border", "none")
|
|
|
|
.attr("src", url)
|
|
|
|
.appendTo(fakeMenu);
|
|
|
|
|
|
|
|
MenuSystem.showMenu(fakeMenu, function(){});
|
|
|
|
MenuSystem.positionMenuLeftRight(fakeMenu, $(elmt));
|
|
|
|
};
|