<?php require "_header.php"; 
?>
<div id="main-content">
<script type="text/javascript">
Ext.onReady(function(){
	Ext.QuickTips.init();
var labelArray;
labelArray = [  
	['Group Name:<span class="comp">*</span>'],
	['Designation:<span class="comp"></span>'],
	['Contact Name:<span class="comp">*</span>'],
	['Address:'],
	['Landline No:'],
	['Mobile (1):<span class="comp">*</span>'],
	['Mobile (2):'],
	['Email:'],
	['Birth Date:'],
	['Bank A/C No:'],
	['Pancard No:'],
	['Biometric Code:'],
	['Joining Date:']];


var GroupStore = new Ext.data.ArrayStore({
           fields: ['group_name'],
	       data: [['Director'],['Principal'],['Admin'],['Mechanical'],['Electrical'],['Civil'],['EC'],['Computer'],['Auto Mobile'],['General']]
        }); 
		
	var	DesignationStore = new Ext.data.JsonStore({
		url:'data/designation-data.php',
		root: 'data',
		totalProperty: 'total',
		autoLoad:true,
		fields: [{
			name: 'designation',
			type:'string'
			}] 
	});
		
var name_fields = [
	{name:'contact_id'},
	{name:'group_name'},
	{name:'designation'},
	{name:'name'},
	{name:'address'},
	{name:'landline_no'},
	{name:'mobile_no1'},
	{name:'mobile_no2'},
	{name:'email'},
	{name:'birth_date'},
	{name:'joining_date'},
	{name:'bankacno'},
	{name:'pancardno'},
	{name:'biometriccode'},
	{name:'busfacility'},
	{name:'groupdesig'}]
var NameStore = new Ext.data.JsonStore({
    url: 'data/contact-data.php',
    root: 'data',
    fields: name_fields
});
NameStore.load({params:{action:'contact-grid'}});

var colModel = new Ext.grid.ColumnModel([{ 
	header: "Group",
	width: 80,
	dataIndex: 'group_name',
	sortable: true
},{ 
	header: "Contact Person",
	width: 130,
	dataIndex: 'name',
	sortable: true
}]);

var grid = new Ext.grid.GridPanel({
	store: NameStore,
	cm: colModel,
	sm: new Ext.grid.RowSelectionModel({
		singleSelect: true,
		listeners:{
			rowselect: function(sm, row, rec){
				Ext.getCmp("ContactForm").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: 400,
	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 group_name = new Ext.form.ComboBox({
	name: 'group_name',
	id:'group_name',
	labelSeparator:'',	
	tabIndex:1,
	width:165,
	fieldLabel:labelArray[0],
	displayField:'group_name',
	valueField:'group_name',
	editable:true,
	triggerAction:'all',
	mode:'local',
	allowBlank:false,
	store:GroupStore,
	listeners:{'select': function(cmb, rec, idx)
	{
		var grpname=this.getValue();
		NameStore.filter('group_name',grpname);
	}}
});

var designation = new Ext.form.ComboBox({
	name: 'designation',
	id:'designation',
	labelSeparator:'',	
	tabIndex:1,
	width:165,
	fieldLabel:labelArray[1],
	displayField:'designation',
	valueField:'designation',
	editable:true,
	triggerAction:'all',
	mode:'local',
	allowBlank:true,
	store:DesignationStore,
	listeners:{'select': function(cmb, rec, idx)
	{
		var combinename=Ext.getCmp('group_name').getValue()+','+this.getValue();
		NameStore.filter('groupdesig',combinename);
	}}
});

var name = new Ext.form.TextField({
	name: 'name',
	id:'name',
	labelSeparator:'',
	width:165,
	tabIndex:2,
	fieldLabel:labelArray[2],
	allowBlank:false
});

var address = new Ext.form.TextArea({
	name: 'address',
	id: 'address',
	width:165,
	tabIndex:3,
	fieldLabel:labelArray[3],
	labelSeparator:''
});

var landline_no = new Ext.form.TextField({
	name:'landline_no',
	id:'landline_no',
	labelSeparator:'',
	width:165,
	tabIndex:4,
	fieldLabel:labelArray[4],
	enableKeyEvents: true,
	listeners:{
		keyup: validphoneno
	}
});

var mobile_no1 = new Ext.form.NumberField({
	name: 'mobile_no1',
	id:'mobile_no1',
	labelSeparator:'',
	allowBlank:false,
	tabIndex:5,
	width:165,
	fieldLabel:labelArray[5]
});

var mobile_no2 = new Ext.form.NumberField({
	name: 'mobile_no2',
	id:'mobile_no2',
	labelSeparator:'',
	width:165,
	tabIndex:6,
	fieldLabel:labelArray[6]
});

var email = new Ext.form.TextField({
	name: 'email',
	id:'email',
	labelSeparator:'',
	width:165,
	tabIndex:7,
	fieldLabel:labelArray[7],
	vtype:'email'
});

var birth_date = new Ext.form.DateField({
	id: 'birth_date',
	name: 'birth_date',
	tabIndex:8,
	labelSeparator:'',
 	fieldLabel :labelArray[8]
});

var joining_date = new Ext.form.DateField({
	id: 'joining_date',
	name: 'joining_date',
	tabIndex:9,
	labelSeparator:'',
 	fieldLabel :labelArray[12]
});

var bankacno = new Ext.form.NumberField({
	name: 'bankacno',
	id:'bankacno',
	labelSeparator:'',
	width:165,
	tabIndex:10,
	fieldLabel:labelArray[9]
});

var pancardno = new Ext.form.TextField({
	name: 'pancardno',
	id:'pancardno',
	labelSeparator:'',
	width:165,
	tabIndex:11,
	fieldLabel:labelArray[10]
});


var biometriccode = new Ext.form.NumberField({
	name: 'biometriccode',
	id:'biometriccode',
	labelSeparator:'',
	width:165,
	tabIndex:12,
	fieldLabel:labelArray[11]
});
var busfacility = new Ext.form.Checkbox({	
	hideLabel: false,
	name: 'busfacility',
	id: 'busfacility',
	labelSeparator:'',
	fieldLabel : 'Bus Facility ?',
	inputValue: '1'
});
var contact_id = new Ext.form.Hidden({
	name: 'contact_id',
	id:'contact_id',
	value:'0'
});


		
	var ContactForm = new Ext.FormPanel({	
		id: 'ContactForm',
		frame: true,
		labelAlign: 'left',
  		bodyStyle:'padding:5px',
   		layout: 'column',
    	items: [{
			
				columnWidth: .45,
				items:[grid]
			},
			{
				columnWidth: .55,
				labelWidth: 100,
				bodyStyle: Ext.isIE ? 'padding:0 0 5px 1px;' : 'padding:0px 5px 0px 10px;',
				border: false,
				layout: 'form',
				items: [group_name,
						designation,
						name,
						address,
						landline_no,
						mobile_no1,
						mobile_no2,
						email,
						birth_date,
						joining_date,
						bankacno,
						pancardno,
						biometriccode,
						busfacility,
						contact_id]
			}
        ]
    });
	
	var ContactWindow = new Ext.Window({
		title: 'Contact Master',
		width:600,		
		height:490,	
		frame: true,
		border: false,
		modal:true,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: ContactForm,
		buttons:[
			{
				text: 'Save', 
				name:'btnSave',
				tabIndex:11,
				iconCls:'icon-save',
				id:'btnSave',
				handler: function(){
					ContactForm.getForm().submit({
						url: 'data/contact-data.php',
						params:{action:'save'},
						waitMsg: 'Saving...',
						success: function () {	
							Ext.MessageBox.show({
								title: 'Message',
								msg: 'Data has been saved.',
								buttons: Ext.MessageBox.OK,
								icon:Ext.MessageBox.INFO
							});
							grid.getSelectionModel().clearSelections();
							Ext.getCmp('btnDelete').disable();	
							NameStore.load({params:{action:'contact-grid'}});
							ContactForm.getForm().reset();	
							DesignationStore.reload();
							Ext.getCmp('group_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:12,
				name: 'btnDelete',
				handler: function(){
					Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This Record?', deleterecord);
				}
			},
			{
				text: 'Reset', 
				name:'btnreset',
				tabIndex:13,
				iconCls:'icon-reset',
				id:'btnreset',
				handler: function (){
					ContactForm.getForm().reset();
					grid.getSelectionModel().clearSelections();
					Ext.getCmp('btnDelete').disable();
					Ext.getCmp('group_name').focus(true,500);
					NameStore.clearFilter();
					if(flgAdd == "true"){
						Ext.getCmp('btnSave').enable();
					}
				}
			},
			{
				text:'Close', 
				name:'btnclose',
				tabIndex:14,
				iconCls:'icon-close',
				id:'btnclose',
				handler: function (){
					ContactWindow.close();
				}
			}
		]
	});
	
	function deleterecord(btn){
    	if(btn=='yes'){
	   		ContactForm.getForm().submit({
				waitMsg: 'Saving...',
				url: 'data/contact-data.php',
				params:{action:'del'},
				success: function () {	
					Ext.MessageBox.show({
						title: 'Message',
						msg: 'Data has been deleted.',
						buttons: Ext.MessageBox.OK,
						icon:Ext.MessageBox.INFO
					});					
					ContactForm.getForm().reset();
					Ext.getCmp('btnDelete').disable();
					Ext.getCmp('contact_id').setValue('0');	
					grid.getSelectionModel().clearSelections();
					NameStore.removeAll();
					GroupStore.load({params:{action:'group-combo'}});
					NameStore.load({params:{action:'contact-grid'}});
				}
			});
	 	}  
  	}
	
	var varWidth =  (screen.width - ContactWindow.width)/2;
	ContactWindow.setPosition(varWidth,((screen.height/4)-105));
	ContactWindow.show();
	

	if(flgAdd == "true"){
		Ext.getCmp('btnSave').enable();
 	}else{
		Ext.getCmp('btnSave').disable();
	}
	Ext.getCmp('group_name').focus(true,1000);
});

</script>
</div>
<?php require "_footer.php";?>
