
EditReservationSysWindow = function(config){
	
	
	
	this.config = config;
	this.isRegionLoad = false;
	this.isGroupLoad = false;
	
	
	
	this.camping_list_uid = this.config.data.camping_list_uid;
	
	
	
	this.nameTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '캠핑장',
		disabled:true,
		name: 'camping_list_name',
        anchor:'100%',
        allowBlank:false,
        disabled:true,
        value:this.config.data.camping_list_name
	});
	
		
	this.userTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '운용자',
		name: 'camping_user_name',
        anchor:'100%',
        allowBlank:false,
        disabled:true,
        value:NAME
	});
	
	this.telTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '연락처',
		blankText:'연락처를 입력해주세요',
		emptyText :'관리자 확인을 위해  연락처로 연락드립니다.',
		anchor:'100%',
		name: 'tel',
        allowBlank:false
	});
	
	this.bankTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '은행',
		blankText:'은행을 입력해 주세요.',
		emptyText :'은행을 입력해 주세요.',
		anchor:'100%',
		name: 'bank',
        allowBlank:false
	});
	
	this.accountnumberTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '계좌번호',
		blankText:'계좌번호를 입력해주세요',
		emptyText :'계좌번호를 입력해주세요.',
		anchor:'100%',
		name: 'accountnumber',
        allowBlank:false
	});
	
	this.accountownerTextField = new Ext.form.TextField({
		//hideLabel: true,
		fieldLabel: '계좌주',
		blankText:'계좌주 입력해 주세요.',
		emptyText :'계좌주 입력해 주세요.',
		anchor:'100%',
		name: 'accountowner',
        allowBlank:false
	});
	
	this.reservationtypeStore = new Ext.data.Store({ 
		
		proxy : new Ext.data.HttpProxy({
	    	url : './src/api/Interface.php',
	       	method : 'POST'
	       	
	    }),
	    baseParams : {
			'class':'Reservation',
			method:'getReservationTypeGrid',
			camping_list_uid:this.config.data.camping_list_uid
		},
	    
	    reader: new Ext.data.JsonReader({ 
            root: 'rows', 
            totalProperty: 'count',
            id:'uid'
        }, [ 
        	{name: 'uid', mapping:'uid', type: 'string'},
        	{name: 'camping_list_uid', mapping: 'camping_list_uid', type: 'string'},
        	{name: 'camping_reservation_uid', mapping: 'camping_reservation_uid', type: 'string'},
        	{name: 'name', mapping: 'name', type: 'string'},
        	{name: 'price', mapping: 'price', type: 'string'},
        	{name: 'capacity', mapping: 'capacity', type: 'string'}
        	
        ])
    })
	
	this.insertReservationTypeButton = new Ext.menu.Item({
    	text:'캠핑장 타입 추가',
		scope:this,
		iconCls:'memo_icon',
		handler:this.insertReservationType
    });
	
	this.editReservationTypeButton = new Ext.menu.Item({
    	text:'캠핑장 타입 편집',
		scope:this,
		iconCls:'memo_icon',
		handler:this.modifyReservationType
    });
	
	this.deleteReservationTypeButton = new Ext.menu.Item({
    	text:'캠핑장 타입 삭제',
		scope:this,
		iconCls:'delete',
		handler:this.deleteReservationType
    });
	
	
	this.popupMenu = new Ext.menu.Menu({
		scope:this,
        items: [
                this.editReservationTypeButton,
                '-',
        		this.deleteReservationTypeButton 
	        	]
    });
	
	
	this.reservationTypeGridPanel = new Ext.grid.GridPanel({
		id:'reservationTypeGridPanelID',
		//title: this.config.data.camping_list_name+' 캠핑장  타입',
		height:250,
		width:'auto',
		border:false,
		clicksToEdit:1,
		viewConfig : {
	            forceFit:true
		},
		
		columns : [
					{
						header: "캠핑장 타입",
						width: 110,
						sortable: true,
						dataIndex: 'name'
					},{
						header: "가격",
						width: 250,
						sortable: true,
						dataIndex: 'price',
						renderer: this.korMoney
					},{
						header: "사이트 수",
						width: 250,
						sortable: true,
						dataIndex:'capacity'
					}
		        ],
        ds : this.reservationtypeStore,
        tbar : [this.insertReservationTypeButton]
  	});
	
	
	this.reservationTypeGridPanel.on('rowcontextmenu',this.contextMenu, this);
	this.reservationTypeGridPanel.on('rowclick',this.contextMenu, this);


	/**
	this.homeTextField = new Ext.form.TextField({
		hideLabel: true,
		fieldLabel: '자체예약 시스템 주소',
		blankText:'자체예약 시스템 주소(http://)를 입력해 주세요.',
		emptyText :'자체예약 시스템 주소를 입력해 주세요.',
		anchor:'100%',
		name: 'homepage',
		allowBlank:false
	});

	
	
	var reservationTypeStore = new Ext.data.SimpleStore({
        fields: ['type', 'name'],
        data : [['Y','캠핑지도 예약시스템 사용'],['N','자체 예약시스템 사용']]
    });
	
	this.reservationTypeComboBox = new Ext.form.ComboBox({
		//hideLabel: true,
		fieldLabel: '예약방식',
		anchor:'100%',
		blankText:'예약 시스템 선택',
		emptyText :'예약 시스템 선택',
		store:reservationTypeStore,
		displayField:'name',
        editable:false,
        hiddenName:'type',
       	valueField:'type',
        typeAhead: true,
        triggerAction: 'all',
        allowBlank:false,
        selectOnFocus:true,
        typeAhead: true,
        mode: 'local'
    });
**/
	//this.nameTextField
	this.formPanel = new Ext.form.FormPanel({
		//labelAlign: 'top',
        labelWidth: 65,
        //baseCls: 'form',      
        frame:true,
        method: 'POST',
        bodyStyle:'padding:5px 5px 0',
	    //bodyStyle:'background-color: #e4e4e4',  userTextField
        items: [{
					layout:'column',//this.locationComboBox
		            border:false,
		            items:[{
				                columnWidth:1,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 5',
				                border:false,
				                items: [this.nameTextField]
		            }]
        		},{
		            layout:'column',//this.locationComboBox
		            //bodyStyle:'padding:5px 5px 0;background-color: #e4e4e4',
		            border:false,
		            items:[{
				                columnWidth:.3,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 5',
				                border:false,
				                items: [this.userTextField]
				          },{
				                columnWidth:.7,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 5',
				                border:false,
				                items: [this.telTextField]
				          }]
        		},{
		            layout:'column',//this.locationComboBox
		            //bodyStyle:'padding:5px 5px 0;background-color: #e4e4e4',
		            border:false,
		            items:[{
				                columnWidth:.3,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 5',
				                border:false,
				                items: [this.bankTextField]
				          },{
				                columnWidth:.4,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 5',
				                border:false,
				                items: [this.accountnumberTextField]
				          },{
				                columnWidth:.3,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 5',
				                border:false,
				                items: [this.accountownerTextField]
				          }]
        		},{
		            layout:'column',//this.locationComboBox
		            //bodyStyle:'padding:5px 5px 0;background-color: #e4e4e4',
		            border:false,
		            items:[{
				                columnWidth:1,
				                layout: 'form',
				                bodyStyle:'padding:0px 10px 0 5',
				                border:false,
				                items: [this.reservationTypeGridPanel]
				          }]
        		}]   
    });//this.descTextField  //this.accountownerTextField  // this.reservationTypeGridPanel
    
    this.config.buttons = [
    	
        {
            text: '확인',
            type:'submit',
            scope:this,
            handler: this.submit
        },{
            text: '취소',
            type:'cancel',
            scope:this,
            handler: this.cancel
        }];
    
    this.config.items = this.formPanel;
    this.config.layout = 'fit';
    this.config.closable = true;
    this.config.plain = true;
    this.config.modal = true;
    this.config.buttonAlign ='right';
    this.config.closeAction ='close';
    
    
	
    EditReservationSysWindow.superclass.constructor.call(this, this.config);
	
		
    this.reservationtypeStore.load();
    this.update();
	
};

Ext.extend(EditReservationSysWindow, Ext.Window, {
	
	deleteReservationType : function(){
		
		Ext.Msg.show({
			title:'삭제 확인',
			scope:this,
			msg: this.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':'Reservation',
							'method':'deleteReservationType',
							'uid':this.record.data.uid,
							camping_list_uid:this.camping_list_uid
						},
						waitMsg:'항목을 삭제하고 있습니다.',
						scope:this,
						success:function(response, options){
							
							 this.reservationtypeStore.load();			
						},
						failure:function(response, options){
							Ext.MessageBox.alert('ERROR', '항목 삭제시 오류가 발생하였습니다..');
						}
						            	
								
					});
				}
			}
		});
		
		
		
	},
	
	insertReservationType : function(){
		this.mode = "add";
		this.showAddWindow();
	},
	modifyReservationType : function(){
		
		this.mode = "modify";
		this.showAddWindow();
	},
	
	showAddWindow : function(){
		
		this.nameTextField2 = new Ext.form.TextField({
			fieldLabel: '캠핑장 타입',
			
			name: 'name',
	        anchor:'100%',
	        allowBlank:false
	     });
		
		this.priceTextField2 = new Ext.form.NumberField({
			//hideLabel: true,
			fieldLabel: '가격(1박2일)',
			
			name: 'price',
	        anchor:'100%',
	        allowBlank:false
		});
		
		this.capacityTextField2 = new Ext.form.NumberField({
			//hideLabel: true,
			fieldLabel: '사이트 수',
			
			name: 'capacity',
	        anchor:'100%',
	        allowBlank:false
		});
		
		if(this.mode == 'modify'){
			
			this.nameTextField2.setValue(this.record.get('name'));
			this.priceTextField2.setValue(this.record.get('price'));
			this.capacityTextField2.setValue(this.record.get('capacity'));
			
			
		}
		
		
		this.addFormPanel = new Ext.form.FormPanel({
			//labelAlign: 'top',
	        labelWidth: 90,
	        //baseCls: 'form',      
	        frame:true,
	        method: 'POST',
	        bodyStyle:'padding:5px 5px 0',
		    //bodyStyle:'background-color: #e4e4e4',  userTextField
	        items: [{
						layout:'column',//this.locationComboBox
			            border:false,
			            items:[{
					                columnWidth:1,
					                layout: 'form',
					                bodyStyle:'padding:0px 10px 0 5',
					                border:false,
					                items: [this.nameTextField2]
			            }]
		            },
		            {
						layout:'column',//this.locationComboBox
			            border:false,
			            items:[{
					                columnWidth:1,
					                layout: 'form',
					                bodyStyle:'padding:0px 10px 0 5',
					                border:false,
					                items: [this.priceTextField2]
			            }]
		            },
		            {
						layout:'column',//this.locationComboBox
			            border:false,
			            items:[{
					                columnWidth:1,
					                layout: 'form',
					                bodyStyle:'padding:0px 10px 0 5',
					                border:false,
					                items: [this.capacityTextField2]
			            }]
		            }]
	        
	        
	    });   
	        
		
		this.addWindow = new Ext.Window({
								title: '캠핑장 타입 추가',
								id:'addWindowID',
								closable:true,
								iconCls:'icon_2',
						        width: 300,
						        height:200,
						        layout:'fit',
						        plain:true,
						        modal:true,
						        bodyStyle:'padding:5px;',
						        buttonAlign:'right',
						        items: [this.addFormPanel],
						        closeAction: 'hide',
					
						        buttons: [
						        	{
							            text: '확인',
							            type:'submit',
							            scope:this,
							            handler: this.submitAddWindow
						        	},{
							            text: '취소',
							            type:'cancel',
							            scope:this,
							            handler: this.closeAddWindow
						       		}
						        ]
							});
		
		this.addWindow.show();
		
	},
	
	submitAddWindow : function(){
		
		
		if(this.addFormPanel.getForm().isValid()){
			this.addFormPanel.form.submit(
			{	waitMsg: '캠핑장 타입 추가 중...',
				url:'./src/api/Interface.php',
				params :{
							'class':'Reservation',
							method:'addReservationType',
							camping_list_uid:this.camping_list_uid,
							mode : this.mode,
							uid : this.record.get('uid')
							
						},
				scope:this,
				success: function(form, action) {
                  	if(action.result.success){
                  		
                  		this.reservationtypeStore.load();
                  		this.closeAddWindow();
						
                  	}else{
                  		
                  		location.reload();
                  	}
  										
				},
				failure: function(form, action) { 
					Ext.MessageBox.alert('Error', 'Error')
				}
			});
            		
		}
		
		
	},
	closeAddWindow : function(){
		
		
		this.addWindow.close();
		
		
	},
	
	
	
	contextMenu : function(grid, index, e){
		
		this.record = this.reservationtypeStore.getAt(index);
		
		this.popupMenu.showAt(e.getXY());
      	
    },
    
	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 + ' 원';
                 
	},
	
	update : function(){
		
		Ext.Ajax.request({
			url: './src/api/Interface.php',
			params:{
				'class':'Reservation',
				'method':'getReservationManager',
				camping_list_uid:this.config.data.camping_list_uid
				
			},
			waitMsg:'변경된 정보를 저장합니다.',
			scope:this,
			success:function(response, options){
				
				var json = Ext.decode(response.responseText);
				
				if(json.success){
					this.telTextField.setValue(json.tel);
					this.bankTextField.setValue(json.bank);
					this.accountnumberTextField.setValue(json.accountnumber);
					this.accountownerTextField.setValue(json.accountowner);
				}
				
				
				
								
			},
			failure:function(response, options){
				alert('정보 변경시 오류가 발생하였습니다.');
				this.obj.ds.reload()
			}
			            	
					
		});
		
		
	},

	submit : function(){
		
		
		if(this.formPanel.getForm().isValid()){
			this.formPanel.form.submit(
			{	waitMsg: '예약 시스템 정보 변경 중...',
				url:'./src/api/Interface.php',
				params :{
							'class':'Reservation',
							method:'modifyReservationSystem',
							camping_list_uid:this.camping_list_uid
							
						},
				scope:this,
				success: function(form, action) {
                  	if(action.result.success){
                  		
						this.close();
						
                  	}else{
                  		
                  		Ext.MessageBox.alert('에러', '예약 시스템 정보 변경 중 오류가 발생하였습니다..')
                  	}
  										
				},
				failure: function(form, action) { 
					Ext.MessageBox.alert('Error', 'Error')
				}
			});
            		
		}
		
	},
	
	cancel : function(){
		this.close();
	}
	

});

