Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

pas2js designtime

Designtime support for Pas2JS Components

The pas2jscomponents.lpk package that comes with lazarus installs design-time support for pas2js webwidgets and design-time editing of components.

Installed functionality

The package also installs support for parsing HTML files and loading HTML id attributes from the html. Properties that need a HTML element ID, will display a dropdown with the discovered ID attributes.

HTML Fragment

The HTML fragment is the HTML equivalent of a form in a native LCL application. An application can contain multiple HTML fragments, which can be shown at the same time or separately.

You can add a new HTML fragment with the File-New dialog:

This will start a new form, which looks like a datamodule in the IDE.

After dropping some components on it, it will look for example like this in the designer:

The object inspector can be used to manipulate the properties, just as for a regular form.

pascal
   Note: 
   You must add -JRjs to the custom compiler options of your project to include the form data in the application.
   Additionally, the p2jsres unit must be added to the uses clause of your program, so the resource data can be loaded when the program is run.

The HTML for the fragment can be loaded in 3 ways:

The ParentID property determines under what HTML element in the main HTML page the HTML fragment will be loaded.

The following events exist:

Installed components

The pas2jscomponents package also installs some components.

THTMLElementActionList

The THTMLElementActionList component is similar to the Action list in design-time concept, but works differently at runtime: You can associate a THTMLElementAction with every element in the HTML fragment's HTML that has an ID, or you can use a CSS selector to let an action respresent a series of HTML Elements.

You don't need to create these actions manually. In the context menu there is an item "Create actions for HTML tags"

This menu will pop up a wizard that finds all elements for which no action exists yet, and proposes to create an action:

If you check the Use Data-Aware Actions checkbox, then DB-Aware actions will be used. These can be used as button actions (to navigate in the data, insert/post/delete etc. etc)

The action editor works similar to the LCL action list editor:

The main properties of an action are:

TBootstrapModal

A component (similar to the LCL Dialog components) to show a modal dialog using Bootstrap. (you need to include the various bootstrap files in your project HTML file)

The following properties exist:

The following events exist:

TBootstrapToastWidget

The TBootstrapToastWidget allow you to show a small Toast message.

It can show a toast embedded in the HTML file, or the HTML can be generated from the properties

The following event exists:

TTemplateLoader

This component can be used to load HTML fragments (in fact, any file) when the webapplication is run.

When loaded, the templates are available in a named array Templates where the index is the name of a template. The list of templates to load can be specified in the PreloadTemplates property, a collection.

The following properties exist:

The following events exist:

Because the loading happens asynchronous, the following method is useful:

pascal
Procedure IfTemplate(const aName : String; aEvent : TTemplateNotifyEvent);

this method will check if template aName is loaded, and calls aEvent if it is. If it is not yet loaded, it will wait till the template is loaded and then call the event.

Additional templates can be loaded with the following 2 calls:

pascal
Procedure LoadTemplate(Const aName,aURL : String; aOnSuccess : TTemplateNotifyEvent = Nil; AOnFail : TTemplateErrorNotifyEvent= Nil);
Procedure LoadTemplates(Const Templates : Array of String; aOnSuccess : TTemplateNotifyEvent = Nil; AOnFail : TTemplateErrorNotifyEvent= nil);

These methods will load a template, even if it was already loaded before. In case of the array, there must be an even number of elements, the odd elements are template names and the even elements are corresponding filenames.

TSQLDBRestConnection

TSQLDBRestDataset

TDBBootstraptableWidget

A widget that renders a bootstrap-table table based on a dataset.

Bootstrap-Table can be downloaded here

It renders a read-only table with paging and search options, based on the properties set, and the data from a dataset:

The component has the following properties:

For each column to be rendered the following properties can be set:

The TStylingClasses has the following properties:

TDBLoopWidget

A widget that renders a HTML template for every record in a dataset. The HTML templates can contain placeholders in the form which will be replaced with the field value of the dataset for that record.

The Groups collection can be used to make groups based on the values in the dataset: when the group value changes, a new group is started and the header template for the group is rendered. When a group ended, a footer template is rendered for that group.

The following properties exist:

TDBSelectWidget

A widget which renders a html SELECT element based on data in a dataset.

The following properties are available:


From the Free Pascal wiki, page "pas2js designtime", as it stood on 2022-05-28 after a change by FTurtle, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .