Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial work in Borges, a demo CMS application built with plaza

  • Loading branch information...
commit 8ca588c3c5664fb6b54bbabe66baf512ce4561bf 1 parent b682fad
@antoniogarrote authored
View
15 apps/borges/README
@@ -0,0 +1,15 @@
+# borges
+
+FIXME: write description
+
+## Usage
+
+FIXME: write
+
+## Installation
+
+FIXME: write
+
+## License
+
+FIXME: write
View
8 apps/borges/project.clj
@@ -0,0 +1,8 @@
+(defproject borges "1.0.0-SNAPSHOT"
+ :description "RIA type CMS"
+ :dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
+ [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]]
+ :dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"]
+ [clojure-http-client "1.1.0-SNAPSHOT"]
+ [autodoc "0.7.1"]
+ [lein-clojars "0.5.0-SNAPSHOT"]])
View
221 apps/borges/public/css/plaza-ui.css
@@ -0,0 +1,221 @@
+.plaza-widget{
+ margin: 0;
+ padding: 0;
+ border: 0;
+ outline: 0;
+ font-weight: normal;
+ font-style: normal;
+ font-family: Tahoma, Geneva, arial, sans-serif;
+ vertical-align: baseline;
+ background-color:#eeeeee;
+ border:2px solid #aaaaaa;
+ margin: 5px
+}
+
+.widget-header{
+ background-color: black;
+ font-size: 120%;
+ color: white;
+ padding: 10px
+}
+
+
+/* entity debugger */
+.entity-debugger-widget{
+ padding: 0px;
+ font-size: 70%
+}
+
+.entity-debugger-widget-header{
+ font-size: 120%
+}
+
+.entity-debugger-widget-prop{
+ background: white;
+ border:1px solid #aaaaaa;
+ margin: 3px;
+}
+
+.entity-debugger-widget-prop-alias{
+ padding: 3px;
+ margin-bottom: 3px;
+ background-color: #aaaaaa;
+ font-style: bold
+}
+
+.entity-debugger-widget-prop-uri{
+ padding: 3px
+}
+
+.entity-debugger-widget-prop-val{
+ padding: 3px
+}
+
+/* TripleSpacesBrowser */
+.triple-spaces-browser-widget {
+ font-size: 70%
+}
+
+.triple-space-browser-panel {
+ background: white;
+ border:1px solid #aaaaaa;
+ margin: 3px
+}
+
+.triple-space-browser-panel-header {
+ background: #aaaaaa;
+ padding: 3px
+}
+
+.triple-space-browser-panel-body {
+ text-align: right;
+ padding: 10px
+}
+
+.triple-space-actions {
+ padding: 5px
+}
+
+.triple-space-browser-panel-body input {
+ width: 350px;
+ margin: 5px
+}
+
+.collection-triple-space-actions {
+ padding: 5px
+}
+
+.collection-triple-space-actions input {
+ margin: 3px
+}
+.overline {
+ border-top:1px solid #aaaaaa;
+ font-size: 80%
+}
+
+/* Toolbox */
+.plaza-toolbox-widget {
+ font-size: 70%
+}
+
+.toolbox-legend-fld {
+ width: 350px;
+ margin-left: 20px
+}
+
+.entity-search-fld {
+ width: 450px;
+ margin-right: 20px
+}
+
+.schema-uri-fld {
+ width: 450px;
+ margin-right: 10px;
+}
+
+.inspect-tbox-toolbox-feature div {
+ margin: 5px;
+ margin-top: 20px
+}
+
+.inspect-tbox-toolbox-feature input {
+ margin: 5px
+}
+
+.inspect-tbox-toolbox-feature select {
+ margin: 5px
+}
+
+
+/* TriplesTable */
+.plaza-triples-table-widget {
+ font-size: 70%
+}
+
+.plaza-triples-table-widget table {
+ width: 100%
+}
+
+.plaza-triples-table-widget thead {
+ background-color: #E7EEF6;
+ font-weight: bold
+}
+
+.plaza-triples-table-widget td {
+ background-color: white;
+ padding: 3px
+}
+
+
+/* PlazaUI.Widgets.ToolboxEntityCreatorForm */
+.toolbox-entity-creator-widget {
+ width: 600px;
+ font-size: 70%;
+}
+
+.toolbox-entity-creator-widget-body {
+ text-align: right
+}
+
+.toolbox-entity-creator-widget-body .property input {
+ width: 400px;
+ margin-right: 20px;
+ margin: 5px
+}
+
+.toolbox-entity-creator-widget-body .entity-creator-actions input {
+ margin: 5px
+}
+
+/* PlazaIO.Widgets.PanelListFrame */
+
+.panel-list-widget {
+ font-size: 70%
+}
+
+.panel-list-header {
+
+}
+
+.panel-list-panel {
+ background: white;
+ border: 1px solid #aaaaaa;
+ margin: 3px
+}
+
+.panel-list-panel-header {
+ background: #aaaaaa;
+ padding: 3px
+}
+
+.panel-list-panel-body {
+ text-align: right;
+ padding: 10px
+}
+
+.panel-list-panel-body input {
+ width: 100px;
+ margin: 5px
+}
+
+/* RDFS Class Browser */
+.class-uri-panel-body {
+ text-align: left
+}
+
+.panel-list-panel input {
+ width: 100px
+}
+
+
+/* Multi Entity selector */
+
+.entities-selector-title select {
+ margin-left:5px;
+ margin-right:10px;
+ width:400px;
+}
+
+.entities-selector-title option {
+ padding: 5px
+}
View
1,443 apps/borges/public/js/plaza-ui.js
@@ -0,0 +1,1443 @@
+/**
+ *
+ * Plaza JS UI library
+ * @author Antonio Garrote
+ * @date 26.06.2010
+ *
+ */
+
+PlazaUI = {};
+
+/**
+ * PlazaUI.Utils
+ */
+
+PlazaUI.Utils = function() {
+ return {
+ showDialog: function(title, txt) {
+ var dialog = jQuery("<div title='"+ title +"'><p>" + txt + "</p></div>");
+ jQuery("body").append(dialog);
+ dialog.dialog();
+ },
+
+ center: function(widget) {
+ widget.css("position","absolute");
+ var top = ($(window).height() - widget.height() ) / 2+$(window).scrollTop();
+ if (top < 0) {
+ top = 20;
+ }
+ widget.css("top", top + "px");
+ widget.css("left", ( $(window).width() - widget.width() ) / 2+$(window).scrollLeft() + "px");
+ },
+
+ generateSetup: function() {
+ var js = "Plaza.setup(\n";
+ js = js + "\t// Schemas\n"
+ for (var i in Plaza.TBox.schemaList) {
+ js = js + '\tPlaza.TBox.registerSchema("'+Plaza.TBox.schemaList[i]+'"),\n'
+ }
+
+ js = js + "\n\t// TripleSpaces\n"
+ for(var spaceId in Plaza.ABox.spacesRegistry) {
+ var space = Plaza.ABox.spacesRegistry[spaceId];
+ var singleResource = Plaza.Services.servicesRegistry[space.singleResource];
+ var collectionResource = Plaza.Services.servicesRegistry[space.collectionResource];
+
+ if(singleResource == null && collectionResource != null) {
+ js = js + '\tPlaza.ABox.TripleSpace.connect("'+spaceId+'", {"collectionResource": "'+collectionResource+'"}),\n'
+ } else if(singleResource != null && collectionResource == null) {
+ js = js + '\tPlaza.ABox.TripleSpace.connect("'+spaceId+'", {"singleResource": "'+singleResource+'"}),\n'
+ } else {
+ js = js + '\tPlaza.ABox.TripleSpace.connect("'+spaceId+'", {"collectionResource": "'+collectionResource+'", "singleResource": "'+singleResource+'"}),\n'
+ }
+ }
+
+ js = js + "\n\tfunction(){\n\t\t//application code here\n\t})";
+
+ return js;
+ }
+ };
+}();
+
+/**
+ * PlazaUI.Base
+ */
+PlazaUI.Base = function(){
+ var base = {
+ build: function() {
+ this.__plz_id = "plz_"+PlazaUI._widgetCounter++;
+ },
+
+ extend: function() {
+ var F = function(){};
+ F.prototype = this;
+ var w = new F();
+ w.build();
+ return w;
+ }
+ };
+
+ return base;
+}();
+
+// Counter for the widgets built
+PlazaUI._widgetCounter = 0;
+
+
+/**
+ * PlazaUI.EntityWidget
+ */
+PlazaUI.EntityWidget = function(){
+ var w = PlazaUI.Base.extend();
+
+ w.build = function() {
+ PlazaUI.Base.build.apply(this,[]);
+
+ this.entity = null;
+ this.connectedTo = null;
+ this.connections = [];
+ this.handlers = {}
+ };
+
+ w.updatedAdapter = function(uri, event, data){
+ var fh = this.handlers["onUpdate"];
+ fh.apply(this,[data]);
+ };
+
+ w.destroyedAdapter = function(uri, event, data){
+ var fh = this.handlers["onDestroy"];
+ fh.apply(this,[data]);
+ this.entity = null;
+ };
+
+ w.setEntity = function(uriOrEntity) {
+ var uri = uriOrEntity;
+ var ent = uriOrEntity;
+
+ if(typeof(uriOrEntity) == "string") {
+ ent = Plaza.ABox.entitiesRegistry[uriOrEntity];
+ } else {
+ uri = ent._uri;
+ }
+
+ if(this.entity != null) {
+ Plaza.ABox.stopObservingEntity(this.entity._uri, Plaza.ABox.EVENTS.UPDATED, this);
+ Plaza.ABox.stopObservingEntity(this.entity._uri, Plaza.ABox.EVENTS.DESTROYED, this);
+ }
+
+ this.entity = ent
+ Plaza.ABox.startObservingEntity(uri, Plaza.ABox.EVENTS.UPDATED, this, this.updatedAdapter);
+ Plaza.ABox.startObservingEntity(uri, Plaza.ABox.EVENTS.DESTROYED, this, this.destroyedAdapter);
+
+ this.updatedAdapter(this.entity._uri, Plaza.ABox.EVENTS.UPDATED, this.entity);
+
+ this.disconnect();
+
+ for(var i in this.connections) {
+ var c = this.connections[i];
+ c.connectionChangeAdapter(this.entity);
+ }
+ };
+
+ w.connectionChangeAdapter = function(entity) {
+ if(this.entity != null) {
+ Plaza.ABox.stopObservingEntity(this.entity._uri, Plaza.ABox.EVENTS.UPDATED, this);
+ Plaza.ABox.stopObservingEntity(this.entity._uri, Plaza.ABox.EVENTS.DESTROYED, this);
+ }
+
+ this.entity = entity;
+ this.updatedAdapter(this.entity._uri, Plaza.ABox.EVENTS.UPDATED, this.entity);
+
+ if(entity != null) {
+ Plaza.ABox.startObservingEntity(entity._uri, Plaza.ABox.EVENTS.UPDATED, this, this.updatedAdapter);
+ Plaza.ABox.startObservingEntity(entity._uri, Plaza.ABox.EVENTS.DESTROYED, this, this.destroyedAdapter);
+ }
+
+ for(var i in this.connections) {
+ var c = this.connections[i];
+ c.connectionChangeAdapter(entity);
+ }
+ };
+
+ w.connect = function(widget) {
+ if(this.entity != null) {
+ Plaza.ABox.stopObservingEntity(this.entity._uri, Plaza.ABox.EVENTS.UPDATED, this);
+ Plaza.ABox.stopObservingEntity(this.entity._uri, Plaza.ABox.EVENTS.DESTROYED, this);
+ }
+
+ this.entity = widget.entity;
+ this.updatedAdapter(this.entity);
+
+ if(this.entity != null) {
+ Plaza.ABox.startObservingEntity(entity._uri, Plaza.ABox.EVENTS.UPDATED, this, this.updatedAdapter);
+ Plaza.ABox.startObservingEntity(entity._uri, Plaza.ABox.EVENTS.DESTROYED, this, this.destroyedAdapter);
+ }
+
+ for(var i in this.connections) {
+ var c = this.connections[i];
+ c.connectionChangeAdapter(entity);
+ }
+
+ this.disconnect();
+
+ this.connectedTo = widget;
+ widget.connections.push(this);
+ };
+
+ w.disconnectConnection = function(otherWidget) {
+ var newConnections = [];
+ for(var i in this.connections) {
+ if(this.connections[i] != otherWidget) {
+ newConnections.push(this.connections[i]);
+ }
+ }
+ this.connections = newConnections;
+ }
+
+ w.disconnect = function() {
+ if(this.connectedTo != null) {
+ this.connectedTo.disconnectConnection(this);
+ }
+ };
+
+ return w;
+}();
+
+
+/**
+ * PlazaUI.SpaceWidget
+ */
+PlazaUI.SpaceWidget = function(){
+ var w = PlazaUI.Base.extend();
+
+ w.build = function() {
+ PlazaUI.Base.build.apply(this,[]);
+
+ this.space = null;
+ this.connectedTo = null;
+ this.connections = [];
+ this.handlers = {}
+ };
+
+ w.createdAdapter = function(spaceId, event, data){
+ var fh = this.handlers["onCreate"];
+ fh.apply(this,[data]);
+ };
+
+ w.updatedAdapter = function(spaceId, event, data){
+ var fh = this.handlers["onUpdate"];
+ fh.apply(this,[data]);
+ };
+
+ w.destroyedAdapter = function(spaceId, event, data){
+ var fh = this.handlers["onDestroy"];
+ fh.apply(this,[data]);
+ this.entity = null;
+ };
+
+ w.setSpace = function(idOrSpace) {
+ var id = idOrSpace;
+ var ent = idOrSpace;
+
+ if(typeof(idOrSpace) == "string") {
+ ent = Plaza.ABox.spacesRegistry[idOrSpace];
+ } else {
+ id = ent.id;
+ }
+
+ if(this.space != null) {
+ Plaza.ABox.stopObservingSpace(this.space.id, Plaza.ABox.EVENTS.CREATED, this);
+ Plaza.ABox.stopObservingSpace(this.space.id, Plaza.ABox.EVENTS.UPDATED, this);
+ Plaza.ABox.stopObservingSpace(this.space.id, Plaza.ABox.EVENTS.DESTROYED, this);
+ }
+
+ this.space = ent
+ Plaza.ABox.startObservingSpace(id, Plaza.ABox.EVENTS.CREATED, this, this.createdAdapter);
+ Plaza.ABox.startObservingSpace(id, Plaza.ABox.EVENTS.UPDATED, this, this.updatedAdapter);
+ Plaza.ABox.startObservingSpace(id, Plaza.ABox.EVENTS.DESTROYED, this, this.destroyedAdapter);
+
+ if (this.space != null) {
+ for(var i in this.space.entities) {
+ var e = this.space.entities[i];
+ this.createdAdapter(this.space.id, Plaza.ABox.EVENTS.CREATED, e.value);
+ }
+ }
+
+ this.disconnect();
+
+ for(var i in this.connections) {
+ var c = this.connections[i];
+ c.connectionChangeAdapter(this.space);
+ }
+ };
+
+ w.connectionChangeAdapter = function(space) {
+ if(this.space != null) {
+ Plaza.ABox.stopObservingSpace(this.space.id, Plaza.ABox.EVENTS.CREATED, this);
+ Plaza.ABox.stopObservingSpace(this.space.id, Plaza.ABox.EVENTS.UPDATED, this);
+ Plaza.ABox.stopObservingSpace(this.space.id, Plaza.ABox.EVENTS.DESTROYED, this);
+ }
+
+ if(this.space != null) {
+ for(var i in this.space.entities) {
+ var e = this.space.entities[i];
+ this.destroyedAdapter(space.id, Plaza.ABox.EVENTS.DESTROYED, e.value);
+ }
+ }
+
+ this.space = space;
+
+ if(space != null) {
+
+ for(var i in this.space.entities) {
+ var e = this.space.entities[i];
+ this.createdAdapter(this.space.id, Plaza.ABox.EVENTS.CREATED, e.value);
+ }
+
+ Plaza.ABox.startObservingSpace(this.space.id, Plaza.ABox.EVENTS.CREATED, this, this.createdAdapter);
+ Plaza.ABox.startObservingSpace(this.space.id, Plaza.ABox.EVENTS.UPDATED, this, this.updatedAdapter);
+ Plaza.ABox.startObservingSpace(this.space.id, Plaza.ABox.EVENTS.DESTROYED, this, this.destroyedAdapter);
+ }
+
+ for(var i in this.connections) {
+ var c = this.connections[i];
+ c.connectionChangeAdapter(this.space);
+ }
+ };
+
+ w.connect = function(widget) {
+ if(this.space != null) {
+ for(var i in this.space.entities) {
+ var e = this.space.entities[i];
+ this.destroyedAdapter(this.space.id, Plaza.ABox.EVENTS.DESTROYED, e.value);
+ }
+
+ Plaza.ABox.stopObservingSpace(this.space.id, Plaza.ABox.EVENTS.CREATED, this);
+ Plaza.ABox.stopObservingSpace(this.space.id, Plaza.ABox.EVENTS.UPDATED, this);
+ Plaza.ABox.stopObservingSpace(this.space.id, Plaza.ABox.EVENTS.DESTROYED, this);
+ }
+
+ this.space = widget.space;
+ this.updatedAdapter(this.space);
+
+ if(this.space != null) {
+ for(var i in this.space.entities) {
+ var e = this.space.entities[i];
+ this.createdAdapter(this.space.id, Plaza.ABox.EVENTS.CREATED, e.value);
+ }
+
+ Plaza.ABox.startObservingSpace(this.space.id, Plaza.ABox.EVENTS.CREATED, this, this.createdAdapter);
+ Plaza.ABox.startObservingSpace(space.id, Plaza.ABox.EVENTS.UPDATED, this, this.updatedAdapter);
+ Plaza.ABox.startObservingSpace(space.id, Plaza.ABox.EVENTS.DESTROYED, this, this.destroyedAdapter);
+ }
+
+ for(var i in this.connections) {
+ var c = this.connections[i];
+ c.connectionChangeAdapter(space);
+ }
+
+ this.disconnect();
+
+ this.connectedTo = widget;
+ widget.connections.push(this);
+ };
+
+ w.disconnectConnection = function(otherWidget) {
+ var newConnections = [];
+ for(var i in this.connections) {
+ if(this.connections[i] != otherWidget) {
+ newConnections.push(this.connections[i]);
+ }
+ }
+ this.connections = newConnections;
+ }
+
+ w.disconnect = function() {
+ if(this.connectedTo != null) {
+ this.connectedTo.disconnectConnection(this);
+ }
+ };
+
+ return w;
+}();
+
+
+/**
+ * PlazaUI.Widgets namespace
+ */
+PlazaUI.Widgets = {
+ makeClosable: function(widget) {
+ widget.find(".widget-header").append('<span style="float: right; margin: -2px -5px 0px 3px; background-color: white; cursor: pointer;" class="remove-widget ui-icon ui-icon-circle-close"></span>');
+ widget.find('.remove-widget').bind("click", function(){
+ widget.remove();
+ });
+ }
+};
+
+/**
+ * PlazaUI.Widgets.EntityDebugger
+ */
+
+PlazaUI.Widgets.EntityDebugger = function(){
+
+ var w = PlazaUI.EntityWidget.extend();
+
+ // Element where the widget will be inserted
+ w.attachedElement = null;
+
+ w.build = function() {
+ PlazaUI.EntityWidget.build.apply(this,[])
+ this.handlers = {};
+ this.handlers["onUpdate"] = w.onUpdated;
+ this.handlers["onDestroy"] = w.onDestroyed;
+ },
+
+ // Insertes the widget in the DOM
+ w.attach = function() {
+ var elem = null;
+ if( arguments.length == 0) {
+ elem = jQuery("body");
+ } else {
+ elem = arguments[0];
+ };
+
+ this.attachedElement = jQuery("<div class='plaza-widget entity-debugger-widget'>");
+ this.attachedElement.append("<div class='entity-debugger-widget-header widget-header'>");
+ this.attachedElement.append("<div class='entity-debugger-widget-body'>");
+
+ if(this.entity == null) {
+ this.onDestroyed(null);
+ } else {
+ this.onUpdated(this.entity);
+ }
+
+ elem.append(this.attachedElement);
+
+ // UI tweaks
+ if(this.entity == null) {
+ this.attachedElement.css("width",300);
+ } else {
+ this.attachedElement.css("width",this.entity._uri.length * 8);
+ }
+
+ var attached = this.attachedElement;
+ PlazaUI.Widgets.makeClosable(attached);
+ attached.resizable();
+ this.attachedElement.find(".entity-debugger-widget-header").bind('mousedown',function(event){
+ attached.draggable();
+ });
+ this.attachedElement.find(".entity-debugger-widget-header").bind('mouseup',function(event){
+ attached.draggable("destroy");
+ });
+
+ PlazaUI.Utils.center(this.attachedElement);
+ };
+
+ w.onUpdated = function(entity) {
+ if(this.attachedElement != null) {
+ if(entity != null) {
+ this.attachedElement.find(".entity-debugger-widget-header").html(entity._uri);
+ this.attachedElement.find(".entity-debugger-widget-body").empty();
+
+ for(var p in entity) {
+ var val = "<div class='entity-debugger-widget-prop'><div class='entity-debugger-widget-prop-alias'>" + p + "</div>";
+ var uri = Plaza.TBox.findPropertyUri(p)[0];
+ if(uri != undefined) {
+ val = val + "<div class='entity-debugger-widget-prop-uri'>uri: " + uri + "</div>";
+ }
+ if(Plaza.Utils.typeOf(entity[p]) === "array") {
+ val = val + "<div class='multiple-values' style='overflow:auto'>"
+ for(var i in entity[p]) {
+ val = val + "<div class='entity-debugger-widget-prop-val'>value: " + entity[p][i] + "</div>";
+ }
+ val = val + "</div></div>";
+ } else {
+ val = val + "<div class='entity-debugger-widget-prop-val'>value: " + entity[p] + "</div></div>";
+ }
+ var props = jQuery(val);
+
+ this.attachedElement.find(".entity-debugger-widget-body").append(props);
+ }
+ }
+ }
+ };
+
+ w.onDestroyed = function(entity) {
+ if(this.attachedElement != null) {
+ this.attachedElement.find(".entity-debugger-widget-header").html();
+ this.attachedElement.find(".entity-debugger-widget-body").empty();
+ }
+ };
+
+ return w;
+}();
+
+/**
+ * PlazaUI.Widgets.TripleSpacesBrowser
+ */
+PlazaUI.Widgets.TripleSpacesBrowser = function(){
+
+ var w = PlazaUI.EntityWidget.extend();
+
+ w.build = function() {
+ PlazaUI.EntityWidget.build.apply(this,[])
+ };
+
+ var makeSpacePanel = function(id, space){
+ var spaceId = space.id;
+ var spaceSingleResource = space.singleResource;
+ var spaceCollectionResource = space.collectionResource;
+
+ var panel = jQuery("<div class='triple-space-browser-panel'><div class='triple-space-browser-panel-header'>" + spaceId + "</div><div class='triple-space-browser-panel-body'></div></div>");
+
+ if(spaceSingleResource != null) {
+ var spaceUri = Plaza.Services.servicesRegistry[spaceSingleResource];
+ panel.find(".triple-space-browser-panel-body").append(jQuery("<div class='triple-space-browser-resource'><label>single resource:</label><input type='text' value='" + spaceUri + "'></input></div>"));
+ }
+
+ if(spaceCollectionResource != null) {
+ var spaceUri = Plaza.Services.servicesRegistry[spaceCollectionResource];
+ panel.find(".triple-space-browser-panel-body").append(jQuery("<div class='triple-space-browser-resource'><label>collection resource:</label><input type='text' value='" + spaceUri + "'></input></div>"));
+ }
+
+ var actions = "<div class='triple-space-actions'><input class='triple-space-show-triples-btn' type='button' value='show triples'></input></div>"
+ panel.append(jQuery(actions));
+ panel.find(".triple-space-show-triples-btn").bind("click", function() {
+ var w = PlazaUI.Widgets.TriplesTable.extend();
+ w.attach();
+ w.setSpace(spaceId);
+ });
+
+ if(spaceCollectionResource != null) {
+ var collectionResourceActions = "<div class='collection-triple-space-actions'><div class='overline'><p>collection resource actions</p></div><input class='load-instances-action' type='button' value='load instances'></input>"
+ collectionResourceActions = collectionResourceActions + "<input class='create-instance-action' type='button' value='create instance'></input></div>";
+
+ panel.append(jQuery(collectionResourceActions));
+
+ panel.find(".load-instances-action").bind("click",function() {
+ Plaza.ABox.loadInstances(spaceId, {});
+ });
+
+ panel.find(".create-instance-action").bind("click",function() {
+ var f = PlazaUI.Widgets.ToolboxEntityCreatorForm.extend();
+ f.attach();
+ f.wrap(spaceId, "post", "collectionResource", {});
+ });
+ }
+
+ return panel;
+ };
+
+ // Inserts the widget in the DOM
+ w.attach = function() {
+ var elem = null;
+ if( arguments.length == 0) {
+ elem = jQuery("body");
+ } else {
+ elem = arguments[0];
+ };
+
+ var attachedElement = jQuery("<div class='plaza-widget triple-spaces-browser-widget'>");
+ attachedElement.append(jQuery("<div class='triple-spaces-browser-header widget-header'>Registered Triple Spaces</div>"));
+
+ for (var i in Plaza.ABox.spacesRegistry) {
+ var panel = makeSpacePanel(i,Plaza.ABox.spacesRegistry[i]);
+ attachedElement.append(panel);
+ }
+
+ elem.append(attachedElement);
+
+ // UI tweaks
+ attachedElement.css("width",500)
+
+ PlazaUI.Widgets.makeClosable(attachedElement);
+ attachedElement.resizable();
+ attachedElement.find(".triple-spaces-browser-header").bind('mousedown',function(event){
+ attachedElement.draggable();
+ });
+ attachedElement.find(".triple-spaces-browser-header").bind('mouseup',function(event){
+ attachedElement.draggable("destroy");
+ });
+
+ PlazaUI.Utils.center(attachedElement);
+ };
+
+ return w;
+}();
+
+
+/**
+ * PlazaUI.Widgets.Toolbox
+ */
+
+PlazaUI.Widgets.Toolbox = function(){
+
+ var w = PlazaUI.Base.extend();
+
+ w.build = function() {
+ PlazaUI.Base.build.apply(this,[]);
+ };
+
+ var _addFeature = function(container, header, cls, featureBody) {
+ var body = container.find(".toolbox-widget-body");
+
+ var elmt = "<h3 class='toolbox-widget-section-header " + cls + "'><a href='#'>" + header + "</a></h3>";
+ var panel = jQuery(elmt);
+
+ body.append(panel);
+
+ var elmt = "<div class='toolbox-widget-section-body'></div>";
+ var panel = jQuery(elmt);
+ panel.append(featureBody);
+
+ body.append(panel);
+ };
+
+
+ var makeSearchTriples = function() {
+ var code = "<div><label>free text:</label><input type='text' class ='entity-search-fld'></input><input class='entity-search-btn' type='button' value='search'></input></div>";
+
+ code = code + "<div><label>triple space:</label><select name='tspace-selector' class='tspace-selector'>";
+ for (var i in Plaza.ABox.spacesRegistry) {
+ code = code + "<option value='"+i+"'>"+i+"</option>";
+ }
+ code = code + "</select><input class='tspace-browse-btn' type='button' value='browse entities'></input></div>";
+
+
+ var elem = jQuery(code);
+
+
+ elem.find(".entity-search-fld").autocomplete({source: function(term,callback) {
+ var matches = [];
+ for(var uri in Plaza.ABox.entitiesRegistry) {
+ var entity = Plaza.ABox.entitiesRegistry[uri];
+ var found = false;
+ for(var p in entity.value) {
+ if(!found && (""+entity.value[p]).indexOf(term.term) != -1) {
+ matches.push(uri);
+ found = true;
+ }
+ }
+ }
+ callback(matches);
+ }});
+
+ elem.find(".entity-search-btn").bind("click", function(event) {
+ var uri = elem.find(".entity-search-fld").val();
+ var w = PlazaUI.Widgets.EntityDebugger.extend();
+ w.setEntity(Plaza.ABox.findEntityByURI(uri));
+ w.attach();
+ });
+
+ elem.find(".tspace-browse-btn").bind("click", function(event) {
+ var spaceId = elem.find(".tspace-selector").val();
+ var w = PlazaUI.Widgets.EntitiesBrowser.extend();
+ w.setSpaceId(spaceId);
+ w.attach();
+ w.setWidth(600);
+ w.setTitle("Entities in triple space"+spaceId);
+ w.createPanels();
+ });
+
+ return elem;
+ };
+
+ var makeLoadSchemas = function() {
+ var code = "<div><input type='text' class ='schema-uri-fld'></input><input class='schema-load-btn' type='button' value='connect'></input></div>"
+ var elem = jQuery(code)
+
+ elem.find(".schema-load-btn").bind("click", function(event) {
+ var uri = elem.find(".schema-uri-fld").val();
+ if(uri != "") {
+ Plaza.TBox.registerSchema(uri, function(loadedUri){
+ var dialog = jQuery("<div title='Schema connection'><p>The schema located at " + loadedUri + " has been loaded successfully</p></div>");
+ jQuery("body").append(dialog);
+ dialog.dialog();
+ });
+ } else {
+ alert("A URI must be provided to load schema information");
+ }
+ });
+ return elem;
+ };
+
+ var makeClassesSelector = function() {
+ var txt = "<div class='tbox-classes-selector-group'><label>RDFS Classes</label>"
+ txt = txt + "<select name='classes-selector' id='tbox-inspector-classes-selector'>";
+ for(var c in Plaza.TBox.classesRegistry) {
+ txt = txt + "<option value='"+c+"'>"+c+"</option>";
+ }
+ txt = txt + "</select><input type='button' value='show'></input></div>";
+
+ return txt;
+ };
+
+ var makeInspectTBox = function() {
+ var code = "<div class='inspect-tbox-toolbox-feature'>";
+ code = code + "<div><input type='button' class='browse-services-btn' value='Browse registered triple spaces'></input></div>";
+ code = code + makeClassesSelector();
+ code = code + "</div>";
+
+ var elem = jQuery(code);
+
+ elem.find(".tbox-classes-selector-group > input").bind("click", function(){
+ var clsAlias = jQuery("#tbox-inspector-classes-selector").val();
+ w = PlazaUI.Widgets.RDFSClassBrowser.extend();
+ w.setRDFSClass(clsAlias);
+ w.attach();
+ w.createPanels();
+ });
+
+ elem.find('.browse-services-btn').bind("click", function(){
+ var w = PlazaUI.Widgets.TripleSpacesBrowser.extend();
+ w.attach();
+ });
+
+ return elem;
+ };
+
+ var makeConnectToService = function() {
+ var code = "<div class='connection-to-service-toolbox-feature' style='height:120px'><fieldset style='text-align:right'>"
+ code = code + "<div><label>Triple Space ID:</label><input type='text' class='ts-id-fld toolbox-legend-fld'></input></div>";
+ code = code + "<div><label>Single Service URI:</label><input type='text' class='single-service-fld toolbox-legend-fld'></input></div>"
+ code = code + "<div><label>Collection Service URI:</label><input type='text' class='collection-service-fld toolbox-legend-fld'></input></div>"
+ code = code + "<input class='service-connect-btn' type='button' value='connect' style='margin-top:10px'></input></fieldset></div>";
+ var elem = jQuery(code)
+
+ elem.find(".service-connect-btn").bind("click", function(event) {
+ var tsId = elem.find(".ts-id-fld").val();
+ var uriSingle = elem.find(".single-service-fld").val();
+ var uriCollection = elem.find(".collection-service-fld").val();
+
+ if(tsId == "") {
+ alert("A name for the triple space must be provided");
+ } else {
+ if(uriSingle == "" && uriCollection == "") {
+ alert("URIs for single resource, collection resource or both of them must be provided");
+ } else {
+ if(Plaza.ABox.spacesRegistry[tsId] != null) {
+ alert("The name for the triple space is already in use");
+ } else {
+ var params = {}
+ if(uriCollection != "") {
+ params["singleResource"] = uriSingle;
+ }
+ if(uriSingle != "") {
+ params["collectionResource"] = uriCollection;
+ }
+ elem.find(".ts-id-fld").val("")
+ elem.find(".single-service-fld").val("");
+ elem.find(".collection-service-fld").val("");
+
+ Plaza.ABox.TripleSpace.connect(tsId, params, function() {
+ var dialog = jQuery("<div title='Service connection'><p>The service " + tsId + " has been registered successfully</p></div>");
+ jQuery("body").append(dialog);
+ dialog.dialog();
+ });
+ }
+ }
+ }
+ });
+ return elem;
+ }
+
+ var makeCodeGeneration = function() {
+ var code = "<div class='code-generation-toolbox-feature' style='height:120px'><fieldset style='padding:10px'>";
+ code = code + "<div><label>Setup code:</label><input type='button' class='setup-code-btn' value='generate'></input></div>";
+ code = code +"</div>";
+
+ var elem = jQuery(code)
+
+ elem.find(".setup-code-btn").bind("click", function(event) {
+ var code = PlazaUI.Utils.generateSetup();
+ var window = jQuery("<div class='plaza-widget'><div class='widget-header plaza-widget-header'>Setup code generation</div><div class='plaza-widget-body'><textarea style='width:100%; height:600px'>"+code+"</textarea></div></div>");
+ PlazaUI.Widgets.makeClosable(window);
+ window.css("width",800)
+ window.css("height",600)
+ window.find(".plaza-widget-header").bind('mousedown',function(event){
+ window.draggable();
+ });
+ window.find(".plaza-widget-header").bind('mouseup',function(event){
+ window.draggable("destroy");
+ });
+ jQuery("body").append(window);
+ });
+ return elem;
+ };
+
+ // Insertes the widget in the DOM
+ w.attach = function() {
+ var elem = null;
+ if( arguments.length == 0) {
+ elem = jQuery("body");
+ } else {
+ elem = arguments[0];
+ };
+
+ this.attachedElement = jQuery("<div class='plaza-toolbox-widget plaza-widget'>");
+ this.attachedElement.append("<div class='toolbox-widget-header widget-header'>( plaza ) toolbox</div>");
+ this.attachedElement.append("<div class='toolbox-widget-body'>");
+
+ _addFeature(this.attachedElement, "Schemas connection", "", makeLoadSchemas());
+ _addFeature(this.attachedElement, "Services connection", "", makeConnectToService());
+ _addFeature(this.attachedElement, "Search entity", "", makeSearchTriples());
+ _addFeature(this.attachedElement, "Inspect tbox", "", makeInspectTBox());
+ _addFeature(this.attachedElement, "Code generation", "", makeCodeGeneration());
+
+ elem.append(this.attachedElement);
+ this.attachedElement.find(".toolbox-widget-body").accordion({collapsible: true, active: false});
+
+ // UI tweaks
+ var attached = this.attachedElement;
+ PlazaUI.Widgets.makeClosable(attached);
+ this.attachedElement.css("width",600)
+ this.attachedElement.find(".widget-header").bind('mousedown',function(event){
+ attached.draggable();
+ });
+ this.attachedElement.find(".widget-header").bind('mouseup',function(event){
+ attached.draggable("destroy");
+ });
+
+ PlazaUI.Utils.center(this.attachedElement);
+ };
+
+ return w;
+}();
+
+
+/**
+ * PlazaUI.Widgets.TriplesTable
+ */
+
+PlazaUI.Widgets.TriplesTable = function(){
+
+ var w = PlazaUI.SpaceWidget.extend();
+
+ // Element where the widget will be inserted
+ w.attachedElement = null;
+
+ w.build = function() {
+ PlazaUI.SpaceWidget.build.apply(this,[])
+ this.handlers = {};
+ this.handlers["onCreate"] = w.onCreated;
+ this.handlers["onUpdate"] = w.onUpdated;
+ this.handlers["onDestroy"] = w.onDestroyed;
+ this.rowsCounter = 0;
+ // uri -> id
+ this.rowsMap = {};
+ };
+
+ w.onCreated = function(data){
+ var titleId = "#plaza-triples-table-"+this.__plz_id;
+ jQuery(titleId).html(this.space.id);
+
+ if(this.attachedElement != null) {
+ var rowClass = "row-" + this.rowsCounter++;
+ var subject = data._uri;
+ for(var p in data) {
+ if(p != "_uri") {
+ var predicates = Plaza.TBox.findPropertyUri(p);
+ if(predicates[0] == null) {
+ predicates = [p];
+ }
+ for(var i in predicates){
+ var predicate = predicates[i]
+ var object = data[p];
+ var txt = "<tr class='" + rowClass + "'><td>" + subject + "</td><td>" + predicate + "</td><td>" + object + "</td></tr>";
+ this.attachedElement.find("tbody").append(jQuery(txt));
+ }
+ }
+ }
+ }
+ };
+
+
+ w.onUpdated = function(){
+ if(this.attachedElement != null) {
+ // @todo
+ }
+ };
+
+ w.onDestroyed = function() {
+ if(this.attachedElement != null) {
+ // @todo
+ }
+ }
+
+ // Insertes the widget in the DOM
+ w.attach = function() {
+ var elem = null;
+ if( arguments.length == 0) {
+ elem = jQuery("body");
+ } else {
+ elem = arguments[0];
+ };
+
+ var spaceId = "";
+ if(this.space != null) {
+ spaceId = this.space.id;
+ }
+
+ this.attachedElement = jQuery("<div class='plaza-triples-table-widget plaza-widget'>");
+ this.attachedElement.append("<div class='toolbox-widget-header widget-header'><span id='plaza-triples-table-"+this.__plz_id +"'>" + spaceId + "</span></div>");
+ this.attachedElement.append("<div class='plaza-triples-widget-body'><table><thead><th>subject</th><th>predicate</th><th>object</th></thead><tbody></tbody></table></div>");
+
+
+ elem.append(this.attachedElement);
+
+ if(this.space != null) {
+ for(var i in this.space.elements) {
+ var elt = this.space.elements[i];
+
+ this.createdAdapter(this.space.id, Plaza.ABox.EVENTS.CREATED, elt.value);
+ }
+ }
+
+ // UI tweaks
+ var attached = this.attachedElement;
+
+ PlazaUI.Widgets.makeClosable(attached);
+
+ this.attachedElement.css("width",1000)
+ this.attachedElement.find(".widget-header").bind('mousedown',function(event){
+ attached.draggable();
+ });
+ this.attachedElement.find(".widget-header").bind('mouseup',function(event){
+ attached.draggable("destroy");
+ });
+
+ PlazaUI.Utils.center(this.attachedElement);
+ };
+
+ return w;
+}();
+
+/* PlazaUI.Widgets.EntityCreatorForm */
+
+PlazaUI.Widgets.EntityCreatorForm = function(){
+ var w = PlazaUI.Base.extend();
+
+ w.build = function() {
+ PlazaUI.Base.build.apply(this,[]);
+ this.spaceId = null;
+ this.method = null;
+ this.serviceKind = null;
+ this.entity = null;
+ this.propertyCounter = 0;
+ this.currentProperties = {};
+ this.attachedElement = null;
+ };
+
+ var attributesForSpace = function(spaceId, serviceKind, method) {
+ var space = Plaza.ABox.findSpace(spaceId);
+ if(space != null) {
+ var serviceAlias = space[serviceKind];
+ if(serviceAlias != null) {
+ return Plaza.Services.inputMessagesMap(serviceAlias, method);
+ } else {
+ PlazaUI.Utils.showDialog("Error", "Servive cannot be found for triple space:"+spaceId)
+ }
+ } else {
+ PlazaUI.Utils.showDialog("Error", "Triple space cannot be found with identifier:"+spaceId)
+ }
+ };
+
+ w.inputTxtForProp = function(prop, entity){
+ var inputId = this.propertyCounter++;
+ var propId = this.__plz_id+"-"+inputId;
+ value = entity[prop];
+ if(value == undefined) {
+ value = "";
+ }
+
+ this.currentProperties[prop] = propId;
+
+ var dt = Plaza.XSD.DATATYPES;
+ // @todo a selector for the type of the property must be added
+ var range = Plaza.TBox.propertiesMap[Plaza.TBox.propertiesRegistry[prop]].range[0];
+ if(range == dt.boolean) {
+ var txt = "<select name='"+prop+"' id='"+propId+"'>";
+ if(value === true) {
+ txt = txt + "<option value='true' selected='true'>true</option>";
+ } else {
+ txt = txt + "<option value='true'>true</option>";
+ }
+ if(value === false) {
+ txt = txt + "<option value='false' selected='true'>true</option>";
+ } else {
+ txt = txt + "<option value='false'>true</option>";
+ }
+ return jQuery(txt + "</select>");
+ } else if(range == dt.dateTime || range == dt.date) {
+ var txt = jQuery("<input type='text' id='"+propId+"'></input>");
+ if (value == "") {
+ value = null;
+ }
+ txt.datepicker({defaultDate: null, dateFormat: "yy-mm-dd"});
+ return txt;
+ } else {
+ if(Plaza.XSD.isKnownUriDatatype(range) || prop == "restResourceId") {
+ return jQuery("<input name='"+prop+"' id='"+propId+"' type='text' value='"+value+"'></input>");
+ } else {
+ var w = PlazaUI.Widgets.MultiEntitiesSelector.extend();
+ w.setRDFSClass(range);
+ w.setPropertyValues(value);
+ w.attach();
+ w.attachedElement.find('.entities-selector-list').attr('id', propId);
+ return w.attachedElement;
+ }
+ }
+ },
+
+ w.addPropertyToForm = function(formBody, prop, entity) {
+ var label = Plaza.Utils.humanize(prop);
+ var propClass = prop
+ if(prop.indexOf("http://") == 0) {
+ label = prop;
+ propClass = ""
+ }
+
+ var value = entity[prop];
+ if(value == null) {
+ value = "";
+ }
+ var propHtml = jQuery("<div class='property'><label class='"+ propClass +"Label'>"+label+"</label></div>");
+ propHtml.append(this.inputTxtForProp(prop,entity));
+
+ formBody.append(propHtml);
+ };
+
+ w.retrieveFormData = function(){
+ var data = {};
+
+ for(var p in this.currentProperties) {
+ var val = this.attachedElement.find("#"+this.currentProperties[p]).val();
+
+ if(val == "") {
+ val = null;
+ }
+
+ if(val != null) {
+ data[p] = val;
+ }
+ }
+
+ return data;
+ };
+
+ w.wrap = function(spaceId, method, serviceKind, entity) {
+ this.spaceId = spaceId;
+ this.method = method;
+ this.serviceKind = serviceKind;
+ this.entity = entity;
+
+ var attributes = attributesForSpace(spaceId, serviceKind, method);
+ this.currentProperties = {};
+
+ if( this.attachedElement != null) {
+ var body = this.attachedElement.find(".entity-creator-form");
+ for(var p in attributes) {
+ this.addPropertyToForm(body,p,entity);
+ }
+
+ var actions = this.attachedElement.find('.entity-creator-actions');
+ var that = this;
+ if(serviceKind == "collectionResource") {
+ var btn = jQuery("<input class='entity-creator-form-btn' type='button' value='save'></input>");
+ btn.bind("click",function() {
+ var data = that.retrieveFormData();
+ Plaza.ABox.createEntity(that.spaceId, data);
+ });
+ actions.append(btn);
+ } else if(serviceKind == "singleResource" && method.toLowerCase() == "get") {
+ var btn = jQuery("<input class='entity-creator-form-btn' type='button' value='load'></input>");
+ actions.append(btn);
+ } else if(serviceKind == "singleResource" && method.toLowerCase() == "put") {
+ var btn = jQuery("<input class='entity-creator-form-btn' type='button' value='update'></input>");
+ btn.bind("click",function() {
+ var data = that.retrieveFormData();
+ Plaza.ABox.updateEntity(entity._uri, data);
+ });
+ actions.append(btn);
+ } else if(serviceKind == "singleResource" && method.toLowerCase() == "delete") {
+ var btn = jQuery("<input class='entity-creator-form-btn' type='button' value='destroy'></input>");
+ btn.bind("click",function() {
+ var data = that.retrieveFormData();
+ Plaza.ABox.destroyEntity(entity._uri);
+ });
+ actions.append(btn);
+ }
+
+ PlazaUI.Utils.center(this.attachedElement);
+ }
+ };
+
+ w.attach = function() {
+ var elem = null;
+ if( arguments.length == 0) {
+ elem = jQuery("body");
+ } else {
+ elem = arguments[0];
+ };
+
+ this.attachedElement = jQuery("<div class='plaza-widget entity-creator-widget'>");
+ this.attachedElement.append(jQuery("<div class='entity-creator-widget-body'><div class='entity-creator-form'></div><div class='entity-creator-actions'></div></div>"));
+
+ if(this.spaceId != null && this.method != null && this.serviceKind != null && this.entity != null) {
+ this.wrap(this.spaceId, this.method, this.serviceKind, this.entity);
+ }
+ elem.append(this.attachedElement);
+ PlazaUI.Utils.center(this.attachedElement);
+ };
+
+ return w;
+}();
+
+
+/**
+ * PlazaUI.Widgets.ToolboxEntityCreatorForm
+ */
+PlazaUI.Widgets.ToolboxEntityCreatorForm = function(){
+ var w = PlazaUI.Widgets.EntityCreatorForm.extend();
+
+ w.build = function(){
+ PlazaUI.Widgets.EntityCreatorForm.build.apply(this, []);
+ };
+
+ w.wrap = function() {
+ PlazaUI.Widgets.EntityCreatorForm.wrap.apply(this,arguments);
+ if(this.spaceId != null && this.method != null && this.serviceKind != null) {
+ this.attachedElement.find(".toolbox-entity-creator-form-header").html("Triple space "+ this.spaceId + " " + this.method + " operation");
+ }
+ PlazaUI.Widgets.makeClosable(this.attachedElement);
+ var attachedElement = this.attachedElement;
+ this.attachedElement.resizable();
+ this.attachedElement.find(".toolbox-entity-creator-form-header").bind('mousedown',function(event){
+ attachedElement.draggable();
+ });
+ this.attachedElement.find(".toolbox-entity-creator-form-header").bind('mouseup',function(event){
+ attachedElement.draggable("destroy");
+ });
+ PlazaUI.Utils.center(this.attachedElement);
+ };
+
+ w.attach = function() {
+ PlazaUI.Widgets.EntityCreatorForm.attach.apply(this,[]);
+ var body = this.attachedElement;
+ body.addClass("toolbox-entity-creator-widget");
+ body.find(".entity-creator-widget-body").addClass("toolbox-entity-creator-widget-body");
+ body.prepend(jQuery("<div class='toolbox-entity-creator-form-header widget-header'></div>"));
+
+ if(this.spaceId != null && this.method != null && this.serviceKind != null) {
+ this.attachedElement.find(".toolbox-entity-creator-form-header").html("Triple space "+ this.spaceId + " " + this.method + " operation");
+ }
+
+ PlazaUI.Widgets.makeClosable(this.attachedElement);
+ var attachedElement = this.attachedElement;
+ this.attachedElement.resizable();
+ this.attachedElement.find(".toolbox-entity-creator-form-header").bind('mousedown',function(event){
+ attachedElement.draggable();
+ });
+ this.attachedElement.find(".toolbox-entity-creator-form-header").bind('mouseup',function(event){
+ attachedElement.draggable("destroy");
+ });
+ PlazaUI.Utils.center(this.attachedElement);
+ };
+
+ return w;
+}();
+
+/**
+ * PlazaUI.Widgets.PanelListFrame
+ */
+PlazaUI.Widgets.PanelListFrame = function(){
+
+ var w = PlazaUI.Base.extend();
+
+ w.build = function() {
+ PlazaUI.Base.build.apply(this,[]);
+ this.panels = [];
+ this.attachedElement = null;
+ };
+
+ w.appendPanels = function() {
+ for(var p in this.panels) {
+ this.attachedElement.find(".panel-list-body").append(this.panels[p]);
+ }
+ };
+
+ // Inserts the widget in the DOM
+ w.attach = function() {
+ var elem = null;
+ if( arguments.length == 0) {
+ elem = jQuery("body");
+ } else {
+ elem = arguments[0];
+ };
+
+ var attachedElement = jQuery("<div class='plaza-widget panel-list-widget'>");
+ attachedElement.append(jQuery("<div class='panel-list-header widget-header'>Panel List</div>"));
+ attachedElement.append(jQuery("<div class='panel-list-body widget-body'></div>"));
+
+ elem.append(attachedElement);
+
+ // UI tweaks
+ attachedElement.css("width",500)
+
+ PlazaUI.Widgets.makeClosable(attachedElement);
+ attachedElement.resizable();
+ attachedElement.find(".panel-list-header").bind('mousedown',function(event){
+ attachedElement.draggable();
+ });
+ attachedElement.find(".panel-list-header").bind('mouseup',function(event){
+ attachedElement.draggable("destroy");
+ });
+
+ this.attachedElement = attachedElement;
+ this.attachedElement.find(".panel-list-body").css("overflow","auto");
+ PlazaUI.Utils.center(this.attachedElement);
+ };
+
+ // @todo refactor to some frame parent prototype
+ w.setWidth = function(width) {
+ this.attachedElement.css('width', width);
+ };
+
+ w.setHeight = function(height) {
+ this.attachedElement.find(".panel-list-body").css('height', height);
+ };
+
+ w.setTitle = function(title) {
+ this.attachedElement.find(".panel-list-header").html(title);
+ };
+
+ w.addWidgetClass = function(cls) {
+ this.attachedElement.find(".panel-list-widget").addClass(cls);
+ };
+
+ w.addWidgetHeaderClass = function(cls) {
+ this.attachedElement.find(".panel-list-header").addClass(cls);
+ };
+
+ return w;
+}();
+
+
+/**
+ * PlazaUI.Widgets.RDFSClassBrowser
+ */
+PlazaUI.Widgets.RDFSClassBrowser = function() {
+ w = PlazaUI.Widgets.PanelListFrame.extend();
+
+ w.build = function(){
+ PlazaUI.Widgets.PanelListFrame.build.apply(this,[]);
+ this.rdfsClass = null;
+ };
+
+ w.setRDFSClass = function(clsAlias) {
+ this.rdfsClass = clsAlias;
+ };
+
+ var classDescriptionPanel = function(classAlias) {
+ var panel = jQuery("<div class='panel-list-panel'><div class='panel-list-panel-header'>Class URI</div><div class='class-uri-panel-body panel-list-panel-body'>"+Plaza.TBox.classesRegistry[classAlias]+"</div></div>");
+ return panel;
+ };
+
+ var makePropertyPanel = function(propertyAlias){
+ var uri = Plaza.TBox.propertiesRegistry[propertyAlias];
+ var def = Plaza.TBox.propertiesMap[uri];
+ var domains = def.domain;
+ var ranges = def.range;
+
+ var panelBody = "<div><label>URI<label><input type='text' value='"+uri+"'></input></div>";
+ for(var domain in domains) {
+ panelBody = panelBody + "<div><label>domain<label><input type='text' value='"+domain+"'></input></div>";
+ }
+ for(var range in rages) {
+ panelBody = panelBody + "<div><label>range<label><input type='text' value='"+range+"'></input></div>";
+ }
+ var panel = jQuery("<div class='panel-list-panel'><div class='panel-list-panel-header'>Property "+propertyAlias+"</div><div class='panel-list-panel-body'>"+panelBody+"</div></div>");
+ return panel;
+ };
+
+ w.createPanels = function() {
+ var clsUri = Plaza.TBox.classesRegistry[this.rdfsClass];
+
+ this.panels = [classDescriptionPanel(this.rdfsClass)];
+
+ for(var p in Plaza.TBox.propertiesRegistry) {
+ var pUri = Plaza.TBox.propertiesRegistry[p];
+ var pDef = Plaza.TBox.propertiesMap[pUri];
+
+ if(Plaza.Utils.includes(pDef.domain, clsUri)) {
+ var panel = makePropertyPanel(p);
+ this.panels.push(panel);
+ }
+ }
+
+ this.appendPanels();
+ this.addWidgetHeaderClass("tbox-class-panel-header");
+ this.addWidgetClass("tbox-class-panel-body");
+ this.setTitle("Class "+clsUri);
+ PlazaUI.Widgets.makeClosable(this.attachedElement);
+ this.setWidth(600);
+ this.setHeight(500);
+ };
+
+ return w;
+}();
+
+
+
+/**
+ * PlazaUI.Widgets.EntitiesBrowser
+ */
+PlazaUI.Widgets.EntitiesBrowser = function() {
+ w = PlazaUI.Widgets.PanelListFrame.extend();
+
+ w.build = function(){
+ PlazaUI.Widgets.PanelListFrame.build.apply(this,[]);
+ this.spaceId = null;
+ };
+
+ w.setSpaceId = function(spaceId) {
+ this.spaceId = spaceId;
+ };
+
+ var makeEntityPanel = function(entity){
+
+ var panelBody = "<div><label> URI<label><input type='text' value='"+entity.uri+"'></input></div>";
+ var panelBody = "<div class='entity-actions'><input class='entity-show' type='button' value='show'><input class='entity-edit' type='button' value='edit'></input><input class='entity-delete' type='button' value='destroy'></input></div>";
+ var panel = jQuery("<div class='panel-list-panel'><div class='panel-list-panel-header'>Entity "+entity.uri+"</div><div class='panel-list-panel-body'>"+panelBody+"</div></div>");
+
+ panel.find(".entity-show").bind("click", function(){
+ var w = PlazaUI.Widgets.EntityDebugger.extend();
+ w.setEntity(Plaza.ABox.findEntityByURI(entity.uri));
+ w.attach();
+ });
+
+ panel.find(".entity-edit").bind("click", function(){
+ var f = PlazaUI.Widgets.ToolboxEntityCreatorForm.extend();
+ f.attach();
+ f.wrap(entity.space.id, "put", "singleResource", entity.value);
+ });
+
+ panel.find(".entity-delete").bind("click", function(){
+ Plaza.ABox.destroyEntity(entity.uri);
+ PlazaUI.Utils.showDialog("Notice", "Trying to destroy triples for entity:"+entity.uri+"\n Open this panel again afterwards.")
+ });
+
+ return panel;
+ };
+
+ w.createPanels = function() {
+ var space = Plaza.ABox.spacesRegistry[this.spaceId];
+
+
+ this.panels = [];
+
+ for(var i in space.entities) {
+ var entity = space.entities[i];
+ var panel = makeEntityPanel(entity);
+ this.panels.push(panel);
+ }
+
+ this.appendPanels();
+ this.addWidgetHeaderClass("tbox-class-panel-header");
+ this.addWidgetClass("tbox-class-panel-body");
+ this.setTitle("Entities in triple space "+this.spaceId);
+ PlazaUI.Widgets.makeClosable(this.attachedElement);
+ this.setWidth(600);
+ this.setHeight(this.panels.count * 50);
+ };
+
+ return w;
+}();
+
+/**
+ * PlazaUI.Widgets.MultiEntitiesSelector
+ */
+PlazaUI.Widgets.MultiEntitiesSelector = function(){
+
+ var w = PlazaUI.Base.extend();
+
+ w.build = function() {
+ PlazaUI.Base.build.apply(this,[]);
+ this.RDFSclass = null;
+ this.attachedElement = null;
+ this.propertyValues = null;
+ };
+
+ w.setRDFSClass = function(cls) {
+ this.RDFSclass = cls;
+ if(this.attachedElement!=null) {
+ this.addOptions();
+ }
+ };
+
+ w.setPropertyValues = function(values) {
+ this.propertyValues = values;
+ };
+
+ w.addOptions = function() {
+ var select = this.attachedElement.find('.entities-selector-list');
+ var selected = [];
+ for(var uri in Plaza.ABox.entitiesRegistry) {
+ var entity = Plaza.ABox.entitiesRegistry[uri];
+ var val = entity.value;
+ var match = false;
+ for(var p in val) {
+ if(val[p] == this.RDFSclass) {
+ match = true;
+ break;
+ }
+ }
+ if(match == true) {
+ selected.push(entity.uri);
+ }
+ }
+
+ for(var i in selected) {
+ var uri = selected[i];
+ if(this.propertyValues != null) {
+ if(Plaza.Utils.includes(this.propertyValues, uri)) {
+ select.append(jQuery("<option value='"+uri+"' selected='true'>"+uri+"</option>"));
+ } else {
+ select.append(jQuery("<option value='"+uri+"'>"+uri+"</option>"));
+ }
+ } else {
+ select.append(jQuery("<option value='"+uri+"'>"+uri+"</option>"));
+ }
+ }
+ };
+
+ // Inserts the widget in the DOM
+ w.attach = function() {
+ var attachedElement = jQuery("<span class='multi-entities-selector-widget'>");
+ attachedElement.append(jQuery("<span class='selector'><span class='entities-selector-title'><select class='entities-selector-list' multiple='multiple'></select></span></span>"));
+
+
+ // UI tweaks
+ this.attachedElement = attachedElement;
+ PlazaUI.Utils.center(this.attachedElement);
+
+ if(this.RDFSclass != null) {
+ this.addOptions();
+ }
+ };
+
+ w.setSelectId = function(value){
+ this.attachedElement.find(".entities-selector-list").attr("id", value);
+ };
+
+ // @todo refactor to some frame parent prototype
+ w.setWidth = function(width) {
+ this.attachedElement.css('width', width);
+ };
+
+ w.setHeight = function(height) {
+ this.attachedElement.css('height', height);
+ };
+
+ return w;
+}();
View
1,129 apps/borges/public/js/plaza.js
@@ -0,0 +1,1129 @@
+/*
+ *
+ * Plaza JS client library and utilities
+ * @author Antonio Garrote
+ * @date 23.06.2010
+ *
+ */
+
+Plaza = {
+
+ // Sequences a list of currified functions
+ setup: function() {
+ var fns = arguments;
+ var cdr = [];
+ var car = null
+
+ var fnsLength = fns.length;
+
+ for(var i=0; i<fnsLength; i++) {
+ if(i==0) {
+ car = fns[i];
+ } else {
+ cdr.push(fns[i]);
+ }
+ }
+
+
+ if(cdr.length == 0) {
+ car();
+ } else {
+ car(function() {
+ Plaza.setup.apply(this,cdr);
+ });
+ }
+ }
+
+};
+
+/* XSD Datatypes */
+
+Plaza.XSD = {
+ DATATYPES: {
+ datatype:"http://www.w3.org/2000/01/rdf-schema#Datatype",
+ string:"http://www.w3.org/2001/XMLSchema#string",
+ boolean:"http://www.w3.org/2001/XMLSchema#boolean",
+ decimal:"http://www.w3.org/2001/XMLSchema#decimal",
+ float:"http://www.w3.org/2001/XMLSchema#float",
+ double:"http://www.w3.org/2001/XMLSchema#double",
+ dateTime:"http://www.w3.org/2001/XMLSchema#dateTime",
+ time:"http://www.w3.org/2001/XMLSchema#time",
+ date:"http://www.w3.org/2001/XMLSchema#date",
+ gYearMonth:"http://www.w3.org/2001/XMLSchema#gYearMonth",
+ gYear:"http://www.w3.org/2001/XMLSchema#gYear",
+ gMonthDay:"http://www.w3.org/2001/XMLSchema#gMonthDay",
+ gDay:"http://www.w3.org/2001/XMLSchema#gDay",
+ gMonth:"http://www.w3.org/2001/XMLSchema#gMonth",
+ hexBinary:"http://www.w3.org/2001/XMLSchema#hexBinary",
+ base64Binary:"http://www.w3.org/2001/XMLSchema#base64Binary",
+ anyURI:"http://www.w3.org/2001/XMLSchema#anyURI",
+ normalizedString:"http://www.w3.org/2001/XMLSchema#normalizedString",
+ token:"http://www.w3.org/2001/XMLSchema#token",
+ language:"http://www.w3.org/2001/XMLSchema#language",
+ NMTOKEN:"http://www.w3.org/2001/XMLSchema#NMTOKEN",
+ Name:"http://www.w3.org/2001/XMLSchema#Name",
+ NCName:"http://www.w3.org/2001/XMLSchema#NCName",
+ integer:"http://www.w3.org/2001/XMLSchema#integer",
+ nonPositiveInteger:"http://www.w3.org/2001/XMLSchema#nonPositiveInteger",
+ negativeInteger:"http://www.w3.org/2001/XMLSchema#negativeInteger",
+ long:"http://www.w3.org/2001/XMLSchema#long",
+ int:"http://www.w3.org/2001/XMLSchema#int",
+ short:"http://www.w3.org/2001/XMLSchema#short",
+ byte:"http://www.w3.org/2001/XMLSchema#byte",
+ nonNegativeInteger:"http://www.w3.org/2001/XMLSchema#nonNegativeInteger",
+ unsignedLong:"http://www.w3.org/2001/XMLSchema#unsignedLong",
+ unsignedInt:"http://www.w3.org/2001/XMLSchema#unsignedInt",
+ unsignedShort:"http://www.w3.org/2001/XMLSchema#unsignedShort",
+ unsignedByte:"http://www.w3.org/2001/XMLSchema#unsignedByte",
+ positiveInteger:"http://www.w3.org/2001/XMLSchema#positiveInteger"
+ },
+
+ DATATYPES_PARSERS: {
+ datatype: function(obj) { return obj.value },
+ string: function(obj) { return obj.value },
+ boolean: function(obj) { return eval(obj.value) },
+ decimal: function(obj) { return parseInt(obj.value) },
+ float: function(obj) { return parseFloat(obj.value)},
+ double: function(obj) { return parseInt(obj.value) },
+ dateTime: function(obj) { return new Date(obj.value) },
+ time: function(obj) { return obj.value },
+ date: function(obj) { return new Date(obj.value) },
+ gYearMonth: function(obj) { return obj.value },
+ gYear: function(obj) {return obj.value } ,
+ gMonthDay: function(obj) {return obj.value },
+ gDay: function(obj) {return obj.value },
+ gMonth: function(obj) {return obj.value },
+ hexBinary: function(obj) {return obj.value },
+ base64Binary: function(obj) {return obj.value },
+ anyURI: function(obj) {return obj.value },
+ normalizedString: function(obj) {return obj.value },
+ token: function(obj) {return obj.value },
+ language: function(obj) {return obj.value },
+ NMTOKEN: function(obj) {return obj.value },
+ Name: function(obj) {return obj.value },
+ NCName: function(obj) {return obj.value },
+ integer: function(obj) { return parseInt(obj.value) },
+ nonPositiveInteger: function(obj) { return parseInt(obj.value) },
+ negativeInteger: function(obj) { return parseInt(obj.value) },
+ long: function(obj) { return parseInt(obj.value) },
+ int: function(obj) { return parseInt(obj.value) },
+ short: function(obj) {return parseInt(obj.value) },
+ byte: function(obj) { return parseInt(obj.value) },
+ nonNegativeInteger: function(obj) { return parseInt(obj.value) },
+ unsignedLong: function(obj) { return parseInt(obj.value) },
+ unsignedInt: function(obj) { return parseInt(obj.value) },
+ unsignedShort: function(obj) { return parseInt(obj.value) },
+ unsignedByte: function(obj) { return parseInt(obj.value) },
+ positiveInteger: function(obj) { return parseInt(obj.value) }
+ }
+};
+
+
+Plaza.XSD.DATATYPES_INV = {};
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2000/01/rdf-schema#Datatype"] = "datatype";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#string"] = "string";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#boolean"]= "boolean";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#decimal"] = "decimal";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#float"] = "float";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#double"] = "double";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#dateTime"] = "dateTime";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#time"] = "time";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#date"] = "date";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#gYearMonth"] = "gYearMonth";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#gYear"] = "gYear";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#gMonthDay"] = "gMonthDay";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#gDay"] = "gDay";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#gMonth"] = "gMonth";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#hexBinary"] = "hexBinary";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#base64Binary"] = "base64Binary";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#anyURI"] = "anyURI";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#normalizedString"] = "normalizedString";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#token"] = "token";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#language"] = "language";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#NMTOKEN"] = "NMTOKEN";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#Name"] = "Name";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#NCName"] = "NCName";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#integer"] = "integer";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#nonPositiveInteger"] = "nonPositiveInteger";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#negativeInteger"] = "negativeInteger";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#long"] = "long";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#int"] = "int";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#short"] = "short";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#byte"] = "byte";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#nonNegativeInteger"] = "nonNegativeInteger";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#unsignedLong"] = "unsignedLong";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#unsignedInt"] = "unsignedInt";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#unsignedShort"] = "unsignedShort";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#unsignedByte"] = "unsignedByte";
+Plaza.XSD.DATATYPES_INV["http://www.w3.org/2001/XMLSchema#positiveInteger" ] = "positiveInteger";
+
+Plaza.XSD.isKnownUriDatatype = function(uri) {
+ for(var du in Plaza.XSD.DATATYPES_INV) {
+ if(du == uri) {
+ return true;
+ }
+ }
+ return false;
+}
+
+// Parses a URI datatype string or a Datatype object to the JS value
+// {"value":"test","datatype":"http://www.w3.org/2001/XMLSchema#string"} -> "test"
+// {"value":"25","datatype":"http://www.w3.org/2001/XMLSchema#int"} -> 25
+// "25^^http://www.w3.org/2001/XMLSchema#int"} -> 25
+Plaza.XSD.parseType= function(uri) {
+ var uriObj = null;
+
+ if(typeof(uri) == "string") {
+ var parts = uri.split("^^");
+ uriObj = { value: parts[0], datatype: parts[1] };
+ } else {
+ uriObj = uri;
+ }
+
+ var alias = Plaza.XSD.DATATYPES_INV[uriObj.datatype];
+ return Plaza.XSD.DATATYPES_PARSERS[alias](uriObj);
+}
+
+
+/* Utils */
+Plaza.Utils = {
+
+ /**
+ * TypeOf capable of detecting arrays and nulls
+ */
+ typeOf: function(obj) {
+ if ( typeof(obj) == 'object' ) {
+ if (obj.length) {
+ return 'array';
+ } else {
+ return 'object';
+ }
+ } else {
+ return typeof(obj);
+ }
+ },
+
+ /**
+ * Registers a new namespace in the javascript
+ * runtime.
+ */
+ registerNamespace: function() {
+ var nsPath = "";
+ for (var i=0; i<arguments.length; i++) {
+ var ns = arguments[i];
+ if(nsPath != "") {
+ nsPath = nsPath + ".";
+ }
+ var nsPath = nsPath + ns;
+ try {
+ var res = eval(nsPath);
+ if(res == null) {
+ throw "Non existant path";
+ }
+ } catch(e) {
+ eval(nsPath + " = {};");
+ }
+ }
+ },
+
+ /**
+ * Extracts the QLocal part from an URI:
+ * - http://test.com/something -> something
+ * - http://test.com/something/else -> else
+ * - http://test.com/something/else/ -> else
+ * - http://test.com/something#more -> more
+ */
+ extractQLocal: function(uri) {
+ if(uri.indexOf("#") != -1) {
+ var parts = uri.split("#");
+ return parts[parts.length - 1];
+ } else {
+ var parts = uri.split("/");
+ if(parts[parts.length - 1] == "") {
+ return parts[parts.length - 2];
+ } else {
+ return parts[parts.length - 1];
+ }
+ }
+ },
+
+ cleanTypedLiteral: function(typed) {
+ var parts = typed.split("^^");
+ var content = parts[0];
+ var datatype = parts[1];
+
+ if(content[0] == '"' && content[content.length-1] == '"') {
+ content = content.substring(1, content.length-1);
+ }
+ if(datatype[0] == '<' && datatype[datatype.length-1] == '>') {
+ datatype = datatype.substring(1, datatype.length-1);
+ }
+
+ return {"value": content, "datatype": datatype};
+ },
+
+ isoDate: function(date) {
+ var year = 1900+date.getYear();
+ var month = date.getMonth() + 1;
+ var day = date.getDate();
+
+ var isoDate = ""+year;
+
+ isoDate = isoDate + "-";
+
+ if(month < 10) {
+ isoDate = isoDate + "0" + month;
+ } else {
+ isoDate = isoDate + month;
+ }
+
+ isoDate = isoDate + "-";
+
+ if(day<10) {
+ isoDate = isoDate + "0" + day;
+ } else {
+ isoDate = isoDate + day;
+ }
+
+ return isoDate;
+ },
+
+ _letters: function(str) {
+ var acum = []
+ for(var i in str) {
+ acum.push(str[i]);
+ }
+
+ return acum;
+ },
+
+ _isUpcase: function(letter) {
+ if(letter.toUpperCase() != letter) {
+ return false;
+ } else {
+ return true;
+ }
+ },
+
+ humanize: function(str) {
+ var lets = Plaza.Utils._letters(str);
+ var acum = [];
+ for(var i in lets) {
+ if(lets[i] == "-" || lets[i] == "_") {
+ if(i != 0) {
+ acum.push(" ")
+ }
+ } else {
+ if(Plaza.Utils._isUpcase(lets[i])) {
+ if(i !=0) {
+ acum.push(" ")
+ }
+ acum.push(lets[i].toLowerCase());
+ } else {
+ acum.push(lets[i]);
+ }
+ }
+ }
+ return String.concat.apply("",acum);
+ },
+
+ includes: function(array, val) {
+ for(var i in array) {
+ var valArray = array[i];
+ if(valArray == val) {
+ return true;
+ }
+ }
+ return false;
+ },
+
+ keysIncludes: function(map,val) {
+ for(var p in map) {
+ if(p == val) {
+ return true;
+ }
+ }
+ return false;
+ }
+};
+
+/* TBox */
+Plaza.TBox = {
+
+ // List with all the schemas loaded
+ schemaList: [],
+
+ // Map URI -> alias
+ classesMap: {},
+
+ // Map alias -> URI
+ classesRegistry: {},
+
+ // Map URI -> definition
+ propertiesMap: {"http://www.w3.org/1999/02/22-rdf-syntax-ns#type": {"uri": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
+ "domain": ["http://www.w3.org/2000/01/rdf-schema#Resource"],
+ "range": ["http://www.w3.org/2000/01/rdf-schema#Resource"] },
+
+ "http://plaza.org/vocabularies/restResourceId": {"uri": "http://plaza.org/vocabularies/restResourceId",
+ "domain": ["http://www.w3.org/2000/01/rdf-schema#Resource"],
+ "range": ["http://www.w3.org/2000/01/rdf-schema#Resource"]}},
+
+ // Map alias -> URI
+ propertiesRegistry: {"rdf_type": ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"],
+ "restResourceId": ["http://plaza.org/vocabularies/restResourceId"] },
+
+ // Map URI -> alias
+ propertiesInvRegistry: {"http://www.w3.org/1999/02/22-rdf-syntax-ns#type": ["rdf_type"],
+ "http://plaza.org/vocabularies/restResourceId": ["restResourceId"] },
+
+ // Retrieves a service in JSON format provided the URI
+ _retrieveSchema: function(uri, callback) {
+ jQuery.ajax({
+ url: uri,
+ dataType: 'json',
+ success: function(data) {
+ callback(data);
+ }
+ })
+ },
+
+ // Process a Class definition
+ _processSchema: function(clsDef) {
+ var uri=clsDef.uri;
+ if(uri != null) {
+ var alias = Plaza.Utils.extractQLocal(uri);
+ Plaza.TBox.classesMap[uri] = alias;
+
+ if(null == Plaza.TBox.classesRegistry[alias]) {
+ Plaza.TBox.classesRegistry[alias] = [uri];
+ } else {
+ if(!Plaza.Utils.includes(Plaza.TBox.classesRegistry[alias], uri)) {
+ Plaza.TBox.classesRegistry[alias].push(uri);
+ }
+ }
+ }
+ },
+
+ // Process a Property definition
+ _processProperty: function(propDef) {
+ var uri= propDef.uri;
+ if(uri != null) {
+ var alias = Plaza.Utils.extractQLocal(uri);
+ if(Plaza.TBox.propertiesMap[uri] == null) {
+ Plaza.TBox.propertiesMap[uri] = propDef;
+ Plaza.TBox.propertiesMap[uri].domain = [propDef.domain];
+ Plaza.TBox.propertiesMap[uri].range = [propDef.range];
+ if(Plaza.TBox.propertiesInvRegistry[uri]==null) {
+ Plaza.TBox.propertiesInvRegistry[uri] = [alias];
+ } else {
+ Plaza.TBox.propertiesInvRegistry[uri].push(alias);
+ }
+ } else {
+ Plaza.TBox.propertiesMap[uri].domain.push(propDef.domain);
+ Plaza.TBox.propertiesMap[uri].range.push(propDef.range);
+ }
+
+ if(Plaza.TBox.propertiesRegistry[alias] == null) {
+ Plaza.TBox.propertiesRegistry[alias] = [uri];
+ } else {
+ if(!Plaza.Utils.includes(Plaza.TBox.propertiesRegistry[alias], uri)) {
+ Plaza.TBox.propertiesRegistry[alias].push(uri);
+ }
+ }
+ }
+ },
+
+ // Registers a schema using an associated URI
+ // * arguments:
+ // - uri : URI of the schema
+ // - callback: Optional callback function that will be notified whe
+ // when the registration is successfull
+ // If no callback is provided a currified version of the function will be
+ // returned.
+ registerSchema: function() {
+ var uri = arguments[0];
+ var clbk = arguments[1];
+
+ var cont = function(callback) {
+ Plaza.TBox._retrieveSchema(uri, function(schema) {
+ if(schema.length > 0) {
+ Plaza.TBox.schemaList.push(uri);
+ for(var i in schema) {
+ if(schema[i].type != null) {
+ Plaza.TBox._processSchema(schema[i]);
+ } else {
+ Plaza.TBox._processProperty(schema[i]);
+ }
+ }
+ callback(uri);
+ } else {
+ callback(null);
+ }
+ });
+ };
+
+ if(clbk == null) {
+ return cont;
+ } else {
+ cont(clbk);
+ }
+ },
+
+ // Finds the alias registered for an URI
+ findPropertyAlias: function(uri) {
+ return Plaza.TBox.propertiesInvRegistry[uri];
+ },
+
+ // Finds the URI registered for an alias
+ findPropertyUri: function(alias) {
+ var choices = Plaza.TBox.propertiesRegistry[alias];
+ for(choice in choices) {
+ if(choice.indexOf(alias) == 0) {
+ return [choice];
+ }
+ }
+ if(choices == undefined) {
+ choices = [undefined];
+ }
+ return choices;
+ }
+
+
+};
+
+/* ABbox */
+Plaza.ABox = {
+
+ // Default events
+ EVENTS: {"CREATED": 0, "DESTROYED": 1, "UPDATED": 2},
+
+ // Mapping URI -> Entity
+ entitiesRegistry: {},
+
+ // Mapping space -> triples
+ spacesRegistry: {},
+
+ // Registers an observer for an entity
+ startObservingEntity: function(uri,event,observer,callback) {
+ var entity = Plaza.ABox.entitiesRegistry[uri];
+ if(entity != null) {
+ var observers = entity.observers[event];
+ if(observers == null) {
+ observers = []
+ entity.observers[event] = observers;
+ }
+ observers.push({"observer": observer, "callback": callback});
+ }
+ },
+
+ // Unregisters an observer in an entity
+ stopObservingEntity: function(uri, event, observer) {
+ var entity = Plaza.ABox.entitiesRegistry[uri];
+ if(entity != null) {
+ var observers = entity.observers[event];
+ if(observers != null) {
+ var observersMod = []
+ for(var i in observers) {
+ var o = observers[i];
+ if(o.observer != observer) {
+ observersMod.push(o)
+ }
+ }
+ entity.observers = observersMod;
+ }
+ }
+ },
+
+ // Sends a notification to the observers of an event on a an entity
+ notifyEntityObservers: function(entityUri, event, data) {
+ var entity = Plaza.ABox.entitiesRegistry[entityUri];
+ for(var i in entity.observers[event]) {
+ var o = entity.observers[event][i];
+
+ o.callback.apply(o.observer,[entity.uri, event, data]);
+ }
+ Plaza.ABox.notifySpaceObservers(entity.space.id, event, data);
+ },
+
+ // Registers an observer for a space
+ startObservingSpace: function(spaceId, event, observer, callback) {
+ var space = Plaza.ABox.spacesRegistry[spaceId];
+ if(space != null) {
+ var observers = space.observers[event];
+ if(observers == null) {
+ observers = []
+ space.observers[event] = observers;
+ }
+ observers.push({"observer": observer, "callback": callback});
+ }
+ },
+
+ // Unregisters an observer in an space
+ stopObservingSpace: function(spaceId, event, observer) {
+ var space = Plaza.ABox.spacesRegistry[spaceId];
+ if(space != null) {
+ var observers = space.observers[event];
+ if(observers != null) {
+ var observersMod = []
+ for(var i in observers) {
+ var o = observers[i];
+ if(o.observer != observer) {
+ observersMod.push(o)
+ }
+ }
+ space.observers = observersMod;
+ }
+ }
+ },
+
+ // Sends a notification to the observers of an event on a space
+ notifySpaceObservers: function(spaceId, event, data) {
+ var space = Plaza.ABox.spacesRegistry[spaceId];
+ if(space != null) {
+ for(var i in space.observers[event]) {
+ var o = space.observers[event][i];
+ o.callback.apply(o.observer,[space.id, event, data]);
+ }
+ }
+ },
+
+ // Initalizes a new ABox entity setting some meta-data for the entity
+ makeEntityMap: function(uri, triples) {
+ return { "uri": uri, "dirty": false, "value": triples, "observers": {}, "space": null };
+ },
+
+ // Registers a new triple space for handling entitities
+ // * spaceId: Identifier of the space
+ // * callback: function where life cycle notifications of the entity will be notified
+ registerSpace: function(spaceId, callback) {
+ if(Plaza.ABox.spacesRegistry[spaceId] != null) {
+ throw "Space already registered:" + spaceId;
+ }
+
+ Plaza.ABox.spacesRegistry[spaceId] = { "id": spaceId, "entities": [], "callback": callback, "observers":{} };
+ },
+
+ // Registers some triples in the ABox
+ // * URI: uri of the new Entity
+ // * triples: value of the entity
+ // * spaceId: identifier of the space managing the entity (e.g. service URI)
+ registerEntity: function(uri, triples, spaceId) {
+ // Entity creation
+ var entity = Plaza.ABox.makeEntityMap(uri, triples);
+ entity.space = Plaza.ABox.spacesRegistry[spaceId];
+
+ // Registering the entity
+ if(Plaza.ABox.spacesRegistry[spaceId] == null) {
+ // @todo What should we do here?
+ throw "error, unknown space:"+ spaceId;
+ }
+ Plaza.ABox.spacesRegistry[spaceId].entities.push(entity);
+
+ if(Plaza.ABox.entitiesRegistry[uri] != null) {
+ //@todo What should we do here?
+ throw "error, entity already registered:"+ uri;
+ }
+ Plaza.ABox.entitiesRegistry[uri] = entity;
+
+ // Creation notifications
+ Plaza.ABox.notifySpaceObservers(spaceId, Plaza.ABox.EVENTS.CREATED, entity.value);
+ },
+
+ // Finds a space provided its identifier