PDA

View Full Version : [OPEN] args not passed to actwhen using routes, defining controller and action throws error.



simeon
25 Apr 2012, 2:38 PM
Sencha touch framework Version: 2.0.1-rc

Background:
I have a list view with a back button.
I am using routes/history in my main controller
I have multiple pathways to this list panel, so the back button will need to support having multiple targets and I am hoping to pass args in the action to help know where the back button should point to.
I encountered this same problem in 2.0.0 release

I have encountered two bugs/issues when using actions/history/routes.

Problem 1 is that explicitly adding a controller and action results in an error


//Note: this is my "User" controller trying to dispatch a call to the "Main" controller when the back button is clicked

control: {
'userlist': {
back: function (){

var controller= this.getApplication().getController('Main')
var action =Ext.create('Ext.app.Action', {
controller:controller,
action: "showNav",
args :["test"]
})

this.getApplication().getHistory().add(action);
}
}
}



Error occurs in framework here:



Note: Scope is the action so this.getApplication() is undefined;

applyController: function(controller) {
var app = this.getApplication(),
profile = app.getCurrentProfile();

if (Ext.isString(controller)) {
controller = app.getController(controller, profile ? profile.getNamespace() : null);
}

return controller;
},




Second problem I have encountered is when using routes. The call to the controller.action does not get the args passed along when using the url feature


// from my "Main" controller

routes: {
'': 'showNav',
'nav/': 'showNav',
'nav': 'showNav'
},





// from my "User" controller

control: {
'userlist': {
back: function (){

var controller= this.getApplication().getController('Main')
var action =Ext.create('Ext.app.Action', {
url: 'nav/',
args :["test"]
})

this.getApplication().getHistory().add(action);
}
}
},



The showNav(config) method gets called but config is always undefined and doesnt contain the args that were defined in the action;

After I instantiate the action it contains the _args data.



this.getApplication().getHistory().getActions()

This returns an array of actions with the one I just created last and it contains the _args.
When showNav method on the main Controller is called, they are not passed.

simeon
27 Apr 2012, 8:09 AM
To anyone that's run into this issue, the workaround I have found that works is
to make the history entries silent and just call the controller actions directly.




var controller= this.getApplication().getController('Main')
var action =Ext.create('Ext.app.Action', {
url: 'nav/'
})

// add true when adding the action and it will update the url without triggering the
controller action that's mapped using routes.

this.getApplication().getHistory().add(action,true);

// then just call the controller action and pass any args by config. In this case I am telling the action which direction to slide.

controller.showNav({
direction: "right"
})

Jamie Avins
27 Apr 2012, 8:42 AM
Thank you for the report.