Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS 4 - how to call function from a certain controller in different views

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) {...
like image 204
Leron_says_get_back_Monica Avatar asked Jun 18 '12 12:06

Leron_says_get_back_Monica


2 Answers

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');
like image 71
sha Avatar answered Sep 24 '22 15:09

sha


You can use this -

this.getController('Controller Name').someFn();
like image 28
Kanchan Avatar answered Sep 20 '22 15:09

Kanchan