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-10-08 03:39:38 +02:00
|
|
|
SchemaAlignmentDialog.UINode = function(dialog, node, table, options) {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._dialog = dialog;
|
|
|
|
this._node = node;
|
|
|
|
this._options = options;
|
|
|
|
|
|
|
|
if ("columnName" in this._node) {
|
|
|
|
this._node.columnNames = [ this._node.columnName ];
|
|
|
|
delete this._node.columnName;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._linkUIs = [];
|
|
|
|
this._detailsRendered = false;
|
|
|
|
|
|
|
|
this._tr = table.insertRow(table.rows.length);
|
|
|
|
this._tdMain = this._tr.insertCell(0);
|
|
|
|
this._tdToggle = this._tr.insertCell(1);
|
|
|
|
this._tdDetails = this._tr.insertCell(2);
|
|
|
|
|
|
|
|
$(this._tdMain).addClass("schema-alignment-node-main").attr("width", "250").addClass("padded");
|
|
|
|
$(this._tdToggle).addClass("schema-alignment-node-toggle").attr("width", "1%").addClass("padded").hide();
|
|
|
|
$(this._tdDetails).addClass("schema-alignment-node-details").attr("width", "90%").hide();
|
|
|
|
|
|
|
|
this._renderMain();
|
|
|
|
|
|
|
|
this._expanded = options.expanded;
|
|
|
|
if (this._isExpandable()) {
|
|
|
|
this._showExpandable();
|
|
|
|
}
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype.dispose = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
// nothing for now
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype.removeLink = function(linkUI) {
|
2011-08-04 22:37:14 +02:00
|
|
|
for (var i = this._linkUIs.length - 1; i >= 0; i--) {
|
|
|
|
if (this._linkUIs[i] === linkUI) {
|
|
|
|
this._linkUIs.splice(i, 1);
|
|
|
|
this._node.links.splice(i, 1);
|
|
|
|
break;
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._isExpandable = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
return this._node.nodeType == "cell-as-topic" ||
|
|
|
|
this._node.nodeType == "anonymous" ||
|
|
|
|
this._node.nodeType == "topic";
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype.render = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._renderMain();
|
|
|
|
if (this._isExpandable()) {
|
|
|
|
this._showExpandable();
|
|
|
|
} else {
|
|
|
|
this._hideExpandable();
|
|
|
|
}
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype.getExpectedType = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
if ("type" in this._node) {
|
|
|
|
return this._node.type.id;
|
|
|
|
}
|
|
|
|
return null;
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._renderMain = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
$(this._tdMain).empty();
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var a = $('<a href="javascript:{}"></a>')
|
|
|
|
.addClass("schema-alignment-node-tag")
|
|
|
|
.appendTo(this._tdMain)
|
|
|
|
.click(function(evt) {
|
|
|
|
self._showNodeConfigDialog();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this._node.nodeType == "cell-as-topic" ||
|
|
|
|
this._node.nodeType == "cell-as-value" ||
|
|
|
|
this._node.nodeType == "cell-as-key") {
|
|
|
|
|
|
|
|
if ("columnNames" in this._node) {
|
|
|
|
for (var c = 0; c < this._node.columnNames.length; c++) {
|
|
|
|
if (c > 0) {
|
|
|
|
$('<span>').text(", ").appendTo(a);
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
$('<span>')
|
|
|
|
.text(this._node.columnNames[c])
|
|
|
|
.addClass("schema-alignment-node-column")
|
|
|
|
.appendTo(a);
|
|
|
|
}
|
|
|
|
|
2013-06-27 12:03:51 +02:00
|
|
|
$('<span>').text(
|
|
|
|
this._node.columnNames.length > 1 ? " "
|
|
|
|
+ $.i18n._('fb-schema-alignment')["cells"] : " "
|
|
|
|
+ $.i18n._('fb-schema-alignment')["cell"]).appendTo(a);
|
2011-08-04 22:37:14 +02:00
|
|
|
} else {
|
2013-06-27 12:03:51 +02:00
|
|
|
a.html(this._options.mustBeCellTopic ? $.i18n._('fb-schema-alignment')["which-column"] : $.i18n._('fb-schema-alignment')["configure"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
} else if (this._node.nodeType == "topic") {
|
|
|
|
if ("topic" in this._node) {
|
|
|
|
a.html(this._node.topic.name);
|
|
|
|
} else if ("id" in this._node) {
|
|
|
|
a.html(this._node.topic.id);
|
|
|
|
} else {
|
2013-06-27 12:03:51 +02:00
|
|
|
a.html($.i18n._('fb-schema-alignment')["which-topic"]);
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
} else if (this._node.nodeType == "value") {
|
|
|
|
if ("value" in this._node) {
|
|
|
|
a.html(this._node.value);
|
|
|
|
} else {
|
2013-06-27 12:03:51 +02:00
|
|
|
a.html($.i18n._('fb-schema-alignment')["what-value"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
} else if (this._node.nodeType == "anonymous") {
|
2013-06-27 12:03:51 +02:00
|
|
|
a.html("("+$.i18n._('fb-schema-alignment')["anonymous"]+")");
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._showExpandable = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
$(this._tdToggle).show();
|
|
|
|
$(this._tdDetails).show();
|
|
|
|
|
|
|
|
if (this._detailsRendered) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._detailsRendered = true;
|
|
|
|
|
|
|
|
this._collapsedDetailDiv = $('<div></div>').appendTo(this._tdDetails).addClass("padded").html("...");
|
|
|
|
this._expandedDetailDiv = $('<div></div>').appendTo(this._tdDetails).addClass("schema-alignment-detail-container");
|
|
|
|
|
|
|
|
this._renderDetails();
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var show = function() {
|
|
|
|
if (self._expanded) {
|
|
|
|
self._collapsedDetailDiv.hide();
|
|
|
|
self._expandedDetailDiv.show();
|
|
|
|
} else {
|
|
|
|
self._collapsedDetailDiv.show();
|
|
|
|
self._expandedDetailDiv.hide();
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
show();
|
|
|
|
|
|
|
|
$(this._tdToggle).html(" ");
|
|
|
|
$('<img />')
|
|
|
|
.attr("src", this._expanded ? "images/expanded.png" : "images/collapsed.png")
|
|
|
|
.appendTo(this._tdToggle)
|
|
|
|
.click(function() {
|
|
|
|
self._expanded = !self._expanded;
|
|
|
|
|
|
|
|
$(this).attr("src", self._expanded ? "images/expanded.png" : "images/collapsed.png");
|
|
|
|
|
2010-10-08 03:39:38 +02:00
|
|
|
show();
|
2011-08-04 22:37:14 +02:00
|
|
|
});
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._hideExpandable = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
$(this._tdToggle).hide();
|
|
|
|
$(this._tdDetails).hide();
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._renderDetails = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._tableLinks = $('<table></table>').addClass("schema-alignment-table-layout").appendTo(this._expandedDetailDiv)[0];
|
|
|
|
|
|
|
|
if ("links" in this._node && this._node.links !== null) {
|
|
|
|
for (var i = 0; i < this._node.links.length; i++) {
|
|
|
|
this._linkUIs.push(new SchemaAlignmentDialog.UILink(
|
|
|
|
this._dialog,
|
|
|
|
this._node.links[i],
|
|
|
|
this._tableLinks,
|
|
|
|
{ expanded: true },
|
|
|
|
this
|
|
|
|
));
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var divFooter = $('<div></div>').addClass("padded").appendTo(this._expandedDetailDiv);
|
|
|
|
|
|
|
|
$('<a href="javascript:{}"></a>')
|
|
|
|
.addClass("action")
|
2013-06-27 12:03:51 +02:00
|
|
|
.text($.i18n._('fb-schema-alignment')["add-property"])
|
2011-08-04 22:37:14 +02:00
|
|
|
.appendTo(divFooter)
|
|
|
|
.click(function() {
|
|
|
|
var newLink = {
|
|
|
|
property: null,
|
|
|
|
target: {
|
|
|
|
nodeType: "cell-as-value"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
self._linkUIs.push(new SchemaAlignmentDialog.UILink(
|
|
|
|
self._dialog,
|
|
|
|
newLink,
|
|
|
|
self._tableLinks,
|
|
|
|
{
|
|
|
|
expanded: true,
|
|
|
|
mustBeCellTopic: false
|
|
|
|
},
|
|
|
|
self
|
|
|
|
));
|
|
|
|
});
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._showColumnPopupMenu = function(elmt) {
|
2011-08-04 22:37:14 +02:00
|
|
|
self = this;
|
|
|
|
|
|
|
|
var menu = [];
|
|
|
|
|
|
|
|
if (!this._options.mustBeCellTopic) {
|
|
|
|
menu.push({
|
2013-06-27 12:03:51 +02:00
|
|
|
label: $.i18n._('fb-schema-alignment')["anonymous-node"],
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() {
|
|
|
|
self._node.nodeType = "anonymous";
|
|
|
|
self._showExpandable();
|
|
|
|
self._renderMain();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
menu.push({
|
2013-06-27 12:03:51 +02:00
|
|
|
label: $.i18n._('fb-schema-alignment')["freebase-topic"],
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() {
|
|
|
|
self._node.nodeType = "topic";
|
|
|
|
self._hideExpandable();
|
|
|
|
self._renderMain();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
menu.push({
|
2013-06-27 12:03:51 +02:00
|
|
|
label: $.i18n._('fb-schema-alignment')["value"],
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() {
|
|
|
|
self._node.nodeType = "value";
|
|
|
|
self._hideExpandable();
|
|
|
|
self._renderMain();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
menu.push({}); // separator
|
|
|
|
}
|
|
|
|
|
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
var createColumnMenuItem = function(index) {
|
|
|
|
menu.push({
|
|
|
|
label: columns[index].name,
|
|
|
|
click: function() {
|
|
|
|
self._node.nodeType = "cell-as-topic";
|
|
|
|
self._node.columnNames = [ columns[index].name ];
|
|
|
|
self._showExpandable();
|
|
|
|
self._renderMain();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
createColumnMenuItem(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuSystem.createAndShowStandardMenu(menu, elmt);
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype._showNodeConfigDialog = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var frame = DialogSystem.createDialog();
|
|
|
|
|
|
|
|
frame.width("750px");
|
|
|
|
|
2013-06-27 12:03:51 +02:00
|
|
|
var header = $('<div></div>').addClass("dialog-header").text($.i18n._('fb-schema-alignment')["skeleton-node"]).appendTo(frame);
|
2011-08-04 22:37:14 +02:00
|
|
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
|
|
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
|
|
|
|
|
|
|
/*--------------------------------------------------
|
|
|
|
* Body
|
|
|
|
*--------------------------------------------------
|
|
|
|
*/
|
|
|
|
var literalTypeSelectHtml =
|
2013-06-27 12:03:51 +02:00
|
|
|
'<option value="/type/text" checked>'+$.i18n._('fb-schema-alignment')["text"]+'</option>' +
|
|
|
|
'<option value="/type/int">'+$.i18n._('fb-schema-alignment')["int"]+'</option>' +
|
|
|
|
'<option value="/type/float">'+$.i18n._('fb-schema-alignment')["float"]+'</option>' +
|
|
|
|
'<option value="/type/double">'+$.i18n._('fb-schema-alignment')["double"]+'</option>' +
|
|
|
|
'<option value="/type/boolean">'+$.i18n._('fb-schema-alignment')["boolean"]+'</option>' +
|
|
|
|
'<option value="/type/datetime">'+$.i18n._('fb-schema-alignment')["date-time"]+'</option>' +
|
|
|
|
'<option value="/type/rawstring">'+$.i18n._('fb-schema-alignment')["rawstring"]+'</option>';
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var html = $(
|
|
|
|
'<div class="grid-layout layout-looser layout-full"><table>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td>' +
|
|
|
|
'<div class="grid-layout layout-loose"><table>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td>' +
|
|
|
|
'<div class="schema-align-node-dialog-node-type">' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<input type="radio" name="schema-align-node-dialog-node-type" value="cell-as" bind="radioNodeTypeCellAs" /> '+$.i18n._('fb-schema-alignment')["set-to-cell"]+'' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'</div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td>' +
|
|
|
|
'<div class="grid-layout layout-normal"><table>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td><div class="schema-alignment-node-dialog-column-list grid-layout layout-tightest" bind="divColumns"></div></td>' +
|
|
|
|
'<td>' +
|
|
|
|
'<div class="grid-layout layout-tight"><table cols="4">' +
|
|
|
|
'<tr>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td colspan="4">'+$.i18n._('fb-schema-alignment')["cell-content-used"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td><input type="radio" name="schema-align-node-dialog-node-subtype" value="cell-as-topic" bind="radioNodeTypeCellAsTopic" /></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td colspan="3">'+$.i18n._('fb-schema-alignment')["specify-fb-topic"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td colspan="3">'+$.i18n._('fb-schema-alignment')["type-new-topic"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
|
|
|
'<td colspan="3"><input bind="cellAsTopicNodeTypeInput" /></td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td><input type="radio" name="schema-align-node-dialog-node-subtype" value="cell-as-value" bind="radioNodeTypeCellAsValue" /></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td colspan="3">'+$.i18n._('fb-schema-alignment')["literal-value"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td colspan="2">'+$.i18n._('fb-schema-alignment')["literal-type"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'<td colspan="1"><select bind="cellAsValueTypeSelect">' + literalTypeSelectHtml + '</select></td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td colspan="2">'+$.i18n._('fb-schema-alignment')["text-language"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'<td colspan="1"><input bind="cellAsValueLanguageInput" /></td>' +
|
|
|
|
'</tr>' +
|
|
|
|
|
|
|
|
'<tr>' +
|
|
|
|
'<td><input type="radio" name="schema-align-node-dialog-node-subtype" value="cell-as-key" bind="radioNodeTypeCellAsKey" /></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td colspan="3">'+$.i18n._('fb-schema-alignment')["key-namespace"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td colspan="2">'+$.i18n._('fb-schema-alignment')["namespace"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'<td colspan="1"><input bind="cellAsKeyInput" /></td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'</table></div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'</table></div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'</table></div>' +
|
|
|
|
'</td>' +
|
|
|
|
|
|
|
|
'<td>' +
|
|
|
|
'<div class="grid-layout layout-normal"><table>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td colspan="3">' +
|
|
|
|
'<div class="schema-align-node-dialog-node-type">' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<input type="radio" name="schema-align-node-dialog-node-type" value="anonymous" bind="radioNodeTypeAnonymous" /> '+$.i18n._('fb-schema-alignment')["generate-anonymous"]+'' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'</div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td>'+$.i18n._('fb-schema-alignment')["assign-type"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'<td> <input bind="anonymousNodeTypeInput" /></td>' +
|
|
|
|
'</tr>' +
|
|
|
|
|
|
|
|
'<tr>' +
|
|
|
|
'<td colspan="3">' +
|
|
|
|
'<div class="schema-align-node-dialog-node-type">' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<input type="radio" name="schema-align-node-dialog-node-type" value="topic" bind="radioNodeTypeTopic" /> '+$.i18n._('fb-schema-alignment')["use-existing-topic"]+'' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'</div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
|
|
|
'<td>Topic</td>' +
|
|
|
|
'<td><input bind="topicNodeTypeInput" /></td>' +
|
|
|
|
'</tr>' +
|
|
|
|
|
|
|
|
'<tr>' +
|
|
|
|
'<td colspan="3">' +
|
|
|
|
'<div class="schema-align-node-dialog-node-type">' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<input type="radio" name="schema-align-node-dialog-node-type" value="value" bind="radioNodeTypeValue" /> '+$.i18n._('fb-schema-alignment')["use-literal-value"]+
|
2011-08-04 22:37:14 +02:00
|
|
|
'</div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td>'+$.i18n._('fb-schema-alignment')["value"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'<td><input bind="valueNodeTypeValueInput" /></td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td>'+$.i18n._('fb-schema-alignment')["value-type"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'<td><select bind="valueNodeTypeValueTypeSelect">' + literalTypeSelectHtml + '</select></td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td></td>' +
|
2013-06-27 12:03:51 +02:00
|
|
|
'<td>'+$.i18n._('fb-schema-alignment')["language"]+'</td>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'<td><input bind="valueNodeTypeLanguageInput" /></td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'</table></div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>' +
|
|
|
|
'</table></div>'
|
|
|
|
).appendTo(body);
|
|
|
|
|
|
|
|
var elmts = DOM.bind(html);
|
|
|
|
|
|
|
|
var tableColumns = $('<table></table>')
|
|
|
|
.attr("cellspacing", "5")
|
|
|
|
.attr("cellpadding", "0")
|
|
|
|
.appendTo(elmts.divColumns)[0];
|
|
|
|
|
|
|
|
var columnMap = {};
|
|
|
|
if ("columnNames" in self._node) {
|
|
|
|
for (var i = 0; i < self._node.columnNames.length; i++) {
|
|
|
|
columnMap[self._node.columnNames[i]] = true;
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var makeColumnChoice = function(column, columnIndex) {
|
|
|
|
var tr = tableColumns.insertRow(tableColumns.rows.length);
|
|
|
|
|
|
|
|
var radio = $('<input />')
|
|
|
|
.attr("type", "checkbox")
|
|
|
|
.attr("value", column.name)
|
|
|
|
.attr("name", "schema-align-node-dialog-column")
|
|
|
|
.appendTo(tr.insertCell(0))
|
|
|
|
.click(function() {
|
|
|
|
elmts.radioNodeTypeCellAs[0].checked = true;
|
|
|
|
|
|
|
|
if ("reconConfig" in column) {
|
|
|
|
var typeID = column.reconConfig.type.id;
|
|
|
|
var typeName = column.reconConfig.type.name;
|
|
|
|
|
|
|
|
elmts.cellAsTopicNodeTypeInput[0].value = typeName;
|
|
|
|
elmts.cellAsTopicNodeTypeInput.data("data.suggest", { "id" : typeID, "name" : typeName });
|
|
|
|
elmts.radioNodeTypeCellAsTopic[0].checked = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (column.name in columnMap) {
|
2013-09-18 21:38:12 +02:00
|
|
|
radio.prop("checked", true);
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
$('<span></span>').text(column.name).appendTo(tr.insertCell(1));
|
|
|
|
};
|
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
makeColumnChoice(columns[i], i);
|
|
|
|
}
|
|
|
|
|
|
|
|
elmts.anonymousNodeTypeInput
|
|
|
|
.bind("focus", function() { elmts.radioNodeTypeAnonymous[0].checked = true; })
|
2012-10-12 20:39:05 +02:00
|
|
|
.suggestT({ filter : "(all type:/type/type)" });
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
elmts.topicNodeTypeInput
|
|
|
|
.bind("focus", function() { elmts.radioNodeTypeTopic[0].checked = true; })
|
|
|
|
.suggest({});
|
|
|
|
|
|
|
|
elmts.valueNodeTypeValueInput
|
|
|
|
.bind("focus", function() { elmts.radioNodeTypeValue[0].checked = true; });
|
|
|
|
elmts.valueNodeTypeValueTypeSelect
|
|
|
|
.bind("focus", function() { elmts.radioNodeTypeValue[0].checked = true; });
|
|
|
|
elmts.valueNodeTypeLanguageInput
|
|
|
|
.bind("focus", function() { elmts.radioNodeTypeValue[0].checked = true; })
|
2012-10-12 20:39:05 +02:00
|
|
|
.suggest({ filter : "(all type:/type/lang)" });
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
elmts.cellAsTopicNodeTypeInput
|
|
|
|
.bind("focus", function() {
|
|
|
|
elmts.radioNodeTypeCellAs[0].checked = true;
|
|
|
|
elmts.radioNodeTypeCellAsTopic[0].checked = true;
|
|
|
|
})
|
2012-10-12 20:39:05 +02:00
|
|
|
.suggestT({ filter : "(all type:/type/type)" });
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
elmts.cellAsValueTypeSelect
|
|
|
|
.bind("focus", function() {
|
|
|
|
elmts.radioNodeTypeCellAs[0].checked = true;
|
|
|
|
elmts.radioNodeTypeCellAsValue[0].checked = true;
|
|
|
|
});
|
|
|
|
elmts.cellAsValueLanguageInput
|
|
|
|
.bind("focus", function() {
|
|
|
|
elmts.radioNodeTypeCellAs[0].checked = true;
|
|
|
|
elmts.radioNodeTypeCellAsValue[0].checked = true;
|
|
|
|
})
|
2012-10-12 20:39:05 +02:00
|
|
|
.suggest({ filter : "(all type:/type/lang)" });
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
elmts.cellAsKeyInput
|
|
|
|
.bind("focus", function() {
|
|
|
|
elmts.radioNodeTypeCellAs[0].checked = true;
|
|
|
|
elmts.radioNodeTypeCellAsKey[0].checked = true;
|
|
|
|
})
|
2012-10-12 20:39:05 +02:00
|
|
|
.suggest({ filter : "(all type:/type/namespace)" });
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
elmts.radioNodeTypeCellAsTopic[0].checked = true; // just make sure some subtype is selected
|
|
|
|
if (this._node.nodeType.match(/^cell-as-/)) {
|
|
|
|
elmts.radioNodeTypeCellAs[0].checked = true;
|
|
|
|
if (this._node.nodeType == "cell-as-topic") {
|
|
|
|
elmts.radioNodeTypeCellAsTopic[0].checked = true;
|
|
|
|
} else if (this._node.nodeType == "cell-as-value") {
|
|
|
|
elmts.radioNodeTypeCellAsValue[0].checked = true;
|
|
|
|
} else if (this._node.nodeType == "cell-as-key") {
|
|
|
|
elmts.radioNodeTypeCellAsKey[0].checked = true;
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
} else if (this._node.nodeType == "anonymous") {
|
|
|
|
elmts.radioNodeTypeAnonymous[0].checked = true;
|
|
|
|
} else if (this._node.nodeType == "topic") {
|
|
|
|
elmts.radioNodeTypeTopic[0].checked = true;
|
|
|
|
} else if (this._node.nodeType == "value") {
|
|
|
|
elmts.radioNodeTypeValue[0].checked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("type" in this._node) {
|
|
|
|
elmts.anonymousNodeTypeInput[0].value = this._node.type.name;
|
|
|
|
elmts.anonymousNodeTypeInput.data("data.suggest", this._node.type);
|
|
|
|
|
|
|
|
elmts.cellAsTopicNodeTypeInput[0].value = this._node.type.name;
|
|
|
|
elmts.cellAsTopicNodeTypeInput.data("data.suggest", this._node.type);
|
|
|
|
}
|
|
|
|
if ("topic" in this._node) {
|
|
|
|
elmts.topicNodeTypeInput[0].value = this._node.topic.name;
|
|
|
|
elmts.topicNodeTypeInput.data("data.suggest", this._node.topic);
|
|
|
|
}
|
|
|
|
if ("namespace" in this._node) {
|
|
|
|
elmts.cellAsKeyInput[0].value = this._node.namespace.name;
|
|
|
|
elmts.cellAsKeyInput.data("data.suggest", this._node.namespace);
|
|
|
|
}
|
|
|
|
if ("lang" in this._node) {
|
|
|
|
elmts.valueNodeTypeLanguageInput[0].value = this._node.lang;
|
|
|
|
elmts.valueNodeTypeLanguageInput.data("data.suggest", { id: this._node.lang });
|
|
|
|
|
|
|
|
elmts.cellAsValueLanguageInput[0].value = this._node.lang;
|
|
|
|
elmts.cellAsValueLanguageInput.data("data.suggest", { id: this._node.lang });
|
|
|
|
}
|
|
|
|
if ("valueType" in this._node) {
|
|
|
|
elmts.valueNodeTypeValueTypeSelect[0].value = this._node.valueType;
|
|
|
|
elmts.cellAsValueTypeSelect[0].value = this._node.valueType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------------------------------
|
|
|
|
* Footer
|
|
|
|
*--------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
var getResultJSON = function() {
|
|
|
|
var node = {
|
|
|
|
nodeType: $("input[name='schema-align-node-dialog-node-type']:checked")[0].value
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
2011-08-04 22:37:14 +02:00
|
|
|
if (node.nodeType == "cell-as") {
|
|
|
|
node.nodeType = $("input[name='schema-align-node-dialog-node-subtype']:checked")[0].value;
|
|
|
|
node.columnNames = $("input[name='schema-align-node-dialog-column']:checked").map(function() {
|
|
|
|
return this.getAttribute("value");
|
|
|
|
}).get();
|
2010-10-08 03:39:38 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
if (node.columnNames.length == 0) {
|
2013-06-27 12:03:51 +02:00
|
|
|
alert($.i18n._('fb-schema-alignment')["column-warning"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.nodeType == "cell-as-topic") {
|
|
|
|
var t = elmts.cellAsTopicNodeTypeInput.data("data.suggest");
|
|
|
|
if (!(t)) {
|
2013-06-27 12:03:51 +02:00
|
|
|
alert($.i18n._('fb-schema-alignment')["new-node-warning"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
elmts.cellAsTopicNodeTypeInput.focus();
|
|
|
|
return null;
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
node.type = {
|
|
|
|
id: t.id,
|
|
|
|
name: t.name
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
2011-08-04 22:37:14 +02:00
|
|
|
} else if (node.nodeType == "cell-as-value") {
|
|
|
|
node.valueType = elmts.cellAsValueTypeSelect[0].value;
|
|
|
|
|
|
|
|
if (node.valueType == "/type/text") {
|
|
|
|
var l = elmts.cellAsValueLanguageInput.data("data.suggest");
|
|
|
|
node.lang = (l) ? l.id : "/lang/en";
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
} else if (node.nodeType == "cell-as-key") {
|
|
|
|
var t = elmts.cellAsKeyInput.data("data.suggest");
|
|
|
|
if (!(t)) {
|
2013-06-27 12:03:51 +02:00
|
|
|
alert($.i18n._('fb-schema-alignment')["namespace-warning"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
return null;
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
node.namespace = {
|
|
|
|
id: t.id,
|
|
|
|
name: t.name
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
} else if (node.nodeType == "anonymous") {
|
|
|
|
var t = elmts.anonymousNodeTypeInput.data("data.suggest");
|
|
|
|
if (!(t)) {
|
2013-06-27 12:03:51 +02:00
|
|
|
alert($.i18n._('fb-schema-alignment')["anonymous-node-warning"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
node.type = {
|
|
|
|
id: t.id,
|
|
|
|
name: t.name
|
|
|
|
};
|
|
|
|
} else if (node.nodeType == "topic") {
|
|
|
|
var t = elmts.topicNodeTypeInput.data("data.suggest");
|
|
|
|
if (!(t)) {
|
2013-06-27 12:03:51 +02:00
|
|
|
alert($.i18n._('fb-schema-alignment')["specify-topic-warning"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
node.topic = {
|
|
|
|
id: t.id,
|
|
|
|
name: t.name
|
|
|
|
};
|
|
|
|
} else if (node.nodeType == "value") {
|
|
|
|
node.value = $.trim(elmts.valueNodeTypeValueInput[0].value);
|
|
|
|
if (!node.value.length) {
|
2013-06-27 12:03:51 +02:00
|
|
|
alert($.i18n._('fb-schema-alignment')["specify-value-warning"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
node.valueType = elmts.valueNodeTypeValueTypeSelect[0].value;
|
|
|
|
|
|
|
|
if (node.valueType == "/type/text") {
|
|
|
|
var l = elmts.valueNodeTypeLanguageInput.data("data.suggest");
|
|
|
|
node.lang = (l) ? l.id : "/lang/en";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
};
|
|
|
|
|
|
|
|
$('<button class="button"></button>').html(" OK ").click(function() {
|
|
|
|
var node = getResultJSON();
|
|
|
|
if (node !== null) {
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
|
|
|
|
self._node = node;
|
|
|
|
self.render();
|
|
|
|
self._dialog.preview();
|
|
|
|
}
|
|
|
|
}).appendTo(footer);
|
|
|
|
|
2013-06-27 12:03:51 +02:00
|
|
|
$('<button class="button"></button>').text($.i18n._('fb-buttons')["cancel"]).click(function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
}).appendTo(footer);
|
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.UINode.prototype.getJSON = function() {
|
|
|
|
var result = null;
|
|
|
|
var getLinks = false;
|
|
|
|
|
|
|
|
if (this._node.nodeType.match(/^cell-as-/)) {
|
|
|
|
if (!("columnNames" in this._node) || !this._node.columnNames) {
|
|
|
|
return null;
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
if (this._node.nodeType == "cell-as-topic") {
|
|
|
|
result = {
|
|
|
|
nodeType: this._node.nodeType,
|
|
|
|
columnNames: this._node.columnNames,
|
|
|
|
type: "type" in this._node ? cloneDeep(this._node.type) : { "id" : "/common/topic", "name" : "Topic", "cvt" : false }
|
|
|
|
};
|
|
|
|
getLinks = true;
|
|
|
|
} else if (this._node.nodeType == "cell-as-value") {
|
|
|
|
result = {
|
|
|
|
nodeType: this._node.nodeType,
|
|
|
|
columnNames: this._node.columnNames,
|
|
|
|
valueType: "valueType" in this._node ? this._node.valueType : "/type/text",
|
|
|
|
lang: "lang" in this._node ? this._node.lang : "/lang/en"
|
|
|
|
};
|
|
|
|
} else if (this._node.nodeType == "cell-as-key") {
|
|
|
|
if (!("namespace" in this._node) || !this._node.namespace) {
|
2010-10-08 03:39:38 +02:00
|
|
|
return null;
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
result = {
|
|
|
|
nodeType: this._node.nodeType,
|
|
|
|
columnNames: this._node.columnNames,
|
|
|
|
namespace: cloneDeep(this._node.namespace)
|
|
|
|
};
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
} else if (this._node.nodeType == "topic") {
|
|
|
|
if (!("topic" in this._node) || !this._node.topic) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
result = {
|
|
|
|
nodeType: this._node.nodeType,
|
|
|
|
topic: cloneDeep(this._node.topic)
|
|
|
|
};
|
|
|
|
getLinks = true;
|
|
|
|
} else if (this._node.nodeType == "value") {
|
|
|
|
if (!("value" in this._node) || !this._node.value) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
result = {
|
|
|
|
nodeType: this._node.nodeType,
|
|
|
|
value: this._node.value,
|
|
|
|
valueType: "valueType" in this._node ? this._node.valueType : "/type/text",
|
|
|
|
lang: "lang" in this._node ? this._node.lang : "/lang/en"
|
|
|
|
};
|
|
|
|
} else if (this._node.nodeType == "anonymous") {
|
|
|
|
if (!("type" in this._node) || !this._node.type) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
result = {
|
|
|
|
nodeType: this._node.nodeType,
|
|
|
|
type: cloneDeep(this._node.type)
|
|
|
|
};
|
|
|
|
getLinks = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (getLinks) {
|
|
|
|
var links = [];
|
|
|
|
for (var i = 0; i < this._linkUIs.length; i++) {
|
|
|
|
var link = this._linkUIs[i].getJSON();
|
|
|
|
if (link !== null) {
|
|
|
|
links.push(link);
|
|
|
|
}
|
2010-10-08 03:39:38 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
result.links = links;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|