PDA

View Full Version : Toolbar Questions



robwilkerson
16 Sep 2009, 5:11 AM
Hey guys -

I have a couple of things I need to do with a toolbar and I'm not having much luck getting there. One, I suspect, is a scoping issue that I'm not sure I can workaround and the other is basic functionality.

1. I'm trying to create a toolbar that will be linked to any application from another domain. For example, http://myapp.mydomain.com/index.htm will include the source file http://resources.mydomain.com/toolbar.js. The toolbar JS, as the name suggests, just renders a toolbar:



Ext.onReady( function() {
Ext.QuickTips.init();
var tb = new Ext.Toolbar({
renderTo: 'toolbar',
height: 30,
width: 'auto',
items: [
// toolbar items
]
})
});
What I'd like to be able to do is, from a script in index.htm, add a button to the toolbar. I've tried accessing the tb variable with no luck - it's undefined. I've also tried moving the initialization of tb outside of onReady, but I haven't been able to get the page to access the toolbar API successfully. Anyone have any hints? I'm not making much headway. The snippet from http://myapp.mydomain.com/index.htm might look like this:



<html>
<head>
// SNIP //

<script type="text/javascript" src="http://resources.mydomain.com/toolbar.js"></script>
<script type="text/javascript">
// <![CDATA[
alert( tb ); // tb is undefined rather than [Object] (or whatever)
// ]]>
</script>
// SNIP //
</head>
<body>
// SNIP //
</body>
</html>
2. Simpler question that assumes I can find a way to solve problem #1 above: Is it possible to modify only the handler of a toolbar item? By default, let's say that the toolbar contains a Logout button that does something. Can the calling application retain the button, but override the action that occurs when clicked?

Really appreciate the help.

Rob

robwilkerson
17 Sep 2009, 4:13 AM
I sorted out the problem in question #1, but I'm still trying to figure out how to replace/modify a button handler. It seems like the only way is to remove the existing listener and add a new one, which is fine, but for the life of me, I can't get Ext to remove a listener.

Confusion over whether I actually submitted this question led me to ask the toolbar question in a new post (http://www.extjs.com/forum/showthread.php?p=387446#post387446). That post contains sample code.

If anyone can help me figure out what I'm doing wrong, I'd appreciate it.

Animal
17 Sep 2009, 4:27 AM
Handler != listener

To modify its functioning, use if statements.

Animal
17 Sep 2009, 4:28 AM
Actually, looking at the code, you can just set the handler property dynamically.

makana
17 Sep 2009, 4:30 AM
You should read the docs at
http://www.extjs.com/deploy/ext-3.0.0/docs/?class=Ext.Button&member=setHandler

Handlers and listeners are not the same here.

robwilkerson
17 Sep 2009, 4:43 AM
You should read the docs at
http://www.extjs.com/deploy/ext-3.0.0/docs/?class=Ext.Button&member=setHandler

Handlers and listeners are not the same here.

Ah. I understand that handlers and listeners are not the same (apologies if I used the terms interchangeably and muddled the message), but I didn't see the setHandler() method. That looks like exactly what I need at first blush.

Thanks for your help, guys.

Animal
17 Sep 2009, 4:46 AM
The "Hide inherited members" button will help you find things.

robwilkerson
17 Sep 2009, 4:51 AM
The "Hide inherited members" button will help you find things.

LOL. I hadn't seen that option either, but thanks. In this case, since I wanted to modify what happened when an event fired - and given the signature of the removeListener() method and the fact that addListener() did exactly what I expected - I guess I made one of those proverbial assumptions. :-)

Thanks again.