In Methode Swing it is possible to configure custom menus and custom object actions.

Prepare the plugin to add menus and action

In general, all the extensions of Méthode Swing are places under

{SWING-APP}/plugins

So, all the Javascript described in the following sections should be placed under

{SWING-APP}/app/plugins/{EXTENSION-FOLDER}/{EXTENSION-NAME}.js

Do not use the word libs as an extension folder. The libs folder is reserved for loading external libs. See the proper documentation to obtain further info on the topic.

DEBUG MODE: by default, all plugins are aggregated into a single plugins.js file at the Tomcat startup. When creating a plugin, it may be frustrating to restart the Tomcat Server every time a change is made.

To avoid this, set the configuration property debugEnabled to true.

Then, that extension will be loaded on every refresh of the page.

Add a custom menu

In order to add a custom menu to Methode Swing, it is necessary to use the following namespace:

eidosmedia.webclient.extensions.header.newcontentmenu

New menus will be added in the next versions.

The syntax is the following:

eidosmedia.webclient.extensions.header.newcontentmenu.add(name, options);

Where:

  • name [string] is the name of the custom menu, alias a unique identifier.

  • options [optional, object] is a Javascript object containing the properties of the custom actions.

The options parameter can be omitted. In this case, Swing will use the previously registered command with the same name property. See example below.

If options is specified, it must follow the guidelines of a generic Swing command. See Commands documentation for further information.

isActive and isEnabled methods are not supported in newcontentmenu actions.

Example

eidosmedia.webclient.commands.add({
    name: 'complex',
    icon: 'icon-compass',
    label: 'Perform some complex operation...',
    action: function( ctx, params, callback ) {
        if ( ctx.component.getType() === 'menu') {
            alert('hello menu');
            // perform same difficult operations...
            if (callbacks && callbacks.success) {
                callbacks.success( /*...*/ );
            }
        }

    }
});

eidosmedia.webclient.extensions.header.newcontentmenu.add('complex');

Add a custom action to an object

In a conceptually similar way, it is possible to add custom actions to objects. They will be shown in the search results, in the detailed preview of the object, and generally speaking everytime the object is available.

The syntax is the following:

eidosmedia.webclient.extensions.objectactions.add(name, options);

Where:

  • name [string] is the name of the custom menu, alias a unique identifier.

Please note that the name parameter will be also used for the action label localization. The key toolbar.name will be to be used in order to retrieve a translated string from Swing translation files.

  • options [optional, object] is a Javascript object containing the properties of the custom actions.

The options parameter can be omitted. In this case, Swing will use the previously registered command with the same name property. See example below.

If options is specified, it must follow the guidelines of a generic Swing command. See Commands documentation for further information.

Example

eidosmedia.webclient.commands.add({
    name: 'complex',
    icon: 'icon-compass',
    label: 'Perform some complex operation...',
    isActive: function( ctx ) {
        // For some buttons ctx.activeObject is not available.
        return ctx.activeObject && ctx.activeObject.getType() === 'Image';
    },
    action: function( ctx, params, callback ) {
        if ( ctx.component.getType() === 'menu') {
            alert('hello menu');
            // perform same difficult operations...
            if (callbacks && callbacks.success) {
                callbacks.success( /*...*/ );
            }
        }

    }
});

eidosmedia.webclient.extensions.objectActions.add('complex');