1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    62
    Vote Rating
    5
    s.t.a.s is on a distinguished road

      1  

    Default How to load controllers dynamically?

    How to load controllers dynamically?


    The question is in the topic. I'm trying to do it in Sencha Touch 2.0 according to solution in ExtJS 4 (http://www.sencha.com/forum/showthre...oller&p=787028), but unfortunately it isn't working.

    I added in my application function for loading controllers.
    Code:
    Ext.app.Application.prototype.addController = function(classPath, config) {
        var self = this,
            config = config || {};
        Ext.Loader.setConfig({ enabled: true });
        Ext.require(classPath);
        Ext.require(classPath, function() {
            var controller = Ext.create(classPath, Ext.apply({
                application : self
            }, config.options || {}));
            //self.controllers.add(classPath, controller);
            self.controllers.push(classPath);
            
            controller.init();
            
            if (config.callback) { config.callback.call((config.scope || this), config); }
        });
    };
    But the problem is that self.controllers.add(classPath, controller) can't be done, because self.controllers in Sencha Touch is an array (not class object) and it hasn't method add(). How to load instance of controller in app?

    And of course, after method init() when I try to get my added before controller I get nothing. My code:
    Code:
    var app = this.getApplication();
    app.addController('ContactsController',
    {
        callback : function() {
            console.log(self.application);
        }
    });
    
    var myController = this.getApplication().getController('ContactsController');
    myController is undefined (but I see ContactsController in array of controllers ('cause I pushed it in array self.controllers) but it's not loaded.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    827
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    It is a better idea to load everything up front on a mobile device. If the connection goes out, your app won't function correctly or even if the connection is slow your app will come to a halt.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    62
    Vote Rating
    5
    s.t.a.s is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    It is a better idea to load everything up front on a mobile device. If the connection goes out, your app won't function correctly or even if the connection is slow your app will come to a halt.
    You see, our main idea is to give our customers a tool where they can change the view of their mobile pages as they want (to add new field, to hide some controls, etc.), that's why Sencha's static model/architecture is not well for us. We need to get the structure of pages/views, controllers, stores from the web server via AJAX.

  4. #4
    Sencha User
    Join Date
    Jan 2012
    Posts
    62
    Vote Rating
    5
    s.t.a.s is on a distinguished road

      1  

    Default How to remove controller?

    How to remove controller?


    And we almost did it. We are successfully adding new controllers, views and model from server, using AJAX. Here is the code:
    Code:
    Ext.app.Application.prototype.addController = function(classPath, config) {
    	var self = this,
    		config = config || {};
    	Ext.Loader.setConfig({ enabled: true });
    	Ext.require(classPath, function() {
    		var controllers = self.getControllerInstances();
    		if (!controllers[classPath]) {
    			var controller = Ext.create(classPath, Ext.apply({
    				application : self
    			}, config.options || {}));
    			controllers[classPath] = controller;
    			self.controllers.push(classPath);
    			controller.init();
    			if (config.callback) { config.callback.call((config.scope || this), config); }
    		}
    	});
    };
    But now we have a problem with removing of controllers. How to do it?

  5. #5
    Sencha User
    Join Date
    Jan 2012
    Posts
    62
    Vote Rating
    5
    s.t.a.s is on a distinguished road

      0  

    Default


    Has anybody idea how to do it? And is it Ok to use
    self.getControllerInstances()?

  6. #6
    Sencha User
    Join Date
    Aug 2012
    Location
    Fabrègues, France
    Posts
    50
    Vote Rating
    0
    gostbuster is an unknown quantity at this point

      0  

    Default


    Very Interesting,
    I tried to add a controller with code got by ajax and it works!

    Did you manage to remove a controller ?

    Thanks

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."