')
.addClass("grid-layout layout-tightest")
.appendTo(this._elmts.typeContainer);
var typeTable = $('
').appendTo(typeTableContainer)[0];
var createTypeChoice = function(type, check) {
var typeID = typeof type == "string" ? type : type.id;
var typeName = typeof type == "string" ? type : (type.name || type.id);
var tr = typeTable.insertRow(typeTable.rows.length);
var td0 = tr.insertCell(0);
var td1 = tr.insertCell(1);
td0.width = "1%";
var radio = $('')
.attr("value", typeID)
.attr("typeName", typeName)
.appendTo(td0)
.click(function() {
self._rewirePropertySuggests(this.value);
});
if (check) {
radio.attr("checked", "true");
}
if (typeName == typeID) {
$(td1).html(typeName);
} else {
$(td1).html(
typeName +
' ' +
'' + typeID + '');
}
};
for (var i = 0; i < this._types.length; i++) {
createTypeChoice(this._types[i], i === 0);
}
} else {
$('
')
.addClass("recon-dialog-standard-service-panel-message")
.text("Sorry, we can't suggest any type for your data. Please specify a type yourself below.")
.appendTo(this._elmts.typeContainer);
this._panel
.find('input[name="type-choice"][value=""]')
.attr("checked", "true");
this._panel.typeInput.focus();
}
/*
* Populate properties
*/
var detailTableContainer = $('
')
.addClass("grid-layout layout-tightest")
.appendTo(this._elmts.detailContainer);
var detailTable = $(
'
' +
'
Column
Include?
As Property
' +
'
'
).appendTo(detailTableContainer)[0];
function renderDetailColumn(column) {
var tr = detailTable.insertRow(detailTable.rows.length);
var td0 = tr.insertCell(0);
var td1 = tr.insertCell(1);
var td2 = tr.insertCell(2);
$(td0).html(column.name);
$('')
.attr("columnName", column.name)
.appendTo(td1);
$('')
.attr("columnName", column.name)
.appendTo(td2);
}
var columns = theProject.columnModel.columns;
for (var i = 0; i < columns.length; i++) {
var column = columns[i];
if (column !== this._column) {
renderDetailColumn(column);
}
}
};
ReconStandardServicePanel.prototype._wireEvents = function() {
var self = this;
var input = this._elmts.typeInput.unbind();
if ("suggest" in this._service && "type" in this._service.suggest) {
var suggestOptions = $.extend({}, this._service.suggest.type);
input.suggestT(suggestOptions);
} else if (this._isInFreebaseSchemaSpace()) {
input.suggestT({ type : '/type/type' });
}
input.bind("fb-select", function(e, data) {
self._panel
.find('input[name="type-choice"][value=""]')
.attr("checked", "true");
self._rewirePropertySuggests(data.id);
});
this._rewirePropertySuggests((this._types.length > 0) ? this._types[0] : null);
};
ReconStandardServicePanel.prototype._rewirePropertySuggests = function(type) {
var inputs = this._panel
.find('input[name="property"]')
.unbind();
if ("property" in this._service && "property" in this._service.suggest) {
var suggestOptions = $.extend({}, this._service.suggest.property);
if (type) {
suggestOptions.schema = typeof type == "string" ? type : type.id;
}
inputs.suggestP(suggestOptions);
} else if (this._isInFreebaseSchemaSpace()) {
inputs.suggestP({
type: '/type/property',
schema: (type) ? (typeof type == "string" ? type : type.id) : "/common/topic"
});
}
};
ReconStandardServicePanel.prototype._isInFreebaseIdentifierSpace = function() {
return ReconciliationManager.isFreebaseId(this._service.identifierSpace);
};
ReconStandardServicePanel.prototype._isInFreebaseSchemaSpace = function() {
return ReconciliationManager.isFreebaseId(this._service.schemaSpace);
};
ReconStandardServicePanel.prototype.start = function() {
var self = this;
var type = this._isInFreebaseIdentifierSpace() ?
this._elmts.typeInput.data("data.suggest") :
{
id: this._elmts.typeInput[0].value,
name: this._elmts.typeInput[0].value
};
var choices = this._panel.find('input[name="type-choice"]:checked');
if (choices !== null && choices.length > 0) {
if (choices[0].value == '-') {
type = null;
} else if (choices[0].value != "") {
type = {
id: choices[0].value,
name: choices.attr("typeName")
};
}
}
var columnDetails = [];
$.each(
this._panel.find('input[name="property"]'),
function() {
var property = $(this).data("data.suggest");
if (property && property.id) {
columnDetails.push({
column: this.getAttribute("columnName"),
property: {
id: property.id,
name: property.name
}
});
} else {
var property = $.trim(this.value);
if (property) {
columnDetails.push({
column: this.getAttribute("columnName"),
property: {
id: property,
name: property
}
});
}
}
}
);
Gridworks.postProcess(
"reconcile",
{},
{
columnName: this._column.name,
config: JSON.stringify({
mode: "standard-service",
service: this._service.url,
identifierSpace: this._service.identifierSpace,
schemaSpace: this._service.schemaSpace,
type: (type) ? { id: type.id, name: type.name } : null,
autoMatch: this._elmts.automatchCheck[0].checked,
columnDetails: columnDetails
})
},
{ cellsChanged: true, columnStatsChanged: true }
);
};