Hi,
I have a viewport that has a toolbar and a container (MainPanel) in vbox layout. When clicking on a button in the toolbar, I want to replace the MainPanel container with another panel.
Without DeftJS, I can do this by adding the following lines to the Toolbar controller which would give me the reference to the MainPanel by calling this.getMainPanel():
refs : [
{
ref : 'mainPanel',
selector : 'app-container'
}
],
I couldn't figure out how I can do this with DeftJS. I tried injecting the MainPanel view into the Toolbar Controller:
By adding the 'mainPanel' to the dependency provider in the IoC configuration in the Application.js file:
buildInjectorConfiguration: function() {
var config;
config = {
appConfig: {
className: "myApp.config.AppConfig",
parameters: [
{
environment: myApp.config.AppConfig.PRODUCTION_ENV
}
]
},
mainPanel: "myApp.view.MainPanel"
};
return config;
},
With the above code, I can access the MainPanel view using mainPanel() method, but this actually creates instance of the view instead of referencing the existing one.
I need to get a handle to the existing MainPanel so that I can switch it's content. How can I get my viewController to access MainPanel view? Is the only way doing this through component query?
Thanks!
Here is my code:
view/MainPanel.js
Ext.define('myApp.view.MainPanel', {
extend: 'Ext.container.Container',
alias: 'widget.view-MainPanel',
requires: [
'myApp.controller.MainPanelController',
'myApp.view.Dashboard'
],
controller: 'myApp.controller.MainPanel',
initComponent: function() {
Ext.applyIf(this, {
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
{
xtype: 'view-Dashboard',
flex: 1
}
]
});
return this.callParent(arguments);
},
changeView: function(component) {
Ext.suspendLayouts();
this.removeAll(true);
this.add(component);
Ext.resumeLayouts(true);
}
});
view/Toolbar.js
Ext.define('myApp.view.Toolbar', {
extend: 'Ext.toolbar.Toolbar',
alias: 'widget.view-Toolbar',
requires: ['myApp.controller.Toolbar'],
controller: 'myApp.controller.Toolbar',
initComponent: function() {
Ext.applyIf(this, {
enableOverflow: true,
defaults: {
scale: 'large'
},
items: [
{
xtype: 'button',
html: 'Show Panel',
itemId: 'toolbar1'
}
]
});
return this.callParent(arguments);
}
});
controller/Toolbar.js
Ext.define('myApp.controller.Toolbar', {
extend: "Deft.mvc.ViewController",
requires: ['myApp.view.MainPanel'],
control: {
toolbar1: {
click: 'showPanel'
}
},
init: function() {
return this.callParent(arguments);
},
showPanel: function() {
this.getMainPanel().changeView({ //need to get getMainPanel() method to give me the reference to the MainPanel view.
xtype : 'view-appPanel',
flex : 1
});
}
});