I have a function which is described in one of my controllers. The function takes care of creating a form that I need to use in different cases, from different views. Is it possible and what is the way to call this function from the views that I need without adding the same code in each controller.
Here is the code of the controller where I try to use a method from other controller:
Ext.define('MY.controller.EventsController', {
extend: 'Ext.app.Controller',
models: [
'EventsRecord'],
stores: [
'Events'],
views: [
'EventsGrid'],
refs: [{
ref: 'EventsGrid',
selector: 'CalendarEvent'
}],
init: function () {
this.control({
'CalendarEvent': {
afterEditFinish: this.askForNotify,
deleteEvent: this.deleteEvent,
calendarEditFunc: this.calendarEditFunc,
addCalendarEvent: this.addCalendarEvent,
itemclick: this.onSelectEnableBtn
}
})
},
Here I try to use something like var contr = Ext.getController('SomeController');
and..nothing..
askForNotify: function(editor, e) {...
Make it part of global class with singleton: true
and access it from anywhere in your code. Just calling controllers methods from views is kind of against MVC paradigm...
Update: If you really can't change existing code - do the following.
Save off reference to the your app somewhere (presumable you have your application defined something like that:
Ext.application({
launch: function() {
_myAppGlobal = this;
}
});
Use this variable to get controller you want:
_myAppGlobal.getController('MyController');
You can use this -
this.getController('Controller Name').someFn();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With