Permalink
Browse files

adds boolean property type

  • Loading branch information...
1 parent af2b664 commit 5848d51f300798c9993b4cf2ba0809f09e147110 @tkurz committed Oct 3, 2013
Showing with 113 additions and 13 deletions.
  1. +4 −0 css/editor.css
  2. +6 −5 index_test.html
  3. +6 −4 js/skos-client.js
  4. +13 −0 pom.xml
  5. +84 −4 skos.js
View
@@ -62,4 +62,8 @@ ul.tree {
min-width: 100px;
border:1px solid gray;
border-top: none;
+}
+
+.list_values .check {
+ margin: 10px;
}
View
@@ -65,11 +65,12 @@
var ioservice = new IOService(editor,HOST);
var user_service = new UserService(editor, HOST);
- /**
- editor.properties.remove("scheme","http://www.w3.org/2000/01/rdf-schema#label");
- editor.properties.add("scheme","http://www.w3.org/2004/02/skos/core#prefLabel",{title:"Label",type:"string",multivalue:false,multilingual:true,editable:true},"right",0);
- editor.properties.alter("scheme","http://purl.org/dc/terms/license",{title:"Licence String",type:"string"});
- **/
+
+ // to test adding and boolean values
+ //editor.properties.remove("scheme","http://www.w3.org/2000/01/rdf-schema#label");
+ //editor.properties.alter("scheme","http://purl.org/dc/terms/license",{title:"Licence String",type:"string"});
+
+ editor.properties.add("graph","http://example.org/value/is_enabled",{title:"Is enabled",type:"boolean",editable:true,confirm:false},"right",0);
editor.init();
View
@@ -104,10 +104,11 @@ function SKOSClient(sparqlClient,options) {
}
this.set = {
- value : function(graph, uri, property, value, language, onsuccess, onfailure) {
+ value : function(graph, uri, property, value, language, type, onsuccess, onfailure) {
var datetime = currentDateTime();
language = language&&language!='none'?"@"+language:"";
- var query = "WITH <" + graph + "> DELETE {<" + uri + "><"+ namespaces.DC_TERMS+"modified>?_mod} INSERT {<" + uri + "> <" + property + ">\"" + value + "\"" + language + ";<"+ namespaces.DC_TERMS+"modified>\""+datetime+"\"^^<http://www.w3.org/2001/XMLSchema#dateTime>} WHERE {OPTIONAL {<" + uri + "><"+ namespaces.DC_TERMS+"modified>?_mod}}";
+ type = type ? "^^<"+type+">" : "";
+ var query = "WITH <" + graph + "> DELETE {<" + uri + "><"+ namespaces.DC_TERMS+"modified>?_mod} INSERT {<" + uri + "> <" + property + ">\"" + value + "\"" + type + language + ";<"+ namespaces.DC_TERMS+"modified>\""+datetime+"\"^^<http://www.w3.org/2001/XMLSchema#dateTime>} WHERE {OPTIONAL {<" + uri + "><"+ namespaces.DC_TERMS+"modified>?_mod}}";
if(OPTIONS.DEBUG)console.debug(query);
sparqlClient.update(query, onsuccess, onfailure);
},
@@ -174,10 +175,11 @@ function SKOSClient(sparqlClient,options) {
}
this.update = {
- value : function(graph,uri,property,value_old,value_new,language,onsuccess, onfailure) {
+ value : function(graph,uri,property,value_old,value_new,type,language,onsuccess, onfailure) {
var datetime = currentDateTime();
language = language&&language!='none'?"@"+language:"";
- var query = "WITH <" + graph + "> DELETE {<" + uri + "> <" + property + "> \"" + value_old + "\"" + language + ";<"+ namespaces.DC_TERMS+"modified>?_mod} INSERT {<" + uri + "> <" + property + "> \"" + value_new + "\"" + language + ";<"+ namespaces.DC_TERMS+"modified>\""+datetime+"\"^^<http://www.w3.org/2001/XMLSchema#dateTime>.} WHERE {<" + uri + "> <" + property + "> \"" + value_old + "\"" + language + ".OPTIONAL {<" + uri + "><"+ namespaces.DC_TERMS+"modified>?_mod}}";
+ type = type ? "^^<"+type+">" : "";
+ var query = "WITH <" + graph + "> DELETE {<" + uri + "> <" + property + "> \"" + value_old + "\"" + type + language + ";<"+ namespaces.DC_TERMS+"modified>?_mod} INSERT {<" + uri + "> <" + property + "> \"" + value_new + "\"" + type + language + ";<"+ namespaces.DC_TERMS+"modified>\""+datetime+"\"^^<http://www.w3.org/2001/XMLSchema#dateTime>.} WHERE {<" + uri + "> <" + property + "> \"" + value_old + "\"" + type + language + ".OPTIONAL {<" + uri + "><"+ namespaces.DC_TERMS+"modified>?_mod}}";
if(OPTIONS.DEBUG)console.debug(query);
sparqlClient.update(query, onsuccess, onfailure);
},
View
@@ -34,6 +34,19 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
+ <distributionManagement>
+ <repository>
+ <id>snml.releases</id>
+ <name>Salzburg NewMediaLab Repository</name>
+ <url>http://devel.kiwi-project.eu:8080/nexus/content/repositories/releases/</url>
+ </repository>
+ <snapshotRepository>
+ <id>snml.snapshots</id>
+ <name>Salzburg NewMediaLab Repository</name>
+ <url>http://devel.kiwi-project.eu:8080/nexus/content/repositories/snapshots/</url>
+ </snapshotRepository>
+ </distributionManagement>
+
<build>
<plugins>
<plugin>
View
@@ -1251,6 +1251,77 @@ function SKOSEditor(options) {
case 'text' : return new StringPropertyView(options.title,options.property,options.multilingual,options.multivalue,options.editable,true);
case 'uri' : return new UriPropertyView(options.title,options.property,options.multivalue,options.editable);
case 'concept' : return new ConceptPropertyView(options.title,options.property,options.droppable,options.editable);
+ case 'boolean' : return new BooleanPropertyView(options.title,options.property,options.editable,options.confirm);
+ }
+ }
+
+ function BooleanPropertyView(title,property,editable,confirm) {
+
+ var box = $("<div></div>").addClass("content_box").append($("<h1></h1>").text(title));
+ var container = $("<div></div>").appendTo(box);
+ load();
+ this.getBox = function() {
+ return box;
+ }
+ this.getType = function() {
+ return "boolean";
+ }
+ this.getProperty = function() {
+ return property;
+ }
+ this.reload = function() {
+ load();
+ }
+
+ //get properties
+ function load(){
+ skos.list.values(graph,current.uri,property,write,function(){popups.alert("Alert","could not list values "+property)});
+ }
+
+ //write properties
+ function write(data) {
+ container.empty();
+
+ var checkbox = $("<input type='checkbox'>").addClass("check");
+ if(!editable) checkbox.attr("disabled","disabled");
+ if(data.length!=0 && data[0].value.value == "true") checkbox.prop("checked",true);
+ $("<div></div>").addClass('list_values').append(checkbox).appendTo(container);
+
+ var isNew = data.length == 0;
+
+ checkbox.click(function() {
+ var _inner_self = this;
+ function setValue() {
+ if(!isNew) {
+ skos.update.value(graph, current.uri, property,!$(_inner_self).is(':checked'),$(_inner_self).is(':checked'),"http://www.w3.org/2001/XMLSchema#boolean",null,function(){
+ load();
+ },function(){
+ alert("Could not set value!");
+ });
+ } else {
+ skos.set.value(graph, current.uri, property,$(_inner_self).is(':checked'),null,"http://www.w3.org/2001/XMLSchema#boolean",function(){
+ load();
+ },function(){
+ alert("Could not set value!");
+ });
+ }
+ }
+
+ if(confirm) {
+ //open confirm dialoge
+ var popup = popups.confirm("Warning","Are you sure you want to set '"+title+"' to '"+($(this).is(':checked') ? "true" : "false")+"'?",[{
+ title:"Yes",
+ action:function() {
+ setValue();
+ }
+ }]);
+ popup.onclose = function(){ console.log($(_inner_self).is(':checked')+"13")
+ $(_inner_self).prop("checked",!$(_inner_self).is(':checked'));
+ }
+ } else {
+ setValue();
+ }
+ });
}
}
@@ -1336,7 +1407,7 @@ function SKOSEditor(options) {
templ2.find(".literal_save").click(function() {
var n3str = templ2.find(".literal_input").val().n3escape();
var htmlStr = templ2.find(".literal_input").val().n3escapeToHMTL();
- skos.update.value(graph, current.uri, property, templ1.find(".literal_text").attr('original').n3escape(), n3str, language, function() {
+ skos.update.value(graph, current.uri, property, templ1.find(".literal_text").attr('original').n3escape(), n3str, undefined, language, function() {
events.fire(new Event(EventCode.PROPERTY.UPDATED, {uri:current.uri,property:property,language:language,value:n3str}, source));
events.fire(new Event(EventCode.CONCEPT.UPDATED,{uris:[current.uri]}));
templ1.find(".literal_text").html(htmlStr);
@@ -1379,7 +1450,7 @@ function SKOSEditor(options) {
if (inp == "") {
popups.alert("Alert","value must not be empty");
} else {
- skos.set.value(graph,current.uri,property,inp,language,function(){
+ skos.set.value(graph,current.uri,property,inp,language,undefined,function(){
events.fire(new Event(EventCode.PROPERTY.CREATED,{uri:current.uri,property:property,language:language,value:inp},source));
events.fire(new Event(EventCode.CONCEPT.UPDATED,{uris:[current.uri]}));
load();
@@ -1854,17 +1925,23 @@ function SKOSEditor(options) {
}
this.alert = function(title,message) {
- new Alert(title,message);
+ return new Alert(title,message);
+ }
+ this.confirm = function(title,message,func) {
+ return new Confirm(title,message,func);
}
this.info = function(title,message) {
- new Info(title,message);
+ return new Info(title,message);
}
this.custom = function(title) {
return new CustomPopup(title);
}
//func is an array of objects {title:t,action:f}
function Confirm(title,message,func) {
+ var _conf_self = this;
+ this.onclose = undefined;
+
$("#"+background).show();
$("#" + container).html(HTML_TEMPLATES.popups.confirm);
$("#popup_title").text(title);
@@ -1873,6 +1950,7 @@ function SKOSEditor(options) {
close();
});
$("#popup_cancel").click(function() {
+ if(_conf_self.onclose) _conf_self.onclose();
close();
});
var buttons = $("#popup_button_list");
@@ -1885,9 +1963,11 @@ function SKOSEditor(options) {
function buildButton(func) {
var b = $("<button></button>").text(func.title).click(function(){
func.action();
+ close();
});
return b;
}
+
}
function CustomPopup(title) {

0 comments on commit 5848d51

Please sign in to comment.