1
votes

I have ExtJS (4.2) app, and I have a modal window with some logic. I want to split up logic by several controllers. For example, I have controller A where I added controls for close window and so on, and inside this window I also have another logic for example some form, with own buttons for save and edit. And for form I want to add new controller but I don't know is it good or bad ?, and when I should init controller for form ?

Thanks.

Abstract application

Modal Window (has close button, and some other controls) 
   - Items Box
       - Item (has own controls)

For Modal Window there is Controller
Item this is xtype which is added dynamically

I want have two controllers, one for modal window (parent) and one for Item (child). And I don't know how better to init second controller from parent.

2
Code is much better than a paragraph. fiddle.sencha.com/#home What version of Ext?Juan Mendes
In Ext 4.2.2 all controllers are initialized at application start up. I actually wrote a little extension to allow dynamic loading of controllers, but I'm still unsure what your question is. You are still not showing your code, Stack Overflow is not for theoretical discussions, it's for actual code that you can't figure out how to make it work. Your question may be a better fit for codereview.stackexchange.comJuan Mendes

2 Answers

0
votes

It is a good practice to add controllers for every view of your project (MVVM). What I like to do is adding a controller with Global Methods that should work for every view that I have, so in this case you can use mixins:

Ext.define('MyApp.view.MyPanel.MyPanelViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.mypanel',

    mixins: {
        GlobalController: 'MyApp.controller.GlobalController'
    },

    control: {
        ...
    }
    ...
});

This way you can use all the methods from your global controller inside your ViewController.

0
votes

I think the best way to do is to initialize the controllers in the initComponent() function of the 'view'. Suppose you have A, B, and C controllers for your modal window, and your app is named 'App', in your modal window's initComponent() function, you load the controller all at once:

initComponent: function () {
......
App.getController("A"); App.getController("B"); App.getController("C");
......
}