Widget
Configuring Editor Panel
Generic Resource Picker
If you need a Generic Resource Picker to edit selected element on your page, you need to proceed as follows:
- Write a Web service which returns a list of resources in application/json or application/rdf+json
- In the method <your-widget>.prototype.configureSetters(), invoke
applicableSetters.push("picker"); - Write <your-widget>.prototype.getPickerConfig() to configure the Generic Resource Picker you requested.
The method should return an object with following members:- serviceUrl: required
- acceptType: optional, default = application/rdf+json
- propertyLinkToResource: optional
- filterParamName: optional, default = "filter"
- callback: optional (however, it does not make any sense if you do not specify callback)
E.g.,<your-widget>.prototype.getPickerConfig = function() { return { serviceUrl: "/admin/poll/get-polls", propertyLinkToResource: "http://clerezza.org/2011/02/poll#hasPoll", callback: function(uri) { alert(uri); } }; }
Treecreeper will request the list of resources through the specified serviceUrl and retrieve the objects of all triples having the predicate as specified by propertyLinkToResource.
The resulting list will be presented and if one is picked by clicking on it, the callback function will be invoked with the chosen object as the parameter.
Each item of this list is represented as
<a href=objectstring>objectstring</a>
e.g.,
<a href="http://localhost:8080/poll/poll1">http://localhost:8080/poll/poll1</a>
If you want to have a different label, you need to provide the method
<your-widget>.prototype.retrieveResourceList = function(data) {
...
}
This method should return an array of objects, each of which has the member title and uri. The title will be used as the label for the anchor element and the uri as the value of its href attribute.
The parameter data passed to the method is the response of the service identified by the serviceUrl.
For example, the json object returned by retrievePolls() method of PollManager.java of org.clerezza.app.poll contains the required array called polls. Therefore, the method retrieveResourceList is as simple as follows:
<your-widget>.prototype.retrieveResourceList = function(data) {
return data.polls;
}
If you make use of retrieveResourceList, you don't need to specify propertyLinkToResource, but you might want to specify acceptType to be "application/json"