                                                                                                                                                                                                                               

var labelArray;
labelArray = [
			 	['Configuration Value :<span class="comp">*</span>']
			];

if(flgEdit == "true") flgEdit1 = true;
			 else flgEdit1 = false;
var secFields = [{
        name: 'config_id',
        type: 'int'
    }, {
        name: 'config_value',
        type: 'string'
    }, {
        name: 'config_key',
        type: 'string'
    }]

var Section = Ext.data.Record.create(secFields);
var Store = new Ext.data.JsonStore({
    url: 'data/siteconfigdetail-grid-filter.php',
    root: 'data',
	remoteSort: true,
    sortInfo: {
            field: 'config_id',
            direction: 'ASC'
     },
    fields: secFields,
    idProperty: 'config_id',
	autoLoad: true,
    writer:new Ext.data.JsonWriter()});
Ext.onReady(function(){
    Ext.QuickTips.init();
    
    function rating(v) {
        if (v == 0) return "No";
        if (v == 1) return "Yes";
    }
	var colModel = new Ext.grid.ColumnModel([
       { header: "School ID", dataIndex: 'school_id', sortable: true, hidden: true },
		{ header: "Configuration ID", dataIndex: 'config_id', sortable: true, hidden: true },
				        { id: 'config_key',
						  header: "Configuration Key",
						  width: 190,
						  align : 'left',
						  dataIndex: 'config_key',
						  sortable: true
        				},
						{ id: 'config_value',
						  header: "Configuration Value",
						  width: 190,
						  align : 'left',
						  dataIndex: 'config_value',
						  sortable: true
        				}
				]);
	var flgalert = 0;
	
	var grid = new Ext.grid.GridPanel({
                ds: Store,
                cm: colModel,
				columnLines:true,
				stripeRows:true,
				loadMask:true,
                sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true,
                    listeners: {
                        rowselect: function(sm, row, rec) {
                            Ext.getCmp("company-form").getForm().loadRecord(rec);
							if(flgEdit == "false"){
								Ext.getCmp('config_value').disable();
								if(flgalert == 0){
									alert("You do not have access to edit the record.");
									flgalert = 1;
								}
							}
                        }
                    }
                }),
                autoExpandColumn: 'config_value',
                height: 260
            });
	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 Records.";
     }
    }
   });
  });
    var gridForm = new Ext.FormPanel({
        id: 'company-form',
        frame: true,
		url:'save-siteconfigdetail.php',
        labelAlign: 'left',
        bodyStyle:'padding:5px',
		labelWidth:130,
        items: [grid,
				{
					xtype: 'textfield',
					name: 'school_id',
					id:'school_id',
					hidden:true
			
            },{
					xtype: 'textfield',
					name: 'config_id',
					id:'config_id',
					hidden:true
            },{height:10},{
					xtype: 'textfield',
					name: 'config_value',
					id:'config_value',
					labelSeparator:'',	
				    fieldLabel :labelArray[0] ,
					width:200,
					allowBlank:false,
					autoCreate: {tag: 'input', type: 'text',  maxlength: '50'}
            }]
    });
	var SiteConfigWindow = new Ext.Window({
        title: 'Site Configuration',
		width:380,		
		modal:true,
		height:380,		
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: gridForm,
		buttonAlign: 'center',
	    buttons: [
					{text: 'Save',iconCls:'icon-save', name:'btnSave',id:'btnSave',	disabled : !flgEdit1,	
						handler: function ()
						{
							gridForm.getForm().submit({
								waitMsg: 'Saving...',		
								success: function () {			
									Store.load();
								},
								failure: function () {		
								Ext.MessageBox.show({
									   title: 'Error',
									   msg: 'Please fill up the Configuration value.',
									   buttons: Ext.MessageBox.OK,
									   icon:Ext.MessageBox.ERROR
				                      });
									}
							});
						}	
					},
		    		{text: 'Close',iconCls:'icon-close', name:'btncancel',id:'btncancel',
								handler: function ()
								{
									
									SiteConfigWindow.close();
								}
							  }]

	});
	var varWidth =  (screen.width - SiteConfigWindow.width)/2;
	SiteConfigWindow.setPosition(varWidth,((screen.height/4)-110));
	SiteConfigWindow.show();
});