Ambrosia
view release on metacpan or search on metacpan
share/Templates/Templates/XSLT+DOJO/tree_json.xsl view on Meta::CPAN
var usGov = JsonRest({
target:"<xsl:value-of select="$url" />/",
getIdentity: function(object){
return object.repository ? object.repository.response.id : object.id
},
mayHaveChildren: function(object){
return object.repository
? "children" in object.repository.response
: "children" in object;
},
getChildren: function(object, onComplete, onError){
var res = object.repository ? object.repository.response : object;
// retrieve the full copy of the object
this.get(res.id).then(function(fullObject){
// copy to the original object so it has the children array as well.
res.children = fullObject.repository ? fullObject.repository.response.children : fullObject.children;
// now that full object, we should have an array of children
onComplete(fullObject.repository ? fullObject.repository.response.children : fullObject.children);
}, function(error){
// an error occurred, log it, and indicate no children
console.error(error);
onComplete([]);
});
},
getRoot: function(onItem, onError){
// get the root object, we will do a get() and callback the result
this.get("root").then(onItem, onError);
},
getLabel: function(object){
// just get the name
return object.repository ? object.repository.response.name : object.name;
},
put: function(object, options){
//this.onChange(object);
this.onChildrenChange(object, object.children);
this.onChange(object);
return JsonRest.prototype.put.apply(this, arguments);
}
});
var tree = new Tree({
model: usGov,
dndController: dndSource
}, "tree");
tree.startup();
query("#add-new-child").on("click", function(){
var selectedObject = tree.get("selectedItems")[0];
if(!selectedObject){
return alert("No object selected");
}
usGov.get(selectedObject.id).then(function(selectedObject){
selectedObject.children.push({
name: "New child",
id: Math.random()
});
usGov.put(selectedObject);
});
});
tree.on("dblclick", function(object){
object.name = prompt("Enter a new name for the object");
usGov.put(object);
}, true);
});
</script>
</head>
<body class="claro">
<div id="tree"></div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
</xslt:template>
</xslt:stylesheet>
( run in 0.590 second using v1.01-cache-2.11-cpan-8dfa8b56332 )