How to redirect default custom module view to another layout?

Hi everyone, I have a custom module and I'm trying to redirect it's default module view (the one that would show a list view) when you click on the module name from the main module menu at the top of the page. The best I can come up with is this:

Add the code below to this file: modules/MyCustomModule/clients/base/layouts/default/default.js

({
  extendsFrom: 'DefaultLayout',
    initialize: function(options) {
        this._super('initialize', [options]);
        window.SUGAR.App.router.navigate('#MyCustomModule/layout/setup', {trigger:true});
    }
})

This works. It will redirect to the layout specified on line 5, however it throws a "Uncaught TypeError: Cannot read property 'append' of null" in sidecar. No matter what I put for line #5 (console.log, alert, another function, etc.) it doesn't matter, it will throw the "Uncaught TypeError". If I remove line #5 there is no error at all.

Is there a way to do this without the javascript error? Is there a better way to redirect from the default module page?

Thanks!

Parents Reply Children
  • Hi Chad,

    My approach would be changing the list view layout with your custom layout.

    In order to do that;

    Copy records.php in ./modules/CustomModule/clients/base/layouts/records/records.php to ./custom/modules/CustomModule/clients/base/layouts/records/records.php and make this changes;

    $viewdefs['CustomModule']['base']['layout']['records'] = array(
        'components' => array(
            array(
                'layout' => array(
                    'components' => array(
                        array(
                            'layout' => array(
                                'components' => array(
                                    array(
                                        'view' => 'list-headerpane',
                                    ),
                                    array(
                                        'view' => 'setup', // here is your layout
                                        'primary' => true,
                                    ),
                                ),
                                'type' => 'simple',
                                'name' => 'main-pane',
                                'span' => 8,
                            ),
                        ),
                        .
                        .
                        .
    

    This would make your list view automatically your custom layout.

    Your redirect approach would work as well but no need to increase loading time.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer