PDA

View Full Version : Extending Button and customizing handler function



shizny
2 Jun 2011, 7:12 PM
I have a component I created (extending toolbar) which instantiates and has in it's item array another component (extending button) that I've created. I would like to pass in an action for my button handler so that I can just use one toolbar and change up where the back button (my extended button) goes. I seem to have lost the functionality of the handler function though... Any ideas?



// JavaScript Document
Ext.namespace('newwidgets');

newwidgets.HeaderMenu = Ext.extend(Ext.Toolbar, {
title: 'Available Projects',
backclickaction: 'goHome',
initComponent: function() {
Ext.apply(this, {
items: this.buildItems()
});
newwidgets.HeaderMenu.superclass.initComponent.call(this);
},
buildItems: function() {
var backClickButton = new newwidgets.BackClickButton({controlleraction: this.backclickaction});
return [backClickButton];
}
});

newwidgets.BackClickButton = Ext.extend(Ext.Button, {
text: 'Back',
ui: 'back',
controlleraction: 'showInstructionsPage',
scope: this,
initComponent: function () {
Ext.apply(this, {
handler: function() {
Ext.dispatch({
controller: apple.controllers.appleController,
action: this.controlleraction
});
}
});
newwidgets.BackClickButton.superclass.initComponent.call(this);
}
});

shizny
2 Jun 2011, 7:46 PM
Nevermind, figured it out. Needed to do a var me = this; before the handler function and then reference my action variable through me like me.action