RodS1967
8 Feb 2012, 10:06 AM
Using the portal example from the examples library, I was trying to create and close and then recreate portlets dynamically. I don't have a problem creating them, and I can create several without issue. Once I close one, I can't create them any more though.I've tried adding a call to portlet.doClose to the onPortletClose method, I've tried removing the overridden method of the same name on the portlet class; nothing seems to be helping. I'm new to ExtJS and I'm thinking it may have something to do with the cleanup process and I'm just not doing something right. Does anyone have any ideas on this? My modified source code is below.
/**
* @class Ext.app.Portal
* @extends Object
* This is from the portal layouts example in ExtJS documentation.
*/
Ext.Loader.setPath('Ext.app', '/app/classes');
Ext.require([
'Ext.layout.container.*',
'Ext.resizer.Splitter',
'Ext.fx.target.Element',
'Ext.fx.target.Component',
'Ext.window.Window',
'Ext.app.Portlet',
'Ext.app.PortalColumn',
'Ext.app.PortalPanel',
'Ext.app.Portlet',
'Ext.app.PortalDropZone'
]);
Ext.define('Ext.app.Portal', {
extend: 'Ext.container.Viewport',
uses: [
'Ext.app.PortalPanel',
'Ext.app.PortalColumn'
],
getTools: function(){
return [{
xtype: 'tool',
type: 'gear',
handler: function(e, target, panelHeader, tool){
var portlet = panelHeader.ownerCt;
portlet.setLoading('Loading...');
Ext.defer(function() {
portlet.setLoading(false);
}, 2000);
}
}];
},
initComponent: function(){
var content = '<div class="portlet-content">Testing material content for a portlet</div>';
Ext.apply(this, {
id: 'app-viewport',
layout: {
type: 'border',
padding: '0 5 5 5' // pad the layout from the window edges
},
items: [{
id: 'app-header',
xtype: 'box',
region: 'north',
height: 40,
html: 'Portal'
},{
xtype: 'container',
region: 'center',
layout: 'border',
items: [{
id: 'app-options',
title: 'Options',
region: 'west',
animCollapse: true,
width: 200,
minWidth: 150,
maxWidth: 400,
split: true,
collapsible: true,
layout:{
type: 'accordion',
animate: true
},
items: [{
title:'Browse',
autoScroll: true,
border: false,
iconCls: 'record-find',
flex: 1,
layout: 'vbox',
items: [
{
xtype: 'button',
text: 'Test',
iconAlign: 'left',
listeners: {
'click': Ext.bind(this.onPortletOpen, this)
}
}
]
}]
},{
id: 'app-portal',
xtype: 'portalpanel',
region: 'center',
items: [
{
items: [
]
},
{
items: [
]
},
{
items: [
]
}
]
}]
}]
});
this.clearMsg(this.msgId);
this.callParent(arguments);
},
onPortletOpen: function (button) {
//window.location="/planning/product";
// check if this portlet is already there, if not, add it
// if so, focus the one that is found, and bring to forefront (and perhaps unmimimize it)
this.showMsg('Clicked portlet open. Button = ' + button.text);
// cheesy, but works for now
var portal = Ext.getCmp('app-portal');
portal.items.items[0].items.add(Ext.widget('portlet', {
title: button.text,
height: 300,
listeners: {
'close': Ext.bind(this.onPortletClose, this)
}
}));
portal.items.items[0].doComponentLayout();
},
onPortletClose: function(portlet) {
this.showMsg('"' + portlet.title + '" was removed');
portlet.doClose;
},
showMsg: function(msg) {
var el = Ext.get('app-msg'),
msgId = Ext.id();
this.msgId = msgId;
el.update(msg).show();
Ext.defer(this.clearMsg, 3000, this, [msgId]);
},
clearMsg: function(msgId) {
if (msgId === this.msgId) {
Ext.get('app-msg').hide();
}
}
});
/**
* @class Ext.app.Portal
* @extends Object
* This is from the portal layouts example in ExtJS documentation.
*/
Ext.Loader.setPath('Ext.app', '/app/classes');
Ext.require([
'Ext.layout.container.*',
'Ext.resizer.Splitter',
'Ext.fx.target.Element',
'Ext.fx.target.Component',
'Ext.window.Window',
'Ext.app.Portlet',
'Ext.app.PortalColumn',
'Ext.app.PortalPanel',
'Ext.app.Portlet',
'Ext.app.PortalDropZone'
]);
Ext.define('Ext.app.Portal', {
extend: 'Ext.container.Viewport',
uses: [
'Ext.app.PortalPanel',
'Ext.app.PortalColumn'
],
getTools: function(){
return [{
xtype: 'tool',
type: 'gear',
handler: function(e, target, panelHeader, tool){
var portlet = panelHeader.ownerCt;
portlet.setLoading('Loading...');
Ext.defer(function() {
portlet.setLoading(false);
}, 2000);
}
}];
},
initComponent: function(){
var content = '<div class="portlet-content">Testing material content for a portlet</div>';
Ext.apply(this, {
id: 'app-viewport',
layout: {
type: 'border',
padding: '0 5 5 5' // pad the layout from the window edges
},
items: [{
id: 'app-header',
xtype: 'box',
region: 'north',
height: 40,
html: 'Portal'
},{
xtype: 'container',
region: 'center',
layout: 'border',
items: [{
id: 'app-options',
title: 'Options',
region: 'west',
animCollapse: true,
width: 200,
minWidth: 150,
maxWidth: 400,
split: true,
collapsible: true,
layout:{
type: 'accordion',
animate: true
},
items: [{
title:'Browse',
autoScroll: true,
border: false,
iconCls: 'record-find',
flex: 1,
layout: 'vbox',
items: [
{
xtype: 'button',
text: 'Test',
iconAlign: 'left',
listeners: {
'click': Ext.bind(this.onPortletOpen, this)
}
}
]
}]
},{
id: 'app-portal',
xtype: 'portalpanel',
region: 'center',
items: [
{
items: [
]
},
{
items: [
]
},
{
items: [
]
}
]
}]
}]
});
this.clearMsg(this.msgId);
this.callParent(arguments);
},
onPortletOpen: function (button) {
//window.location="/planning/product";
// check if this portlet is already there, if not, add it
// if so, focus the one that is found, and bring to forefront (and perhaps unmimimize it)
this.showMsg('Clicked portlet open. Button = ' + button.text);
// cheesy, but works for now
var portal = Ext.getCmp('app-portal');
portal.items.items[0].items.add(Ext.widget('portlet', {
title: button.text,
height: 300,
listeners: {
'close': Ext.bind(this.onPortletClose, this)
}
}));
portal.items.items[0].doComponentLayout();
},
onPortletClose: function(portlet) {
this.showMsg('"' + portlet.title + '" was removed');
portlet.doClose;
},
showMsg: function(msg) {
var el = Ext.get('app-msg'),
msgId = Ext.id();
this.msgId = msgId;
el.update(msg).show();
Ext.defer(this.clearMsg, 3000, this, [msgId]);
},
clearMsg: function(msgId) {
if (msgId === this.msgId) {
Ext.get('app-msg').hide();
}
}
});