<?php 
	require "_header.php"; 
	require "data/combo_semester.php";
?>
<div id="main-content"> 
<script type="text/javascript">
var Setup_Fields = [
	{name:'gtuhead_id',type: 'int'},
	{name:'gtuhead_name'},
	{name:'gtuhead_amount',type: 'int'},
	{name:'max_amount',type: 'int'},
	{name:'gtufee_type'},
	{name:'head_active'},
]

var labelArray;
labelArray = [  
	['Enrollment No:<span class="comp">*</span>'],
	['Type:<span class="comp">*</span>'],
	['Fees Amount:<span class="comp">*</span>'],
	['Max Limit:<span class="comp"></span>'],
];

var GTUFeessetupStore = new Ext.data.JsonStore({
    url: 'data/GTUfeessetup-grid-data.php',
    root: 'data',
    fields: Setup_Fields,
    autoLoad: true
});

var GTUFeestypeStore = new Ext.data.ArrayStore({		
	fields: ['gtufee_type'],
	data:Ext.semester.gtufeestype
});

var GTUFeesheadStore = new Ext.data.ArrayStore({		
	fields: ['gtuhead_name'],
	data:Ext.semester.gtuheadname
});

Ext.onReady(function(){
	Ext.QuickTips.init();
	var colModel = new Ext.grid.ColumnModel([
	{ 
		header: "Head Name",
		width: 115,
		dataIndex: 'gtuhead_name',
		sortable: true
  	},
	{ 
		header: "Fees Amount",
		width: 110,
		dataIndex: 'gtuhead_amount',
		sortable: true
  	},
	{ 
		header: "Type",
		width: 80,
		dataIndex: 'gtufee_type',
		sortable: true
  	}
	]);
	
	var grid = new Ext.grid.GridPanel({
   		store: GTUFeessetupStore,
        cm: colModel,
        sm: new Ext.grid.RowSelectionModel({
        	singleSelect: true,
            listeners: {
            	rowselect: function(sm, row, rec) {
                	Ext.getCmp("GTUFeesform").getForm().loadRecord(rec);
					
					
					if(flgEdit == "true"){
									Ext.getCmp('btnSave').enable();
					 }
					else{
						 Ext.getCmp('btnSave').disable();
						 alert('You do not have access to edit the record.');
					 }
					   if(flgDelete == "true"){
									Ext.getCmp('btnDelete').enable();
					 }
					 
				}
         	}
   		}),
		height: 250,
		border: true
 	});
	
	grid.on('render', function(){
		grid.tip = new Ext.ToolTip({
    		view: grid.getView(),
    		target: grid.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 GTUFeesform = new Ext.FormPanel({	
		id: 'GTUFeesform',
		frame: true,
		url: 'save-gtufeessetup.php',
    	labelAlign: 'left',
  		bodyStyle:'padding:5px',
   		layout: 'column',
    	items: [
			{
				columnWidth: 1,
				xtype: 'fieldset',
				labelWidth: 100,
				defaults: {border:false},
				autoHeight: true,
				bodyStyle: Ext.isIE ? 'padding:0 0 2px 1px;' : 'padding:2px 1px;',
				border: false,
				items: [{
					xtype: 'combo',
					name: 'gtuhead_name',
					hiddenName: 'gtuhead_name',
					id:'gtuhead_name',
					labelSeparator:'',	
					fieldLabel :labelArray[0] ,
					forceSelection:true,				
					displayField:'gtuhead_name',
					valueField: 'gtuhead_name',
					allowBlank:false,
					triggerAction:'all',
					tabIndex:1,
					mode:'local',
					store: GTUFeesheadStore,
					width:180,
					selectOnFocus: true
            	},{
					xtype: 'combo',
					name: 'gtufee_type',
					hiddenName: 'gtufee_type',
					id:'gtufee_type',
					labelSeparator:'',	
					fieldLabel :labelArray[1] ,
					forceSelection:true,				
					displayField:'gtufee_type',
					valueField: 'gtufee_type',
					allowBlank:false,
					triggerAction:'all',
					tabIndex:2,
					mode:'local',
					store: GTUFeestypeStore,
					width:180,
					selectOnFocus: true
            	},{
					xtype: 'numberfield',
					labelSeparator:'',	
					fieldLabel :labelArray[2] ,
					name: 'gtuhead_amount',
					id: 'gtuhead_amount',
					tabIndex:3,
					width:180,
					allowBlank:false
				},{
					xtype: 'numberfield',
					labelSeparator:'',	
					fieldLabel :labelArray[3] ,
					name: 'max_amount',
					id: 'max_amount',
					tabIndex:4,
					width:180,
					allowBlank:false
				},{
					xtype: 'textfield',
					name: 'gtuhead_id',
					id:'gtuhead_id',
					value:'0',
					hidden:true
				},{height:5},grid
				]
			}
        ]
    });
	

	var GTUFeesWindow = new Ext.Window({
		title: 'Fees Setup Master',
		width:340,		
		height:425,	
		frame: true,
		border: false,
		modal:true,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: GTUFeesform,
		buttons:[
			{
				text: 'Save', 
				name:'btnSave',
				tabIndex:3,
				iconCls:'icon-save',
				id:'btnSave',
				handler: function(){
					
				
									GTUFeesform.getForm().submit({
										waitMsg: 'Saving...',
										success: function () {	
											grid.getSelectionModel().clearSelections();
											Ext.getCmp('btnDelete').disable();	
											GTUFeessetupStore.load();
											GTUFeesform.getForm().reset();	
											Ext.getCmp('gtuhead_name').focus(true,500);								
										},
										failure: function () {
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Please fill up complete form.',
												buttons: Ext.MessageBox.OK,
												icon:Ext.MessageBox.ERROR
											});									
										}
									});
								}
					
			},
			{
				text: 'Delete',
				iconCls:'remove',
				disabled:true,
				id: 'btnDelete',
				tabIndex:6,
				name: 'btnDelete',
				handler: function(){
					
								Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This Record.?', deleterecord);
							}
										
					
			},
			{
				text: 'Reset', 
				name:'btnreset',
				tabIndex:7,
				iconCls:'icon-reset',
				id:'btnreset',
				handler: function (){
					GTUFeesform.getForm().reset();
					grid.getSelectionModel().clearSelections();
					Ext.getCmp('btnDelete').disable();
					Ext.getCmp('gtuhead_name').focus(true,500);
					if(flgAdd == "true"){
									Ext.getCmp('btnSave').enable();
					 }
				}
			},
			{
				text:'Close', 
				name:'btnclose',
				tabIndex:8,
				iconCls:'icon-close',
				id:'btnclose',
				handler: function (){
					GTUFeesWindow.close();
				}
			}
		]
	});
	
	function deleterecord(btn){
    	if(btn=='yes'){
	   		GTUFeesform.getForm().submit({
				waitMsg: 'Saving...',
				params:{act:'del'},
				success: function () {	
					GTUFeesform.getForm().reset();
					Ext.getCmp('btnDelete').disable();
					Ext.getCmp('gtuhead_id').setValue('0');	
					GTUFeessetupStore.load();	
					Ext.getCmp('gtuhead_name').focus(true,500);								
				}
			});
	 	}  
  	}
	
	var varWidth =  (screen.width - GTUFeesWindow.width)/2;
	GTUFeesWindow.setPosition(varWidth,((screen.height/4)-85));
	GTUFeesWindow.show();
	Ext.getCmp('gtuhead_name').focus(true,500);
	if(flgAdd == "true"){
				Ext.getCmp('btnSave').enable();
	 }else
	{
					Ext.getCmp('btnSave').disable();
	}
});
</script>
</div>
<?php require "_footer.php";?>