How to add an action button to the toolbar in a View
Please refer here for general informations about Views and Action Controllers.
if you want to add one or more action buttons to a View toolbar, you have to add a ToolController in MainTable/Controller/ToolViews node and set the specific parameters for the tool.
Example from HelloKitto: two buttons added to export data in Text and CSV format (standard tools)
# view dolls.yaml
Type: Data
.....
MainTable:
Model: Doll
Fields:
.....
Controller:
.....
ToolViews:
DownloadText:
DisplayLabel: _(Download in TXT)
Controller: ExportTextTool
RequireSelection: False
IncludeHeader: False
ClientFileName: DollList.txt
DownloadCSV:
DisplayLabel: _(Download in CSV)
ImageName: download
Controller: ExportCSVTool
RequireSelection: FalseYou can use one of the standard controllers included in Kittox or define a new one by your own. In this case you have to define the new Tool in a Delphi Tool.pas unit of your project. You have to inherit from TKXDataToolController in case you need to pass recordId to the tool, otherwise use TKXToolController.
The following example from a real project defines a tool that raises an exception in case field Petitioner has not been filled. The tool is used in the BeforeExecute node of a standard tool to prevent sending a mail.
#unit tool.pas
type
TCheckPetitioner Controller = class(TKXDataToolController)
strict private
strict protected
procedure ExecuteTool; override;
public
end;
{ TCheckPetitioner Controller }
procedure TCheckPetitioner Controller.ExecuteTool;
begin
//check presence of field petitioner
if ServerRecord.FieldByName('Petitioner').AsString = '' then
raise Exception.Create('Petitioner has no value: it is impossible to send the email');
inherited;
end; Controller:
AutoOpen: True
ToolViews:
CheckPetitioner :
IsVisible: False
Controller: CheckPetitioner
SendEmail:
BeforeExecute:
ToolView: CheckPetitioner
Controller: SendEmail
....