PDA

View Full Version : [FIXED] How do I create the event handler from my view?



blomasky
7 Aug 2015, 12:50 PM
I must be missing something. I thought there is an easy way when I am adding a listener to a component. i.e. click for a button, that there is a way to have the event handler created in the viewController. How do I do that?

Thanks

Bruce

blomasky
8 Aug 2015, 5:25 AM
What I thought the plug does, is that if I create an listener in my View, it would automatically create the function in the viewController with the correct parameters.Bruce

blomasky
10 Aug 2015, 11:58 AM
In my View, I add a few listeners, i.e.:



listeners: {
show: {
fn: 'onTemplateWindowShow',
scope: 'controller'
},
beforeclose: {
fn: 'onTemplateWindowBeforeClose',
scope: 'controller'
}
},Question, will the plugin create the function with the appropriate parameters in the viewController, or do I have to do that (and hopefully remember all of the params!)

Thanks

Bruce

Chris.OBrien
12 Aug 2015, 6:04 AM
We do support generation of function in a controller, but we currently support it with a different syntax in the view:


controller: 'main',
listeners: {
afterlayout: 'myTestFunction',
scope: 'controller'
}

If "myTestFunction" doesn't exist in the controller, it will display as grey. If you move your cursor into "myTestFunction" and wait a second, JetBrains will display the lightbulb "QuickFix" icon. In OSX, You can also hit option-return when your cursor is in "myTestFunction" to immediately force the QuickFix menu to open.

From here you can select "Create method 'myTestFunction' in..." and it will create the function in your controller with the appropriate arguments:


/**
* @param {Ext.container.Container} component
* @param {Ext.layout.container.Container} layout
*/
myTestFunction: function (component, layout) {

}

Chris.OBrien
12 Aug 2015, 6:09 AM
FYI - I've merged these two threads regarding event handler creation.

Chris.OBrien
12 Aug 2015, 10:10 AM
Good news! Mark Brocato updated our code today to support the syntax you were using:

listeners: {
show: {
fn: 'onTemplateWindowShow',
scope: 'controller'
},
beforeclose: {
fn: 'onTemplateWindowBeforeClose',
scope: 'controller'
}
}

So in our next release, you should be able to quick fix on a "fn" attribute for a function that doesn't exist yet.

Until then, if you want to rely on the quick-fix, you'll have to use the syntax I mentioned earlier above:

listeners: {
afterlayout: 'myTestFunction',
scope: 'controller'
}

blomasky
12 Aug 2015, 10:56 AM
Thanks, I have no problems using your scope. Mine was extra wordy anyway.Bruce