In-Portal Developers Guide

This is a wiki-based Developers Guide for In-Portal Open Source CMS. The purpose of this guide is to provide advanced users, web developers and programmers with documentation on how to expand, customize and improve the functionality and the code the In-Portal software. Please consider contributing to our documentation writing effort.

K4:Adding New Button to Toolbar

From In-Portal Developers Guide

Jump to: navigation, search
Работа с шаблонами и блоками Работа с шаблонами и блоками
Статьи в этой категории

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:
  • tool_sample_button.gif - default state of the button (can be clicked);
  • tool_sample_button_f1.gif - button when you mouse-over it (can be clicked);;
  • tool_sample_button_f2.gif - 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 (":"). There is no need to specify module in the button name if it's "core" 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 "Delete" button in a toolbar until at least one grid record is selected.

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.
$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.
prefix (string) Префикс that is used for the current button.