<?php 
	require "_header.php"; 
?>
<div id="main-content" >
<script type="text/javascript">
var scholarship_Fields = [
	{name:'scholarship_id',type: 'int'},
	{name:'scholarship_name'},
	
]

if(flgDelete == "true") flgDelete1 = true;
			 else flgDelete1 = false;
if(flgAdd == "true") flgAdd1 = true;
			 else flgAdd1 = false;
var flgalert = 0;


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

Ext.onReady(function(){
	Ext.QuickTips.init();
	var colModel = new Ext.grid.ColumnModel([
	{ 
		header: "Scholarship Name",
		width: 140,
		dataIndex: 'scholarship_name',
		sortable: true
  	},	
  	]);

	
	var grid = new Ext.grid.GridPanel({
   		store: Scholarship,
        cm: colModel,
		columnLines:true,
		stripeRows:true,
		loadMask:true,
        sm: new Ext.grid.RowSelectionModel({
        	singleSelect: true,
            listeners: {
            	rowselect: function(sm, row, rec) {
                	Ext.getCmp("scholarshipform").getForm().loadRecord(rec);
                	Ext.getCmp('scholarship_name').setValue(rec.data.scholarship_name);
									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: 210,
		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 scholarshipform = new Ext.FormPanel({	
		id: 'scholarshipform',
		frame: true,
		url: 'save-scholarship.php',
    	labelAlign: 'left',
    	items: [
    			{
						xtype: 'textfield',
						labelSeparator:'',	
						fieldLabel :'Scholarship Name' ,
						name: 'scholarship_name',
						id: 'scholarship_name',
						tabIndex:1,
						allowBlank:false
					},
    			
				
					{
						xtype: 'textfield',
						name: 'scholarship_id',
						id:'scholarship_id',
						value:'0',
						hidden:true
					},{height:10},
					grid
				]
    });
	

	var scholarshipWindow = new Ext.Window({
		title: 'Scholarship Master',
		width:350,		
		height:340,	
		frame: true,
		border: false,
		modal:true,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: scholarshipform,
		buttons:[
			{
				text: 'Save', 
				name:'btnSave',
				tabIndex:2,
				iconCls:'icon-save',
				id:'btnSave',
				handler: function(){
					
					
					var scholarship_name = Ext.getCmp('scholarship_name').getValue();
					
					var scholarship_id = Ext.getCmp('scholarship_id').getValue();
					if(scholarship_name!= '')
					{
									scholarshipform.getForm().submit({
										waitMsg: 'Saving...',
										success: function () {	
											grid.getSelectionModel().clearSelections();
											Ext.getCmp('btnDelete').disable();	
											Scholarship.load();
											scholarshipform.getForm().reset();	
											Ext.getCmp('scholarship_name').focus(true,500);								
										},
										
									});							
				}
					else
					{
						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: 10,
                        name: 'btnDelete',
                        handler: function () {
                            Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This Record.?', deleterecord);
                        }
                    },
			{
				text: 'Reset', 
				name:'btnreset',
				tabIndex:4,
				iconCls:'icon-reset',
				id:'btnreset',
				handler: function (){
					scholarshipform.getForm().reset();
					grid.getSelectionModel().clearSelections();
					Ext.getCmp('btnDelete').disable();
					Ext.getCmp('scholarship_name').focus(true,500);
					if(flgAdd == "true"){
									Ext.getCmp('btnSave').enable();
					 }
				}
			},
			{
				text:'Close', 
				name:'btnclose',
				tabIndex:5,
				iconCls:'icon-close',
				id:'btnclose',
				handler: function (){
					scholarshipWindow.close();
				}
			}
		]
	});
	
	function deleterecord(btn) {
                if (btn == 'yes') {
                    scholarshipform.getForm().submit({
                        waitMsg: 'Saving...',
                        params: { act: 'del' },
                        success: function () {
                            Ext.getCmp('scholarship_id').reset();
                            Ext.getCmp('scholarship_name').reset();
                            Ext.getCmp('btnDelete').disable();
							Scholarship.load();	
                            Ext.getCmp('scholarship_name').focus(true, 500);
                        }
                    });
                }
            }
	
	var varWidth =  (screen.width - scholarshipWindow.width)/2;
	scholarshipWindow.setPosition(varWidth,((screen.height/4)-85));
	scholarshipWindow.show();
	
if(flgAdd == "true"){
				Ext.getCmp('btnSave').enable();
 }else
{
				Ext.getCmp('btnSave').disable();
}

Ext.getCmp('scholarship_name').focus(true,1000);

});
</script>
</div>

<?php require "_footer.php";?>