Sign in Join
Wiki copytemporary

pas2js designtime: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11# Designtime support for Pas2JS Components
22
33The *pas2jscomponents.lpk* package that comes with lazarus installs design-time support for pas2js webwidgets and design-time editing of components.
44
55## Installed functionality
66
77- there is a new file type 'HTML Fragment', this is akin to a 'Form' or 'Frame'.
88- There are several components that allow you to interact with the HTML.
99 - THTMLElementActionList
1010 - TBootstrapModal
1111 - TBootstrapToastWidget
1212 - TTemplateLoader
1313 - TSQLDBRestConnection
1414 - TSQLDBRestDataset
1515 - TDBBootstraptableWidget
1616 - TDBLoopTableWidget
1717 - TDBSelectWidget
1818
1919The 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.
2020
2121## HTML Fragment
2222
2323The 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.
2424
2525You can add a new HTML fragment with the File-New dialog:
2626
2727![](/wiki-images/1/1c/Htmlfragment.png)
2828
2929This will start a new form, which looks like a datamodule in the IDE.
3030
3131After dropping some components on it, it will look for example like this in the designer:
3232
3333![](/wiki-images/9/9f/Fragment-design.png)
3434
3535The object inspector can be used to manipulate the properties, just as for a regular form.
3636
37-`   Note: `\
38-`   You must add `**`-JRjs`**` to the custom compiler options of your project to include the form data in the application.`\
39-`   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.`
37+``` pascal
38+ Note:
39+ You must add -JRjs to the custom compiler options of your project to include the form data in the application.
40+ 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.
41+```
4042
4143The HTML for the fragment can be loaded in 3 ways:
4244
4345- Set the **UseProjectHTMLFile** property to *True* if you will only use the main html file of your project. No additional HTML will be loaded.
4446- Set the **TemplateName** property to the name of a template to load.
4547- Set the **HTMLFilename** property to the name of a HTML file to load. It will be loaded using the global template loader in unit *rtl.TemplateLoader*
4648
4749The **ParentID** property determines under what HTML element in the main HTML page the HTML fragment will be loaded.
4850
4951The following events exist:
5052
5153- **OnAllowUnrender** is called when you wish to show another HTML fragment instead of this one. It is equivalent to **OnCloseQuery** in an LCL form.
5254- **OnCreate** Called when the fragment is created. note that the HTML is not yet available.
5355- **OnDestroy** Called when the fragment is destroyed.
5456- **OnHTMLLoaded** Called when the HTML fragment has been loaded from the server.
5557- **OnRendered** Called when the HTML fragment has been inserted in the DOM.
5658- **OnUnRendered** Called when the HTML fragment has been removed from the DOM.
5759
5860## Installed components
5961
6062The *pas2jscomponents* package also installs some components.
6163
6264### THTMLElementActionList
6365
6466The **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.
6567
6668You don't need to create these actions manually. In the context menu there is an item "Create actions for HTML tags"
6769
6870![](/wiki-images/3/3f/Htmlelementactionlist.png)
6971
7072This menu will pop up a wizard that finds all elements for which no action exists yet, and proposes to create an action:
7173
7274![](/wiki-images/e/e7/Createhtmlactions.png)
7375
7476If 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)
7577
7678The action editor works similar to the LCL action list editor:
7779
7880![](/wiki-images/1/17/Elementactioneditor.png)
7981
8082The main properties of an action are:
8183
8284- **ElementID** the ID of the element you want to control.
8385- **CSSSelector** A css selector for thes element you want to control in case of multiple elements (e.g. to get all rows in a table use **\#tableid tr**)
8486- **Events** a set of events to listen for. When the event is triggered, the **OnExecute** event handler is executed.
8587- **CustomEvents** a space separated list of HTML to listen for, for events that do not appear in **Events**
8688- **PreventDefault** can be set to **True** to prevent the default HTML action from happening.
8789- **StopPropagation** can be set to **True** to prevent the event from *bubbling*, i.e. propagating to parent elements.
8890
8991### TBootstrapModal
9092
9193A 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)
9294
9395The following properties exist:
9496
9597- **ShowOnRender** set to *True* if you wish to show the modal as soon as it is rendered (meaning, the HTML was generated).
9698- **BackDrop** show a backdrop shadow over the rest of the HTML page.
9799- **KeyBoard** Allow keyboard actions
98100- **Focus** set focus to the modal.
99101- **Template** the HTML for the modal.
100102- **TemplateName** the name of a template in **TempateLoader** containing the modal HTML.
101103- **TemplateLoader** a custom template loader. If not set, a global template loader is used.
102104- **References** a collection of CSS Selectors which can be used to get a reference to elements in the modal. These can be used to retrieve entered values during the **OnHide** event handler..
103105
104106The following events exist:
105107
106108- **OnHide** event triggered when the modal is hidden.
107109
108110### TBootstrapToastWidget
109111
110112The **TBootstrapToastWidget** allow you to show a small *Toast* message.
111113
112114It can show a toast embedded in the HTML file, or the HTML can be generated from the properties
113115
114116- **Header** a string with the HTML for the header tag.
115117- **SmallHeader** a string with the HTML for the sub (smaller) header tag.
116118- **Body** a string with the HTML for body of the modal.
117119- **HeaderImage** an URL for the header image.
118120- **CloseButton** set to *True* to add a close button to the dialog.
119121- **Contextual** an enumerated which allows you to select one of the primary bootstrap color schemes.
120122- **HideDelay** a number of milliseconds before the toast automatically disappears when *AutoHide* is *True*.
121123- **AutoHide** set to *True* to let the toast disappear automatically after *HideDelay* milliseconds.
122124- **Animate** set to *True* to animate showing and hiding of the modal.
123125- **MinWidth** minimum width for the modal.
124126- **UnrenderOnHide** if set to *True* the HTML of the toast will be removed from the DOM when the toast is hidden.
125127
126128The following event exists:
127129
128130- **OnHide** triggered when the toast is hidden.
129131
130132### TTemplateLoader
131133
132134This component can be used to load HTML fragments (in fact, any file) when the webapplication is run.
133135
134136When 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.
135137
136138The following properties exist:
137139
138140- **BaseURL** all filenames for templates are relative to this URL.
139141- **CheckResources** When loading a template, check if a resource with the same name as the template exists. If yes, load the template from the resource.
140142- **PreloadTemplates** List of templates to load as soon as the component is loaded from the form file.
141143
142144The following events exist:
143145
144146- **OnLoad** triggered when a template is loaded. The name of the loaded template is passed to the event handler.
145147- **OnLoadFail** triggered when a template fails to load. The name of the loaded template is passed to the event handler.
146148
147149Because the loading happens asynchronous, the following method is useful:
148150
149151``` pascal
150152Procedure IfTemplate(const aName : String; aEvent : TTemplateNotifyEvent);
151153```
152154
153155this 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.
154156
155157Additional templates can be loaded with the following 2 calls:
156158
157159``` pascal
158160Procedure LoadTemplate(Const aName,aURL : String; aOnSuccess : TTemplateNotifyEvent = Nil; AOnFail : TTemplateErrorNotifyEvent= Nil);
159161Procedure LoadTemplates(Const Templates : Array of String; aOnSuccess : TTemplateNotifyEvent = Nil; AOnFail : TTemplateErrorNotifyEvent= nil);
160162```
161163
162164These 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.
163165
164166### TSQLDBRestConnection
165167
166168### TSQLDBRestDataset
167169
168170### TDBBootstraptableWidget
169171
170172A widget that renders a bootstrap-table table based on a dataset.
171173
172174[Bootstrap-Table can be downloaded here](https://bootstrap-table.com/)
173175
174176It renders a read-only table with paging and search options, based on the properties set, and the data from a dataset:
175177
176178The component has the following properties:
177179
178180- **StylingClasses** a set of properties that affect how a column with a button is rendered. See below for the list of properties.
179181- **Columns** A column with the columns to render in the table.
180182- **DataSource** a reference to the dataset for which to render the table. The table is rendered when the dataset opens, it is unrendered when the dataset closes.
181183- **Options** a set of general options for the table behaviour.
182184- **ViewOptions** a set of options that determine the look-and-feel of the table.
183185- **PaginationOptions** a set of options that govern the pagination mechanism of the table.
184186- **SearchOptions** a set of options that control the search mechanism of the table.
185187- **SortOptions** a set of options that control the sorting mechanism of the table.
186188- **DisplayReadOnly** set all edit/delete buttons readonly.
187189- **AfterBodyDraw** event triggered after the table body has been rendered.
188190
189191For each column to be rendered the following properties can be set:
190192
191193- **FieldName**: The Fieldname for this column
192194- **Title**: The Title for this column
193195- **RenderMode**: The Render mode for the column: text, number, checkbox, button custom render
194196- **ButtonType**: When rendermode is rmButton, what button must be rendered.
195197- **ButtonIconClass**: When buttontype is btCustom, use the following class (in \<i class=""\>\</i\>)
196198- **OnTransformValue**: Event called when rendermode is rmTransformValue
197199- **OnCustomFormat**: EVent called when rendermode is rmCustom
198200- **Width**: Column Width (in WidthUnits units)
199201- **WidthUnits**: Column Width (in CSS units)
200202- **CSSClassName**: a CSS Class name applied on cells for this column
201203- **CheckBoxClassName**: CSS Class name for this column if there is a check box.
202204- **Visible**: Visible column or not ?
203205- **Searchable**: A boolean that Indicates whether the column is searchable
204206- **Sortable**: A boolean that Indicates whether the column is sortable
205207- **ButtonURL**: string URL to use when the button is clicked
206208- **ButtonURLTarget**: link element target attribute.
207209
208210The **TStylingClasses** has the following properties:
209211
210212- **CheckBoxClass** a space-separated list of classes to apply to a checkbox column.
211213- **ButtonClass** a space-separated list of classes to apply to a button column.
212214- **InfoClass** a space-separated list of classes to apply to a info button column.
213215- **EditClas** a space-separated list of classes to apply to a edit button column.
214216- **ReadonlyEditClass** a space-separated list of classes to apply to a read-only edit column.
215217- **DeleteClass** a space-separated list of classes to apply to a delete button column.
216218
217219### TDBLoopWidget
218220
219221A 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.
220222
221223The **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.
222224
223225The following properties exist:
224226
225227- **HeaderTemplate** The header template is rendered before starting the loop.
226228- **ItemTemplate** The Item template is rendered for each record in the dataset.
227229- **FooterTemplate** The footer template is rendered before starting the loop.
228230- **OnGetValue** event called to get the value of a placeholder.
229231- **References** use CSS selectors to get references to the nodes in the rendered content;
230232- **Datasource** a reference to the data for which to render the loop.
231233- **OnFormatField** an event to get a custom formatted version of a field.
232234- **Groups** a collection of groups for which an expression, a footer and header template can be specified.
233235- **OnGetGroupValue** to get a custom value for a group expression.
234236
235237### TDBSelectWidget
236238
237239A widget which renders a html SELECT element based on data in a dataset.
238240
239241The following properties are available:
240242
241243- **Datasource** a reference to the data from which to generate the SELECT element.
242244- **ItemField** the field whose value is used to create an OPTION element in the SELECT.
243245- **ValueField** when set, the field whose value is used to set the **value** attribute of an OPTION element in the select.
244246- **NullIsNotValue** if a field is null, no value is generated.
245247- **SelectedIndex** set the selected item index.
246248- **Multiple** allow multiselect.
247249
248250---
249251*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](/wiki-contact).*
250252Category: Pas2js

Back to history