<?php
	require "_header.php";
	require "../data/combo_student.php";
	/*echo "<pre>";
	print_r($_SESSION);
	exit;*/

?>

<script>

Ext.onReady(function() {
	Ext.QuickTips.init();
	
	var branchstore = new Ext.data.ArrayStore({
		fields: ['branch_id','branch_name'],
		data: Ext.student.branch2
	});
	var bookFields = [
				{	
					name:'book_id',
					type: 'int'
				},{
					name: 'book_name',
					type: 'string'
				},{
					name: 'branch_name',
					type: 'string'
				},{
					name: 'book_language',
					type: 'string'
				},{
					name: 'book_author',
					type: 'string'
				},{
					name: 'publisher_name',
					type: 'string'
				},{
					name: 'book_edition',
					type: 'string'
				}];	
				
				
	var gridStore = new Ext.data.JsonStore({
	  	url: '../library/data/search-book-data.php',
	   	root: 'rows',
		fields: bookFields,
		autoLoad: false
	});
	var colModel = new Ext.grid.ColumnModel([
		{ 
			header: "Book Id",
			dataIndex: 'book_id', 
			sortable: true, 
			hidden: true 
		},new Ext.grid.RowNumberer({
			width:38,
			header:'Sr.No'
			}),
		{ 
			id: 'book_name',
			header: "Book Name",
			width: 200,
			dataIndex: 'book_name',
			sortable: true
        },{ 
			id: 'branch_name',
			header: "Branch Name",
			width: 90,
			dataIndex: 'branch_name',
			sortable: true
        },{ 
			id: 'book_language',
			header: "Book Langage",
			width: 90,
			dataIndex: 'book_language',
			sortable: true
        },{ 
			id: 'book_author',
			header: "Book Auther",
			width: 125,
			dataIndex: 'book_author',
			sortable: true
        },{ 
			id: 'publisher_name',
			header: "Book Publisher",
			width: 120,
			dataIndex: 'publisher_name',
			sortable: true
        },{ 
			id: 'book_edition',
			header: "Book Edition",
			width: 90,
			dataIndex: 'book_edition',
			sortable: true
        }
    ]);
		var grid = new Ext.grid.GridPanel({
   		store: gridStore,
		frame: true,
        cm: colModel,
		columnLines: true,
		loadMask:true,
		stripeRows: true,
        sm: new Ext.grid.RowSelectionModel({
        	singleSelect: true,
            listeners: {
            	rowselect: function(sm, row, rec) {
					Ext.getCmp("bookregister").getForm().loadRecord(rec);
					
				}
         	}
   		}),
		height: 330,
	 	});
	
	
	
	
	var bookregister= new Ext.FormPanel({
        id: 'bookregister',
        frame: true,
		//url:'report-book-register-result.php',
		columnWidth: 1,
		layout:'column',
		items:[{
				columnWidth: 1,
                layout: 'column',
				labelWidth:105,	
				items:[{
					columnWidth: 0.40,
					layout: 'form',
					labelWidth:105,	
					items:[{
						xtype: 'combo',
						name: 'book_branch_name',
						id:'book_branch_name',
						labelSeparator:'',	
						displayField:'branch_name',
						valueField:'branch_name',
						hiddenName:'branch_hidden',
						width:150,
						tabIndex:1,	
						fieldLabel:'Book branch', 	
						allowBlank:true,
						editable :true,
						triggerAction:'all',
						emptyText : 'Select Branch',
						mode:'local',
						forceSelection:true,
						store: branchstore
					}]
						
				},{
					columnWidth: 0.45,
                	layout: 'form',
					labelWidth:105,	
					items:[{
						xtype: 'textfield',
						id: 'search_text',
						tabIndex:2,
						name: 'search_text',
						width:190,
						emptyText:'Book Name',
						labelSeparator:'',	
						fieldLabel :'Search Book :<span class="comp"></span>' ,
						autoCreate: {tag: 'input', type: 'text',  maxlength: '100'}
										//store: branchstore
					}]
				},{
					columnWidth: 0.15,
                	layout: 'form',
					//labelWidth:105,	
					items:[{ 
						xtype:'button',
						text: 'View Books',
						tabIndex:3,
						iconCls:'icon-view',
						handler: function (){ 
							var search_text = Ext.getCmp('search_text').getValue();
							var book_branch_name = Ext.getCmp('book_branch_name').getValue();
							gridStore.load({params: {action:'setup',book_branch_name:book_branch_name,search_text:search_text}});
							//Ext.getCmp('search_text').reset();
							
						}
					 }]
				}]
		},{
			columnWidth: 1,
            layout: 'form',
			labelWidth:105,	
			items:[grid]
		}]
	});
	
	var BookRegisterWindow = new Ext.Window({
        title: 'Report Book Register',
		width:810,	
		height:450,		
		layout: 'fit',
		border: false,
		//closeAction:'close',
		modal:true,
		collapsible:true,
		items: bookregister,
		buttonAlign:'center',
	    buttons:[{
						text: 'Reset', 
						iconCls:'icon-reset',
						handler: function () {   
							bookregister.getForm().reset();
							//bookregister.getForm().findField('book_registerid').focus(true,500);
						}
					},
					{
						text: 'Close',
						iconCls:'icon-close',
						handler: function () {    
							
							BookRegisterWindow.close();
						}
					}]
	});	
	var varWidth =  (screen.width - BookRegisterWindow.width)/2;
	BookRegisterWindow.setPosition(varWidth,((screen.height/4)-110));
	BookRegisterWindow.show();
	
});


</script>