extjs call objects in parent page, logout example

extjs call objects in parent page(eg. close tab):

parent.Ext.getCmp(“ptab”).close();

here’s an example about open a new tab and auto logout:

//tree panel click event

var treePanel = Ext.create(‘Ext.tree.Panel’,{
id: ‘treePanel’,
title: ‘菜单’,
region: ‘west’,
width : 200,
split: true,
collapsible: true,
autoScroll: true,
resizabel: true,
store: menuTreeStore,
rootVisible : false,
listeners: {
itemclick: function(view,record){
if(record.data.url!=null && record.data.url!=””){
addTab(record);
}
}
}
});

//add tab

function addTab(record){
var id = record.data.id;
var text = record.data.text;
var url = record.data.url;
var tab =Ext.getCmp(‘tab_’+id);
if(url.indexOf(‘?’)==-1){
url = url + ‘?tabid=tab_’+id;
}else{
url = url + ‘&tabid=tab_’+id;
}
var centerP = Ext.getCmp(‘centerPanel’);
if(!tab){
tab = Ext.create(‘Ext.panel.Panel’,{
id: ‘tab_’+id,
title: text,
closable: true,
html: ”
});
centerP.add(tab);
}else{
//reload
}
centerP.setActiveTab(tab);
}

//logout

<script type=”text/javascript”>
var tabid='<%=tabid%>’;
Ext.onReady(function(){
function logout(){
Ext.Msg.confirm(‘警告’, ‘您确认要注销登录并退出系统吗?’, function(bt) {
if (bt == ‘yes’) {
var conn = Ext.create(‘Ext.data.Connection’);
conn.request({
url : ‘logoutUser.action’,
callback : function(options, success, response) {
if (success) {
Ext.Msg.alert(“成功”, “注销成功!”);
window.parent.location=’login.jsp’
} else {
Ext.Msg.alert(“错误”, “注销失败!”);
}
}
});
}else{
parent.Ext.getCmp(tabid).close();
}
});
}

logout();
});
</script>

This entry was posted in Computer, Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s