此内容没有您所选择的语言版本。
2.6. Extending Business Central
Starting with version 6.1 of Red Hat JBoss BPM Suite, Business Central can be configured to add new screens, menus, editors, splashscreens and perspectives by the Administrator. These elements can extend functionality of Business Central and can be accessed through the Extensions
You can now define your own Javascript and HTML based plugins to extend Business Central and add them without having to worry about copying files in the underlying filesystem. Let us add a new screen in the system to show you the basics of this functionality.
2.6.1. Plugin Management 复制链接链接已复制到粘贴板!
You access the Plugin Management
screen by clicking on Extensions
- Perspective Plugin
- Screen Plugin
- Editor Plugin
- Splashscreen Plugin
- and Dynamic Menu
Open any of these, and you will see the existing plugins in each category, including the uneditable system generated ones.
Let us create a new plugin that echoes "Hello World" when users visit the screen for that plugin. In general, the steps to creating a new plugin are:
- Create a new screen
- Create a new perspective (and add the new screen to it)
- Create a new menu (and add the new perspective to it)
- Apps (optional)
Adding a New Screen
Click the
button and select New Screen. You will be prompted to enter the name of this new screen. Enter "HelloWorldJS" and press the OK button. The Screen plugin editor will open, divided into 4 sections: Template, CSS, JavaScript and Media.
All manually created elements go into their respective categories in case you want to edit them later. In this case, to open the Screen plugin editor again if you close it, open the Screen Plugin category and scroll past the system generated screens to your manually created plugin and click on it to open the Screen plugin editor again.
Template is where your HTML goes, CSS is for styling, JavaScript is for your functions and Media is for uploading and managing images.
Since we are making a simple Hello World plugin, enter the following code in the Template section: <div>My Hello World Screen</div>
. This can be any HTML code, and you can use the supplied Angular
and Knockout
frameworks. For the purposes of this example, we are not using any of those frameworks, but you can choose to by selecting them from the drop down in the Template section.
Enter your JavaScript code in the JavaScript section. Some common methods and properties are defined for you, including main
, on_close
and on_open
. For this demo, select the on_open
and enter the following: function () { alert('Hello World'); }
Click the Save button to finish creating the screen. After you save the screen, refresh business central so that the Screen Plugin is listed in the Screen Component of Perspective plugin.
Adding New Perspective
Once a screen has been created, you need to create a perspective on which this screen will reside. Perspectives can also be created similar to the way a screen is created by clicking on the New button and then selecting New Perspective. You can now provide a name for this perspective, say HelloWorldPerspective
. This will open the Perspective plugin editor, similar to the Screen plugin editor.
The Perspective Editor is like a drag and drop grid builder for screens and HTML components. Remove any existing grids and then drag a 6×6 grid on the right hand side to the left hand side.
Next, open the Components category and drag a Screen Component on the right hand side to the left hand side (in any grid). This will open the Edit Component dialog box that allows you to select the screen created in the previous step (HelloWorldJS
). Click the OK button and then click Save to save this perspective. To tag your perspective, enter Home
in the tag name field and click Tags. Click OK and save the changes.
You can open this perspective again from the Perspective plugins listed on the left hand side.
Adding New Menu
The final step in creating our plugin is to add a dynamic menu from where the new screen/perspective can be called up. To do so, go to Extensions HelloWorldMenu
) and then click the OK button. The dynamic menu editor opens up.
Enter the perspective name (HelloWorldPerspective
) as the Activity Id and the name for the drop down menu (HelloWorldMenuDropDown
). Click OK and then Save.
This new menu will be added to your workbench the next time you refresh Business Central. Refresh it now to see HelloWorldMenu added to your top level menu. Click on it to reveal HelloWorldMenuDropDown, which when clicked will open your perspective/screen with the message Hello World
.
You have created your first Plugin!
Working with Apps (Optional)
If you create multiple plugins, you can use the Apps directory feature to organize your own components and plugins, instead of having to rely on just the top menu entries.
When you save a new perspective, you can add labels (tags) for them and these labels (tags) are used to associate a perspective with an App directory. You can open the App directories by clicking on Extensions
The Apps directory provides an alternate way to open your perspective. When you created your HelloWorldPerspective
, you entered the tag Home
. The Apps directory by default contains a single directory called Home
with which you associated your perspective. This is where you will find it when you open the Apps directory. You can click on it to run the perspective now.
You can create multiple directories and associate perspectives with those directories depending on functional and vertical business requirements. For example, you could create an HR directory and then associate all HR related perspectives with that directory to better manage Apps.
You can create a new directory by clicking the
button.
2.6.2. The JavaScript (JS) API for Extensions 复制链接链接已复制到粘贴板!
The extensibility of Business Central is achieved by an underlying JavaScript (JS) API which is automatically loaded if it is placed in the plugins
folder of the Business Central webapp (typically: INSTALL_DIR/business-central.war/plugins/
), or it can be loaded via regular JavaScript calls.
This API is divided into multiple sets depending on the functionality it performs.
- Register Perspective API
Allows for the dynamic creation of perspectives. The example below creates a panel using the
registerPerspective
method:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Editor API
Allows you to dynamically create editors and associate them with a file type. The example below creates a sample editor and associates it with
filename
file type.Copy to Clipboard Copied! Toggle word wrap Toggle overflow In addition to
on_startup
andon_open
methods seen in the previous example, the API exposes the following callback events for managing the editor’s lifecycle:-
on_concurrent_update;
-
on_concurrent_delete;
-
on_concurrent_rename;
-
on_concurrent_copy;
-
on_rename;
-
on_delete;
-
on_copy;
-
on_update;
-
on_open;
-
on_close;
-
on_focus;
-
on_lost_focus;
-
on_may_close;
-
on_startup;
-
on_shutdown;
You can display this editor via an HTML template:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
- PlaceManager API
-
The methods of this API allow you to request that the Business Central display a particular component associated with a target:
$goToPlace("componentIdentifier");
- Register plugin API
The methods of this API allow you to create dynamic plugins (that will be transformed in Business Central screens) via the JS API.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The plugin references the
angular.sample.html
template:Copy to Clipboard Copied! Toggle word wrap Toggle overflow A plugin can be hooked to Business Central events via a series of JavaScript callbacks:
-
on_concurrent_update;
-
on_concurrent_delete;
-
on_concurrent_rename;
-
on_concurrent_copy;
-
on_rename;
-
on_delete;
-
on_copy;
-
on_update;
-
on_open;
-
on_close;
-
on_focus;
-
on_lost_focus;
-
on_may_close;
-
on_startup;
-
on_shutdown;
-
- Register splash screens API
use the methods in this API to create splash screens.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Virtual File System (VFS) API
with this API, you can read and write a file saved in the file system using an asynchronous call.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow