PDA

View Full Version : Have Ext.TabPanel but which property points to the body of the tab



geewhizbang
23 Jul 2009, 1:45 PM
In the question mark area, I need to add some elements to my text.

PageTabs = new Ext.TabPanel
(
{
renderTo: 'divPageTabs',
activeTab: 0,
height:500,
defaults:{autoScroll: true},
plain:true,
items:
[
{
title: 'Home',
html: '<h2>Home Page</h2>'
},{
title: 'About',
autoLoad:'Home.mvc/About'
},{
title: 'Forum',
autoLoad: 'Home.mvc/ForumPage',
listeners: {activate: ForumInit}
}
]
}


function ForumInit()
{
if (!MyApp.Forum.Init)
DirectRequest.GetForumList
(
function(result, response)
{
MyApp.Forum.Init = true;
MyApp.Forum.ForumList = result;
if (!MyApp.Forum.ForumList)
{
// no forum handler ..
}
PageTabs. ????? .addElement (:???)/
}
, this);
}

I can hack this by adding a specific element with an id when I fill the tab, but it would make more sense to me to just get the object directly if it is already a property of the tab.

geewhizbang
23 Jul 2009, 2:54 PM
This is my hack so far. My tab body is loaded with a new element:

<h2>Forum Page</h2>
<div id="divForumContent"></div>

The code on the tab:

function ForumInit()
{
if (!MyApp.Forum.Init)
{
DirectRequest.GetForumList
(
function(result, response)
{
MyApp.Forum.Init = true;
MyApp.Forum.ForumList = result;
}
, this);
Page.WhenExists.Exec("divForumContent", LoadForum);
}
}

function LoadForum(o)
{
if (!MyApp.Forum.ForumList)
{
o.innerHTML += "<p>This Portal has no Forums</p>";
}
}

The new function I wrote:

function _WhenExists()
{
this.Exec = function(id, funct)
{
if (typeof(id) != "undefined")
{
this.funct = funct;
this.id = id;
this.timer = null;
this.tries = 0;
}
var o = document.getElementById(this.id, true);
if (o != null)
{
if (this.timer != null) self.clearTimeout(this.timer);
closeTimeout(this.timer);
this.funct(o);
}
else
{
this.tries++;
if (this.tries < 20)
{
this.timer = self.setTimeout("Page.WhenExists.Exec()", 50);
}
else
{
alert("Could not find: " + this.id);
}
}
};
}
Page.WhenExists = new _WhenExists();

Condor
24 Jul 2009, 3:52 AM
So you want:

PageTabs.getComponent(2).body.dom.innerHTML += '<p>This Portal has no Forums</p>';

ps. I would give your tabs an itemId (e.g. itemId:'forum'), so you can use 'forum' instead of '2'.

geewhizbang
24 Jul 2009, 6:18 AM
Thanks, I much prefer that to my hack.