MODX Console Init

Hey there, folks.

Can someone show me a little more information about the script output to the MODX console widget?

This docs is pretty nice, but i cannot understand how call my Console in custom Menu button.

I always get JS error:

Uncaught SyntaxError: Unexpected token return

I will be appreciate for any help!

1 Like

Can you show the code that’s currently throwing that error?

2 Likes

Hi Mark, thanks for attention to my problem!

This error i get, couse i did not clear my cache. But i am pretty sure that I’m doing something wrong, i’m weak in ExtJS. And I need help to move the right way.

Firstly, here is my console.window.js file, which i load in my controller.

var topic = '/generateinfo/';
var register = 'mgr';
var console = MODx.load({
    xtype: 'modx-console'
    , register: register
    , topic: topic
    , show_filename: 0
    , listeners: {
        'shutdown': {
            fn: function () {
                /* do code here when you close the console */
            }, scope: this
        }
    }
});
console.show(Ext.getBody());

MODx.Ajax.request({
    url: generateInfo.config.connector_url
    , params: {
        action: 'mgr/generateinfo'
        , register: register
        , topic: topic
    }
    , listeners: {
        'success': {
            fn: function () {
                console.fireEvent('complete');
            }, scope: this
        }
    }
});

And here is my processor, generateinfo

class generateInfoProcessor extends modObjectProcessor
{

    public function process()
    {

        $modx->log(modX::LOG_LEVEL_INFO,'An information message in normal colors.');
        $modx->log(modX::LOG_LEVEL_ERROR,'An error in red!');
        $modx->log(modX::LOG_LEVEL_WARN,'A warning in blue!');

    }
}
return 'generateInfoProcessor';

I want to understand, how i can call console with this logs…

Because the request to the connector contains a topic and register parameter, the request automatically enables the register logging (modRequest.registerLogging(), called in modManagerRequest.loadErrorHandler()) which means log messages are automatically written to where the console will read from.

I’m guessing the JS error you see comes from the lack of a response in the process() method. You should end it with return $this->success('Optional Success Message');

Your calls to $modx->log should also be $this->modx->log as you’re in a class.

1 Like

Ok, got it! Thank you very much. But how should i correctly call the console using the “Menu” button? I think I should do something like this?

'handler' => 'MODx.generateinfo(); return false;'

Or not? If i do it, i get error:

Uncaught TypeError: MODx.generateinfo is not a function
    at HTMLAnchorElement.onclic

Try wrapping the code you posted before (which has the MODx.load({}) ) in a function, and calling that function in the handler. Or is that already your MODx.generateinfo ?

1 Like

Here is my js file:

Ext.extend(MODx, Ext.Component, {
    infoGenerator: function () {
        var topic = '/infoGenerator/';
        var register = 'mgr';
        var console = MODx.load({
            xtype: 'modx-console'
            , register: register
            , topic: topic
            , show_filename: 0
            , listeners: {
                'shutdown': {
                    fn: function () {
                        /* do code here when you close the console */
                    }, scope: this
                }
            }
        });
        console.show(Ext.getBody());

        MODx.Ajax.request({
            url: infoGenerator.config.connector_url
            , params: {
                action: 'mgr/infogenerator'
                , register: register
                , topic: topic
            }
            , listeners: {
                'success': {
                    fn: function () {
                        console.fireEvent('complete');
                    }, scope: this
                }
            }
        });
    }
});

Still get same error:

MODx.infoGenerator is not a function

Nevermind, Mark, it was my fault with addJavascript. Now everything works fine! Thanks so much for your amazing help!

exmp

1 Like