K4:Adding New Button to Toolbar
From In-Portal Developers Guide
Path to article:
m (1 версия) |
Current revision (18:07, 26 November 2010) (view source) (Translation) |
||
(5 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
{{toc | category = Работа с шаблонами и блоками | sortkey = 003.001}} | {{toc | category = Работа с шаблонами и блоками | sortkey = 003.001}} | ||
- | + | ||
+ | The Toolbar is one of the key elements to control events in the templates. In order to add a new button to already existing Toolbar you would need to use the following Javascript code: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
Line 14: | Line 15: | ||
</source> | </source> | ||
- | + | Class constructor <code>ToolBarButton</code> accepts 5 parameters where only first 3 are requires: | |
+ | |||
{| class="prettytable" | {| class="prettytable" | ||
- | ! | + | ! Name || Description |
|- | |- | ||
- | | {{ConfigProperty|title|string}} || | + | | {{ConfigProperty|title|string}} || Button identifier (ID). The identifier must unique within a Toolbar. Additionally, in there is a way to specify a Module name in identifier which will be used in building the source path to the image of button (see [[K4:Структура директорий|Структура директорий]]). Below are examples of filename for the button images which also determine type of the button: |
- | * '''<code>tool_sample_button.gif</code>''' - | + | * '''<code>tool_sample_button.gif</code>''' - default state of the button (can be clicked); |
- | * '''<code>tool_sample_button_f1.gif</code>''' - | + | * '''<code>tool_sample_button_f1.gif</code>''' - button when you mouse-over it (can be clicked);; |
- | * '''<code>tool_sample_button_f2.gif</code>''' - | + | * '''<code>tool_sample_button_f2.gif</code>''' - button when it's disabled (inactive and can't be clicked). |
- | + | ||
+ | In the example above "sample_button" should be replaced with the actual button name. The Module name is separated from the button name with a colon ("<code>:</code>"). There is '''no need''' to specify module in the button name if it's "<code>core</code>" module. Later on the template the button can be referred by name (not identifier) in order to Enable or Disable it on the toolbar. Good example would be disabling "<code>Delete</code>" button in a toolbar until at least one grid record is selected. | ||
|- | |- | ||
- | | {{ConfigProperty|alt|string}} || | + | | {{ConfigProperty|alt|string}} || Phrase that is shown when you mouse-over the button. The same phrase will be used to show the text right under the actual button (only if [[K4:Configuration#UseToolbarLabels|UseToolbarLabels]] configuration option is on). Also, there is a way to have 2 separate phrases for a '''Hint''' (shown on mouse-over) and the one below the button, in this case they should be separated with double-colon ("<code>::</code>"). The phrase when double-colon will be used for a Hint while the one after the separator will be shown below the button. |
|- | |- | ||
- | | {{ConfigProperty|onclick|string}} || | + | | {{ConfigProperty|onclick|string}} || The action that takes place when button is clicked. Usually, there is a call for dynamic Javascript function which has the actual Javascript that should be executed on click. |
|- | |- | ||
- | | {{ConfigProperty|$hidden|int}} || | + | | {{ConfigProperty|$hidden|int}} || Button needs to be hidden right after Toolbar initialization. This is done for cases when you need more visual control over when to show the button in the toolbar, but at the same time all buttons needs to be initialized when the toolbar is created. |
|- | |- | ||
- | | {{ConfigProperty|prefix|string}} || [[K4:Unit Configs#Prefix|Префикс]] | + | | {{ConfigProperty|prefix|string}} || [[K4:Unit Configs#Prefix|Префикс]] that is used for the current button. |
|} | |} | ||
+ | |||
+ | [[en:{{FULLPAGENAME}}]] | ||
+ | [[ru:K4:Добавление_кнопки_в_панель_инструментов]] |
Current revision
| ||
---|---|---|
Статьи в этой категории | ||
|
The Toolbar is one of the key elements to control events in the templates. In order to add a new button to already existing Toolbar you would need to use the following Javascript code:
a_toolbar.AddButton( new ToolBarButton( 'custom:sample_button', '<inp2:m_phrase label="la_ToolTip_SampleButton" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_SampleButton" escape="1"/>', function() { // alert('button worked'); } ) );
Class constructor ToolBarButton
accepts 5 parameters where only first 3 are requires:
Name | Description |
---|---|
title (string) | Button identifier (ID). The identifier must unique within a Toolbar. Additionally, in there is a way to specify a Module name in identifier which will be used in building the source path to the image of button (see Структура директорий). Below are examples of filename for the button images which also determine type of the button:
In the example above "sample_button" should be replaced with the actual button name. The Module name is separated from the button name with a colon (" |
alt (string) | Phrase that is shown when you mouse-over the button. The same phrase will be used to show the text right under the actual button (only if UseToolbarLabels configuration option is on). Also, there is a way to have 2 separate phrases for a Hint (shown on mouse-over) and the one below the button, in this case they should be separated with double-colon (":: "). The phrase when double-colon will be used for a Hint while the one after the separator will be shown below the button.
|
onclick (string) | The action that takes place when button is clicked. Usually, there is a call for dynamic Javascript function which has the actual Javascript that should be executed on click. |
(int) | Button needs to be hidden right after Toolbar initialization. This is done for cases when you need more visual control over when to show the button in the toolbar, but at the same time all buttons needs to be initialized when the toolbar is created. |
prefix (string) | Префикс that is used for the current button. |