* nodes from a specified URL. The response must be a javascript Array definition
* who's elements are node definition objects. eg:
* <pre><code>
- [{ 'id': 1, 'text': 'A folder Node', 'leaf': false },
- { 'id': 2, 'text': 'A leaf Node', 'leaf': true }]
+{ success : true,
+ data : [
+
+ { 'id': 1, 'text': 'A folder Node', 'leaf': false },
+ { 'id': 2, 'text': 'A leaf Node', 'leaf': true }
+ ]
+}
+
+
</code></pre>
* <br><br>
+ * The old style respose with just an array is still supported, but not recommended.
+ * <br><br>
+ *
* A server request is sent, and child nodes are loaded only when a node is expanded.
* The loading node's id is passed to the server under the parameter name "node" to
* enable the server to produce the correct child nodes.
myTreeLoader.on("beforeload", function(treeLoader, node) {
this.baseParams.category = node.attributes.category;
}, this);
-</code></pre><
+
+</code></pre>
+ *
* This would pass an HTTP parameter called "category" to the server containing
* the value of the Node's "category" attribute.
* @constructor
Roo.apply(this, config);
this.addEvents({
+
/**
* @event beforeload
* Fires before a network request is made to retrieve the Json text which specifies a node's children.
* @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
* @param {Object} callback The callback function specified in the {@link #load} call.
*/
- "beforeload" : true,
+ beforeload : true,
/**
* @event load
* Fires when the node has been successfuly loaded.
* @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
* @param {Object} response The response object containing the data from the server.
*/
- "load" : true,
+ load : true,
/**
* @event loadexception
* Fires if the network request failed.
* @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
* @param {Object} response The response object containing the data from the server.
*/
- "loadexception" : true
+ loadexception : true,
+ /**
+ * @event create
+ * Fires before a node is created, enabling you to return custom Node types
+ * @param {Object} This TreeLoader object.
+ * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
+ */
+ create : true
});
Roo.tree.TreeLoader.superclass.constructor.call(this);
* to be loaded.
*/
/**
+ * @cfg {String} requestMethod either GET or POST
+ * defaults to POST (due to BC)
+ * to be loaded.
+ */
+ /**
* @cfg {Object} baseParams (optional) An object containing properties which
* specify HTTP parameters to be passed to each request for child nodes.
*/
*/
/**
* @cfg {Object} uiProviders (optional) An object containing properties which
+ *
+ * DEPRECATED - use 'create' event handler to modify attributes - which affect creation.
* specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
* <i>uiProvider</i> attribute of a returned child node is a string rather
* than a reference to a TreeNodeUI implementation, this that string value
}
},
- /**
- * Override this function for custom TreeNode node implementation
- */
- createNode : function(attr){
+ // private
+ createNode : function(attr)
+ {
// apply baseAttrs, nice idea Corey!
if(this.baseAttrs){
Roo.applyIf(attr, this.baseAttrs);
if(this.applyLoader !== false){
attr.loader = this;
}
+ // uiProvider = depreciated..
+
if(typeof(attr.uiProvider) == 'string'){
-
attr.uiProvider = this.uiProviders[attr.uiProvider] ||
/** eval:var:attr */ eval(attr.uiProvider);
}
if(typeof(this.uiProviders['default']) != 'undefined') {
attr.uiProvider = this.uiProviders['default'];
}
+
+ this.fireEvent('create', this, attr);
+
attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
return(attr.leaf ?
new Roo.tree.TreeNode(attr) :
new Roo.tree.AsyncTreeNode(attr));
},
- processResponse : function(response, node, callback){
+ processResponse : function(response, node, callback)
+ {
var json = response.responseText;
try {
- var o = /** eval:var:zzzzzzzzzz */ eval("("+json+")");
+ var o = Roo.decode(json);
+
+ if (this.root === false && typeof(o.success) != undefined) {
+ this.root = 'data'; // the default behaviour for list like data..
+ }
+
+ if (this.root !== false && !o.success) {
+ // it's a failure condition.
+ var a = response.argument;
+ this.fireEvent("loadexception", this, a.node, response);
+ Roo.log("Load failed - should have a handler really");
+ return;
+ }
+
+
+
if (this.root !== false) {
- o = o[this.root];
+ o = o[this.root];
}
for(var i = 0, len = o.length; i < len; i++){
this.fireEvent("load", this, a.node, response);
},
- handleFailure : function(response){
+ handleFailure : function(response)
+ {
+ // should handle failure better..
this.transId = false;
var a = response.argument;
this.fireEvent("loadexception", this, a.node, response);