RdfSchemaAlignmentDialog.UINode = function(dialog, node, table, options) { this._dialog = dialog; this._node = node; this._options = options; 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._renderTypes(); this._expanded = options.expanded; if (this._isExpandable()) { this._showExpandable(); } }; RdfSchemaAlignmentDialog.UINode.prototype._renderMain = function() { $(this._tdMain).empty(); var self = this; var type_html = !this._isExpandable()? '' : '' + '' + '' + '' + '' + '' + '' + '
 
' + '
' + 'add rdf:type' + '
' + '
' + '' + ''; var html = $( '' + '' + '' + '' + type_html + '
' + '
' ).appendTo(this._tdMain) ; var elmts = DOM.bind(html); this._tdNodeLabel = elmts.nodeLabel; if(elmts.addRdfTypeLink){ var typesTable = $('
')[0]; if(self._node.rdfTypes && self._node.rdfTypes.length>0){ var func = function(i){ return function(){ self._removeRdfType(i); self._renderMain(); }; }; for(var i=0;i').attr("title", "remove type").attr("src", "images/close.png").css("cursor", "pointer").click( func(i) ); $(tr).append($('').append(img)); $(tr).append($('').text(self._getTypeName(self._node.rdfTypes[i]))); } elmts.rdfTypesTd.html(typesTable); }else{ elmts.rdfTypesTr.remove(); } elmts.addRdfTypeLink.click(function(evt){ evt.preventDefault(); self._addRdfType(evt.target); }); } var a = $('') .addClass("schema-alignment-node-tag") .appendTo(this._tdNodeLabel) .click(function(evt) { self._showNodeConfigDialog(); }); if (this._node.nodeType == "cell-as-resource" || this._node.nodeType == "cell-as-literal") { if(this._node.columnIndex===-1){ $('') .text('Row Number') .addClass("schema-alignment-node-column") .prependTo(a); }else{ if ("columnName" in this._node) { a.html(" cell"); $('') .text(this._node.columnName) .addClass("schema-alignment-node-column") .prependTo(a); } else { a.html(this._options.mustBeCellTopic ? "Which column?" : "Configure..."); } } } else if (this._node.nodeType == "resource") { if ("uri" in this._node) { a.html(this._node.uri); } else { a.html("Which Resource?"); } } else if (this._node.nodeType == "literal") { if ("value" in this._node) { a.html(this._node.value); } else { a.html("What value?"); } } else if (this._node.nodeType == "blank") { a.html("(blank) "); }else if (this._node.nodeType == "cell-as-blank") { a.html("(blank) cell"); } //Types /*var aux_table = $('').appendTo($(this._tdMain)); aux_table.append($('').append(td)); this._typesTd = $('').appendTo(aux_table)); this._renderTypes();*/ }; RdfSchemaAlignmentDialog.UINode.prototype._isExpandable = function() { return this._node.nodeType == "cell-as-resource" || this._node.nodeType == "blank" || this._node.nodeType == "resource" || this._node.nodeType == "cell-as-blank" ; }; RdfSchemaAlignmentDialog.UINode.prototype._showExpandable = function() { $(this._tdToggle).show(); $(this._tdDetails).show(); if (this._detailsRendered) { return; } this._detailsRendered = true; this._collapsedDetailDiv = $('
').appendTo(this._tdDetails).addClass("padded").html("..."); this._expandedDetailDiv = $('
').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(); } }; show(); $(this._tdToggle).html(" "); $('') .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"); show(); }); }; RdfSchemaAlignmentDialog.UINode.prototype._renderDetails = function() { var self = this; this._tableLinks = $('
').attr("width", "250").appendTo($('
').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 RdfSchemaAlignmentDialog.UILink( this._dialog, this._node.links[i], this._tableLinks, { expanded: true }, this )); } } var divFooter = $('
').addClass("padded").appendTo(this._expandedDetailDiv); $('') .addClass("action") .text("add property") .appendTo(divFooter) .click(function() { var newLink = { property: null, target: { nodeType: "cell-as-literal" } }; self._linkUIs.push(new RdfSchemaAlignmentDialog.UILink( self._dialog, newLink, self._tableLinks, { expanded: true, mustBeCellTopic: false }, self )); }); }; RdfSchemaAlignmentDialog.UINode.prototype._showNodeConfigDialog = function(){ var self = this; var frame = DialogSystem.createDialog(); frame.width("800px"); var header = $('
').addClass("dialog-header").text("RDF Node").appendTo(frame); var body = $('
').addClass("dialog-body").appendTo(frame); var footer = $('
').addClass("dialog-footer").appendTo(frame); /*-------------------------------------------------- * Body *-------------------------------------------------- */ var literalTypeSelectHtml = '' + '' + '' + //'' + //'' + //'' + ''; var html = $( '' + '' + '' + '' + '' + '
' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + ' Set to Cell in Column' + '
' + '
' + '' + '' + '' + '' + '' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
The cell\'s content is used ...
as a resource
URI:
preview/edit
as a literal value
Literal type
Language (for text)
as a blank node
* relative URIs will be resolved against base URI
' + '
' + '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + ' Use a constant resource' + '
' + '
URI:
' + '
' + ' Use a constant literal value' + '
' + '
Value
Value type
Language
' + '
' + ' Generate a blank node (shared between all rows)' + '
' + '
' + '
' ).appendTo(body); var elmts = DOM.bind(html); var tableColumns = $('
') .attr("cellspacing", "5") .attr("cellpadding", "0") .appendTo(elmts.divColumns)[0]; var makeColumnChoice = function(column, columnIndex) { var tr = tableColumns.insertRow(tableColumns.rows.length); var radio = $('') .attr("type", "radio") //.attr("value", column.name) .attr("value",columnIndex) .attr("name", "schema-align-node-dialog-column") .appendTo(tr.insertCell(0)) .click(function() { elmts.radioNodeTypeCellAs[0].checked = true; }); if ((!("columnName" in self._node) || !self._node.columnName) && columnIndex === -1) { radio.attr("checked", "true"); } else if (column.name == self._node.columnName) { radio.attr("checked", "true"); } var td = tr.insertCell(1); if(columnIndex===-1){ $(td).addClass('highlighted'); } $('').text(column.name).appendTo(td); }; //Add Row Number makeColumnChoice({name:'Row Number'},-1); var columns = theProject.columnModel.columns; for (var i = 0; i < columns.length; i++) { makeColumnChoice(columns[i], i); } elmts.cellAsResourceUriInput.attr("disabled","disabled"); /* elmts.previewCellUri.add(elmts.radioNodeTypeCellAsResource[0]) .bind("click", function() { alert("shifit"); elmts.radioNodeTypeCellAs[0].checked=true; elmts.radioNodeTypeCellAsResource[0].checked = true; });*/ elmts.cellAsLiteralTypeSelect.add(elmts.radioNodeTypeCellAsLiteral[0]) .bind("focus", function() { elmts.radioNodeTypeCellAs[0].checked=true; elmts.radioNodeTypeCellAsLiteral[0].checked = true; }); elmts.cellAsLiteralLanguageInput .bind("focus", function() { elmts.radioNodeTypeCellAs[0].checked=true; elmts.radioNodeTypeCellAsLiteral[0].checked = true; }); elmts.radioNodeTypeCellAsBlank.add(elmts.radioNodeTypeCellAsResource).add(elmts.radioNodeTypeCellAsLiteral).bind("focus", function() { elmts.radioNodeTypeCellAs[0].checked=true; }); elmts.resourceNodeTypeInput .bind("focus", function() { elmts.radioNodeTypeResource[0].checked = true; }); elmts.literalNodeTypeValueInput .bind("focus", function() { elmts.radioNodeTypeLiteral[0].checked = true; }); elmts.literalNodeTypeValueTypeSelect .bind("focus", function() { elmts.radioNodeTypeLiteral[0].checked = true; }); elmts.literalNodeTypeLanguageInput .bind("focus", function() { elmts.radioNodeTypeLiteral[0].checked = true; }); elmts.resourceNodeTypeInput.add(elmts.literalNodeTypeValueInput[0]).add(elmts.literalNodeTypeValueTypeSelect[0]) .add(elmts.literalNodeTypeLanguageInput[0]).add(elmts.radioNodeTypeBlank[0]).add(elmts.radioNodeTypeResource[0]) .add(elmts.radioNodeTypeLiteral[0]) .bind("focus",function(){ elmts.radioNodeTypeCellAsBlank[0].checked = false; elmts.radioNodeTypeCellAsLiteral[0].checked = false; elmts.radioNodeTypeCellAsResource[0].checked = false; }); // elmts.radioNodeTypeCellAsResource[0].checked = true; // just make sure some subtype is selected var uri_expr = "gel:value.urlify(baseURI)"; if (this._node.nodeType.match(/^cell-as-/)) { elmts.radioNodeTypeCellAs[0].checked = true; if (this._node.nodeType == "cell-as-resource") { elmts.radioNodeTypeCellAsResource[0].checked = true; uri_expr = this._node.uriExpression || uri_expr; } else if (this._node.nodeType == "cell-as-literal") { elmts.radioNodeTypeCellAsLiteral[0].checked = true; $('>option[value=' +this._node.valueType +']',elmts.cellAsLiteralTypeSelect).attr('selected','selected'); } else if (this._node.nodeType == "cell-as-blank") { elmts.radioNodeTypeCellAsBlank[0].checked = true; } } else if (this._node.nodeType == "blank") { elmts.radioNodeTypeBlank[0].checked = true; } else if (this._node.nodeType == "resource") { elmts.radioNodeTypeResource[0].checked = true; if(this._node.uri){ elmts.resourceNodeTypeInput.val(this._node.uri); } } else if (this._node.nodeType == "literal") { elmts.radioNodeTypeLiteral[0].checked = true; if(this._node.value){ elmts.literalNodeTypeValueInput.val(this._node.value); } $('>option[value=' +this._node.valueType +']',elmts.literalNodeTypeValueTypeSelect).attr('selected','selected'); } elmts.cellAsResourceUriInput.val(uri_expr); //preview/edit URI //elmts.cellAsResourceUriInput.attr("disabled","disabled").val('"' + RdfSchemaAlignment._defaultNamespace + '" + value.urlify()'); elmts.previewCellUri.click(function(evt){ evt.preventDefault(); var cellIndex = $("input[name='schema-align-node-dialog-column']:checked")[0].value; var expr = $("input[name='cellAsResourceUri']").val(); self._previewURI(expr,cellIndex,elmts); }); /*-------------------------------------------------- * Footer *-------------------------------------------------- */ var getResultJSON = function() { var node = { nodeType: $("input[name='schema-align-node-dialog-node-type']:checked")[0].value }; if (node.nodeType == "cell-as") { node.nodeType = $("input[name='schema-align-node-dialog-node-subtype']:checked")[0].value; node.columnIndex = parseInt($("input[name='schema-align-node-dialog-column']:checked")[0].value); if(node.columnIndex!==-1){ node.columnName = theProject.columnModel.columns[node.columnIndex].name; }else{ node.isRowNumberCell = true; } if (node.nodeType == "cell-as-resource") { node.uriExpression = elmts.cellAsResourceUriInput[0].value; } else if (node.nodeType == "cell-as-literal") { node.valueType = elmts.cellAsLiteralTypeSelect[0].value; if (node.valueType == "untyped") { var l = elmts.cellAsLiteralLanguageInput[0].value; node.lang = l; } } else if (node.nodeType == "cell-as-blank") { //DO NOTHING } } else if (node.nodeType == "blank") { //DO NOTHING } else if (node.nodeType == "resource") { node.uri = elmts.resourceNodeTypeInput[0].value; if (!node.uri.length) { alert("Please specify the URI to use."); return null; } } else if (node.nodeType == "literal") { node.value = $.trim(elmts.literalNodeTypeValueInput[0].value); if (!node.value.length) { alert("Please specify the value to use."); return null; } node.valueType = elmts.literalNodeTypeValueTypeSelect[0].value; if (node.valueType == "untyped") { node.lang = elmts.literalNodeTypeLanguageInput[0].value; } } return node; }; $('').html("  OK  ").click(function() { var node = getResultJSON(); if(self._node.rdfTypes){ node.rdfTypes = cloneDeep(self._node.rdfTypes); } if (node !== null) { DialogSystem.dismissUntil(level - 1); self._node = node; /*if('columnIndex' in node){ if(node.columnIndex!==-1){ self._node.columnName = theProject.columnModel.columns[node.columnIndex].name; }else{ self._node.isRowNumberCell = true; } }*/ self.render(); //self._dialog.preview(); } }).appendTo(footer); $('').text("Cancel").click(function() { DialogSystem.dismissUntil(level - 1); }).appendTo(footer); var level = DialogSystem.showDialog(frame); }; RdfSchemaAlignmentDialog.UINode.prototype._previewURI = function(expr,cellIndex,elmts){ var self = this; //FIXME cellIndex = cellIndex==='-1'?0:cellIndex; DataTableView.promptExpressionOnVisibleRows( { "cellIndex":cellIndex }, "Custom Facet on column ", expr, function(expression){ expression = expression.substring(4); $("input[name='cellAsResourceUri']").val(expression); elmts.radioNodeTypeCellAs[0].checked=true; elmts.radioNodeTypeCellAsResource[0].checked = true; } ); }; RdfSchemaAlignmentDialog.UINode.prototype.render = function() { this._renderMain(); if (this._isExpandable()) { this._showExpandable(); } else { this._hideExpandable(); } }; RdfSchemaAlignmentDialog.UINode.prototype.removeLink = function(linkUI) { 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; } } }; RdfSchemaAlignmentDialog.UINode.prototype._hideExpandable = function() { $(this._tdToggle).hide(); $(this._tdDetails).hide(); }; RdfSchemaAlignmentDialog.UINode.prototype._addRdfType = function(src){ var self = this; new RdfSchemaAlignmentDialog.RdfResourceDialog(src,'class', function (obj) { self._addNodeRdfType(obj.id,obj.name); }); }; RdfSchemaAlignmentDialog.UINode.prototype._removeRdfType = function(index){ var self = this; self._node.rdfTypes.splice(index,1); }; RdfSchemaAlignmentDialog.UINode.prototype._addNodeRdfType = function(uri,curie){ if(!this._node.rdfTypes){ this._node.rdfTypes = []; } this._node.rdfTypes.push({uri:uri,curie:curie}); this._renderMain(); }; RdfSchemaAlignmentDialog.UINode.prototype._getTypeName = function(t){ if(!t){return '';} if(t.curie !== undefined && t.curie!==''){ return t.curie; }else{ return t.uri; } }; RdfSchemaAlignmentDialog.UINode.prototype.getJSON = function() { var result = null; var getLinks = false; if (this._node.nodeType.match(/^cell-as-/)) { if (!("columnIndex" in this._node || this._node.isRowNumberCell) || this._node.columnIndex===undefined) { return null; } if (this._node.nodeType == "cell-as-resource") { if (!this._node.isRowNumberCell){ result = { nodeType: this._node.nodeType, columnIndex: this._node.columnIndex, uriExpression: this._node.uriExpression, isRowNumberCell: this._node.isRowNumberCell || false, columnName: this._node.columnName // type: "type" in this._node ? cloneDeep(this._node.type) : { "id" : "/common/topic", "name" : "Topic", "cvt" : false } }; }else{ result = { nodeType: this._node.nodeType, columnIndex: this._node.columnIndex, uriExpression: this._node.uriExpression, isRowNumberCell: this._node.isRowNumberCell || false // 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-literal") { result = { nodeType: this._node.nodeType, columnIndex: this._node.columnIndex, valueType: "valueType" in this._node ? this._node.valueType : "untyped", lang: "lang" in this._node ? this._node.lang : "en", columnName: this._node.columnName }; } else if (this._node.nodeType == "cell-as-blank") { result = { nodeType: this._node.nodeType, columnIndex: this._node.columnIndex, columnName: this._node.columnName }; getLinks = true; } } else if (this._node.nodeType == "resource") { result = { nodeType: this._node.nodeType, uri: this._node.uri }; getLinks = true; } else if (this._node.nodeType == "literal") { 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 : "untyped", lang: "lang" in this._node ? this._node.lang : "en" }; } else if (this._node.nodeType == "blank") { result = { nodeType: this._node.nodeType, columnIndex: this._node.columnIndex }; getLinks = true; } if (!result) { return null; } if (getLinks) { var rdfTypes = []; if(this._node.rdfTypes){ for(var i=0;i' + 'URI: (relative URIs will be resolved against base URI)' + '
' + '' + '' //'' ); MenuSystem.showMenu(menu,function(){}); MenuSystem.positionMenuLeftRight(menu, $(elmt)); var elmts = DOM.bind(menu); elmts.newResourceUri.val(defaultVal).focus().select(); elmts.cancelBtn.click(function(){ MenuSystem.dismissAll(); }); elmts.applyBtn.click(function(){ var val = elmts.newResourceUri.val(); if(!val){ alert('Enter URI'); return; } MenuSystem.dismissAll(); if(val.substring(0,1)===':'){ val = val.substring(1); } var obj = { id:val, name:val.match('^http://')?val:':'+val }; onDone(obj); }); }; RdfSchemaAlignmentDialog.RdfResourceDialog = function(elmt,lookFor,onDone,defaultVal){ var menu = MenuSystem.createMenu().width('400px'); menu.html('