                                                                                                                                                                                                                               

var BatchStore = new Ext.data.JsonStore({
    url:'data/get-batch.php',
    root: 'data',
	remoteSort: true,
    fields: [{
        name:'batch_id',
        type: 'int'
    },{
        name: 'batch_name',
        type: 'string'
    }],autoLoad:true,
});

var BatchColModel = new Ext.grid.ColumnModel([
		new Ext.grid.RowNumberer(),
		{ 
			id: 'batch_name',
			header: "Batch Name",
			width: 230,
			dataIndex: 'batch_name',
			sortable: true
        }
	]);

var BatchGrid = new Ext.grid.GridPanel({
					id:'BatchGrid',
					name:'BatchGrid',
					ds: BatchStore,
					cm: BatchColModel,
					columnLines:true,
					stripeRows:true,
					sm: new Ext.grid.RowSelectionModel({
						singleSelect:false,
						listeners: {
							rowselect: function(sm, row, rec) {
								Ext.getCmp("AddbatchForm").getForm().loadRecord(rec);
								Ext.getCmp('batch_id1').setValue(rec.data.batch_id);
								Ext.getCmp('btnDel').enable();
							}
						}
					}),
					autoExpandColumn: 'batch_name',
					height: 250,
					border: true
				});
				
	BatchGrid.on('render', function() {
	   BatchGrid.tip = new Ext.ToolTip({
		view: BatchGrid.getView(),
		target: BatchGrid.getView().mainBody,
		delegate: '.x-grid3-row',
		trackMouse: true,
		renderTo: document.body,
		listeners: {
		 beforeshow: function updateTipBody(tip) {
		  tip.body.dom.innerHTML = "Please Click Here To Edit Record.";
		 }
		}
	   });
	  });

 var AddbatchForm = new Ext.FormPanel ({
    	id:'AddbatchForm',
		name:'AddbatchForm',
		layout: 'form',
		labelWidth: 80,
       	url:'save-batch.php',
        method:'post',
		frame:true,
        items: [{
					xtype:'textfield',                  
				  	labelSeparator:'',	
					fieldLabel :'Batch Name:<span class="comp">*</span>' ,
					id:'batch_name',
					name: 'batch_name',
					width:175,
					tabIndex:1,
				  	allowBlank: false
				},
				{
					xtype:'textfield',
					name: 'batch_id1',
					id:'batch_id1',
					hidden:true   
				
				},BatchGrid]
				       						
		});
		
			
 AddBatchWindow = new Ext.Window({
	title: 'Add New Batch',
	autoHeight:true,
	width:400,	
	border: false,
	modal:true,
	closeAction:'hide',
	collapsible:true,
	items:AddbatchForm,
	buttonAlign: 'center',
	buttons: [{
             text: 'Save',
			 iconCls:'icon-save',
			 tabIndex:2,
			 name:'btnSave',
			 id:'btnSave',				
			 handler: function () {
				
				AddbatchForm.getForm().submit({
					waitMsg: 'Saving...',		
					success: function () {
						BatchStore.load();
						AddbatchForm.getForm().reset();
						Ext.getCmp('batch_name').focus(true,500);
					},
					failure: function () {	
						Ext.MessageBox.show({
									   title: 'Error',
									   msg: 'Please fill complete form.',
									   buttons: Ext.MessageBox.OK,
									   icon:Ext.MessageBox.ERROR
				                      });
					}
				});
				
				/*var groupid=Ext.getCmp('batch_id').getValue();
				var groupname=Ext.getCmp('batch_name').getValue();
				if(groupname!="")
				{ 
					Ext.Ajax.request({
							  loadMask: true,
							  sync : true,
							  url: 'data/check-tt-duplicate.php',
							  params: {action:'group',batch_name:groupname,batch_id: groupid},
							  success: function(resp) {
								resbool=Ext.decode(resp.responseText).success;			                     
										if(resbool=='false')
										{
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Group name already exist.',
												buttons: Ext.MessageBox.OK,
												icon:Ext.MessageBox.ERROR
											});
											AddbatchForm.getForm().reset();
											BatchGrid.getSelectionModel().clearSelections();
			   								Ext.getCmp('batch_name').focus(true,500);
										}
										else{
											
											
										}
											 			
							  }				
							});		
				}else
				{
					Ext.MessageBox.show({
												title: 'Error',
												msg: 'Enter Group Name First.',
												buttons: Ext.MessageBox.OK,
												icon: Ext.MessageBox.ERROR,
												fn: function(btn){
												if (btn == 'ok'){
														AddbatchForm.getForm().reset();
														Ext.getCmp('btnDel').disable();
														Ext.getCmp('batch_name').focus(true,500);
													}
												}});  
				}
					*/
					
			}

          },{
						text: 'Delete',
						name:'btnDel',
						tabIndex:3,
						iconCls:'remove',
						id:'btnDel',
			            disabled: true,
					    handler: function (){
								Ext.MessageBox.confirm('Confirmation', 'Do u want to Delete this record?',deletegroup);
							}	
						},
		   {text: 'Reset',
			  iconCls:'icon-reset',
			   name:'btnReset',
			   tabIndex:4,
			   id:'btnReset',
			   handler: function (){
			   AddbatchForm.getForm().reset();
			   Ext.getCmp('btnDel').disable();
			   BatchGrid.getSelectionModel().clearSelections();
			   Ext.getCmp('batch_name').focus(true,500);
			 }
        	}, {
				   text: 'Close',
				   tabIndex:5,
				   iconCls:'icon-close',
				   handler: function () {    
							AddBatchWindow.hide();	
				   }
		  }]
  });
  
  var varWidth =  (screen.width - AddBatchWindow.width)/2;
	AddBatchWindow.setPosition(varWidth,((screen.height/4)-60));
	
 
 function deletegroup(btn){
									if(btn=='yes')
									{	
										AddbatchForm.getForm().submit({
										params: {act:'del'},
										waitMsg: 'Loading...',
										success: function () {
												AddbatchForm.getForm().reset();
												Ext.getCmp('btnDel').disable();
												BatchStore.load();
												Ext.getCmp('batch_name').focus(true,500);
												
										},
										failure: function () {
												
												Ext.MessageBox.show({
												title: 'Error',
												msg: 'Fill Compalit Form.',
												buttons: Ext.MessageBox.OK,
												icon: Ext.MessageBox.ERROR,
												fn: function(btn){
												if (btn == 'ok'){
														AddbatchForm.getForm().reset();
														Ext.getCmp('btnDel').disable();
														Ext.getCmp('batch_name').focus(true,500);
													}
												}});  
											 									
										}
									});
									}
									else
									{
										AddbatchForm.getForm().reset();
										Ext.getCmp('btnDel').disable();
										BatchStore.load();
										Ext.getCmp('batch_name').focus(true,500);
									}

								}
								


	