The step-by-step guide for replacing the extJs Controller component

I have developed a versatile component that is being utilized across different products. In this case, I have a generic window and window controller which I am customizing to fit our specific product requirements.

This is my generic window:

Ext.define('App.win.Panel', {
    extend: 'Ext.window.Window',
    closeAction:'destroy',
    maximizable:true,
    hideToolbar:false,
    requires: [
        'App.MyWinCon.PanelController'
    ],
    xtype: 'MyWin',
    name:'MyWin',

    controller: 'MyWinCon',
    layout: {
        type: 'border'
    },
    gridConfigs:{},
    initComponent:function(){
        var p=this;
       p.items = [{
        //items
       }];
        p.callParent(arguments);
    }
});

In our product application, I am utilizing this generic window by overriding it in the following way:

var Window1 = Ext.create('App.win.Panel', {
            title: 'Window',
            modal:true,
            height: '90%',
            width: '95%',
            parentGridObj:gridObj,
        });
        Window1.show();

Everything is working fine so far, and the window is displaying as expected. Now, I have also created a generic controller. Here is a snippet of the code:

Ext.define('App.MyWinCon.PanelController', {
    extend: 'Ext.app.ViewController',

    alias: 'controller.MyWinCon',

    init: function(){
        var p = this;
        p.control({
        #:{
            beforeclose : function(this){
            // Some code
            }
        }
       });     
    }

Can someone guide me on how to access the 'beforeclose' method or similar methods in my application that are defined in the generic class? Your assistance will be greatly appreciated. Thank you.

Answer №1

Unfortunately, it's not a simple task or, at the very least, extremely complicated. However, there is a much simpler way to achieve the same result with minimal refactoring:

Define('App.MyWinCon.PanelController', {
    extend: 'Ext.app.ViewController',

    alias: 'controller.MyWinCon',

    init: function(){
        var p = this;
        p.control({
        #:{
            beforeclose : p.beforeClose // just a reference to function below!
        }
       });     
    },
    beforeClose: function(component){ // Avoid using a variable named "this"!
        // Some code
    }

Now, you can easily access this function from your view:

view.getController().beforeClose()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error Encountered in NextJS - Hydration Unsuccessful

Currently, I am utilizing NextLink in my project to generate links. However, it appears that using NextLink is causing the following error: Hydration failed because the initial UI does not match what was rendered on the server. Upon inspecting the console ...

Using ExpressJS with the Promise.all method for handling promises

I am facing an issue with my code where ExpressJS is not waiting for Promises to resolve before sending back the data to the client. Despite logging the data correctly, the responses are empty. I have tried various refactorings and followed tutorials on ha ...

I am facing difficulties retrieving the JSON object returned from the Express GET route in Angular

After setting up an express route, the following JSON is returned: [{"_id":"573da7305af4c74002790733","postcode":"nr22ry","firstlineofaddress":"20 high house avenue","tenancynumber":"12454663","role":"operative","association":"company","hash":"b6ba35492f3 ...

Building an Angular form that is reactive and dynamically populates fields from an array

I am currently working with Angular 9 and I am facing a challenge in implementing a component that utilizes reactive forms. Below is a snippet of my code: approval-edit.component.ts public nominationAllOf: NominationAllOf[]; public approvalEditForm: Form ...

Aligning a navigation bar with a hamburger menu in the center

I recently implemented a hamburger menu with some cool animations into my site for mobile devices. Now, I am facing the challenge of centering the menu on desktop screens and it's proving to be tricky. The positioning is off, and traditional methods l ...

Encountering the issue of "Cannot read properties of undefined" while attempting to pass data to a prop

Currently, I am developing a Vue application that heavily relies on charts. The issue lies in the fact that I am fetching data from the database individually for each chart component, resulting in multiple calls and a slower page load time. I am looking to ...

Is the promises functionality respected by the Nextjs API?

Greetings, I hope all is well with you. I am currently learning NEXTJS and working with its API, but I have encountered a problem. When I click too quickly, the promises seem to get stuck or encounter issues. You can see the tests in action in this brief 3 ...

I am attempting to rebuild Vuex's Getting Started example by utilizing multiple components, yet I am struggling to understand how to call root methods from within these components

The project I'm working on can be found here. It is a simple one, but for the purpose of learning, I divided it into index and four js files (parent, child, root, and store). My challenge lies in figuring out how to call the increment and decrement ro ...

Disabling the submit button after submitting the form results in the page failing to load

I am encountering an issue with my HTML form that submits to another page via POST. After the form validates, I attempt to disable or hide the submit button to prevent double submission and inform the user that the next page may take some time to load. He ...

Tips for managing content and tables that exceed their container's boundaries

On my webpage, I have a slide-out sidebar that shifts the other contents and causes overflow with a scrollbar. I want the content to remain inside the window and adjust according to the available space. Image of Slide-out Sidebar As seen in the image, t ...

Adding style tags dynamically to a component and then encapsulating the styles again (using Angular)

Currently, I am in the process of upgrading from AngularJS to Angular. Our app is currently a hybrid one being bundled up with webpack instead of just angular cli. Due to this setup, we have encountered issues where our css or scss files are not correctly ...

What's the best way to incorporate a clear options icon when choosing an option in a MaterialUI select component?

I am looking to enhance the user experience by adding a clear options icon that appears when a selection is made from the list of options. <Select InputProps={{ startAdornment: ( <InputAdornment position='end'> <Cl ...

When incorporating MDX and rehype-highlight on a next.js site to display MD with code snippets, a crash occurs due to Object.hasOwn

I'm encountering an issue with my setup that is based on examples from next.js and next-mdx-remote. Everything was working fine until I added rehypeHighlight to the rehypePlugins array, which resulted in this error. Any thoughts on why this could be h ...

javascript categorize data by key and display in a tabular format

I have a Client ID and gender information available. Shown below is a JSON response along with a JavaScript function to display the data in a table format. The JSON response structure is as follows: studies = [{ "id": { "Value&qu ...

Exploring the concept of front-end deletion through ajax technology

I'm currently tackling a front-end CRUD RESTful API project and encountering challenges specifically related to the DELETE and PUT methods. While I have successfully managed to implement the GET and POST functionalities, utilizing a forms.html file f ...

Checkbox fails to display as checked

I am currently working on implementing checkbox inputs in React JS. I have encountered an issue where the checkboxes do not visually show as checked when clicked, but I am still able to retrieve the value of the checkbox. Here is my code: Simple Checkbox I ...

Retrieve a field that has been overwritten in a constructor without using templates

I am struggling to access an overridden field in the child class from the parent C++ constructor. Unfortunately, using templates is not an option as the upstream project does not utilize them. This Python prototype serves as a working example that I am at ...

MinifyJS - optimize all .js files within a directory

Seeking assistance to finalize my build process: I am currently transpiling es6 > es5 using babel. Once that is complete, I aim to minify all my .js files recursively with uglifyJS solely using NPM scripts (no grunt or gulp). My Requirements; Convert ...

Choosing between radio buttons either horizontally or vertically within a table

Here is the markup I am working with: <table> <tr> <td><input type="radio" name="radio"></td> <td><input type="radio" name="radio"></td> <td><input type="radio" name="radio"></ ...

Can you please explain the significance of file.max and file.FBX within the context of a model in three.js

I am currently working on developing a video game using three.js. Recently, I downloaded a model from the internet and upon checking the directory, I found the following files: city.obj city.mtl city.max city.FBX After some research, I learned that cit ...