You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

用法 

  • 插件属性选项允许插件从插件用户收集配置数据。
  • 插件属性选项应该在每个插件的抽象方法“getPropertyOptions”中返回。

结构体 

  • 插件属性选项是JSON格式。
  • 插件属性选项是一个属性页面对象的数组
  • 属性页面对象具有称为“title”和“properties”的两个强制属性。它还具有称为“validators”和“buttons”的2个可选属性。
[
    {
        title : 'Page Title',
        properties : [
            {
                name : 'Property Name',
                label : 'Property Label',
                description : 'Property Description', //optional, default is NULL
                type : 'Property Type',
                value : 'Property Value', //optional, default is null
                required : 'Mandatory or Not', //optional, 'true' or 'false', default is 'false'
                //… more attributes …
            }, //… more fields …
        ],
        validators : [  //optional
            //… properties custom validators …
        ],
        buttons : [  //optional
            //… custom properties page buttons …
        ]
    }, //… more properties page …
]

样品外观和大体感官

字段类型

Check Box

Code Editor

  • type : 'CodeEditor'
  • mode : 可选,用于指定高亮语言。默认为'text',可用值为'text','java','html','javascript','css','json','sql'和'xml'。
  • 请参阅  依赖关系字段属性  以获取额外的属性,以根据其他字段值显示/隐藏此字段。
  • 请参阅  检索插件中的属性值 - 单值字段中关于如何在插件代码中使用此字段类型的值。

Combine Grid

  • Combine Grid 用于将两个或多个单值属性字段从旧版本插件(等待文本字段和选择框)迁移到GridView中的多值字段。
  • Combine Grid 不支持“value”属性
  • type : 'GridCombine'
  • columns :  'column' JSON数组必须有JSON 对象。 {key : 'key', label : 'Columns'}   其中 key ,lable 必填,required 和 options 选填 
    • key :此列的标识符。该值需要 与  需要从单值字段迁移到多个值字段的字段“name”相同。
    • label : 列标题的标签
    • options : 可选,  具有“ value”和“label”属性的JSON对象数组。具有'options'属性的列将显示输入字段作为选择框。
    • required : 可选,'true'或'false'。“row”和“column”的“required”属性设置为“true”值的网格单元是必填字段。
    columns : [
        {key : 'key', label : 'Columns'}, 
        {key : 'value', label : 'Value', required: 'true'},
        {key : 'label', label : 'Label', required: 'true'},
        {key : 'width', label : 'Width', options:[
            {value : '10%', label : '10%'},
            {value : '20%', label : '20%'},
            {value : '30%', label : '20%'},
            {value : '40%', label : '20%'}
        ]}
    ]
  • 参阅  依赖关系字段属性  以获取额外的属性,以根据其他字段值显示/隐藏此字段。
  • 参阅  检索插件中的属性值 - 组合网格字段  ,了解如何在插件代码中使用此字段类型的值。

Element Select Box

  • type : 'ElementSelect'
  • url :将返回所选元素的属性选项JSON对象的URL。内置的URL是 "[CONTEXT_PATH]/web/property/json[APP_PATH]/getPropertyOptions" 这将会返回插件属性中的 json 对象。
  • keep_value_on_change : 可选,'true'或'false'。用于决定在选择新元素时是否保留先前选定元素的属性选项的配置。
  • 有关额外的属性,请参阅  选项字段属性
  • 参阅  依赖关系字段属性  以获取额外的属性,以根据其他字段值显示/隐藏此字段。
  • 常用于选择插件并配置所选插件的属性。
  • 参阅  检索插件中的属性值 - ElementSelectBox  如何在插件代码中使用此字段类型的值。

Fixed Row Grid

  • type : 'GridFixedRow'
  • columns :具有2个强制“key ”和“label ”属性的“列” ,JSON对象的JSON数组和2个可选的“required ”和“options ”属性。
    • key :此列的标识符。
    • label : 列标题的标签
    • options : 可选,  具有“ value”和“label”属性的JSON对象数组。具有'options'属性的列将显示输入字段作为选择框。
    • required : 可选,'true'或'false'。“row”和“column”的“required”属性设置为“true”值的网格单元是必填字段。
  • rows : 具有'label'属性和可选的“required”属性的“row”  JSON对象的JSON数组。“row” , “column”的“required”属性设置为“true”的网格单元是必填字段。
    • label : 一行的标签。用于填充第一列或每行。
    • required : 可选,'true'或'false'。“row”和“column”的“required”属性设置为“true”值的网格单元是必填字段。
  • value : JSON对象格式的JSON列数组,其中所有用作“column”对象的“key”属性用作属性。
columns : [
    {key : 'key', label : 'Columns'}, // first column will used to populate row label
    {key : 'value', label : 'Value', required: 'true'},
    {key : 'label', label : 'Label', required: 'true'},
    {key : 'width', label : 'Width', options:[
        {value : '10%', label : '10%'},
        {value : '20%', label : '20%'},
        {value : '30%', label : '20%'},
        {value : '40%', label : '20%'}
    ]}
],
rows : [
    {label : 'Username', required: 'true'},
    {label : 'Status'},
    {label : 'Message'},
    {label : 'Date'}
],
value : [
    {label : 'Username'},
    {label : 'Status'},
    {label : 'Message', width : '20%'},
    {label : 'Date', value : 'dateCreated'}
]

Grid

  • type : 'Grid'
  • columns : A JSON array of 'column' JSON objects which has 2 mandatory 'key' & 'label' attributes and 2 optional 'required' & 'options' attribute. 
    • key : Identifier of this column.
    • label : Label of the column header
    • options : Optional, an array of JSON object with 'value' and 'label' attributes. A column with 'options' attribute will display the input field as select box.
    • required : Optional, 'true' or 'false'. A grid cell with the 'required' attribute of 'row' and 'column' set to 'true' value is a mandatory field.
  • value : A JSON array of grid row values in JSON Object format with all the 'key' attribute of 'column' object used as attribute.  

    columns : [
        {key : 'value', label : 'Value', required: 'true'},
        {key : 'label', label : 'Label', required: 'true'},
        {key : 'width', label : 'Width', options:[
            {value : '10%', label : '10%'},
            {value : '20%', label : '20%'},
            {value : '30%', label : '20%'},
            {value : '40%', label : '20%'}
        ]}
    ],
    value : [
        {label : 'Username', value : 'username'},
        {label : 'Status', value : 'status'},
        {label : 'Message', value : 'message', width : '20%'},
        {label : 'Date', value : 'dateCreated'}
    ]
  • Refer to Dependency Field Attributes for extra attributes to do show/hide this field based on other field value.
  • Refer to Retrieve Properties Value in Plugin - Grid Field on how to use the value of this field type in the plugin code.

Header

  • type : 'Header'
  • Header does not support 'value' and 'required' attributes.
  • Refer to Dependency Field Attributes for extra attributes to do show/hide this field based on other field value.
  • This field type is used for separate the fields into different groups. It is not use for capture data. 

Hidden Field

HTML Editor

Label

Multi Select Box

Password Field

Radio Button

Readonly Text Field

Select Box

Text Area

Text Field

Regular Express (Regex) Validation Attributes

  • The following attributes are designed for Password Field, Text Area and Text Field
  • regex_validation : Optional, regular express in string format. 
  • validation_message : Optional, error message to display when validation failure. 
{
    regex_validation : '^[a-zA-Z0-9_]+$',
    validation_message : 'Invalid ID!!'
}

Dependency Field Attributes

  • The following attributes are available for all field types.
  • These attributes are used to show/hide a field based on the value of another field.
  • The value of a field hidden by these attributes will be ignore during save.
  • control_field : Optional, 'name' of another field used to control the show/hide of current field.
  • control_value : Optional, value or regular expression (regex) in string format. This value need to match the value of the controlling field in order to make the field visible.
  • control_use_regex : Optional, 'true' or 'false'. Default to 'false'. Set to 'true' to use regular expression (regex) in matching the value.
{
    control_field: 'chartType',
    control_value: 'bar|xy|area|bubble|line|candlestick|ohlc',
    control_use_regex: 'true',
}

Options Field Attributes

  • The following attributes are designed for options fields like Check Box, Element Select Box, Multi Select Box, Radio Button and Select Box.
  • You can choose to use one of the following attributes "options", "options_ajax", "options_callback" or "options_script" to populate the options for the field.
  • options : Optional, an array of JSON object with 'value' and 'label' attributes.
options : [
    {value: 'value1', label : 'Value 1'},
    {value: 'value2', label : 'Value 2'},
    {value: 'value3', label : 'Value 3'}
]
  • options_ajax : Optional, a URL which will return an array of JSON object with 'value' and 'label' attributes.
options_ajax : '[CONTEXT_PATH]/web/json/console/app[APP_PATH]/datalist/options'
  • options_ajax_on_change : Optional, name of a property field. Used together with 'options_ajax' attribute. The field name and its value will passed as HTTP request parameter to the URL.
options_ajax_on_change : 'type'
options_ajax : '[CONTEXT_PATH]/web/json/app[APP_PATH]/plugin/org.joget.plugin.enterprise.SamplePlugin/service?action=getJson'
  • options_callback : Optional, a javascript function name. All attributes in the field will passed as a single JSON object parameter to this function. The function should return an array of JSON object with 'value' and 'label' attributes.
options_callback: 'DatalistBuilder.getColumnOptions'
  • options_script : Optional, a string of javascript which will return an array of JSON object with 'value' and 'label' attributes.
options_script: 'var tempArray = [{\'label\':\'\',\'value\':\'\'}]; 
for(ee in DatalistBuilder.availableColumns){ var temp = {
\'label\' : UI.escapeHTML(DatalistBuilder.availableColumns[ee].label),
\'value\' : DatalistBuilder.availableColumns[ee].id}; 
tempArray.push(temp);}tempArray;'

Built-in JSON API for 'options_ajax' 

  • [CONTEXT_PATH]/web/json/console/app/[APP_PATH]/forms/options
    Return all available forms of current app.
  • [CONTEXT_PATH]/web/json/console/app/[APP_PATH]/datalist/options
    Return all available datalists of current app.
  • [CONTEXT_PATH]/web/json/console/app/[APP_PATH]/userview/options
    Return all available userviews of current app.
  • [CONTEXT_PATH]/web/property/json/getElements?classname={plugin interface/abstract class name, optional}
    Return all available plugins based on the classname filter.

Built-in Javascript Function for 'options_callback'

  • DatalistBuilder.getColumnOptions(properties)
    Can be used by plugins related to Datalist Builder. It return all available columns based on binder configuration.

Validator Types

  • Page validator is execute during change page.
  • All fields data in the same page will pass to the validator for validation.

AJAX

  • Call to a URL for validation.
  • type : 'AJAX'
  • url : An URL return a JSON Object with status (success or fail) & message (JSONArray of String) attribute
  • default_error_message : Optional. A string of error message.

Page Button

  • Page button can be added on the bottom of each page to provide extra feature. Such as send an test email to test the email configuration or make a test connection to database.
  • Page button will collect the required fields data from the page and popup dialog and call an AJAX URL. 
  • name : Identifier of this button.
  • label : Label of the button.
  • ajax_url : A URL to execute the button action. The URL should return a JSON Object with message (String) attribute.
  • fields : An array of fields name in the same page that will be used by this button. 
  • addition_fields :  An array of Property Field JSON object that will be shown in a popup dialog to collect extra data.
  • Example:

    buttons : [{
        name : 'testmail',    
        label : 'Send Test Email',
        ajax_url : '[CONTEXT_PATH]/web/json/app[APP_PATH]/plugin/org.joget.apps.app.lib.EmailTool/service?action=testmail',
        fields : ['host', 'port', 'security', 'username', 'password'],
        addition_fields : [
            {
                name : 'from',
                label : 'From',
                type : 'textfield',
                required : 'True'
            },
            {
                name : 'toSpecific',
                label : 'To',
                type : 'textfield',
                required : 'True'
            }
        ]
    }]

Variable

[CONTEXT_PATH]

  • This variable will be replaced by Context Path of current URL.
  • Usually used in property attribute value which is URL
  • Example : '[CONTEXT_PATH]/web/property/json/getElements?classname=org.joget.apps.form.model.FormValidator'
  • Resulted URL : '/jw/web/property/json/getElements?classname=org.joget.apps.form.model.FormValidator'

[APP_PATH]

  • This variable will be replaced by Current App Id and App Version of current URL.
  • Usually used in property attribute value which is URL
  • Example : '[CONTEXT_PATH]/web/json/console/app[APP_PATH]/datalist/options'
  • Resulted URL : '/jw/web/json/console/app/crm/3/datalist/options'

Retrieve Properties Value in Plugin

  • All the plugin must extends the "org.joget.plugin.base.ExtDefaultPlugin" abstract class. We can use the "Object getProperty(String)" and "String getPropertyString(String)" method to retrieve the configured properties.

Single Value Field

String value = getPropertyString("property_name");

Multi Values Field

String[] values = getPropertyString("property_name").split(";");

Combine Grid Field

String[] col1_values = getPropertyString("col1_name").split(";");
String[] col2_values = getPropertyString("col2_name").split(";");

Grid Field

Object columns = getProperty("property_name");
if (columns != null) {
    for (Object colObj : (Object[]) columns) {
        Map col = (Map) colObj;
        String col1_value = (String) opt.get("col1_key");
        String col2_value = (String) opt.get("col2_key");
    }
}

Element Select Box

import org.joget.plugin.base.PluginManager;
import org.joget.apps.app.service.AppUtil;
import org.joget.plugin.base.ExtDefaultPlugin;
 
Object element = getProperty("property_name");
if (element != null && element instanceof Map) {
    Map elementMap = (Map) element;
    String className = (String) elementMap.get("className");
    Map<String, Object> properties = (Map<String, Object>) elementMap.get("properties");
 
    //convert it to plugin
    PluginManager pm = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager");
    ExtDefaultPlugin plugin = (ExtDefaultPlugin) pm.getPlugin(className);
    if (plugin != null) {
        plugin.setProperties(properties);
    }
}
  • No labels