Ext.namespace("Ext.hansub.daumAPI");

Ext.hansub.daumAPI.DaumIMGOpenAPIPanel = function(config) { 
	
	this.config = config;
	
	
	this.store = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url : './src/api/OpenAPI.php',
	       	method : 'POST'
        }),  
        baseParams:{
				'class':'OpenAPI',
				'method':'getDaumXML',
				target:this.config.data.target,
				keyword:this.config.data.keyword,
				start:this.config.start,
				display:this.config.display
		},

        reader: new Ext.data.XmlReader(
            {
            	record: 'item',
            	totalProperty: 'total'
            },
            
            [
            	{name: 'title', mapping:'title', type: 'string'},
            	{name: 'link', mapping:'link', type: 'string'},
            	{name: 'thumbnail', mapping:'thumbnail', type: 'string'}
            	]
//
        )
    });
    
    this.store.load();

    var tpl;
    
    if(EMAIL == "hansub@samsung.com"){
  		//'<a href={link} target=_blank><img src="{thumbnail}"></a>&nbsp;',
  		//'<a href=http://www.campingjido.com/src/api/setCampingMainImage.php?imagelink={thumbnail} target=_blank><img src="{thumbnail}"></a>&nbsp;',
      tpl = new Ext.XTemplate(
  		'<iframe name=ifr width=0 height=0></iframe><br><br><tpl for=".">',
              '',
  		'<a href=./src/api/setCampingMainImage.php?force=true&camping_tool_uid='+this.config.data.camping_tool_uid+'&camping_list_uid='+this.config.data.camping_list_uid+'&imagelink={thumbnail} target=ifr><img src="{thumbnail}"></a>&nbsp;',
  		    '',
          '</tpl>',
          '<div class="x-clear"></div>'
    	);
    }else{
      tpl = new Ext.XTemplate(
  		'<iframe name=ifr width=0 height=0></iframe><br><br><tpl for=".">',
              '',
  		//'<a href={link} target=_blank><img onLoad="cvi_corner.add(this, \{ radius:5\});" src="{thumbnail}" width="100"></a>&nbsp;',
              '<a href={link} target=_blank><img src="{thumbnail}" width="100"></a>&nbsp;',
  		    '',
          '</tpl>',
          '<div class="x-clear"></div>'
    	);
	}
   
  
	Ext.hansub.daumAPI.DaumIMGOpenAPIPanel.superclass.constructor.call(this, {
		
		id:this.config.id,
		border:false,
		//frame:true,
		iconCls:this.config.iconCls,
       	region:this.config.region,
		//title:this.config.data.keyword+ " 이미지 검색결과",
		split: true,

        items: new Ext.DataView({
            store: this.store,
            loadMask: {msg:'화면 구성 중'},
          	scope:this,
            tpl: tpl,
            autoHeight:true,
            multiSelect: true,
            overClass:'x-view-over',
            itemSelector:'div.thumb-wrap',
            //emptyText: '<center>이미지 정보가 없습니다.</center>',

            prepareData: function(data){
            	
                data.s_title = Ext.util.Format.ellipsis(data.title, 8);
                return data;
            },
            //click : ( Ext.DataView this, Number index, HTMLElement node, Ext.EventObject e )
            listeners: {
            	scope:this,
            	click: {
            		fn: function(dv,index){
            			
            			
            			
            			records = this.store.getAt(index);
            			
            			window.open(records.data.link,"_blank");
            			
            			/**
            			title= Ext.util.Format.ellipsis(records.data.title, 15);
            			if(Ext.getCmp('imgFrameID')){
            				Ext.getCmp('imgFrameID').setSrc(records.data.link);
							Ext.getCmp('centerRightTabPanelID').activate(Ext.getCmp(records.data.link));
							Ext.getCmp('imgFrameID').setTitle(title);
						}else{
							
							var iframe = new Ext.ux.ManagedIframePanel({
									id:'imgFrameID',
									iconCls:'img_icon',
									title:title,
									loadMask:true,
									cls:'scroll',
									closable:true,
									defaultSrc:records.data.link,
									loadMask : false,
						    		animCollapse:true
							});
							
							Ext.getCmp('centerCenterPanel').add(iframe);
							Ext.getCmp('centerCenterPanel').activate(iframe);
							
						}
						Ext.getCmp('mainToolbarID').layout('main_right2');
						**/
            			
            		}
            	}
            }
        })

        
							        
									
	});
	
	
	this.on('activate', function(){Ext.getCmp('mainToolbarID').layout('main_right2');},this);
};

Ext.extend(Ext.hansub.daumAPI.DaumIMGOpenAPIPanel, Ext.Panel, {
	
	onTriggerClear:function() {
        this.searchTextField.setValue('');
        this.field.focus();
        
    },
    
    search:function(){
		
		this.keyword = this.searchTextField.getValue();
		
		this.store.load(
				{
					params:{
						keyword:this.keyword
					}
				}
			);

	}
	

});

