Skip to end of metadata
Go to start of metadata

 

Creating a plug-in that provides a conditional action for hiding form variables.

 

Project of the created plugin is available in the public repository http://192.168.1.61/developers/tutorials. A compiled version can be downloaded from here:

hide-action-1.0.0.jar

Assumed that the plugin project has already been created. The description of creating the system plugin is given above.

Introduction

This course describes the creating a plug-in process for the PlusWorkflow system at least 3.1 version. This plugin will provide a form action that:

  • will hide the variables defined in the parameter when the action execution condition is met
  • will display messages about hidden variables

Action definition on the server

The first step is to create an action definition. In this way, you inform the process editor that such action is available and can be used to build a task form. To do this, you should create a class with the appropriate set of annotations and methods:

@Actions
@ActionsScript( "resources/actions/hide-action.js" )
public class HideAction
{
    @Define
    public void action( ActionDefinitionBuilder action )
    {
        action
            .id( "hide-action-tutorial" )
            .name( "action.hiding.variables.name" )
            .description( "action.hiding.variables.desc" )
            .icon( SilkIconPack.APPLICATION_FORM )
            .category( Categories.TEST )
            .destination( ActionDestination.form() )
            .parameter()
				.id( "variables" )
				.name( "action.hiding.variables.parameter.name" )
	            .description( "action.hiding.variables.parameter.desc" )
				.type( Types.VARIABLE_ARRAY )
				.create();
    }
}

Above, a hide-action-tutorialaction is defined with one array parameter, which elements are VARIABLE type, that is form variables objects. The action implementation on the browser side is in the resources/actions/hide-action.js script. As the names and descriptions of the action and its parameter we gave the keys, because we would like these properties to be translated depending on the user language.

Translations you add in files /resources/locale/messages.properties (default - Polish version) or /resources/locale/messages_en.properties (English version).

messages.properties
action.hiding.variables.name=Warunkowe ukrywanie zmiennych
action.hiding.variables.desc=Akcja ukrywa zmienne na formularzu, jeżeli jest spełniony podany warunek
action.hiding.variables.parameter.name=Zmienne do ukrycia
action.hiding.variables.parameter.desc=Parametr tablicowy, który przyjmuje zmienne do ukrycia
messages_en.properties
action.hiding.variables.name=Conditional variables hiding
action.hiding.variables.desc=Action hiding variables on form, if given condition is fulfilled
action.hiding.variables.parameter.name=Variables to hide
action.hiding.variables.parameter.desc=Array parameter which accepts variables to hide

In action definition we also gave the category: Categories.TEST.It is necessary to create that category or using category that already exists. The category implementation looks as follows:

public enum Categories
    implements Category
{
    TEST( "Test" );

    private String name;

    private Categories( String name )
    {
        this.name = name;
    }
 
    @Override
    public String getName()
    {
        return name;
    }
}

Actions implementation on the browser side

Form actions work at the task form level. Using available functions, you must provide that such action implementation. Our implementation is as follows:

It will be useful the API documentation : PW.FormActions

var variableService = ServiceFactory.getVariableService(),
	messageService = ServiceFactory.getMessageService(),
	Action = {
		t: PW.I18N.createT('com.suncode.tutorial-hide-action')
	};

/**
 * Hide action implementation. 
 */
PW.FormActions.create('hide-action-tutorial', {
	
    init: function(){
    	this.variables = this.get("variables");
    	this.variablesNames = [];
    	
		PW.each(variables, function(variable){
			this.variables.push(variable.getId());
			this.variablesNames.push(variable.getName());
		}, this);
    },
    
    enable: function(){
    	this.hideVariables();
    	this.showMessage();
    },
    
    disable: function(){
    	this.showVariables();
    },
    
    hideVariables: function() {
    	this.setVariablesVisibility(false);
    },
    
    showMessage: function() {
    	var message = Action.t('action.hiding.variables.success', this.variablesNames);
    	messageService.showSuccess(message);
    },
    
    showVariables: function() {
    	this.setVariablesVisibility(true);
    },
    
    setVariablesVisibility: function(visible) {
		if(visible) {
			variableService.show(this.variables);
		}
		else {
			variableService.hide(this.variables);
		}
    }
});

Now you already have ready action. The action using the enable and disable methods means that it is suitable for conditional execution. When the variables are hidden, an appropriate message appears. The message is translated based on the key provided.

Translations are downloaded using TranslationAPI. The object  PW.I18N is used for this . The translator's name in the case of plugins is their key (plugin key). 

Action = {
	t: PW.I18N.createT('com.suncode.tutorial-hide-action')
};

Files with translations can be found in/resources/messages_browser.properties i /resources/messages_browser_en.properties.

messages_browser.properties
action.hiding.variables.success=Zmienne [{0}] zostały ukryte.
messages_browser_en.properties
action.hiding.variables.success=Variables [{0}] were hidden.

Plugin configuration

The action has already been defined. You should also "tell" the system that the plugin provides actions and functions and uses translations. The suncode-plugin.xml file should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<plugin key="${project.groupId}-${project.artifactId}" name="Hide Action Tutorial">
	<!-- Translations -->
	<i18n key="i18n-bundle"/>
	
	<workflow-components key="components" />
</plugin>

Action use in a task

The created action can be used in the process editor after launching the plugin. To check its task, you should create a simple process and then add our action. To do this, enter the task form, then on the left, expand the Actions and drag our action to the form.

After dropping the action, a window with the action definition will appear on the form. The action parameter and the calling condition must be completed.

At this point, action are added to the task that will hide the Floating point number and Date and Time variables, if the value of Total variable is less than 0. Otherwise, the variables will be shown. The condition uses the built-in function lt() (a list of all standard functions can be found here:  Available functions ).

 

Below the Total variable value is -1, so the variables have been hidden.

 

However, if the Total variable is positive, the variables will be displayed again.

  • No labels

2 Comments

  1. Anonymous

    W linii

    @ActionsScript( "resources/actions/hide-action.js" )
    ścieżkę należy podać bez "resources/"
    1. Wszystko zależy od projektu. W projekcie testowym dostępnym na gicie mamy ścieżkę src/resources/resources/actions/hide-action.js, dlatego podajemy ścieżkę z uwzględnieniem folderu resources. Jest to oczywiście zła praktyka i w wiekszości przypadków będzie istniał tylko jeden folder resources i wtedy prawidłową ścieżką będzie "actions/hide-action.js".