Code:
Ext.ux.empManPanel = Ext.extend(Ext.Panel, {
layout:'border'
,initComponent:function() {
Ext.apply(this, {
items:[{
xtype: 'tabpanel'
,region: 'center'
}]
});
Ext.ux.empManPanel.superclass.initComponent.call(this);
this.cPanel = this.items.itemAt(0);
}
,afterRender: function() {
Ext.ux.empManPanel.superclass.afterRender.call(this);
this.getButtons();
}
,loadGrid: function (id,title,action,url,btns) {
// autosubmit grid is just an extension of grid that uses server side paging/filtering
// buttons is loaded into bbar; it works in other places that do not load when the
// panel is created and after this is resized.
var grid = new Ext.ux.grid.AutoSubmitGrid({
id: id,
title: title,
buttons: btns,
region: 'center',
loadMask: true,
autoScroll:true,
selModel: new Ext.grid.CheckboxSelectionModel({singleSelect: true}),
params: {
'pv': pv,
action : action
},
conn: {url: url},
pageSize: 50,
pagerLocation: 'top',
scope:this
});
this.cPanel.add(grid);
this.cPanel.body.mask('Loading','x-mask-loading');
grid.on('render',this.onGridRender,this);
this.cPanel.layout.setActiveItem(grid);
grid.store.load();
}
,getButtons: function (){
// Getting the button information for the grid
Ext.Ajax.request({
url: 'empInfo.php',
scope: this,
method: 'POST',
params: {'pv': pv, action: 'buttons'},
failure: function() { MyDesktop.showSessionExpired(); return false;},
success: function(r,o) {
var jsonObj = Ext.util.JSON.decode(r.responseText);
if(jsonObj.showClasses==true){
var classButtons = ((jsonObj.showClassBtns==true)?jsonObj.classButtons:false);
this.loadGrid('emp-class-grid','Classes','classView','empInfo.php',classButtons);
}
var buttons = ((jsonObj.showButtons==true)?jsonObj.buttons:false);
this.loadGrid('emp-man-grid','Employees','view','empInfo.php',buttons);
return true;
}
});
}
,onGridRender: function(grid){
// Attempt to relayout so buttons will actually show up??
this.doLayout();
// This just deactivates the buttons if nothing is selected
var bbar = grid.getBottomToolbar();
if(bbar){
var curButtons = bbar.items.items;
for(var i=0; i < curButtons.length; i++){
if(curButtons[i].action && (curButtons[i].action.indexOf('modify')!=-1 || curButtons[i].action=='changeEmpPassword')){
curButtons[i].disable();
}
}
}
this.cPanel.body.unmask();
return true;
}
});
Ext.reg('autoGridPanel',Ext.ux.empManPanel);
Thanks!