What is the controller responsibility in ExtJS? Events in instance of Ext.window.Window?
up vote
1
down vote
favorite
Currently using ExtJS 4 and I am trying to use the controller for implementing all events but there are some events that i am handling in the Window itself which are the close and destroy events. I need to execute some code here.
Is this bad practice ? If the events happen in the Window (an instance of Ext.window.Window).
Should I but forwarding these events to the controller to handle ?
I am unsure the correct way of doing this but I presume I would have to get a reference to the controller from my "window" in it's event and then call fireEvent on the controller?
What is the best practice here?
I am using ExtJS 4.2 so cannot use MVVM.
ExtJS seems to let me implement the events directly in "Components" but following the MVC pattern, is this not bad practice and everything should really pass through the controller.
javascript extjs extjs4 extjs4.2 extjs5
add a comment |
up vote
1
down vote
favorite
Currently using ExtJS 4 and I am trying to use the controller for implementing all events but there are some events that i am handling in the Window itself which are the close and destroy events. I need to execute some code here.
Is this bad practice ? If the events happen in the Window (an instance of Ext.window.Window).
Should I but forwarding these events to the controller to handle ?
I am unsure the correct way of doing this but I presume I would have to get a reference to the controller from my "window" in it's event and then call fireEvent on the controller?
What is the best practice here?
I am using ExtJS 4.2 so cannot use MVVM.
ExtJS seems to let me implement the events directly in "Components" but following the MVC pattern, is this not bad practice and everything should really pass through the controller.
javascript extjs extjs4 extjs4.2 extjs5
I also have to implement afterlayout of the window too as I need to some more things. I am currently handling this in the "window", should i be forwarding this to the controller and having the controller manipulate the component rather than the company manipulating itself ?
– Martin
Sep 11 '15 at 15:00
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Currently using ExtJS 4 and I am trying to use the controller for implementing all events but there are some events that i am handling in the Window itself which are the close and destroy events. I need to execute some code here.
Is this bad practice ? If the events happen in the Window (an instance of Ext.window.Window).
Should I but forwarding these events to the controller to handle ?
I am unsure the correct way of doing this but I presume I would have to get a reference to the controller from my "window" in it's event and then call fireEvent on the controller?
What is the best practice here?
I am using ExtJS 4.2 so cannot use MVVM.
ExtJS seems to let me implement the events directly in "Components" but following the MVC pattern, is this not bad practice and everything should really pass through the controller.
javascript extjs extjs4 extjs4.2 extjs5
Currently using ExtJS 4 and I am trying to use the controller for implementing all events but there are some events that i am handling in the Window itself which are the close and destroy events. I need to execute some code here.
Is this bad practice ? If the events happen in the Window (an instance of Ext.window.Window).
Should I but forwarding these events to the controller to handle ?
I am unsure the correct way of doing this but I presume I would have to get a reference to the controller from my "window" in it's event and then call fireEvent on the controller?
What is the best practice here?
I am using ExtJS 4.2 so cannot use MVVM.
ExtJS seems to let me implement the events directly in "Components" but following the MVC pattern, is this not bad practice and everything should really pass through the controller.
javascript extjs extjs4 extjs4.2 extjs5
javascript extjs extjs4 extjs4.2 extjs5
edited Nov 10 at 19:19
halfer
14.2k757105
14.2k757105
asked Sep 11 '15 at 14:40
Martin
9,12838165278
9,12838165278
I also have to implement afterlayout of the window too as I need to some more things. I am currently handling this in the "window", should i be forwarding this to the controller and having the controller manipulate the component rather than the company manipulating itself ?
– Martin
Sep 11 '15 at 15:00
add a comment |
I also have to implement afterlayout of the window too as I need to some more things. I am currently handling this in the "window", should i be forwarding this to the controller and having the controller manipulate the component rather than the company manipulating itself ?
– Martin
Sep 11 '15 at 15:00
I also have to implement afterlayout of the window too as I need to some more things. I am currently handling this in the "window", should i be forwarding this to the controller and having the controller manipulate the component rather than the company manipulating itself ?
– Martin
Sep 11 '15 at 15:00
I also have to implement afterlayout of the window too as I need to some more things. I am currently handling this in the "window", should i be forwarding this to the controller and having the controller manipulate the component rather than the company manipulating itself ?
– Martin
Sep 11 '15 at 15:00
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The controller or viewport should handle the event.
You don't need a reference to the controller inside the window.
If you want custom events, you need to fire the event from inside the window like:
this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]);
Then you then need to listen to the event inside the controller using a reference to the window:
yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]);
There are also ways to listen to events without having a reference to the event triggering element.
Edit- Regarding your comment:
If you need to do stuff on afterlayout regarding elements inside the window, then i would do it inside the window. If you want to do stuff to elements that are not defined inside the window, then let the controller, that instantiated the elements, handle it. In ExtJS 5 there is something called a ViewController. I don't know if it's already in 4.2. You could utilize the ViewController to split the stuff that happens in your window. Here is a link on that:
https://www.sencha.com/blog/using-viewcontrollers-in-ext-js-5/
EDIT 2:
If you don't want custom events, just listen with the controller to the events the window already throws on important occasions.
Thanks! Is this syntax right ? this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]); and yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]); ? The square brackets meaning optional ?
– Martin
Sep 11 '15 at 15:11
square brackets mean optional. But you are not bound to only one parameter. You could pass what you want. Take a look at: docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/… and search for fireEvent.
– Lucian Depold
Sep 11 '15 at 15:12
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The controller or viewport should handle the event.
You don't need a reference to the controller inside the window.
If you want custom events, you need to fire the event from inside the window like:
this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]);
Then you then need to listen to the event inside the controller using a reference to the window:
yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]);
There are also ways to listen to events without having a reference to the event triggering element.
Edit- Regarding your comment:
If you need to do stuff on afterlayout regarding elements inside the window, then i would do it inside the window. If you want to do stuff to elements that are not defined inside the window, then let the controller, that instantiated the elements, handle it. In ExtJS 5 there is something called a ViewController. I don't know if it's already in 4.2. You could utilize the ViewController to split the stuff that happens in your window. Here is a link on that:
https://www.sencha.com/blog/using-viewcontrollers-in-ext-js-5/
EDIT 2:
If you don't want custom events, just listen with the controller to the events the window already throws on important occasions.
Thanks! Is this syntax right ? this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]); and yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]); ? The square brackets meaning optional ?
– Martin
Sep 11 '15 at 15:11
square brackets mean optional. But you are not bound to only one parameter. You could pass what you want. Take a look at: docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/… and search for fireEvent.
– Lucian Depold
Sep 11 '15 at 15:12
add a comment |
up vote
1
down vote
accepted
The controller or viewport should handle the event.
You don't need a reference to the controller inside the window.
If you want custom events, you need to fire the event from inside the window like:
this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]);
Then you then need to listen to the event inside the controller using a reference to the window:
yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]);
There are also ways to listen to events without having a reference to the event triggering element.
Edit- Regarding your comment:
If you need to do stuff on afterlayout regarding elements inside the window, then i would do it inside the window. If you want to do stuff to elements that are not defined inside the window, then let the controller, that instantiated the elements, handle it. In ExtJS 5 there is something called a ViewController. I don't know if it's already in 4.2. You could utilize the ViewController to split the stuff that happens in your window. Here is a link on that:
https://www.sencha.com/blog/using-viewcontrollers-in-ext-js-5/
EDIT 2:
If you don't want custom events, just listen with the controller to the events the window already throws on important occasions.
Thanks! Is this syntax right ? this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]); and yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]); ? The square brackets meaning optional ?
– Martin
Sep 11 '15 at 15:11
square brackets mean optional. But you are not bound to only one parameter. You could pass what you want. Take a look at: docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/… and search for fireEvent.
– Lucian Depold
Sep 11 '15 at 15:12
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The controller or viewport should handle the event.
You don't need a reference to the controller inside the window.
If you want custom events, you need to fire the event from inside the window like:
this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]);
Then you then need to listen to the event inside the controller using a reference to the window:
yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]);
There are also ways to listen to events without having a reference to the event triggering element.
Edit- Regarding your comment:
If you need to do stuff on afterlayout regarding elements inside the window, then i would do it inside the window. If you want to do stuff to elements that are not defined inside the window, then let the controller, that instantiated the elements, handle it. In ExtJS 5 there is something called a ViewController. I don't know if it's already in 4.2. You could utilize the ViewController to split the stuff that happens in your window. Here is a link on that:
https://www.sencha.com/blog/using-viewcontrollers-in-ext-js-5/
EDIT 2:
If you don't want custom events, just listen with the controller to the events the window already throws on important occasions.
The controller or viewport should handle the event.
You don't need a reference to the controller inside the window.
If you want custom events, you need to fire the event from inside the window like:
this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]);
Then you then need to listen to the event inside the controller using a reference to the window:
yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]);
There are also ways to listen to events without having a reference to the event triggering element.
Edit- Regarding your comment:
If you need to do stuff on afterlayout regarding elements inside the window, then i would do it inside the window. If you want to do stuff to elements that are not defined inside the window, then let the controller, that instantiated the elements, handle it. In ExtJS 5 there is something called a ViewController. I don't know if it's already in 4.2. You could utilize the ViewController to split the stuff that happens in your window. Here is a link on that:
https://www.sencha.com/blog/using-viewcontrollers-in-ext-js-5/
EDIT 2:
If you don't want custom events, just listen with the controller to the events the window already throws on important occasions.
edited Sep 11 '15 at 15:32
answered Sep 11 '15 at 15:01
Lucian Depold
1,79321124
1,79321124
Thanks! Is this syntax right ? this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]); and yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]); ? The square brackets meaning optional ?
– Martin
Sep 11 '15 at 15:11
square brackets mean optional. But you are not bound to only one parameter. You could pass what you want. Take a look at: docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/… and search for fireEvent.
– Lucian Depold
Sep 11 '15 at 15:12
add a comment |
Thanks! Is this syntax right ? this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]); and yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]); ? The square brackets meaning optional ?
– Martin
Sep 11 '15 at 15:11
square brackets mean optional. But you are not bound to only one parameter. You could pass what you want. Take a look at: docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/… and search for fireEvent.
– Lucian Depold
Sep 11 '15 at 15:12
Thanks! Is this syntax right ? this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]); and yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]); ? The square brackets meaning optional ?
– Martin
Sep 11 '15 at 15:11
Thanks! Is this syntax right ? this.fireEvent("myCustomEvent"[,elementThatTriggeredTheEvent]); and yourWindow.on("myCustomEvent",this.myCustomEventHandler[,scope]); ? The square brackets meaning optional ?
– Martin
Sep 11 '15 at 15:11
square brackets mean optional. But you are not bound to only one parameter. You could pass what you want. Take a look at: docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/… and search for fireEvent.
– Lucian Depold
Sep 11 '15 at 15:12
square brackets mean optional. But you are not bound to only one parameter. You could pass what you want. Take a look at: docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/… and search for fireEvent.
– Lucian Depold
Sep 11 '15 at 15:12
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32526091%2fwhat-is-the-controller-responsibility-in-extjs-events-in-instance-of-ext-window%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I also have to implement afterlayout of the window too as I need to some more things. I am currently handling this in the "window", should i be forwarding this to the controller and having the controller manipulate the component rather than the company manipulating itself ?
– Martin
Sep 11 '15 at 15:00