2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2010-10-20 20:11:15 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2010-10-20 20:11:15 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2010-10-20 20:11:15 +02:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2010-10-20 20:11:15 +02:00
|
|
|
|
2010-02-09 20:23:11 +01:00
|
|
|
function DataTableCellUI(dataTableView, cell, rowIndex, cellIndex, td) {
|
2011-08-04 22:37:14 +02:00
|
|
|
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
|
|
|
|
2019-02-27 11:32:57 +01:00
|
|
|
DataTableCellUI.previewMatchedCells = true;
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: "command/core/get-preference?" + $.param({
|
|
|
|
name: "cell-ui.previewMatchedCells"
|
|
|
|
}),
|
|
|
|
success: function(data) {
|
|
|
|
if (data.value && data.value == "false") {
|
|
|
|
DataTableCellUI.previewMatchedCells = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
dataType: "json",
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
2010-02-09 20:23:11 +01:00
|
|
|
DataTableCellUI.prototype._render = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var cell = this._cell;
|
|
|
|
|
|
|
|
var divContent = $('<div/>')
|
|
|
|
.addClass("data-table-cell-content");
|
|
|
|
|
|
|
|
var editLink = $('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass("data-table-cell-edit")
|
2018-11-21 18:30:00 +01:00
|
|
|
.attr("title", $.i18n('core-views/edit-cell'))
|
2011-08-04 22:37:14 +02:00
|
|
|
.appendTo(divContent)
|
|
|
|
.click(function() { self._startEdit(this); });
|
|
|
|
|
|
|
|
$(this._td).empty()
|
|
|
|
.unbind()
|
|
|
|
.mouseenter(function() { editLink.css("visibility", "visible"); })
|
|
|
|
.mouseleave(function() { editLink.css("visibility", "hidden"); });
|
|
|
|
|
|
|
|
if (!cell || ("v" in cell && cell.v === null)) {
|
2018-03-17 17:55:46 +01:00
|
|
|
$('<span>').addClass("data-table-null").html('null').appendTo(divContent);
|
2011-08-04 22:37:14 +02:00
|
|
|
} else if ("e" in cell) {
|
|
|
|
$('<span>').addClass("data-table-error").text(cell.e).appendTo(divContent);
|
|
|
|
} else if (!("r" in cell) || !cell.r) {
|
2011-09-20 03:36:47 +02:00
|
|
|
if (typeof cell.v !== "string" || "t" in cell) {
|
2011-08-04 22:37:14 +02:00
|
|
|
if (typeof cell.v == "number") {
|
|
|
|
divContent.addClass("data-table-cell-content-numeric");
|
|
|
|
}
|
|
|
|
$('<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);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var r = cell.r;
|
|
|
|
var service = (r.service) ? ReconciliationManager.getServiceFromUrl(r.service) : null;
|
|
|
|
|
|
|
|
if (r.j == "new") {
|
|
|
|
$('<span>').text(cell.v).appendTo(divContent);
|
|
|
|
$('<span>').addClass("data-table-recon-new").text("new").appendTo(divContent);
|
|
|
|
|
|
|
|
$('<a href="javascript:{}"></a>')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('core-views/choose-match'))
|
2011-08-04 22:37:14 +02:00
|
|
|
.addClass("data-table-recon-action")
|
|
|
|
.appendTo(divContent).click(function(evt) {
|
|
|
|
self._doRematch();
|
|
|
|
});
|
|
|
|
} else if (r.j == "matched" && "m" in r && r.m !== null) {
|
|
|
|
var match = cell.r.m;
|
|
|
|
var a = $('<a></a>')
|
|
|
|
.text(match.name)
|
|
|
|
.attr("target", "_blank")
|
|
|
|
.appendTo(divContent);
|
|
|
|
|
|
|
|
if (service && (service.view) && (service.view.url)) {
|
2013-08-06 19:35:34 +02:00
|
|
|
a.attr("href", encodeURI(service.view.url.replace("{{id}}", match.id)));
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
|
2019-02-27 11:32:57 +01:00
|
|
|
if (DataTableCellUI.previewMatchedCells) {
|
|
|
|
self._previewOnHover(service, match, a, a, false);
|
|
|
|
}
|
2019-02-19 17:46:24 +01:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
$('<span> </span>').appendTo(divContent);
|
|
|
|
$('<a href="javascript:{}"></a>')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('core-views/choose-match'))
|
2011-08-04 22:37:14 +02:00
|
|
|
.addClass("data-table-recon-action")
|
|
|
|
.appendTo(divContent)
|
|
|
|
.click(function(evt) {
|
|
|
|
self._doRematch();
|
|
|
|
});
|
2010-02-09 20:23:11 +01:00
|
|
|
} else {
|
2011-08-04 22:37:14 +02:00
|
|
|
$('<span>').text(cell.v).appendTo(divContent);
|
|
|
|
|
|
|
|
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);
|
2019-02-19 17:46:24 +01:00
|
|
|
var liSpan = $('<span></span>').appendTo(li);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
$('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass("data-table-recon-match-similar")
|
2018-11-21 18:30:00 +01:00
|
|
|
.attr("title", $.i18n('core-views/match-all-cells'))
|
2019-02-19 17:46:24 +01:00
|
|
|
.appendTo(liSpan).click(function(evt) {
|
2011-08-04 22:37:14 +02:00
|
|
|
self._doMatchTopicToSimilarCells(candidate);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass("data-table-recon-match")
|
2018-11-21 18:30:00 +01:00
|
|
|
.attr("title", $.i18n('core-views/match-this-cell') )
|
2019-02-19 17:46:24 +01:00
|
|
|
.appendTo(liSpan).click(function(evt) {
|
2011-08-04 22:37:14 +02:00
|
|
|
self._doMatchTopicToOneCell(candidate);
|
|
|
|
});
|
|
|
|
|
2010-06-26 07:34:54 +02:00
|
|
|
var a = $('<a></a>')
|
2011-08-04 22:37:14 +02:00
|
|
|
.addClass("data-table-recon-topic")
|
|
|
|
.attr("target", "_blank")
|
2015-10-16 20:47:31 +02:00
|
|
|
.text(_.unescape(candidate.name)) // TODO: only use of _.unescape - consolidate
|
2019-02-19 17:46:24 +01:00
|
|
|
.appendTo(liSpan);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
if ((service) && (service.view) && (service.view.url)) {
|
2013-08-06 19:35:34 +02:00
|
|
|
a.attr("href", encodeURI(service.view.url.replace("{{id}}", candidate.id)));
|
2010-06-26 07:34:54 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2019-02-23 10:18:18 +01:00
|
|
|
self._previewOnHover(service, candidate, liSpan.parent(), liSpan, true);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var score;
|
|
|
|
if (candidate.score < 1) {
|
|
|
|
score = Math.round(candidate.score * 1000) / 1000;
|
|
|
|
} else {
|
|
|
|
score = Math.round(candidate.score);
|
|
|
|
}
|
2019-02-19 17:46:24 +01:00
|
|
|
$('<span></span>').addClass("data-table-recon-score").text("(" + score + ")").appendTo(liSpan);
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < candidates.length; i++) {
|
|
|
|
renderCandidate(candidates[i], i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var liNew = $('<div></div>').addClass("data-table-recon-candidate").appendTo(ul);
|
|
|
|
$('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass("data-table-recon-match-similar")
|
2018-11-21 18:30:00 +01:00
|
|
|
.attr("title", $.i18n('core-views/create-topic-cells'))
|
2011-08-04 22:37:14 +02:00
|
|
|
.appendTo(liNew).click(function(evt) {
|
|
|
|
self._doMatchNewTopicToSimilarCells();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass("data-table-recon-match")
|
2018-11-21 18:30:00 +01:00
|
|
|
.attr("title", $.i18n('core-views/create-topic-cell'))
|
2011-08-04 22:37:14 +02:00
|
|
|
.appendTo(liNew).click(function(evt) {
|
|
|
|
self._doMatchNewTopicToOneCell();
|
|
|
|
});
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<span>').text($.i18n('core-views/create-topic')).appendTo(liNew);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var suggestOptions;
|
|
|
|
var addSuggest = false;
|
|
|
|
if ((service) && (service.suggest) && (service.suggest.entity)) {
|
|
|
|
suggestOptions = service.suggest.entity;
|
2019-02-19 15:37:11 +01:00
|
|
|
if ('view' in service && 'url' in service.view && !('view_url' in suggestOptions)) {
|
|
|
|
suggestOptions.view_url = service.view.url;
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
addSuggest = true;
|
2010-02-09 20:23:11 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var extraChoices = $('<div>').addClass("data-table-recon-extra").appendTo(divContent);
|
|
|
|
if (addSuggest) {
|
|
|
|
$('<a href="javascript:{}"></a>')
|
|
|
|
.click(function(evt) {
|
|
|
|
self._searchForMatch(suggestOptions);
|
|
|
|
return false;
|
|
|
|
})
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('core-views/search-match'))
|
2011-08-04 22:37:14 +02:00
|
|
|
.appendTo(extraChoices);
|
|
|
|
}
|
|
|
|
}
|
2010-02-09 20:23:11 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
divContent.appendTo(this._td);
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
DataTableCellUI.prototype._doRematch = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._doJudgment("none");
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
2010-02-22 02:28:13 +01:00
|
|
|
DataTableCellUI.prototype._doMatchNewTopicToOneCell = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._doJudgment("new");
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
2010-10-22 09:25:27 +02:00
|
|
|
DataTableCellUI.prototype._doClearOneCell = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._postProcessOneCell(
|
|
|
|
"recon-clear-one-cell",
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
row: this._rowIndex,
|
|
|
|
cell: this._cellIndex
|
|
|
|
},
|
|
|
|
true
|
|
|
|
);
|
2010-10-22 09:25:27 +02:00
|
|
|
};
|
|
|
|
|
2010-02-22 02:28:13 +01:00
|
|
|
DataTableCellUI.prototype._doMatchNewTopicToSimilarCells = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._doJudgmentForSimilarCells("new", {}, { shareNewTopics: true }, true);
|
2010-02-22 02:28:13 +01:00
|
|
|
};
|
|
|
|
|
2010-10-22 09:25:27 +02:00
|
|
|
DataTableCellUI.prototype._doClearSimilarCells = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._postProcessSeveralCells(
|
|
|
|
"recon-clear-similar-cells",
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
columnName: Refine.cellIndexToColumn(this._cellIndex).name,
|
|
|
|
similarValue: this._cell.v
|
|
|
|
},
|
|
|
|
true
|
|
|
|
);
|
2010-10-22 09:25:27 +02:00
|
|
|
};
|
|
|
|
|
2010-02-22 21:25:45 +01:00
|
|
|
DataTableCellUI.prototype._doMatchTopicToOneCell = function(candidate) {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._doJudgment("matched", {}, {
|
|
|
|
id : candidate.id,
|
|
|
|
name: 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) {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._doJudgmentForSimilarCells("matched", {}, {
|
|
|
|
id : candidate.id,
|
|
|
|
name: candidate.name,
|
|
|
|
score: candidate.score,
|
|
|
|
types: candidate.types.join(",")
|
|
|
|
}, true);
|
2010-02-22 02:28:13 +01:00
|
|
|
};
|
|
|
|
|
2010-06-30 19:20:59 +02:00
|
|
|
DataTableCellUI.prototype._doJudgment = function(judgment, params, bodyParams) {
|
2011-08-04 22:37:14 +02:00
|
|
|
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) {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._postProcessSeveralCells(
|
|
|
|
"recon-judge-similar-cells",
|
|
|
|
params || {},
|
|
|
|
$.extend(bodyParams || {}, {
|
|
|
|
columnName: Refine.cellIndexToColumn(this._cellIndex).name,
|
|
|
|
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) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var frame = $(DOM.loadHTML("core", "scripts/views/data-table/cell-recon-search-for-match.html"));
|
|
|
|
var elmts = DOM.bind(frame);
|
2013-07-09 15:57:25 +02:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
elmts.dialogHeader.html($.i18n('core-views/search-match'));
|
|
|
|
elmts.or_views_searchFor.html($.i18n('core-views/search-for'));
|
|
|
|
elmts.or_views_matchOther.html($.i18n('core-views/match-other'));
|
|
|
|
elmts.or_views_matchThis.html($.i18n('core-views/match-this'));
|
|
|
|
elmts.okButton.html($.i18n('core-buttons/match'));
|
|
|
|
elmts.newButton.html($.i18n('core-buttons/new-topic'));
|
|
|
|
elmts.clearButton.html($.i18n('core-buttons/dont-reconcile'));
|
|
|
|
elmts.cancelButton.html($.i18n('core-buttons/cancel'));
|
2010-04-07 20:23:07 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
var level = DialogSystem.showDialog(frame);
|
|
|
|
var dismiss = function() {
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
elmts.cellTextSpan.text(this._cell.v);
|
|
|
|
|
|
|
|
var match = null;
|
|
|
|
var commit = function() {
|
|
|
|
if (match !== null) {
|
2012-11-20 20:03:35 +01:00
|
|
|
var notable_types = null;
|
|
|
|
if (match.notable) {
|
|
|
|
notable_types = $.map(match.notable, function(elmt) {
|
|
|
|
return typeof elmt == "string" ? elmt : elmt.id;
|
|
|
|
}).join(",");
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
var params = {
|
|
|
|
judgment: "matched",
|
|
|
|
id: match.id,
|
|
|
|
name: match.name,
|
2012-11-20 20:03:35 +01:00
|
|
|
types: notable_types
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (elmts.radioSimilar[0].checked) {
|
|
|
|
params.similarValue = self._cell.v;
|
|
|
|
params.columnName = Refine.cellIndexToColumn(self._cellIndex).name;
|
|
|
|
|
|
|
|
self._postProcessSeveralCells("recon-judge-similar-cells", {}, params, true);
|
|
|
|
} else {
|
|
|
|
params.row = self._rowIndex;
|
|
|
|
params.cell = self._cellIndex;
|
|
|
|
|
|
|
|
self._postProcessOneCell("recon-judge-one-cell", {}, params, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
dismiss();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var commitNew = function() {
|
|
|
|
if (elmts.radioSimilar[0].checked) {
|
|
|
|
self._doMatchNewTopicToSimilarCells();
|
|
|
|
} else {
|
|
|
|
self._doMatchNewTopicToOneCell();
|
|
|
|
}
|
|
|
|
dismiss();
|
|
|
|
};
|
|
|
|
var commitClear = function() {
|
|
|
|
if (elmts.radioSimilar[0].checked) {
|
|
|
|
self._doClearSimilarCells();
|
|
|
|
} else {
|
|
|
|
self._doClearOneCell();
|
|
|
|
}
|
|
|
|
dismiss();
|
|
|
|
};
|
|
|
|
|
|
|
|
elmts.okButton.click(commit);
|
|
|
|
elmts.newButton.click(commitNew);
|
|
|
|
elmts.clearButton.click(commitClear);
|
|
|
|
elmts.cancelButton.click(dismiss);
|
|
|
|
|
2012-11-20 21:15:52 +01:00
|
|
|
var suggestOptions2 = $.extend({ align: "left" }, suggestOptions
|
|
|
|
|| { all_types: true, // FIXME: all_types isn't documented for Suggest. Is it still implemented?
|
2013-03-03 15:17:48 +01:00
|
|
|
filter: "(not (any type:/common/document type:/type/content type:/common/resource))" }); // blacklist documents and images
|
2012-10-12 20:39:05 +02:00
|
|
|
if (suggestOptions2.service_url) {
|
|
|
|
// Old style suggest API
|
|
|
|
suggestOptions2.key = null;
|
|
|
|
suggestOptions2.query_param_name = "prefix";
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
elmts.input
|
|
|
|
.attr("value", this._cell.v)
|
|
|
|
.suggest(suggestOptions2)
|
|
|
|
.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) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
2010-02-26 22:56:41 +01:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
Refine.postCoreProcess(
|
|
|
|
command,
|
|
|
|
params,
|
|
|
|
bodyParams,
|
|
|
|
{ columnStatsChanged: columnStatsChanged },
|
|
|
|
{
|
|
|
|
onDone: function(o) {
|
|
|
|
if (o.cell.r) {
|
|
|
|
o.cell.r = o.pool.recons[o.cell.r];
|
2010-02-09 21:04:43 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
self._cell = o.cell;
|
|
|
|
self._dataTableView._updateCell(self._rowIndex, self._cellIndex, self._cell);
|
|
|
|
self._render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
|
|
|
|
2010-06-30 19:20:59 +02:00
|
|
|
DataTableCellUI.prototype._postProcessSeveralCells = function(command, params, bodyParams, columnStatsChanged) {
|
2011-08-04 22:37:14 +02:00
|
|
|
Refine.postCoreProcess(
|
|
|
|
command,
|
|
|
|
params,
|
|
|
|
bodyParams,
|
|
|
|
{ cellsChanged: true, columnStatsChanged: columnStatsChanged }
|
|
|
|
);
|
2010-02-09 21:04:43 +01:00
|
|
|
};
|
2010-02-09 21:36:47 +01:00
|
|
|
|
2019-02-19 17:56:07 +01:00
|
|
|
DataTableCellUI.prototype._previewCandidateTopic = function(candidate, elmt, preview, showActions) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var id = candidate.id;
|
2019-02-19 17:46:24 +01:00
|
|
|
var fakeMenu = $('<div></div>')
|
|
|
|
.addClass("menu-container");
|
2011-08-04 22:37:14 +02:00
|
|
|
fakeMenu
|
2013-10-15 17:37:31 +02:00
|
|
|
.width(preview.width?preview.width:414)
|
2019-02-19 17:56:07 +01:00
|
|
|
.addClass('data-table-topic-popup');
|
|
|
|
if (showActions) {
|
|
|
|
fakeMenu
|
|
|
|
.html(DOM.loadHTML("core", "scripts/views/data-table/cell-recon-preview-popup-header.html"));
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2013-07-26 16:55:42 +02:00
|
|
|
if (preview && preview.url) { // Service has a preview URL associated with it
|
2014-07-31 18:58:27 +02:00
|
|
|
var url = encodeURI(preview.url.replace("{{id}}", id));
|
2013-07-26 16:55:42 +02:00
|
|
|
var iframe = $('<iframe></iframe>')
|
|
|
|
.width(preview.width)
|
|
|
|
.height(preview.height)
|
|
|
|
.attr("src", url)
|
|
|
|
.appendTo(fakeMenu);
|
2019-02-19 17:46:24 +01:00
|
|
|
} else {
|
|
|
|
return; // no preview service available
|
2013-07-26 16:55:42 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
MenuSystem.positionMenuLeftRight(fakeMenu, $(elmt));
|
2019-02-19 17:46:24 +01:00
|
|
|
fakeMenu.appendTo(elmt);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2019-02-19 17:46:24 +01:00
|
|
|
var dismissMenu = function() {
|
|
|
|
fakeMenu.remove();
|
|
|
|
fakeMenu.unbind();
|
|
|
|
};
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2019-02-19 17:56:07 +01:00
|
|
|
if (showActions) {
|
|
|
|
var elmts = DOM.bind(fakeMenu);
|
|
|
|
|
|
|
|
elmts.matchButton.html($.i18n('core-views/match-cell'));
|
|
|
|
elmts.matchSimilarButton.html($.i18n('core-views/match-identical'));
|
|
|
|
elmts.cancelButton.html($.i18n('core-buttons/cancel'));
|
|
|
|
|
|
|
|
elmts.matchButton.click(function() {
|
|
|
|
self._doMatchTopicToOneCell(candidate);
|
|
|
|
dismissMenu();
|
|
|
|
});
|
|
|
|
elmts.matchSimilarButton.click(function() {
|
|
|
|
self._doMatchTopicToSimilarCells(candidate);
|
|
|
|
dismissMenu();
|
|
|
|
});
|
|
|
|
elmts.cancelButton.click(function() {
|
|
|
|
dismissMenu();
|
|
|
|
});
|
|
|
|
}
|
2019-02-19 17:46:24 +01:00
|
|
|
return dismissMenu;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up a preview widget to appear when hovering the given DOM element.
|
|
|
|
*/
|
2019-02-23 10:18:18 +01:00
|
|
|
DataTableCellUI.prototype._previewOnHover = function(service, candidate, hoverElement, coreElement, showActions) {
|
2019-02-19 17:46:24 +01:00
|
|
|
var self = this;
|
|
|
|
var preview = null;
|
|
|
|
if ((service) && (service.preview)) {
|
|
|
|
preview = service.preview;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preview) {
|
|
|
|
var dismissCallback = null;
|
2019-02-23 10:18:18 +01:00
|
|
|
hoverElement.hover(function(evt) {
|
2019-02-19 17:46:24 +01:00
|
|
|
if (!evt.metaKey && !evt.ctrlKey) {
|
2019-02-23 10:18:18 +01:00
|
|
|
dismissCallback = self._previewCandidateTopic(candidate, coreElement, preview, showActions);
|
2019-02-19 17:46:24 +01:00
|
|
|
evt.preventDefault();
|
|
|
|
}
|
|
|
|
}, function(evt) {
|
|
|
|
if(dismissCallback !== null) {
|
|
|
|
dismissCallback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-02-09 21:36:47 +01:00
|
|
|
};
|
2010-03-05 09:11:48 +01:00
|
|
|
|
|
|
|
DataTableCellUI.prototype._startEdit = function(elmt) {
|
2011-08-04 22:37:14 +02:00
|
|
|
self = this;
|
|
|
|
|
|
|
|
var originalContent = !this._cell || ("v" in this._cell && this._cell.v === null) ? "" : this._cell.v;
|
|
|
|
|
|
|
|
var menu = MenuSystem.createMenu().addClass("data-table-cell-editor").width("400px");
|
|
|
|
menu.html(DOM.loadHTML("core", "scripts/views/data-table/cell-editor.html"));
|
|
|
|
var elmts = DOM.bind(menu);
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
elmts.or_views_dataType.html($.i18n('core-views/data-type'));
|
|
|
|
elmts.or_views_text.html($.i18n('core-views/text'));
|
|
|
|
elmts.or_views_number.html($.i18n('core-views/number'));
|
|
|
|
elmts.or_views_boolean.html($.i18n('core-views/boolean'));
|
|
|
|
elmts.or_views_date.html($.i18n('core-views/date'));
|
|
|
|
elmts.okButton.html($.i18n('core-buttons/apply'));
|
|
|
|
elmts.or_views_enter.html($.i18n('core-buttons/enter'));
|
|
|
|
elmts.okallButton.html($.i18n('core-buttons/apply-to-all'));
|
|
|
|
elmts.or_views_ctrlEnter.html($.i18n('core-views/ctrl-enter'));
|
|
|
|
elmts.cancelButton.html($.i18n('core-buttons/cancel'));
|
|
|
|
elmts.or_views_esc.html($.i18n('core-buttons/esc'));
|
2013-07-09 15:57:25 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
MenuSystem.showMenu(menu, function(){});
|
|
|
|
MenuSystem.positionMenuLeftRight(menu, $(this._td));
|
|
|
|
|
|
|
|
var commit = function() {
|
|
|
|
var type = elmts.typeSelect[0].value;
|
|
|
|
|
|
|
|
var applyOthers = 0;
|
|
|
|
if (this === elmts.okallButton[0]) {
|
|
|
|
applyOthers = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
var text = elmts.textarea[0].value;
|
|
|
|
var value = text;
|
|
|
|
|
|
|
|
if (type == "number") {
|
|
|
|
value = parseFloat(text);
|
|
|
|
if (isNaN(value)) {
|
2018-11-21 18:30:00 +01:00
|
|
|
alert($.i18n('core-views/not-valid-number'));
|
2011-08-04 22:37:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (type == "boolean") {
|
|
|
|
value = ("true" == text);
|
|
|
|
} else if (type == "date") {
|
|
|
|
value = Date.parse(text);
|
2011-11-27 21:22:58 +01:00
|
|
|
if (!value) {
|
|
|
|
value = DateTimeUtil.parseIso8601DateTime(text);
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
if (!value) {
|
2018-11-21 18:30:00 +01:00
|
|
|
alert($.i18n('core-views/not-valid-date'));
|
2011-08-04 22:37:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
value = value.toString("yyyy-MM-ddTHH:mm:ssZ");
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuSystem.dismissAll();
|
|
|
|
|
|
|
|
if (applyOthers) {
|
|
|
|
Refine.postCoreProcess(
|
|
|
|
"mass-edit",
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
columnName: Refine.cellIndexToColumn(self._cellIndex).name,
|
|
|
|
expression: "value",
|
|
|
|
edits: JSON.stringify([{
|
|
|
|
from: [ originalContent ],
|
|
|
|
to: value,
|
|
|
|
type: type
|
|
|
|
}])
|
|
|
|
},
|
|
|
|
{ cellsChanged: true }
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
Refine.postCoreProcess(
|
|
|
|
"edit-one-cell",
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
row: self._rowIndex,
|
|
|
|
cell: self._cellIndex,
|
|
|
|
value: value,
|
|
|
|
type: type
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
onDone: function(o) {
|
|
|
|
if (o.cell.r) {
|
|
|
|
o.cell.r = o.pool.recons[o.cell.r];
|
2010-03-05 09:11:48 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
self._cell = o.cell;
|
|
|
|
self._dataTableView._updateCell(self._rowIndex, self._cellIndex, self._cell);
|
|
|
|
self._render();
|
2011-09-02 00:03:10 +02:00
|
|
|
self._dataTableView._adjustDataTables();
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2010-03-05 09:11:48 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
elmts.okButton.click(commit);
|
|
|
|
elmts.okallButton.click(commit);
|
|
|
|
elmts.textarea
|
|
|
|
.text(originalContent)
|
|
|
|
.keydown(function(evt) {
|
|
|
|
if (!evt.shiftKey) {
|
|
|
|
if (evt.keyCode == 13) {
|
|
|
|
if (evt.ctrlKey) {
|
|
|
|
elmts.okallButton.trigger('click');
|
2010-03-07 01:25:00 +01:00
|
|
|
} else {
|
2011-08-04 22:37:14 +02:00
|
|
|
elmts.okButton.trigger('click');
|
2010-03-07 01:25:00 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
} else if (evt.keyCode == 27) {
|
2010-03-08 07:30:47 +01:00
|
|
|
MenuSystem.dismissAll();
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.select()
|
|
|
|
.focus();
|
|
|
|
|
|
|
|
elmts.cancelButton.click(function() {
|
|
|
|
MenuSystem.dismissAll();
|
|
|
|
});
|
2013-02-26 01:45:25 +01:00
|
|
|
};
|