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();
|
2010-04-08 21:52:23 +02:00
|
|
|
}
|
2010-02-09 20:23:11 +01:00
|
|
|
|
|
|
|
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-03-05 09:11:48 +01:00
|
|
|
var divContent = $('<div/>')
|
|
|
|
.addClass("data-table-cell-content");
|
|
|
|
|
2010-04-26 01:43:53 +02:00
|
|
|
var editLink = $('<a href="javascript:{}"> </a>')
|
2010-03-05 09:11:48 +01:00
|
|
|
.addClass("data-table-cell-edit")
|
2010-04-26 01:43:53 +02:00
|
|
|
.attr("title", "edit this cell")
|
2010-03-05 09:11:48 +01:00
|
|
|
.appendTo(divContent)
|
|
|
|
.click(function() { self._startEdit(this); });
|
|
|
|
|
|
|
|
$(this._td).empty()
|
|
|
|
.unbind()
|
|
|
|
.mouseenter(function() { editLink.css("visibility", "visible"); })
|
|
|
|
.mouseleave(function() { editLink.css("visibility", "hidden"); });
|
2010-02-09 21:04:43 +01:00
|
|
|
|
2010-04-08 22:18:38 +02:00
|
|
|
if (!cell || ("v" in cell && cell.v === null)) {
|
2010-03-05 09:11:48 +01:00
|
|
|
$('<span>').html(" ").appendTo(divContent);
|
2010-03-01 01:21:13 +01:00
|
|
|
} else if ("e" in cell) {
|
|
|
|
$('<span>').addClass("data-table-error").text(cell.e).appendTo(divContent);
|
2010-04-08 22:16:08 +02:00
|
|
|
} else if (!("r" in cell) || !cell.r) {
|
2010-04-26 01:43:53 +02:00
|
|
|
if (typeof cell.v !== "string") {
|
2010-09-29 02:16:17 +02:00
|
|
|
if (typeof cell.v == "number") {
|
|
|
|
divContent.addClass("data-table-cell-content-numeric");
|
|
|
|
}
|
2010-05-27 06:48:48 +02:00
|
|
|
$('<span>')
|
|
|
|
.addClass("data-table-value-nonstring")
|
|
|
|
.text(cell.v)
|
|
|
|
.appendTo(divContent);
|
|
|
|
} else if (URL.looksLikeUrl(cell.v)) {
|
|
|
|
$('<a>')
|
|
|
|
.text(cell.v)
|
|
|
|
.attr("href", cell.v)
|
|
|
|
.attr("target", "_blank")
|
|
|
|
.appendTo(divContent);
|
|
|
|
} else {
|
|
|
|
$('<span>')
|
|
|
|
.text(cell.v)
|
|
|
|
.appendTo(divContent);
|
2010-04-26 01:43:53 +02:00
|
|
|
}
|
2010-02-09 20:23:11 +01:00
|
|
|
} else {
|
|
|
|
var r = cell.r;
|
2010-06-26 07:34:54 +02:00
|
|
|
var service = (r.service) ? ReconciliationManager.getServiceFromUrl(r.service) : null;
|
|
|
|
|
2010-02-09 20:23:11 +01:00
|
|
|
if (r.j == "new") {
|
2010-03-05 09:11:48 +01:00
|
|
|
$('<span>').text(cell.v + " (new topic) ").appendTo(divContent);
|
2010-02-09 21:04:43 +01:00
|
|
|
|
2010-03-16 22:01:27 +01:00
|
|
|
$('<a href="javascript:{}"></a>')
|
|
|
|
.text("re\u2011match")
|
2010-02-09 21:04:43 +01:00
|
|
|
.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-04-09 03:00:44 +02:00
|
|
|
} else if (r.j == "matched" && "m" in r && r.m !== null) {
|
2010-02-09 20:23:11 +01:00
|
|
|
var match = cell.r.m;
|
2010-06-26 07:34:54 +02:00
|
|
|
var a = $('<a></a>')
|
2010-03-05 09:11:48 +01:00
|
|
|
.text(match.name)
|
2010-02-09 20:23:11 +01:00
|
|
|
.attr("target", "_blank")
|
2010-02-10 19:54:53 +01:00
|
|
|
.appendTo(divContent);
|
2010-02-09 21:04:43 +01:00
|
|
|
|
2010-07-01 04:29:27 +02:00
|
|
|
if (service && (service.view) && (service.view.url)) {
|
|
|
|
a.attr("href", service.view.url.replace("{{id}}", match.id));
|
|
|
|
} else if (ReconciliationManager.isFreebaseId(r.identifierSpace)) {
|
|
|
|
a.attr("href", "http://www.freebase.com/view" + match.id);
|
2010-06-26 07:34:54 +02:00
|
|
|
}
|
|
|
|
|
2010-02-10 19:54:53 +01:00
|
|
|
$('<span> </span>').appendTo(divContent);
|
2010-03-05 09:11:48 +01:00
|
|
|
$('<a href="javascript:{}"></a>')
|
2010-03-16 22:01:27 +01:00
|
|
|
.text("re\u2011match")
|
2010-02-09 21:04:43 +01:00
|
|
|
.addClass("data-table-recon-action")
|
2010-03-05 09:11:48 +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-03-05 09:11:48 +01:00
|
|
|
$('<span>').text(cell.v).appendTo(divContent);
|
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);
|
|
|
|
});
|
|
|
|
|
2010-06-26 07:34:54 +02:00
|
|
|
var a = $('<a></a>')
|
2010-02-23 21:20:14 +01:00
|
|
|
.addClass("data-table-recon-topic")
|
|
|
|
.attr("target", "_blank")
|
|
|
|
.text(candidate.name)
|
2010-06-26 07:34:54 +02:00
|
|
|
.appendTo(li);
|
|
|
|
|
2010-07-01 04:29:27 +02:00
|
|
|
if ((service) && (service.view) && (service.view.url)) {
|
|
|
|
a.attr("href", service.view.url.replace("{{id}}", candidate.id));
|
|
|
|
} else if (ReconciliationManager.isFreebaseId(r.identifierSpace)) {
|
|
|
|
a.attr("href", "http://www.freebase.com/view" + candidate.id);
|
|
|
|
}
|
2010-06-26 07:34:54 +02:00
|
|
|
|
2010-07-01 04:29:27 +02:00
|
|
|
var preview = null;
|
|
|
|
if ((service) && (service.preview)) {
|
|
|
|
preview = service.preview;
|
|
|
|
} else if (ReconciliationManager.isFreebaseId(r.identifierSpace)) {
|
|
|
|
preview = DataTableCellUI.topicBlockPreview;
|
|
|
|
}
|
|
|
|
if (preview) {
|
|
|
|
a.click(function(evt) {
|
|
|
|
if (!evt.metaKey && !evt.ctrlKey) {
|
|
|
|
self._previewCandidateTopic(candidate, this, preview);
|
|
|
|
evt.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2010-06-26 07:34:54 +02:00
|
|
|
}
|
2010-02-23 21:20:14 +01:00
|
|
|
|
2010-04-29 00:53:13 +02:00
|
|
|
var score;
|
|
|
|
if (candidate.score < 1) {
|
|
|
|
score = Math.round(candidate.score * 1000) / 1000;
|
|
|
|
} else {
|
2010-05-05 02:26:26 +02:00
|
|
|
score = Math.round(candidate.score);
|
2010-04-29 00:53:13 +02:00
|
|
|
}
|
|
|
|
$('<span></span>').addClass("data-table-recon-score").text("(" + score + ")").appendTo(li);
|
2010-02-23 21:20:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
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-07-01 04:29:27 +02:00
|
|
|
var suggestOptions;
|
|
|
|
var addSuggest = false;
|
|
|
|
if ((service) && (service.suggest) && (service.suggest.entity)) {
|
|
|
|
suggestOptions = service.suggest.entity;
|
|
|
|
addSuggest = true;
|
|
|
|
} else if (ReconciliationManager.isFreebaseId(r.identifierSpace)) {
|
|
|
|
addSuggest = true;
|
|
|
|
}
|
2010-06-27 05:31:56 +02:00
|
|
|
|
2010-07-01 04:29:27 +02:00
|
|
|
if (addSuggest) {
|
|
|
|
$('<a href="javascript:{}"></a>')
|
|
|
|
.addClass("data-table-recon-search")
|
|
|
|
.click(function(evt) {
|
|
|
|
self._searchForMatch(suggestOptions);
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
.text("search for match")
|
|
|
|
.appendTo($('<div>').appendTo(divContent));
|
2010-06-27 05:31:56 +02:00
|
|
|
}
|
2010-02-23 21:20:14 +01:00
|
|
|
}
|
2010-02-09 20:23:11 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-05 09:11:48 +01:00
|
|
|
|
2010-04-08 21:52:23 +02:00
|
|
|
divContent.appendTo(this._td);
|
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-06-30 19:20:59 +02:00
|
|
|
this._doJudgmentForSimilarCells("new", {}, { shareNewTopics: true }, true);
|
2010-02-22 02:28:13 +01:00
|
|
|
};
|
|
|
|
|
2010-02-22 21:25:45 +01:00
|
|
|
DataTableCellUI.prototype._doMatchTopicToOneCell = function(candidate) {
|
2010-06-30 19:20:59 +02:00
|
|
|
this._doJudgment("matched", {}, {
|
|
|
|
id : candidate.id,
|
|
|
|
name: candidate.name,
|
2010-02-22 21:25:45 +01:00
|
|
|
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) {
|
2010-06-30 19:20:59 +02:00
|
|
|
this._doJudgmentForSimilarCells("matched", {}, {
|
|
|
|
id : candidate.id,
|
|
|
|
name: candidate.name,
|
2010-02-22 21:25:45 +01:00
|
|
|
score: candidate.score,
|
|
|
|
types: candidate.types.join(",")
|
2010-02-27 00:33:16 +01:00
|
|
|
}, true);
|
2010-02-22 02:28:13 +01:00
|
|
|
};
|
|
|
|
|
2010-06-30 19:20:59 +02:00
|
|
|
DataTableCellUI.prototype._doJudgment = function(judgment, params, bodyParams) {
|
|
|
|
this._postProcessOneCell(
|
|
|
|
"recon-judge-one-cell",
|
|
|
|
params || {},
|
|
|
|
$.extend(bodyParams || {}, {
|
|
|
|
row: this._rowIndex,
|
|
|
|
cell: this._cellIndex,
|
|
|
|
judgment: judgment,
|
|
|
|
identifierSpace: (this._cell.r) ? this._cell.r.identifierSpace : null,
|
|
|
|
schemaSpace: (this._cell.r) ? this._cell.r.schemaSpace : null
|
|
|
|
}),
|
|
|
|
true
|
|
|
|
);
|
2010-02-20 01:47:08 +01:00
|
|
|
};
|
|
|
|
|
2010-06-30 19:20:59 +02:00
|
|
|
DataTableCellUI.prototype._doJudgmentForSimilarCells = function(judgment, params, bodyParams) {
|
|
|
|
this._postProcessSeveralCells(
|
|
|
|
"recon-judge-similar-cells",
|
|
|
|
params || {},
|
|
|
|
$.extend(bodyParams || {}, {
|
2010-09-23 00:55:28 +02:00
|
|
|
columnName: Refine.cellIndexToColumn(this._cellIndex).name,
|
2010-06-30 19:20:59 +02:00
|
|
|
similarValue: this._cell.v,
|
|
|
|
judgment: judgment,
|
|
|
|
identifierSpace: (this._cell.r) ? this._cell.r.identifierSpace : null,
|
|
|
|
schemaSpace: (this._cell.r) ? this._cell.r.schemaSpace : null
|
|
|
|
}),
|
|
|
|
true
|
|
|
|
);
|
2010-02-22 02:28:13 +01:00
|
|
|
};
|
|
|
|
|
2010-06-27 05:31:56 +02:00
|
|
|
DataTableCellUI.prototype._searchForMatch = function(suggestOptions) {
|
2010-02-20 01:47:08 +01:00
|
|
|
var self = this;
|
2010-08-09 01:49:31 +02:00
|
|
|
var frame = $(DOM.loadHTML("core", "scripts/views/data-table/cell-recon-search-for-match.html"));
|
|
|
|
var elmts = DOM.bind(frame);
|
|
|
|
elmts.cellTextSpan.text(this._cell.v);
|
2010-02-22 02:28:13 +01:00
|
|
|
|
2010-03-17 23:42:59 +01:00
|
|
|
var match = null;
|
|
|
|
var commit = function() {
|
2010-04-09 03:00:44 +02:00
|
|
|
if (match !== null) {
|
2010-06-27 05:31:56 +02:00
|
|
|
var params = {
|
|
|
|
judgment: "matched",
|
|
|
|
id: match.id,
|
|
|
|
name: match.name,
|
|
|
|
types: $.map(match.type, function(elmt) {
|
|
|
|
return typeof elmt == "string" ? elmt : elmt.id;
|
|
|
|
}).join(",")
|
2010-02-22 02:28:13 +01:00
|
|
|
};
|
2010-04-07 20:23:07 +02:00
|
|
|
|
2010-06-27 05:31:56 +02:00
|
|
|
if (elmts.checkSimilar[0].checked) {
|
|
|
|
params.similarValue = self._cell.v;
|
2010-09-23 00:55:28 +02:00
|
|
|
params.columnName = Refine.cellIndexToColumn(self._cellIndex).name;
|
2010-04-07 20:23:07 +02:00
|
|
|
|
2010-06-30 19:20:59 +02:00
|
|
|
self._postProcessSeveralCells("recon-judge-similar-cells", {}, params, true);
|
2010-06-27 05:31:56 +02:00
|
|
|
} else {
|
|
|
|
params.row = self._rowIndex;
|
|
|
|
params.cell = self._cellIndex;
|
2010-04-07 20:23:07 +02:00
|
|
|
|
2010-06-30 19:20:59 +02:00
|
|
|
self._postProcessOneCell("recon-judge-one-cell", {}, params, true);
|
2010-06-27 05:31:56 +02:00
|
|
|
}
|
2010-04-07 20:23:07 +02:00
|
|
|
|
2010-06-27 05:31:56 +02:00
|
|
|
DialogSystem.dismissUntil(level - 1);
|
2010-02-22 02:28:13 +01:00
|
|
|
}
|
2010-03-17 23:42:59 +01:00
|
|
|
};
|
2010-02-22 02:28:13 +01:00
|
|
|
|
2010-08-09 01:49:31 +02:00
|
|
|
elmts.okButton.click(commit);
|
|
|
|
elmts.cancelButton.click(function() { DialogSystem.dismissUntil(level - 1); });
|
2010-02-20 01:47:08 +01:00
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
2010-03-17 23:42:59 +01:00
|
|
|
|
|
|
|
elmts.input
|
|
|
|
.attr("value", this._cell.v)
|
2010-08-09 01:49:31 +02:00
|
|
|
.suggest(suggestOptions || { all_types: true })
|
2010-03-17 23:42:59 +01:00
|
|
|
.bind("fb-select", function(e, data) {
|
|
|
|
match = data;
|
|
|
|
commit();
|
|
|
|
})
|
|
|
|
.focus()
|
|
|
|
.data("suggest").textchange();
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
2010-06-30 19:20:59 +02:00
|
|
|
DataTableCellUI.prototype._postProcessOneCell = function(command, params, bodyParams, columnStatsChanged) {
|
2010-02-09 21:04:43 +01:00
|
|
|
var self = this;
|
2010-02-26 22:56:41 +01:00
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postCoreProcess(
|
2010-02-26 22:56:41 +01:00
|
|
|
command,
|
|
|
|
params,
|
2010-06-30 19:20:59 +02:00
|
|
|
bodyParams,
|
2010-02-27 00:33:16 +01:00
|
|
|
{ columnStatsChanged: columnStatsChanged },
|
2010-02-26 22:56:41 +01:00
|
|
|
{
|
|
|
|
onDone: function(o) {
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.preparePool(o.pool);
|
2010-04-23 21:39:12 +02:00
|
|
|
if (o.cell.r) {
|
|
|
|
o.cell.r = o.pool.recons[o.cell.r];
|
|
|
|
}
|
|
|
|
|
2010-03-05 02:42:21 +01:00
|
|
|
self._cell = o.cell;
|
2010-04-11 23:54:56 +02:00
|
|
|
self._dataTableView._updateCell(self._rowIndex, self._cellIndex, self._cell);
|
2010-02-09 21:04:43 +01:00
|
|
|
self._render();
|
|
|
|
}
|
|
|
|
}
|
2010-02-26 22:56:41 +01:00
|
|
|
);
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
2010-06-30 19:20:59 +02:00
|
|
|
DataTableCellUI.prototype._postProcessSeveralCells = function(command, params, bodyParams, columnStatsChanged) {
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postCoreProcess(
|
2010-02-26 22:56:41 +01:00
|
|
|
command,
|
|
|
|
params,
|
2010-06-30 19:20:59 +02:00
|
|
|
bodyParams,
|
2010-02-27 00:33:16 +01:00
|
|
|
{ cellsChanged: true, columnStatsChanged: columnStatsChanged }
|
2010-02-09 21:04:43 +01:00
|
|
|
);
|
|
|
|
};
|
2010-02-09 21:36:47 +01:00
|
|
|
|
2010-06-26 07:34:54 +02:00
|
|
|
DataTableCellUI.topicBlockPreview = {
|
|
|
|
url: 'http://www.freebase.com/widget/topic{{id}}?mode=content&blocks=[{"block":"full_info"},{"block":"article_props"}]',
|
2010-04-29 01:51:38 +02:00
|
|
|
width: 430,
|
|
|
|
height: 300
|
|
|
|
};
|
|
|
|
|
2010-06-26 07:34:54 +02:00
|
|
|
DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt, preview) {
|
2010-04-29 01:51:38 +02:00
|
|
|
var self = this;
|
|
|
|
var id = candidate.id;
|
2010-06-26 07:34:54 +02:00
|
|
|
var url = preview.url.replace("{{id}}", id);
|
|
|
|
|
|
|
|
var fakeMenu = MenuSystem.createMenu();
|
|
|
|
fakeMenu
|
|
|
|
.width(preview.width)
|
|
|
|
.css("background", "none")
|
|
|
|
.css("border", "none")
|
2010-08-09 01:49:31 +02:00
|
|
|
.html(DOM.loadHTML("core", "scripts/views/data-table/cell-recon-preview-popup-header.html"));
|
2010-06-26 07:34:54 +02:00
|
|
|
|
|
|
|
var iframe = $('<iframe></iframe>')
|
|
|
|
.addClass("data-table-topic-popup-iframe")
|
|
|
|
.width(preview.width)
|
|
|
|
.height(preview.height)
|
|
|
|
.attr("src", url)
|
|
|
|
.appendTo(fakeMenu);
|
|
|
|
|
|
|
|
MenuSystem.showMenu(fakeMenu, function(){});
|
|
|
|
MenuSystem.positionMenuLeftRight(fakeMenu, $(elmt));
|
|
|
|
|
|
|
|
var elmts = DOM.bind(fakeMenu);
|
|
|
|
elmts.matchButton.click(function() {
|
|
|
|
self._doMatchTopicToOneCell(candidate);
|
|
|
|
MenuSystem.dismissAll();
|
|
|
|
});
|
|
|
|
elmts.matchSimilarButton.click(function() {
|
|
|
|
self._doMatchTopicToSimilarCells(candidate);
|
|
|
|
MenuSystem.dismissAll();
|
|
|
|
});
|
2010-02-09 21:36:47 +01:00
|
|
|
};
|
2010-03-05 09:11:48 +01:00
|
|
|
|
|
|
|
DataTableCellUI.prototype._startEdit = function(elmt) {
|
|
|
|
self = this;
|
|
|
|
|
2010-04-08 22:18:38 +02:00
|
|
|
var originalContent = !this._cell || ("v" in this._cell && this._cell.v === null) ? "" : this._cell.v;
|
2010-03-07 01:25:00 +01:00
|
|
|
|
2010-03-08 07:30:47 +01:00
|
|
|
var menu = MenuSystem.createMenu().addClass("data-table-cell-editor").width("400px");
|
2010-08-09 01:49:31 +02:00
|
|
|
menu.html(DOM.loadHTML("core", "scripts/views/data-table/cell-editor.html"));
|
2010-03-05 09:11:48 +01:00
|
|
|
var elmts = DOM.bind(menu);
|
|
|
|
|
|
|
|
MenuSystem.showMenu(menu, function(){});
|
2010-03-05 20:28:35 +01:00
|
|
|
MenuSystem.positionMenuLeftRight(menu, $(this._td));
|
2010-03-05 09:11:48 +01:00
|
|
|
|
|
|
|
var commit = function() {
|
2010-03-07 01:25:00 +01:00
|
|
|
var type = elmts.typeSelect[0].value;
|
|
|
|
var applyOthers = elmts.applyOthersCheckbox[0].checked;
|
|
|
|
|
2010-03-05 09:11:48 +01:00
|
|
|
var text = elmts.textarea[0].value;
|
|
|
|
var value = text;
|
|
|
|
|
|
|
|
if (type == "number") {
|
|
|
|
value = parseFloat(text);
|
|
|
|
if (isNaN(value)) {
|
|
|
|
alert("Not a valid number.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (type == "boolean") {
|
|
|
|
value = ("true" == text);
|
|
|
|
} else if (type == "date") {
|
|
|
|
value = Date.parse(text);
|
2010-04-08 22:16:08 +02:00
|
|
|
if (!value) {
|
2010-03-05 09:11:48 +01:00
|
|
|
alert("Not a valid date.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
value = value.toString("yyyy-MM-ddTHH:mm:ssZ");
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuSystem.dismissAll();
|
|
|
|
|
2010-03-07 01:25:00 +01:00
|
|
|
if (applyOthers) {
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postCoreProcess(
|
2010-03-07 01:25:00 +01:00
|
|
|
"mass-edit",
|
|
|
|
{},
|
|
|
|
{
|
2010-09-23 00:55:28 +02:00
|
|
|
columnName: Refine.cellIndexToColumn(self._cellIndex).name,
|
2010-03-07 01:25:00 +01:00
|
|
|
expression: "value",
|
|
|
|
edits: JSON.stringify([{
|
|
|
|
from: [ originalContent ],
|
|
|
|
to: value,
|
|
|
|
type: type
|
|
|
|
}])
|
|
|
|
},
|
|
|
|
{ cellsChanged: true }
|
|
|
|
);
|
|
|
|
} else {
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postCoreProcess(
|
2010-03-07 01:25:00 +01:00
|
|
|
"edit-one-cell",
|
2010-09-28 06:41:05 +02:00
|
|
|
{},
|
2010-03-07 01:25:00 +01:00
|
|
|
{
|
|
|
|
row: self._rowIndex,
|
|
|
|
cell: self._cellIndex,
|
|
|
|
value: value,
|
|
|
|
type: type
|
2010-09-28 06:41:05 +02:00
|
|
|
},
|
2010-03-07 01:25:00 +01:00
|
|
|
{},
|
|
|
|
{
|
|
|
|
onDone: function(o) {
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.preparePool(o.pool);
|
2010-04-23 21:39:12 +02:00
|
|
|
if (o.cell.r) {
|
|
|
|
o.cell.r = o.pool.recons[o.cell.r];
|
|
|
|
}
|
|
|
|
|
2010-03-07 01:25:00 +01:00
|
|
|
self._cell = o.cell;
|
2010-04-11 23:54:56 +02:00
|
|
|
self._dataTableView._updateCell(self._rowIndex, self._cellIndex, self._cell);
|
2010-03-07 01:25:00 +01:00
|
|
|
self._render();
|
|
|
|
}
|
2010-03-05 09:11:48 +01:00
|
|
|
}
|
2010-03-07 01:25:00 +01:00
|
|
|
);
|
|
|
|
}
|
2010-03-05 09:11:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
elmts.okButton.click(commit);
|
|
|
|
elmts.textarea
|
2010-03-07 01:25:00 +01:00
|
|
|
.text(originalContent)
|
2010-03-05 09:11:48 +01:00
|
|
|
.keydown(function(evt) {
|
2010-03-08 20:27:37 +01:00
|
|
|
if (!evt.shiftKey) {
|
|
|
|
if (evt.keyCode == 13) {
|
|
|
|
if (evt.ctrlKey) {
|
|
|
|
elmts.applyOthersCheckbox[0].checked = true;
|
|
|
|
}
|
|
|
|
commit();
|
|
|
|
} else if (evt.keyCode == 27) {
|
|
|
|
MenuSystem.dismissAll();
|
2010-03-08 07:30:47 +01:00
|
|
|
}
|
2010-03-05 09:11:48 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.select()
|
|
|
|
.focus();
|
2010-03-08 07:30:47 +01:00
|
|
|
|
|
|
|
elmts.cancelButton.click(function() {
|
|
|
|
MenuSystem.dismissAll();
|
|
|
|
});
|
2010-03-05 09:11:48 +01:00
|
|
|
};
|