
var Publisher_Fields = [
	{name:'publisher_id',type: 'int'},
	{name:'publisher_name'},
	{name:'contact_no1'},
	{name:'contact_no2'},
	{name:'address'},
	]

var labelArray;
labelArray = [  
	['Publisher Name:<span class="comp">*</span>'],
	['Contact No1:<span class="comp">*</span>'],
	['Contact No2:'],
	['Address:'],
	];

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

	Ext.QuickTips.init();
	var colModel = new Ext.grid.ColumnModel([{ 
		header: "Publisher Name",
		width: 80,
		dataIndex: 'publisher_name',
		sortable: true
  	},{
		header: "ContactNo",
		width: 100,
		dataIndex: 'contact_no1',
		sortable: true  		
	}]);
	
	var grid = new Ext.grid.GridPanel({
   		store: PublisherStore,
        cm: colModel,
        sm: new Ext.grid.RowSelectionModel({
        	singleSelect: true,
            listeners: {
            	rowselect: function(sm, row, rec) {
                	Ext.getCmp("publisherform").getForm().loadRecord(rec);
						Ext.getCmp('btnSave1').enable();
						Ext.getCmp('btnDelete1').enable();
				}
         	}
   		}),
		height: 200,
		border: true,
		frame:true,
		width:200
 	});
	
	var publisher_id = new Ext.form.TextField({
		name: 'publisher_id',
		id:'publisher_id',
		value:'0',
		hidden:true
	});
	
	var publisher_name = new Ext.form.TextField({
		name: 'publisher_name',
		id:'publisher_name',
		labelSeparator:'',
		width: 150,
		tabIndex:'1',
		fieldLabel:labelArray[0],
		allowBlank:false
	});
	
	var contact_no1 = new Ext.form.NumberField({
		name: 'contact_no1',
		id:'contact_no1',
		labelSeparator:'',
		tabIndex:'2',
		fieldLabel:labelArray[1],
		allowBlank:false,
		width: 150
	});

	var address = new Ext.form.TextArea({
		name: 'address',
		id:'address',
		labelSeparator:'',
		width: 150,
		tabIndex:'4',
		fieldLabel:labelArray[3],
		allowBlank:true
	});
	
	var contact_no2 = new Ext.form.NumberField({
		name: 'contact_no2',
		id:'contact_no2',
		labelSeparator:'',
		tabIndex:'3',
		width: 150,
		fieldLabel:labelArray[2],
		allowBlank:true
	});

	
	
	
		
	var publisherform = new Ext.FormPanel({	
		id: 'publisherform',
		frame: true,
		url: 'save-publisher.php',
    	labelAlign: 'left',
  		bodyStyle:'padding:5px',
   		layout: 'column',
    	items: [
			{
				columnWidth: .57,
				xtype: 'fieldset',
				labelWidth: 95,
				autoHeight: true,
				layout: 'form',
				bodyStyle: Ext.isIE ? 'padding:0 0 3px 1px;' : 'padding:2px 1px;',
				border: false,
				items: [
					publisher_name,contact_no1,contact_no2,address,publisher_id					
				]
			},{
				columnWidth: .43,
				xtype: 'fieldset',
				labelWidth: 85,
				defaults: {border:false},
				defaultType: 'textfield',
				autoHeight: true,
				bodyStyle: Ext.isIE ? 'padding:0 0 2px 1px;' : 'padding:2px 1px;',
				border: false,
				items:[grid]
			}
               ]
    });
	
	var PublisherWindow = new Ext.Window({
		title: 'Publisher Information',
		width:500,		
		height:290,	
		frame: true,
		border: false,
		modal:true,
       html        : 'Unable to move or resize.',	
	    resizable   : false,
	 	layout: 'fit',
		closeAction:'close',
		 constrain: true, 
		closable: false, 
		collapsible:true,
		items: publisherform,
		buttons:[
			{
				text: 'Save', 
				name:'btnSave1',
				tabIndex:'5',
				iconCls:'icon-save',
				id:'btnSave1',
				handler: function(){
					
									publisherform.getForm().submit({
										waitMsg: 'Saving...',
										success: function () {	
											grid.getSelectionModel().clearSelections();
											Ext.getCmp('btnDelete1').disable();	
											PublisherStore.load();
											publisherform.getForm().reset();	

											PublisherWindow.hide();
										},
										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: 'btnDelete1',
				tabIndex:'6',
				name: 'btnDelete1',
				handler: function(){
					/*var group_id=Ext.getCmp('group_id').getValue();
					Ext.Ajax.request({
						loadMask: true,
						sync : true,
						url: 'data/getRelatedRecord.php',
						params: {action:'group',group_id:group_id},
						success: function(resp){
							var str = "";
							resbool=resp.responseText;
							if(resbool != 0){
								str = "It has related record in " + resbool +"Please Delete This Record First";
								Ext.MessageBox.show({
									title: 'Error',
									msg: str,
									buttons: Ext.MessageBox.OK,
									icon:Ext.MessageBox.ERROR
								});			
							}
							else{
								*/
								Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This Record?', deleterecord);
								/*
							}
						}				
					});*/
				}
			},
			{
				text: 'Reset', 
				tabIndex:'7',
				name:'btnreset1',
				iconCls:'icon-reset',
				id:'btnreset1',
				handler: function (){
					publisherform.getForm().reset();
					grid.getSelectionModel().clearSelections();
					Ext.getCmp('btnDelete1').disable();
					Ext.getCmp('publisher_name').focus(true,500);
					Ext.getCmp('publisher_id').setValue('0');	
					Ext.getCmp('btnSave1').enable();
					
				}
			},
			{
				text:'Close', 
				name:'btnclose1',
				tabIndex:'8',
				iconCls:'icon-close',
				id:'btnclose1',
				handler: function (){
					PublisherWindow.hide();
				}
			}
		]
	});
	
	function deleterecord(btn){
    	if(btn=='yes'){
	   		publisherform.getForm().submit({
				waitMsg: 'Saving...',
				params:{act:'del'},
				success: function () {	
					publisherform.getForm().reset();
					Ext.getCmp('btnDelete1').disable();
					Ext.getCmp('publisher_id').setValue('0');	
					PublisherStore.load();									
				}
			});
	 	}  
  	}
	
	var varWidth =  (screen.width - PublisherWindow.width)/2;
	PublisherWindow.setPosition(varWidth,((screen.height/4)-60));
	//PublisherWindow.show();
	

