How i can open a tab from a grid every tab calling dynamic function for items of tab [solved]

by admin on February 20th, 2012

Ext.QuickTips.init();
Ext.override(Desktop.ReportsWindow, {
createProxy: {},
createWindow: function () {

var desktop = this.app.getDesktop();
var win = desktop.getWindow(this.moduleId);
var app = this.app;
var url = this.app.connection;
var moduleId = this.moduleId;

var myData = [
[‘Diagnosis registry’, ‘Search patients that have a particular diagnosis or ICD9 code.’, ‘diagnosis’],
[‘Medication report’, ‘Search patients that have been prescribed a particular medicine.’, ‘medication’]
];

var store = new Ext.data.ArrayStore({
fields: [{
name: ‘title’
},
{
name: ‘description’
},
{
name: ‘report_for’
}]
});

store.loadData(myData);

if (!win) {

var winWidth = desktop.getWinWidth() / 1.1;
var winHeight = desktop.getWinHeight() / 1.2;
win = desktop.createWindow({
id: moduleId,
title: ‘Reports’,
width: winWidth,
height: winHeight,
maximized: true,
iconCls: ‘reports-icon-cls’,
layout: ‘fit’,
items: [{
xtype: ‘tabpanel’,
activeItem: 0,
id: ‘reportsTabPanel’,
items: [{
title: ‘Reports’,
items: [{
xtype: ‘grid’,
id: ‘allReportsGrid’,
columnLines: true,
autoHeight: true,
stripeRows: true,
tbar: {
xtype: ‘toolbar’,
items: [‘->’,
{
text: ‘Run Report’,
disabled: true,
id: ‘runReportBtn’,
handler: this.addNewtab,
scope: this,
}, ‘ ‘]
},
viewConfig: {
forceFit: true,
},
selModel: new Ext.grid.RowSelectionModel({
listeners: {
rowselect: function (sel, row, rec) {
Ext.getCmp(‘runReportBtn’).enable();
},
rowdeselect: function (sel, row, rec) {
Ext.getCmp(‘runReportBtn’).disable();
}
}
}),
store: store,

columns: [{
header: ‘Title’,
dataIndex: ‘title’,
width: 100
},
{
header: ‘Description’,
dataIndex: ‘description’,
width: 200
}, ],
listeners: {
rowdblclick: this.addNewtab,
scope: this
},
}]
}]
}]
})
}
win.show();
},

addNewtab: function () {

var url = this.app.connection;
var moduleId = this.moduleId;

var tabpanel = Ext.getCmp(‘reportsTabPanel’);
var rec = Ext.getCmp(‘allReportsGrid’).getSelectionModel().getSelected();
var title = rec.get(‘title’).replace(/^\s+/, ”).replace(/\s+$/, ”);
var tabId = title.toLowerCase();
var tabId = tabId.replace(/ /g, ‘_’);

// varaible getting the value which function to call
var reportTab = rec.get(‘report_for’);

if (Ext.getCmp(tabId)) {
tabpanel.setActiveTab(tabId);
return;
}

var tabs = Ext.getCmp(‘reportsTabPanel’).add({
title: title,
id: tabId,
layout: ‘fit’,
closable: true,

items: this[reportTab](),
//reportTab, //calling the function according to selected record
scope: this,

});
tabpanel.setActiveTab(tabs);
},

diagnosis: function () {
var url = this.app.connection;
var moduleId = this.moduleId;
var report_item = [{
xtype: ‘panel’,
layout: ‘border’,
items: [{
xtype: ‘form’,
region: ‘north’,
autoHeight: true,
frame: true,
bodyStyle: ‘padding : 10px;’,
items: [{
xtype: ‘fieldset’,
border: false,
width: 280,
style: ‘padding:0px;margin:0px; float : left’,
labelWidth: 55,
items: [{
xtype: ‘combo’,
style: ‘float:left’,
fieldLabel: ‘Providers’,
}]
},
{
xtype: ‘button’,
text: ‘Advance Search’,
style: ‘float : left’,
handler: function () {
//Ext.getCmp(‘check’).show();
}
}]
},
{
xtype: ‘grid’,
region: ‘center’,
id: ‘center_grid’,
viewConfig: {
forceFit: true,
},
store: new Ext.data.Store({}),
columns: [{
header: ‘Patient Name’,
dataIndex: ”
},
{
header: ‘IDC9 Code’,
dataIndex: ”
},
{
header: ‘Diagnosis’,
dataIndex: ”
},
{
header: ‘Dx Date’,
dataIndex: ”
},
{
header: ‘Last Seen’,
dataIndex: ”
},
{
header: ‘Provider’,
dataIndex: ”
}, ]
}]
}];

return report_item;

},
medication: function () {
var url = this.app.connection;
var moduleId = this.moduleId;
var medication_tab = [{
xtype: ‘panel’,
layout: ‘border’,
items: [{
xtype: ‘form’,
region: ‘north’,
autoHeight: true,
frame: true,
bodyStyle: ‘padding : 10px;’,
items: [{
xtype: ‘fieldset’,
border: false,
width: 280,
style: ‘padding:0px;margin:0px; float : left’,
labelWidth: 55,
items: [{
xtype: ‘combo’,
style: ‘float:left’,
fieldLabel: ‘Providers’,
}]
},
{
xtype: ‘button’,
text: ‘Advance Search’,
style: ‘float : left’,
handler: function () {

}
}]
},
{
xtype: ‘grid’,
region: ‘center’,
id: ‘center_grid’,
viewConfig: {
forceFit: true,
},
store: new Ext.data.Store({}),
columns: [{
header: ‘Patient Name’,
dataIndex: ”
},
{
header: ‘Medication’,
dataIndex: ”
},
{
header: ‘Strength’,
dataIndex: ”
},
{
header: ‘Rx Start Date’,
dataIndex: ”
},
{
header: ‘Rx Stop Date’,
dataIndex: ”
},
{
header: ‘Last Seen’,
dataIndex: ”
},
{
header: ‘Provider’,
dataIndex: ”
}, ]
}]
}];

return medication_tab;
}
})

This code calling dynamic functions for the items of tab.
items: this[reportTab]()

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>