Méthode Swing can be extended by providing the so called validators, that is a set of function to validate the input before it is sent to the Server to be saved.

Location of the Validators extensions

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.

Supported validators

With the evolution of Méthode Swing, more validators will be added. At the moment, the application supports the following validators.

renameFile validator

As the name suggests, the renameFile validator is called whenever the user tries to rename a file. This happens in an opened editor, or in the Explorer area, or during a Worflow/Release action.

To add a renameFile validator, it is necessary to register it inside Swing by calling the following Javascript function, inside your Javascript file:

eidosmedia.webclient.extensions.validators.addValidator('renameFile', function( ctx, onSuccess, onError ) { /* ... */ } );

The function requires three parameters:

  • ctx: The ctx is a JSON object which represents the object’s context. See Context Object (ctx parameter) for further details. See the code for further details on the available properties.

  • onSuccess: function to be called when the validation has passed. It wants a single parameter, newName, which is optional. See the code for further details on the parameters.

  • onError: function to be called when the validation failed. It wants a single parameter, errorMessage. See the code for further details.

Example and explanation of parameters

eidosmedia.webclient.extensions.validators.addValidator('renameFile', function( ctx, onSuccess, onError ) {
    // The ctx object contains the following properties.
    // context: 'application'
    // activeObject->getInfo() : {
    //    id: the story id,
    //    newName: the name specified by the user
    //    originalName: the originalName of the file
    // }

    // We obtain the information
    var info = ctx.activeObject.getInfo(); // { id, newName, originalName }

    // SAMPLE IMPLEMENTATION.

    if ( info.newName === "FORBIDDEN.xml" ) {

        // onError = function (errorMessage). Call it with the error message to be shown.
        onError( "This name is absolutely forbidden!" );
        return;
    } else {
        // The parameter is optional. If not passed, the document will be saved with the name specified
        // by the user. Passing the parameter, it is possible to change the name in the validator.
        onSuccess(); // Same as: onSuccess( info.newName );
        // OR
        onSuccess( "VALIDATED_" + info.newName );
    }
});

Editor URL Redirect validator

As the name suggests, the Editor URL Redirect validator is called whenever the user tries to add or edit a url in the Editor Url Redirect.

To add a Editor URL Redirect validator, it is necessary to register it inside Swing by calling the following Javascript function, inside your Javascript file:

eidosmedia.webclient.extensions.validators.addValidator('url-redirect', function( ctx, urlInfo, callback ) { /* ... */ } );

The function requires three parameters:

  • ctx: The ctx is a JSON object which represents the object’s context. See Context Object (ctx parameter) for further details. See the code for further details on the available properties.

  • urlInfo: a Javascript object containing all the information regarding the selected url. See the code for further details on the available properties.

  • callback: function to be called when the validation has been completed. See the code to know how to call it.

Example and explanation of parameters

eidosmedia.webclient.extensions.validators.addValidator('url-redirect', function( ctx, urlInfo, callback ) {
    // The ctx object contains the following properties.
    // context: 'editor'
    // area->getName: 'editor-url-redirect',
    // activeObject->getInfo() : the document information.

    // The urlInfo contains the following properties
    // urlInfo: {
    //  type: 'redirect' // or 'permanentredirect', or 'temporaryredirect' or 'forward'
    //  url: the starting url
    //  redirect: the target url
    //  isEditing: true / false ( if the url is a new one or not )
    //}

    // Perform the validation here...
    callback( true ); // Will tell the editor that the validation has passed.
    // callback() or callback( false ) or callback( any falsy value ) will tell the editor that the validation has failed.
}

Context Object (ctx parameter)

Basic structure of the Context Object

The Context object is made of a specific list of properties, and a number of publicly available methods.

{
    application: {
        getId: function()
    },
    area: {
        getType: function(),
        getName: function(),
        getContext: function()
    },
    component: {
        getType: function()
    },
    activeObject: {
        // Methods of the single object.
    },
    activeObjects: [{activeObject}] // An array of activeObject
    selection: [ ] // Array of objects. See below.
}
Table 1. Parameters list
Parameter Value type Description Values

application.getId()

String

Returns the application Id.

"swing", …​

area.getType()

String

Returns the area type.

"main" (for the main views), "editor"

area.getName()

String

Returns the area name.

"explorer", "dashboard", "myarea", "liveblogmanagement" (for "main" areas). "story" (for editors).

area.getContext()

String

Returns the area context.

"story-editor", "report-editor", "dwp-editor", "topic@editor", "topic@search", "topic@binder", "topicplan@editor", "topicplan@search", "topicplan@binder", "topicitem", "upload", "diagram-workflow", "search", "planning-calendar"

component.getType()

String

Returns the component type.

"toolbar", "grid", "objectpanel"…​

activeObject

Object

Returns an object with a set of methods. Refer to : Methods of the single object for the list of methods.

activeObjects

Array

Returns an array of activeObject(s). In bulk selection mode all selected items are returned here as array. In single selection mode array length is 1. Each activeObject is coupled with one selected item. Methods of the single object operate to that item.

selection

Array of Object

Returns an array with the currently selected items. Each item has the same set of methods available. Refer to : Methods of the single object for the list of methods.

Each context has a different value for these properties.

Methods available in the Context Object

Further details on the methods available in the Context Object can be found in the Context Object Methods reference.