Ext.namespace("Ext.hansub.tree");

Ext.hansub.tree.BlogTreePanel = function(parent, config) {
	this.config = config;
	this.root =  new Ext.tree.AsyncTreeNode({
                        	id:'treeBlogRoot_'+this.config.id,
                        	leaf:false,
                            text:'캠핑 인기 블러거',
                            leafview:true
                        })
	this.config.autoHeight = true;
	this.config.autoScroll = true;
	this.config.lines = true;
	this.config.singleExpand = false;
	this.config.useArrows = false;
	this.config.rootVisible = true;
	this.config.root = this.root;
	this.config.dropConfig = {appendOnly:true};
  this.config.enableDD = true;
	this.config.animate = true;
	
	Ext.hansub.tree.BlogTreePanel.superclass.constructor.call(this, this.config);
	this.config.loader.on("beforeload", function(treeLoader, node) {  
   	this.config.loader.baseParams.uid = node.attributes.uid;
  	this.config.loader.baseParams.table = node.attributes.table;
    }, this);					      
	
  this.on('click', this.onClick, this);
  this.on('click', this.onDoubleClick, this);
	this.on('render', this.init, this);
};

Ext.extend(Ext.hansub.tree.BlogTreePanel, Ext.tree.TreePanel, {
	
	init : function(){
		this.root.expand(false);
		this.onClick(this.root,null);
	},
	
	reload : function(){
		this.root.reload();
	},
	
	onDoubleClick : function(node, e){
	},
		
	onClick : function(node, e){
		
		this.selectedNode = node;

		if (!this.selectedNode.attributes.leaf) {
			
		}else{
			
			
			
			
  		  dataSrc = Ext.util.Format.htmlDecode(this.selectedNode.attributes.url)

    		Ext.Ajax.request({
    			url: './src/api/Interface.php',
    			params:{
    					'class':'Camping',
    					'method':'updateBlogCount',
    					'camping_blog_uid':this.selectedNode.attributes.uid
    					},
    			scope:this,
    			success:function(response, options){
    				var json = Ext.decode(response.responseText);
    				if(json.success){
    				}else{
    				}
    			},
    			failure:function(response, options){
    			}
    		});	

  		  	
  		  	window.open(this.selectedNode.attributes.url,"_blank");
  		  /**
				title= Ext.util.Format.ellipsis(this.selectedNode.attributes.textonly, 15);
				var iframe = new Ext.ux.ManagedIframePanel({
						id:this.selectedNode.attributes.url,
						title:title,
						cls:'scroll',
						width:100,
						height:100,
						closable:true,
						defaultSrc:dataSrc,
						loadMask : false,
			    		animCollapse:true
				});
				
				iframe.on('activate', function(){
					Ext.getCmp('layout').doLayout();
				},this);
				
				Ext.getCmp('centerCenterPanel').add(iframe);
				Ext.getCmp('centerCenterPanel').activate(iframe);
			**/
		}
		
		//Ext.getCmp('layout').doLayout();

	}

});

