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.










share|improve this question























  • 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














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.










share|improve this question























  • 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












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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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












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.






share|improve this answer






















  • 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











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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.






share|improve this answer






















  • 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















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.






share|improve this answer






















  • 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













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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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


















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線