Ext.namespace("Ext.hansub.camping");

Ext.hansub.camping.CampingIMGPanel = function(config) { 
	
	this.config = config;
	
	
	this.store = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url : './src/api/Interface.php',
	       	method : 'POST'
        }),  
        baseParams:{
				'class':'Camping',
				'method':'getCampingFile',
				camping_list_uid:this.config.camping_list_uid
		},

       	reader: new Ext.data.JsonReader(
	  		{
	   			root:'file'
			},
	  		[
				{name: 'camping_user_name', mapping:'camping_user_name'},
			 	{name: 'uid', mapping:'uid'},
				{name: 'name', mapping:'name'},
				{name: 'realname', mapping:'realname'},
				{name: 'regdate', mapping:'regdate'},
				{name: 'content', mapping:'content'}
				]
		)
    });
    
    this.store.load();
  
    var tpl = new Ext.XTemplate(
		'<tpl for=".">',
            '<div class="thumb-wrap2" id="{name}">',
			'<div class="content2"><br><img src=http://www.campingjido.com/campingicons/PNG/16x16/window_edit.png><b><font color=#1d4273> {content}</b> ({camping_user_name})</font></div>',
			'<div class="content2"><table width=100% height=3 border=0 style=\'border-top-width:2; border-top-color:#8db2e3; border-top-style:solid;\'><tr><td width=20></td></tr></table> </div>',
//			'<div class="content2"><br><table width=100% height=18 border=0 style=\'border-bottom-width:2; border-bottom-color:#8db2e3; border-bottom-style:solid;\'><tr><td width=20><img src=http://www.campingjido.com/campingicons/PNG/16x16/window_edit.png></td><td><b><font color=#1d4273> {content}</b> ({camping_user_name})</font></td></tr></table> </div>',
		    '<div class="thumb2" align=center><br><img src="./images/upload/thumb/camping/720/{realname}" title="{name}"><br><br></div>',
			'</div>',
        '</tpl>',
        '<div class="x-clear"></div>'
	);
   
  
	Ext.hansub.camping.CampingIMGPanel.superclass.constructor.call(this, {
		
		id:this.config.id,
		border:false,
		iconCls:this.config.iconCls,

        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.content, 8);
                return data;
            }
        })

        
							        
									
	});
	
	
	//this.on('activate', function(){Ext.getCmp('mainToolbarID').layout('main_right2');},this);
	//this.view.target = this.config.target;
	/**
	this.boardGridSM = this.getSelectionModel();

    this.boardGridSM.on('rowselect', function(sm, index, record){
    	
    	this.selectedRecord = record;
    	if(index == 1){
    		this.linkLoad();
    	}
    	
    	
    }, this)
    **/

    
    
    
 
};

Ext.extend(Ext.hansub.camping.CampingIMGPanel, Ext.Panel, {
	
    load:function(){
		
		this.store.load();
	}
	
	/**
	
	setKeyword:function(keyword){
		
		this.isloaded = false;
		this.config.data.keyword = keyword.replace(" ", "+");
		this.config.data.keyword = "결혼+"+this.config.data.keyword
		
	},
	
	setViewType:function(viewtype){
		
		this.config.data.viewtype = viewtype
		this.view.showView = this.config.data.viewtype;
		this.view.refresh();

	},
	
	loadAPI : function(){
		if(!this.isloaded){
			this.store.load(
				{
					params:{
						keyword:this.config.data.keyword
					}
				}
			);
			this.isloaded = true;
		}
		
		
		
	},
	
	onDbClick:function(grid,index,e){
		this.addTab(null,this.store.getAt(index),null,null);
	},
	
	addTab:function(grid, records, action, groupId){
		
		if(records && records.data.link ){
			
			records.data.link = Ext.util.Format.htmlDecode( records.data.link) 
			
			//title = Ext.util.Format.ellipsis(this.selectedRecord.data.title, 20);
			title = records.data.title;
			
			
			if(Ext.getCmp(records.data.link)){
				Ext.getCmp('centerTopPanelID').activate(Ext.getCmp(records.data.link));
			}else{
				title= Ext.util.Format.ellipsis(title, 15);
				var iframe = new Ext.ux.ManagedIframePanel({
						id:records.data.link,
						title:title,
						cls:'scroll',
						closable:true,
						defaultSrc:records.data.link,
						loadMask : false,
			    		animCollapse:true
				});
				
				iframe.on('activate', function(){Ext.getCmp('centerRightPanelID').collapse(false);},this);
				
				Ext.getCmp('centerTopPanelID').add(iframe);
				Ext.getCmp('centerTopPanelID').activate(iframe);
				
				
				
			}
			
			
		}
	},
	/**
	linkLoad:function(selectedRecord){
		
		if(selectedRecord && selectedRecord.data.link ){
			
			selectedRecord.data.link = Ext.util.Format.htmlDecode( selectedRecord.data.link) 
			
			//title = Ext.util.Format.ellipsis(this.selectedRecord.data.title, 20);
			title = selectedRecord.data.title;
			
			if(Ext.getCmp(selectedRecord.data.title)){
				Ext.getCmp('centerTopPanelID').activate(Ext.getCmp(selectedRecord.data.title));
			}else{
				
				var iframe = new Ext.ux.ManagedIframePanel({
						id:selectedRecord.data.title,
						title:title,
						cls:'scroll',
						closable:true,
						defaultSrc:selectedRecord.data.link,
						loadMask : false,
			    		animCollapse:true
				});
				
				Ext.getCmp('centerTopPanelID').add(iframe);
				Ext.getCmp('centerTopPanelID').activate(iframe);
				
			}
			
			
		}
		
	},
	
	applyRowClass: function(record, rowIndex, p, ds) {
		
        if(this.showView == 'title'){			
        	return 'x-grid3-row-collapsed';     	
        }else if(this.showView == 'summary'){
        	content = Ext.util.Format.stripTags(record.data.description);
        	if(content == ""){
        		return 'x-grid3-row-collapsed';
        	}
        	p.body = '<div class=boardsummary>' + content + '</div>';
            return 'x-grid3-row-expanded';
        }else if(this.showView == 'full'){
			p.body = '<div class=boardcontent>' + record.data.description + '</div>';
            return 'x-grid3-row-expanded';
        }else{
        	return 'x-grid3-row-collapsed';
        }
        
    },
    
    formatDate : function(date) {
        if (!date) {
            return '';
        }
        var now = new Date();
        var d = now.clearTime(true);
        var notime = date.clearTime(true).getTime();
        if (notime == d.getTime()) {
            return '오늘 ' + date.dateFormat('g:i a');
        }
        d = d.add('d', -6);
        if (d.getTime() <= notime) {
            return date.dateFormat('D g:i a');
        }
        return date.dateFormat('n/j g:i a');
    },
    

    
    titleFormat: function(value, p, record,rowIndex, colIndex, store) {
    	
    	return String.format(
                '<div class="'+store.baseParams.target+'">{0}<span class="author">{1}</span></div>',
                value, record.data.author, record.id, record.data.forumid
                );
    },
    
    imageFormat: function(value, p, record) {
    	return String.format('<img src={0} height=100>',value);
    },
    
    korMoney :  function(v, params, record){
		
		var usMoney = Ext.util.Format.usMoney(v);
		if(usMoney == '$NaN.00'){
			hanMoney = '0';
			record.data.expected = 0;
		}else{
			hanMoney = usMoney.substr(1,usMoney.length-4);
		}
		return hanMoney + ' 원';
                 
	},
    
    onContextClick : function(grid,index,e){
    	
    	this.getSelectionModel().selectRow(index);
    	this.selectedRecord = this.store.getAt(index);
		
        this.addMenu.showAt(e.getXY());
      
    },
    onTriggerClear:function() {
        this.searchTextField.setValue('');
        this.field.focus();
        
    },
    
    search:function(){
		
		keyword = this.searchTextField.getValue();

		if(keyword){
			
			this.setKeyword(keyword);
			this.loadAPI();
						
		}
	},
	
	setListLayout:function(viewtype){
    	   	
  
		if(viewtype == 'title'){
			
    		this.layoutItemButton.setText('간략하게 보기');
    		this.layoutItemButton.setIconClass('view_summary');
    		this.titleLayoutButton.disable();
    		this.summaryLayoutButton.enable();
				
    	}else if(viewtype == 'summary'){
    		
    		this.layoutItemButton.setText('제목만 보기');
    		this.layoutItemButton.setIconClass('view_title');
    		this.titleLayoutButton.enable();
    		this.summaryLayoutButton.disable();
			
    	}else{
    		
    		if(this.viewtype == 'title'){
    			this.layoutItemButton.setText('제목만 보기');
    			this.layoutItemButton.setIconClass('view_title');
    			this.titleLayoutButton.enable();
    			this.summaryLayoutButton.disable();
    			viewtype = "summary";
    		}else{
    			this.layoutItemButton.setText('간략하게 보기');
    			this.layoutItemButton.setIconClass('view_summary');
    			this.titleLayoutButton.disable();
    			this.summaryLayoutButton.enable();
    			viewtype = "title";
    		}
 		
    	}
		
    	this.viewtype = viewtype;
    	
		this.setViewType(viewtype);

		

    }
	**/

});

