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);
|
|
|
|
$('<span> </span>').appendTo(divContent);
|
2010-02-09 21:04:43 +01:00
|
|
|
$('<a href="javascript:{}">mark as new</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._doMarkAsNew();
|
|
|
|
});
|
|
|
|
|
2010-02-09 20:23:11 +01:00
|
|
|
if (this._dataTableView._showRecon && "c" in r && r.c.length > 0) {
|
|
|
|
var candidates = r.c;
|
2010-02-10 19:54:53 +01:00
|
|
|
var ul = $('<ul></ul>').addClass("data-table-recon-candidates").appendTo(divContent);
|
2010-02-09 21:04:43 +01:00
|
|
|
var renderCandidate = function(candidate, index) {
|
2010-02-09 20:23:11 +01:00
|
|
|
var li = $('<li></li>').appendTo(ul);
|
|
|
|
$('<a></a>')
|
2010-02-09 21:04:43 +01:00
|
|
|
.addClass("data-table-recon-topic")
|
2010-02-09 20:23:11 +01:00
|
|
|
.attr("href", "http://www.freebase.com/view" + candidate.id)
|
|
|
|
.attr("target", "_blank")
|
2010-02-09 21:36:47 +01:00
|
|
|
.click(function(evt) {
|
|
|
|
self._previewCandidateTopic(candidate.id, this);
|
|
|
|
evt.preventDefault();
|
|
|
|
return false;
|
|
|
|
})
|
2010-02-09 20:23:11 +01:00
|
|
|
.text(candidate.name)
|
|
|
|
.appendTo(li);
|
2010-02-09 21:04:43 +01:00
|
|
|
|
|
|
|
$('<span></span>').addClass("data-table-recon-score").text("(" + Math.round(candidate.score) + ")").appendTo(li);
|
|
|
|
$('<a href="javascript:{}">match</a>')
|
|
|
|
.addClass("data-table-recon-action")
|
|
|
|
.appendTo(li).click(function(evt) {
|
|
|
|
self._doSetAsMatch(candidate.id);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < candidates.length; i++) {
|
|
|
|
renderCandidate(candidates[i], i);
|
2010-02-09 20:23:11 +01:00
|
|
|
}
|
|
|
|
}
|
2010-02-20 01:47:08 +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() {
|
|
|
|
this._doJudgment("discard");
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableCellUI.prototype._doMarkAsNew = function() {
|
|
|
|
this._doJudgment("new");
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableCellUI.prototype._doSetAsMatch = function(candidateID) {
|
|
|
|
this._doJudgment("match", { candidate : candidateID });
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableCellUI.prototype._doJudgment = function(judgment, params) {
|
|
|
|
params = params || {};
|
|
|
|
params.row = this._rowIndex;
|
|
|
|
params.cell = this._cellIndex;
|
|
|
|
params.judgment = judgment;
|
2010-02-20 01:47:08 +01:00
|
|
|
this.doPostThenUpdate("recon-judge-one-cell", params);
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableCellUI.prototype._searchForMatch = function() {
|
|
|
|
var self = this;
|
|
|
|
var frame = DialogSystem.createDialog();
|
|
|
|
frame.width("200px");
|
|
|
|
|
|
|
|
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));
|
|
|
|
input.suggest({}).bind("fb-select", function(e, data) {
|
|
|
|
var params = {
|
|
|
|
row: self._rowIndex,
|
|
|
|
cell: self._cellIndex,
|
|
|
|
topicID: data.id,
|
|
|
|
topicGUID: data.guid,
|
|
|
|
topicName: data.name,
|
|
|
|
types: $.map(data.type, function(elmt) { return elmt.id; }).join(",")
|
|
|
|
};
|
|
|
|
self.doPostThenUpdate("recon-judge-one-cell", params);
|
|
|
|
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<button></button>').text("Cancel").click(function() {
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
}).appendTo(footer);
|
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
|
|
|
input[0].focus();
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableCellUI.prototype.createUpdateFunction = function(onBefore) {
|
|
|
|
var self = this;
|
|
|
|
return function(data) {
|
|
|
|
if (data.code == "ok") {
|
|
|
|
var onDone = function() {
|
|
|
|
self._cell = data.cell;
|
|
|
|
self._render();
|
|
|
|
ui.historyWidget.update();
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
var onDone = function() {
|
|
|
|
ui.processWidget.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onBefore) {
|
|
|
|
onBefore(onDone);
|
|
|
|
} else {
|
|
|
|
onDone();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
DataTableCellUI.prototype.doPostThenUpdate = function(command, params) {
|
|
|
|
params.project = theProject.id;
|
|
|
|
$.post(
|
|
|
|
"/command/" + command + "?" + $.param(params),
|
|
|
|
null,
|
|
|
|
this.createUpdateFunction(),
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
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));
|
|
|
|
};
|