Ext.namespace("Ext.hansub.camping");

Ext.hansub.camping.CampingGridPanelEx = function(obj) {
	//this.activate = false;
	this.obj = obj;
	this.pageSize = 40;
	this.isloaded = false;
	this.isSetData = false;
	text = "캠핑장 등록";
	
	 this.regButton = new Ext.Button({
		text:'캠핑장 등록',
		iconCls:'add',
		handler:this.regCamping,
		scope:this
	});

	 this.conquerorInfoButton = new Ext.Button({
		text:'                             ',
		iconCls:'user_icon',
		scope:this
	});



	this.addButton = new Ext.Action({
    	text:text,
		//tooltip:{title:text, text:'게시글을 작성합니다.'},
		iconCls:'write',
		scope:this,
		handler:this.addItem
    });
    
 
    
    
    
    
    
    this.titleButton = new Ext.menu.Item({
		text:'제목만 보기',
		iconCls:'view_title',
		scope:this,
		handler:this.setListLayout.createDelegate(this, ['title'])
	        
	});
	this.summaryButton = new Ext.menu.Item({
		text:'간략하게 보기',
		iconCls:'view_summary',
		scope:this,
		handler: this.setListLayout.createDelegate(this, ['summary'])
	});
	this.detailButton = new Ext.menu.Item({
		text:'전체내용 보기',
		iconCls:'view_full',
		scope:this,
		handler: this.setListLayout.createDelegate(this, ['full'])
	});
	
	/**
	 * view 메뉴
	 */
	
	items = [this.titleButton,this.summaryButton,this.detailButton];
	
	this.viewMenu = new Ext.menu.Menu({
		scope:this,
        items: items
    });

    
    /**
     * SpliteButton
     */
    this.viewSplitButton = new Ext.Toolbar.SplitButton({
		iconCls:'view_summary',
		text:'간략하게 보기',
		menu:this.viewMenu,
		handler:this.setListLayout.createDelegate(this, ['swiching'])
    })
	
	
    
    
    /**
    this.deleteButton = new Ext.Toolbar.Button({
    	text:'삭제',
		tooltip:{title:'삭제', text:'선택한 항목을 삭제 합니다.'},
		iconCls:'delete',
		scope:this,
		handler:this.deleteItem
    });
    **/
    /**
    this.newWinButton = new Ext.Toolbar.Button({
    	text:'새창보기',
		tooltip:{title:'새 창에서 보기', text:'현재 게시판을 새창으로 봅니다.'},
		iconCls:'new_win_icon',
		scope:this,
		handler:this.newWin
    });
 	**/
    //Ext.DomHelper.append(Ext.getCmp('id').body, {tag: 'img', src: 'foo', width: '50', height: '50'});
    /**
	 * 버튼 메뉴
	 */
    /**
	this.addMenu = new Ext.menu.Menu({
		scope:this,
        items: [
        		this.addButton ,
        		'-',
        		this.newWinButton
	        	]
    });
    **/
    
	// data store 설정
	this.obj.ds = new Ext.data.GroupingStore({ 
		proxy : new Ext.data.HttpProxy({
	    	url : './src/api/Interface.php',
	       	method : 'POST'
	       	
	    }),
	    baseParams : {
			'class':'Camping',
			method:'getCampingList',
			html:'true'
		},
	    
	    reader: new Ext.data.JsonReader({ 
            root: 'rows', 
            totalProperty: 'count',
            id:'uid'
        }, [ 
        	{name: 'uid', mapping:'uid', type: 'string'},
        	{name: 'camping_region1_name', mapping: 'camping_region1_name', type: 'string'},
			{name: 'camping_region2_name', mapping: 'camping_region2_name', type: 'string'},
            {name: 'name', mapping: 'name', type: 'string'},
            {name: 'clabel', mapping: 'clabel', type: 'string'},
			{name: 'content', mapping: 'content', type: 'string'},
			{name: 'location', mapping: 'location', type: 'string'},
			{name: 'capacity', mapping: 'capacity', type: 'auto'},
			{name: 'internet', mapping: 'internet', type: 'string'},
			{name: 'power', mapping: 'power', type: 'string'},
			{name: 'water', mapping: 'water', type: 'string'},
            {name: 'files', mapping: 'files', type: 'auto'},
			{name: 'x', mapping: 'x', type: 'auto'},
			{name: 'y', mapping: 'y', type: 'auto'},
			
			{name: 'homepage', mapping: 'homepage', type: 'auto'},
			{name: 'tel', mapping: 'tel', type: 'auto'},
			{name: 'address', mapping: 'address', type: 'auto'},
			{name: 'toilet', mapping: 'toilet', type: 'auto'},
			{name: 'shower', mapping: 'shower', type: 'auto'},
			{name: 'sink', mapping: 'sink', type: 'auto'},
			{name: 'winter', mapping: 'winter', type: 'auto'},
			{name: 'autocaping', mapping: 'autocaping', type: 'auto'},
			{name: 'store', mapping: 'store', type: 'auto'},
			{name: 'waterplay', mapping: 'waterplay', type: 'auto'},
			{name: 'rental', mapping: 'rental', type: 'auto'},
			{name: 'playground', mapping: 'playground', type: 'auto'},
			{name: 'withcampingcar', mapping: 'withcampingcar', type: 'auto'},
			{name: 'barbecue', mapping: 'barbecue', type: 'auto'},
			{name: 'fishing', mapping: 'fishing', type: 'auto'},
			{name: 'mtb', mapping: 'mtb', type: 'auto'},
			{name: 'swimming', mapping: 'swimming', type: 'auto'},
			{name: 'mountain', mapping: 'mountain', type: 'auto'},
			{name: 'canoe', mapping: 'canoe', type: 'auto'},
			{name: 'ski', mapping: 'ski', type: 'auto'},
			{name: 'landtype', mapping: 'landtype', type: 'auto'},
			{name: 'reservationtype', mapping: 'reservationtype', type: 'auto'},
			{name: 'description', mapping: 'description', type: 'auto'},
			{name: 'camping_list_uid', mapping: 'camping_list_uid', type: 'auto'},
			{name: 'groupfieldname', mapping: 'groupfieldname', type: 'auto'},
			{name: 'updatetxt', mapping: 'updatetxt', type: 'auto'},
			{name: 'isConqueror', mapping: 'isConqueror', type: 'auto'},
			{name: 'conquerorCount', mapping: 'conquerorCount', type: 'auto'},
			{name: 'imagelink', mapping: 'imagelink', type: 'auto'},
			{name: 'comment', mapping: 'comment', type: 'auto'},
			
			//conquerorCount
			
		
			//
			
            {name: 'regdate', mapping: 'regdate', type: 'string'}
        ]),
       	//groupField: 'camping_region1_name',
       	remoteSort:true,
       	remoteGroup:true,
       	//groupOnSort:true,
        //sortInfo: {field: 'camping_region1_name', direction: 'asc'}
        sortInfo: {field: 'conquerorCount', direction: 'desc'}
    });
    
    this.pagingBar = new Ext.PagingToolbar({
        pageSize: this.pageSize,
        store: this.obj.ds,
        displayInfo: true,
        displayMsg: '<b>{0} - {1} of {2}</b>',
        autoWidth:true,
        emptyMsg: "내용이 없습니다.",
        plugins:new Ext.ux.PageSizePlugin()
      
    });
    
   // this.pageSizePlugin = new Ext.ux.PageSizePlugin();

	
	
	/**
	
	this.expander = new Ext.grid.RowExpander({
		lazyRender:true,
		enableCaching:false,
        tpl : new Ext.XTemplate(
        	'<div class=boardcontent>',
        		'{content}',
        	'</div>'
        )
    });
    **/
    if(this.obj.text){
		this.obj.title = this.obj.text;
	}
	
	// rowaction
	/**
	this.rowAction = new Ext.ux.grid.RowActions({
		header:'',
		autoWidth:false,
		scope:this,
		width:120,
		actions:[
					{
						iconCls:'row_modify',
						text:'변경',
						qtip:'선택된 내용을 변경합니다.',
						scope:this,
						callback:this.modify
					},{
						iconCls:'row_delete',
						text:'삭제',
						qtip:'선택된 내용을 삭제합니다.',
						scope:this,
						callback:this.deleteItem
					}
					
					
				]
	});
	**/
	//this.rowAction.s_boardtype_uid = this.obj.data.s_boardtype_uid;this.searchField.field.setValue('')
	//alert(this.rowAction.s_boardtype_uid);
	this.searchField = new Ext.ux.grid.Search({
					        position:'top',
				            iconCls:'board_search',
				            searchTipText:'검색어를 입력하세요',
				            dateFormat:'m/d/Y',
				            minLength:2,
				            //disableIndexes:['s_boardcat_name','s_user_name','regdate'],
				            width:150,
				            searchText:'캠핑장 검색',
				            selectAllText:'전체',
				            paramNames: {
						         fields:'fields'
						        ,query:'keyword'
						    }
				        })
	/**
	this.rowAction.on({ 
		header:'Actions',
		action:function(grid, record, action, row, col) {}
	})
**/
	/**
		this.selectModel = new Ext.grid.CheckboxSelectionModel({
			checkOnly : false,
			header :''
//			width : 30
		});
		**/
		//conquerorCount
		this.obj.columns = [	//this.expander,
		//this.selectModel,
		{
			header: "정복",
			width: 30,
			sortable: true,
			menuDisabled:true,
			dataIndex: 'isConqueror',
			renderer: this.conqueror
		},{
			header: "도/시",
			width: 30,
			sortable: true,
			dataIndex: 'camping_region1_name'
		},{
			header: "시군구",
			width: 40,
			sortable: true,
			dataIndex: 'camping_region2_name'
		},{
			header: "한장컷",
			width: 70,
			sortable: true,
			dataIndex: 'imagelink'
		},{
			header: "캠핑장 (최근 주요 한줄 평)",
			width: 340,
			sortable: true,
			dataIndex: 'comment'
/*
		},{
			header: "최근 한줄 후기",
			width: 300,
			sortable: true,
			dataIndex: 'comment'
		},{
			header: "업데이트",
			width: 50,
			sortable: true,
			dataIndex: 'updatetxt'
*/
		},{
			header: "정복수",
			width: 30,
			sortable: true,
			dataIndex: 'conquerorCount'
		},{
			header: "규모",
			width: 20,
			sortable: true,
			dataIndex: 'capacity'
		},{
			header: "화로",
			width: 30,
			sortable: true,
			dataIndex: 'barbecue',
			renderer: this.xyIcon
		},{
			header: "인터넷",
			width: 30,
			sortable: true,
			dataIndex: 'internet',
			renderer: this.xyIcon
		},{
			header: "전기",
			width: 30,
			sortable: true,
			dataIndex: 'power',
			renderer: this.xyIcon
		},{
			header: "온수",
			width: 30,
			sortable: true,
			dataIndex: 'water',
			renderer: this.xyIcon
		}/*, {
			header: "연락처",
			width: 85,
			sortable: true,
			dataIndex: 'tel'
		}  */     
		];

    // select model
    //this.obj.sm = this.selectModel;
	
   this.obj.viewConfig = {
            forceFit:true
   };
   
   this.obj.loadMask = {msg:'캠핑장 목록 구성 중..'};
   
   this.obj.view = new Ext.grid.GroupingView({
            forceFit:true,
            enableRowBody:true,
            showGroupName: false,
            showPreview:true,
           	getRowClass : this.applyRowClass,
            //groupTextTpl: '<font face=\"맑은 고딕\"><span style=font-size:11px;>{text} ( {[values.rs.length]} {[values.rs.length > 1 ? "개 캠핑장이 등록됨</font></span>" : "개 캠핑장이 등록됨</font></span>"]})'
            groupTextTpl: '<span style=font-size:12px;>{text}지역 캠핑지도<span>'
        })
        
    this.obj.plugins = [
    		//this.rowAction,
			//this.expander, 
			this.searchField
			];
    //this.obj.tbar = [this.titleButton, this.summaryButton, this.detailButton,'-',this.addButton ];
			
	
	this.obj.tbar = [" ",this.regButton, "-", this.conquerorInfoButton];
    
    this.obj.bbar = this.pagingBar;
	   
	Ext.hansub.camping.CampingGridPanelEx.superclass.constructor.call(this, this.obj);
							      
	
	
	/*
	this.boardGridSM = this.getSelectionModel();
	this.boardGridSM.on('rowselect', this.selectedRow, this);
	*/
	//this.on('rowclick',this.clickRow, this);
	
			
	this.obj.ds.on("beforeload", function(store, options){
		
		//start = (this.pagingBar.getPageData().activePage-1) * 10;
           
		//alert(this.pagingBar.getPageData().activePage);
		//this.obj.ds.baseParams.start = 0;
		this.obj.ds.baseParams.limit = this.pagingBar.pageSize,
		this.obj.ds.baseParams.table = this.obj.data.table;
		this.obj.ds.baseParams.uid = this.obj.data.uid;
		//this.obj.ds.baseParams.keyword = this.searchField.field.getValue();
		
	
	},this);
	
	
	this.view.showView = this.obj.data.viewtype;
  	
  	this.on('cellclick',this.clickRow, this);
  	
  	this.obj.ds.on('load', this.updateSelect,this);
  	
  	
  	
	this.obj.ds.load();
  	
  	
  	
  	//this.obj.ds.on('beforeload', this.preUpdateSelect,this);
	
	/**
	this.obj.ds.load({
			params:{
					start:0,
					limit:this.pagingBar.pageSize
					}
				});
	**/
	/**
	this.obj.ds.on("load", function(store){
		
		//this.view.refresh(true);
		//this.getView().refresh();
		//alert('view refresh');
		//this.expander
		
	},this);
	**/
	//});
	/**
	this.on('activate', function(){

		if(this.isloaded == false){	  
			  
			if(this.isSetData == false){  
			   	this.obj.ds.load();
			    this.isSetData = false;
			  	this.view.refresh(true);
			}
	
	
		 	this.view.showView = this.obj.data.viewtype;
		  	
		  	this.on('cellclick',this.clickRow, this);
		  	
		  	//this.on('render',this.updateSelect,this);
		  	
		  	this.obj.ds.on('load', this.updateSelect,this);
		  	this.obj.ds.on('beforeload', this.preUpdateSelect,this);
		  	
		  	//this.selectModel.on('rowdeselect', this.deselectRow, this);
		  	//this.selectModel.on('rowselect', this.markRow, this);
		  	this.isloaded = true;
		}},this);
//			Ext.getCmp('mainToolbarID').viewtype('price');
//		Ext.getCmp('layout').doLayout();
									//Ext.getCmp('mainToolbarID').layout('main_right');
									//Ext.getCmp('centerRightTabPanelID').remove('commentGridPanelID');
									//Ext.getCmp('centerRightTabPanelID').remove('acountCommentGridPanelID');
								
	
	/*
		Ext.Ajax.request({
			url: './src/api/Interface.php',
			params:{
					'class':'Camping',
					'method':'getConquerorRateByUser'
					},
			scope:this,
			success:function(response, options){
				var json = Ext.decode(response.responseText);
				if(json.success){
		    	this.conquerorInfoButton.setText("\""+NAME+"\"님의 캠핑지도 정복률 : <font color=red>"+json.conqueror_rate+"</font>% (전국 "+json.conqueror_count+"/"+json.total_count+"개 정복)");
       	}else{
		    	this.conquerorInfoButton.setText('오늘의 캠지캠퍼: \"꽃님엄마\"님의 캠핑지도 정복률 : <font color=red>8</font>% (전국 24/359개 정복)');
		    	this.conquerorInfoButton.setDisabled(true);
				}
			},
			failure:function(response, options){
				Ext.MessageBox.alert('오류', '서버에 응답이 없습니다. 잠시 후 다시 접근해 주세요.')
			}
		});	
*/
	//this.updateConquerorInfo();
		
	//rowdeselect : ( SelectionModel this, Number rowIndex, Record record ) 
	//cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e ) 
    //this.regButton.setVisible(true);
};

Ext.extend(Ext.hansub.camping.CampingGridPanelEx, Ext.grid.GridPanel, {
	
	// toolbar 업데이트
	updateConquerorInfo:function(){
		Ext.Ajax.request({
			url: './src/api/Interface.php',
			params:{
					'class':'Camping',
					'method':'getConquerorRateByUser'
					},
			scope:this,
			success:function(response, options){
				var json = Ext.decode(response.responseText);
				if(json.success){
		    	this.conquerorInfoButton.setText("\""+NAME+"\"님의 캠핑지도 정복률 : <font color=red>"+json.conqueror_rate+"</font>% (전국 "+json.conqueror_count+"/"+json.total_count+"개 정복)");
		    	Ext.getCmp('mainToolbarID').userButton.setText("<b>"+NAME+" ("+EMAIL+", 정복률 : <font color=blue>"+json.conqueror_rate+"</font>%)</b> ");
       	}else{
		    	this.conquerorInfoButton.setText('오늘의 캠지캠퍼: \"꽃님엄마\"님의 캠핑지도 정복률 : <font color=red>8</font>% (전국 24/410개 정복)');
		    	//this.conquerorInfoButton.setDisabled(true);
				}
			},
			failure:function(response, options){
				Ext.MessageBox.alert('오류', '서버에 응답이 없습니다. 잠시 후 다시 접근해 주세요.')
			}
		});	
	},

	markRow:function(record){
		
		//if(!this.activate){return};
		if (!IS_LOGIN) {

			if(!Ext.getCmp('loginWindowID')){
				this.loginWin = new Ext.hansub.user.LoginWindow();
			    this.loginWin.on('login', this.loginState, this);
	        }
	        Ext.getCmp('loginWindowID').reset();
	    	Ext.getCmp('loginWindowID').show();
	
				return;
		}
		
		this.record = record;

		Ext.Msg.prompt('캠핑지도 정복지 등록하기', record.data.name+'을(를) 내가 정복한 캠핑장으로 마크합니다. <br>정복 기념으로 다른 캠지 캠퍼들을 위해 한줄 평 부탁드립니다.^^<br><br>(작성된 한줄 평은 내년도 \'캠핑지도 500\'책자에 실릴수 있습니다.)', function(btn, text){
					if (btn == 'ok'){
	
						Ext.Ajax.request({
							url: './src/api/Interface.php',
							params:{
								'class':'Camping',
								'method':'setConqueror',
								'camping_list_uid':record.data.camping_list_uid,
								camping_inline_comment:text,
								mode:'add'
								
							},
							waitMsg:'선택한 캠핑장을 정복지로 등록하고 있습니다.',
							scope:this,
							success:function(response, options){
								this.updateConquerorInfo();
								this.record.set('isConqueror', true);
								this.getView().refresh(false);
								
							},
							failure:function(response, options){
								Ext.MessageBox.alert('ERROR', '항목 등록시 오류가 발생하였습니다..');
							}
						});
						
					}else{ //취소 선택 시
						
						//this.activate = false;
						//this.selectModel.deselectRow(this.rowIndex,true);
						//this.getView().refresh(false);
						//this.activate = true;
					}
			},this);
		//여기까지 msg박스를 이용한 정복지 마크

		
	},
	/**
	cancelRow:function(rowIndex){
		//this.activate = false;
		this.selectModel.deselectRow(rowIndex,true);
		this.getView().refresh(false);
		//this.activate = true;
	},
	**/
	deselectRow:function(record){
		
		//if(!this.activate){return};
		if (!IS_LOGIN) {
			//Ext.Msg.show('정복지 등록', '캠핑장 정복지 등록은 로그인 후 가능합니다.');
	  		if(!Ext.getCmp('loginWindowID')){
	  			this.loginWin = new Ext.hansub.user.LoginWindow();
	  		    this.loginWin.on('login', this.loginState, this);
	  		}
	  		Ext.getCmp('loginWindowID').reset();
	      	Ext.getCmp('loginWindowID').show();
			return;
		}
		this.record = record; 
		Ext.Msg.show({
			title:'정복지 취소',
			scope:this,
			msg: record.data.name+' 에 대한 정복지 마크를 취소 하시겠습니까 ?',
			buttons:Ext.Msg.YESNO,
			icon:Ext.MessageBox.QUESTION,
			fn:function(btn, text){
				if(btn == 'yes'){
					Ext.Ajax.request({
						url: './src/api/Interface.php',
						params:{
							'class':'Camping',
							'method':'setConqueror',
							'camping_list_uid':record.data.camping_list_uid
							
						},
						waitMsg:'정복지를 취소하고 있습니다.',
						scope:this,
						success:function(response, options){
							this.updateConquerorInfo();
							this.record.set('isConqueror', false);
							this.getView().refresh(false);
										
						},
						failure:function(response, options){
							Ext.MessageBox.alert('ERROR', '항목 삭제시 오류가 발생하였습니다..');
						}
						            	
								
					});
				}else{
					//this.activate = false;
					//this.selectModel.selectRow(this.obj.ds.indexOf(record),true);
					//this.getView().refresh();
					//this.activate = true;
				}
			}
		});
		
	},
	
	preUpdateSelect:function(){
		//this.activate = false;
	},
	
	updateSelect:function(){
		this.updateConquerorInfo();
		
		//this.searchField.field.setValue('');
		delete(this.obj.ds.baseParams[this.searchField.paramNames.fields]);
        delete(this.obj.ds.baseParams[this.searchField.paramNames.query]);
        /**
		size = this.obj.ds.getCount();
		for(i=0;i<size;i++){
			record = this.obj.ds.getAt(i);
			if(record.get('isConqueror')){
				this.activate = false;
				this.selectModel.selectRow(this.obj.ds.indexOf(record),true);
			}
		}	
		this.activate = true;
		**/
	},
	
	loginState: function(){
		/**
		if (IS_LOGIN) {
			this.regButton.setVisible(true);
		}else{
			this.regButton.setVisible(false);
		}
		**/
	},
	
	regCamping : function(){
		
			if(IS_LOGIN){
		
				this.addCampingContentWindow = new Ext.hansub.camping.AddCampingContentWindow({
							id:'addCampingContentWindowID',
							title: '캠핑장 등록',
							iconCls:'add',
					        width:800,
					        resizable:true,
					        height: 570,
							data:{
	
								parentID : this.getId()
							
														
							}
						        				        
				});
			
				
			
					
				this.addCampingContentWindow.show();
				
			}else{
				if(!Ext.getCmp('loginWindowID')){
					this.loginWin = new Ext.hansub.user.LoginWindow();
				    //this.loginWin.on('login', this.loginState, this);
		        }
		        Ext.getCmp('loginWindowID').reset();
		    	Ext.getCmp('loginWindowID').show();
				
			}
		
		
	},
	
	conqueror : function(value,p,record){
	
		if(value){
			return "<center><img src='./images/icons/flag_red.png'></center>";
		}else{
			return "<center><img src='./images/icons/flag_white.png'></center>";
		}
		



	},
	
	xyIcon : function(value,p,record){
		
			return "<center><img src='./images/icons/"+value+".png'></center>";
		
		
		
	},
	clickRow : function(grid, index, columnIndex, e){
		
		record = this.obj.ds.getAt(index);
		
		if(columnIndex == 0){
		
			if(record.get('isConqueror')){
				this.deselectRow(record);
			}else{
				this.markRow(record);
			}
			return;
		}
		
		
    	/**
    	if(!Ext.getCmp('boardContentPanel_'+record.data.uid)){
			var boardContentPanel = new Ext.hansub.camping.CampingContentPanel(
									this,
									{
										title:record.data.name,
										id:'boardContentPanel_'+record.data.uid,
										closable:true,
										closeAction:'false',
										height:300,
										collapsible: true,								
										border:false,
										split: true,
										data:record.data								
									}
								);
		}else{
			Ext.getCmp('boardContentPanel_'+record.data.uid).setContent(record.data);
		}
		
		**/
		
		if (Ext.getCmp("CampingWrapperPanel_"+record.data.uid)) {
		
			Ext.getCmp('centerCenterPanel').activate("CampingWrapperPanel_"+record.data.uid);
		}
		else {
			
			this.campingDetailPortalPanel = new Ext.hansub.camping.CampingDetailPortalPanel({
												id:"CampingWrapperPanel_"+record.data.uid,
												x:record.data.x,
												y:record.data.y,
												name: record.data.name,
												record_data : record.data
											});
			
			Ext.getCmp('centerCenterPanel').add(this.campingDetailPortalPanel);
			Ext.getCmp('centerCenterPanel').activate(this.campingDetailPortalPanel);
			
			/**
			this.campingWrapperPanel = new Ext.hansub.camping.CampingWrapperPanel({
				id:"CampingWrapperPanel_"+record.data.uid,
				x:record.data.x,
				y:record.data.y,
				name: record.data.name,
				record_data : record.data
			});
			Ext.getCmp('centerCenterPanel').add(this.campingWrapperPanel);
			Ext.getCmp('centerCenterPanel').activate(this.campingWrapperPanel);
			**/
		}
		
		/**
		this.naverImg = Ext.hansub.naverAPI.NaverIMGOpenAPIPanel({
	   		id:"naverImgID",
	   		title:record.data.name,
	   		target:'image',
	   		keyword:record.data.name,
	   		viewtype:'summary',
	   		border:false,
	   		start:1,
	   		display:10
	   		
	   	});
		
		
		
		
		
		
		Ext.getCmp('centerCenterPanel').add(this.naverImg);
		Ext.getCmp('centerCenterPanel').activate(this.naverImg);
		**/
		
		
	},
	modify:function(grid, records, action, groupId){
		
		if(!Ext.getCmp('addBoardContentWindowID')){
		
			this.addBoardContentWindow = new Ext.hansub.camping.AddBoardHtmlContentWindow({
						id:'addBoardContentWindowID',
						title: '게시물 등록',
						iconCls:'add',
				        width: 1024,
				        resizable:false,
				        height: 768			        
			});
		}
		
		Ext.getCmp('addBoardContentWindowID').setData({
			s_boardtype_uid : records.data.s_boardtype_uid,
			s_boardcat_uid : records.data.s_boardcat_uid,
			s_board_uid : records.data.uid,
			s_boardcat_name: records.data.s_boardcat_name,
			name : records.data.name,
			content : records.data.content,
			parentID : grid.getId()
								
		});
		
		Ext.getCmp('addBoardContentWindowID').show();
		
		
		
		
	},
	setData:function(obj){
		
		this.isSetData = true;
		this.obj.data = obj;
		this.setTitle(this.obj.data.text);
		this.view.showView = this.obj.data.viewtype;
		
		this.obj.ds.load();
	
	},
	
	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.content);
        	if(content == ""){
        		return 'x-grid3-row-collapsed';
        	}
        	p.body = '<div class=boardsummary>' + Ext.util.Format.ellipsis(content, 70) + '</div>';
            return 'x-grid3-row-expanded';
        }else if(this.showView == 'full'){
			p.body = '<div class=boardcontent>' + record.data.content + '</div>';
            return 'x-grid3-row-expanded';
        }else{
        	return 'x-grid3-row-collapsed';
        }
       
    },
    
	
	newWin : function(){
		
		var window = new DetailWindow();
        window.init("centerBottomTabPanelID", Ext.getCmp('ItemInfoLayoutPanelID'));
	},
	
	
   /**
    selectedRow : function(sm, index, record){
    	
    	if(this.view.showView == 'full'){
    		if(!Ext.getCmp('commentGridPanelID')){
	    		this.commentGridPanel = new Ext.ux.hansub.board.CommentGridPanel({
					title: "댓글 목록",
					id: "commentGridPanelID",
					closable:false,
					loadMask: {msg:'댓글화면 구성 중'},
					defaults: {autoScroll:true},
					split: true,
					collapsible: true,
			        animCollapse: false,
			        border:false,
			        hideHeaders:true
				});
	    		
	    	}
	    	
	    	Ext.getCmp('commentGridPanelID').setData({
					dbtable_uid:record.get('uid'),
					dbtable:'s_board'
				});
		
			Ext.getCmp('centerCenterPanel').add('commentGridPanelID');
			Ext.getCmp('centerCenterPanel').activate('commentGridPanelID');
    		return;
    	}
    	
		if(!Ext.getCmp('boardContentPanel_'+record.data.uid)){
			var boardContentPanel = new Ext.hansub.camping.BoardContentPanel(
									this,
									{
										title:record.data.name,
										id:'boardContentPanel_'+record.data.uid,
										closable:true,
										closeAction:'false',
										height:300,
										collapsible: true,								
										border:false,
										split: true,
										data:record.data								
									}
								);
		}else{
			Ext.getCmp('boardContentPanel_'+record.data.uid).setContent(record.data);
		}
							
    	Ext.getCmp('centerCenterPanel').add('boardContentPanel_'+record.data.uid);
		Ext.getCmp('centerCenterPanel').activate('boardContentPanel_'+record.data.uid);
 	
	},
	**/
	
	addItem : function(){
		
		
			
			if(!Ext.getCmp('addCampingContentWindowID')){
		
				this.addCampingContentWindow = new Ext.hansub.camping.AddCampingContentWindow({
							id:'addCampingContentWindowID',
							title: '게시물 등록',
							iconCls:'add',
					        width:800,
					        resizable:true,
					        height: 670,
							data:{
					
								//s_boardtype_uid : this.obj.data.s_boardtype_uid,
								//s_boardcat_uid : this.obj.data.s_boardcat_uid,
								parentID : this.getId()
								
													
							}
					        				        
				});
			}
			
			Ext.getCmp('addCampingContentWindowID').setData({
					
				//s_boardtype_uid : this.obj.data.s_boardtype_uid,
				//s_boardcat_uid : this.obj.data.s_boardcat_uid,
				parentID : this.getId()
									
			});
				
			Ext.getCmp('addCampingContentWindowID').show();
		
		
		


	},
	
	deleteItem : function(grid, record, action, rowIndex, col){
		
		if(record == null){
			return;
		}
		
		
		//alert(this.text);
		this.dataStore = grid.getStore();
		this.selectRecord = record;
		
		Ext.Msg.show({
			title:'삭제 확인',
			scope:this,
			msg: record.data.name+' 을 삭제 하시겠습니까 ?',
			buttons:Ext.Msg.YESNO,
			icon:Ext.MessageBox.QUESTION,
			fn:function(btn, text){
				if(btn == 'yes'){
					Ext.Ajax.request({
						url: './src/api/Interface.php',
						params:{
							'class':'Board',
							'method':'deleteContent',
							's_board_uid':this.selectRecord.data.uid
						},
						waitMsg:'항목을 삭제하고 있습니다.',
						scope:this,
						success:function(response, options){
							
							this.dataStore.reload();				
						},
						failure:function(response, options){
							Ext.MessageBox.alert('ERROR', '항목 삭제시 오류가 발생하였습니다..');
						}
						            	
								
					});
				}
			}
		});
		
		
		
	},
	
	reload : function(){
		this.obj.ds.reload();
	},
	
	titleFormat: function(value, p, record,rowIndex, colIndex, store) {
    	
    	return String.format(
                '<div class=board_title>{0}</div>', value
                );
    },
    
    setListLayout:function(viewtype){
 	
	  	if (this.obj.data.s_boardtype_type == 'acount') {
			if(viewtype == 'title'){
				
	    		this.viewSplitButton.setText('간략하게 보기');
	    		this.viewSplitButton.setIconClass('view_summary');
	    		this.titleButton.disable();
	    		this.summaryButton.enable();
	    		this.detailButton.enable();
					
	    	}else if(viewtype == 'summary'){
	    		
	    		this.viewSplitButton.setText('제목만 보기');
	    		this.viewSplitButton.setIconClass('view_title');
	    		this.detailButton.disable();
	    		this.titleButton.enable();
	    		this.summaryButton.enable();
			
	    		
	    	}else{
	    		
	    		if(this.view.showView == 'title'){
	    			
	    			this.viewSplitButton.setText('간략하게 보기');
	    			this.viewSplitButton.setIconClass('view_full');
	    			this.summaryButton.disable();
	    			this.titleButton.enable();
	    			this.detailButton.enable();;
	    			viewtype = "summary";
	    			
	    		}else if(this.view.showView == 'summary'){
	    			
	    			this.viewSplitButton.setText('제목만  보기');
	    			this.viewSplitButton.setIconClass('view_summary');
	    			this.titleButton.disable();
		    		this.summaryButton.enable();
		    		this.detailButton.enable();
	    			viewtype = "title";
	    		}
	 		
	    	}
			
			
			
		}
		else {
			if(viewtype == 'title'){
				
	    		this.viewSplitButton.setText('간략하게 보기');
	    		this.viewSplitButton.setIconClass('view_summary');
	    		this.titleButton.disable();
	    		this.summaryButton.enable();
	    		this.detailButton.enable();
					
	    	}else if(viewtype == 'summary'){
	    		
	    		this.viewSplitButton.setText('전체내용 보기');
	    		this.viewSplitButton.setIconClass('view_full');
	    		this.summaryButton.disable();
	    		this.titleButton.enable();
	    		this.detailButton.enable();
			
	    	}else if(viewtype == 'full'){
	    		
	    		this.viewSplitButton.setText('제목만 보기');
	    		this.viewSplitButton.setIconClass('view_title');
	    		this.detailButton.disable();
	    		this.titleButton.enable();
	    		this.summaryButton.enable();
			
	    		
	    	}else{
	    		
	    		if(this.view.showView == 'title'){
	    			
	    			this.viewSplitButton.setText('전체내용 보기');
	    			this.viewSplitButton.setIconClass('view_full');
	    			this.summaryButton.disable();
	    			this.titleButton.enable();
	    			this.detailButton.enable();;
	    			viewtype = "summary";
	    			
	    		}else if(this.view.showView == 'summary'){
	    			
	    			this.viewSplitButton.setText('제목만 보기');
	    			this.viewSplitButton.setIconClass('view_title');
	    			this.detailButton.disable();
	    			this.titleButton.enable();
	    			this.summaryButton.enable();
	    			viewtype = "full";
	    			
	    		}else{
	    			this.viewSplitButton.setText('간략하게 보기');
	    			this.viewSplitButton.setIconClass('view_summary');
	    			this.titleButton.disable();
		    		this.summaryButton.enable();
		    		this.detailButton.enable();
	    			viewtype = "title";
	    		}
	 		
	    	}
			
		}
		
	
		
    	this.view.showView = viewtype;
		this.view.refresh();
	    
		

    },
	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 + ' 원';
                 
	}
		

});

