Search code examples
javascriptextjs6-classic

how can i close the view parent from view child?


I m using the template admin-dashbord from the ext framework 6.2.0.

When i use this, in my AuthenticationController

this.getView().destroy();

only the child view login close.Not the parent.

The app-main component is build behind the parent view.

I don't know how to close the parent view.

I have this following structure :

LoginWindow.js

Ext.define('Admin.view.authentication.LockingWindow', {
    extend: 'Ext.window.Window',
    xtype: 'lockingwindow',

    requires: [
       'Admin.view.authentication.AuthenticationController',
       'Ext.layout.container.VBox'
    ],

    cls: 'auth-locked-window',
    closable: false,
    resizable: false,
    autoShow: true,
    titleAlign: 'center',
    maximized: true,
    modal: true,

    ....

});

Login.js

Ext.define('Admin.view.authentication.Login', {
    extend: 'Admin.view.authentication.LockingWindow',
    xtype: 'login',

    requires: [
        'Admin.view.authentication.Dialog',
        'Ext.container.Container',
        'Ext.form.field.Text',
        'Ext.form.field.Checkbox',
        'Ext.button.Button'
    ],

    title: 'Let\'s Log In',
    defaultFocus: 'authdialog', // Focus the Auth Form to force field focus as well
 ....

           {
                xtype: 'button',
                reference: 'loginButton',
                scale: 'large',
                ui: 'soft-green',
                iconAlign: 'right',
                iconCls: 'x-fa fa-angle-right',
                text: 'Login',
                formBind: true,
                listeners: {
                    click: 'onLoginButton'
                }
            },

});

AuthenticationController.js

Ext.define('Admin.view.authentication.AuthenticationController', {
   extend: 'Ext.app.ViewController',
   alias: 'controller.authentication',

   onLoginButton: function() {

       var me = this;

        localStorage.setItem("TutorialLoggedIn", true);

        // Remove Login Window

        this.getView().destroy();

        // Add the main view to the viewport
            var main  = Ext.create({
            xtype: 'app-main'
        });

        me.redirectTo('dashboard', true);
    },

});

Solution

    1. Get the view :login
    2. Get the parent :LockingWindow
    3. destroy the parent: LockingWindow

    here is my method added to AuthenticationController.js and called in onLoginButton() method.

    createInterface : function(){
    
            var me = this,
                view = me.getView(),
                window = view.up('window');
    
            Ext.create({
                xtype: 'app-main'
            });
            window.destroy();
    
            me.redirectTo('dashboard', true);
     }