/*
 * Ext JS Library 1.1.1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://www.extjs.com/license
 */

Ext.tree.TreeLoader=function(A){this.baseParams={};this.requestMethod="POST";Ext.apply(this,A);this.addEvents({"beforeload":true,"load":true,"loadexception":true});Ext.tree.TreeLoader.superclass.constructor.call(this)};Ext.extend(Ext.tree.TreeLoader,Ext.util.Observable,{uiProviders:{},clearOnLoad:true,load:function(D,E){if(this.clearOnLoad){while(D.firstChild){D.removeChild(D.firstChild)}}if(D.attributes.children){var C=D.attributes.children;for(var B=0,A=C.length;B<A;B++){D.appendChild(this.createNode(C[B]))}if(typeof E=="function"){E()}}else{if(this.dataUrl){this.requestData(D,E)}}},getParams:function(D){var A=[],C=this.baseParams;for(var B in C){if(typeof C[B]!="function"){A.push(encodeURIComponent(B),"=",encodeURIComponent(C[B]),"&")}}A.push("node=",encodeURIComponent(D.id));return A.join("")},requestData:function(A,B){if(this.fireEvent("beforeload",this,A,B)!==false){this.transId=Ext.Ajax.request({method:this.requestMethod,url:this.dataUrl||this.url,success:this.handleResponse,failure:this.handleFailure,scope:this,argument:{callback:B,node:A},params:this.getParams(A)})}else{if(typeof B=="function"){B()}}},isLoading:function(){return this.transId?true:false},abort:function(){if(this.isLoading()){Ext.Ajax.abort(this.transId)}},createNode:function(attr){if(this.baseAttrs){Ext.applyIf(attr,this.baseAttrs)}if(this.applyLoader!==false){attr.loader=this}if(typeof attr.uiProvider=="string"){attr.uiProvider=this.uiProviders[attr.uiProvider]||eval(attr.uiProvider)}return(attr.leaf?new Ext.tree.TreeNode(attr):new Ext.tree.AsyncTreeNode(attr))},processResponse:function(response,node,callback){var json=response.responseText;try{var o=eval("("+json+")");for(var i=0,len=o.length;i<len;i++){var n=this.createNode(o[i]);if(n){node.appendChild(n)}}if(typeof callback=="function"){callback(this,node)}}catch(e){this.handleFailure(response)}},handleResponse:function(B){this.transId=false;var A=B.argument;this.processResponse(B,A.node,A.callback);this.fireEvent("load",this,A.node,B)},handleFailure:function(B){this.transId=false;var A=B.argument;this.fireEvent("loadexception",this,A.node,B);if(typeof A.callback=="function"){A.callback(this,A.node)}}});