Skip to main content
Light Dark System

Portlet

<et2-portlet> | Et2Portlet

Overview

Participate in Home

When to use it

<et2-portlet> is one card on the Home page. It is the base class every Home widget extends rather than something you drop into an ordinary template: it gives you the card frame, the title bar, the context menu with Configure and Remove, drag-to-move and drag-to-resize on the Home grid, and the plumbing that saves the resulting size and position back to the user’s preferences.

You use it by subclassing it. A portlet of your own supplies its content and, if it has anything to configure, the list of settings the Configure dialog should offer.

Examples

A portlet of your own

Override bodyTemplate() to say what the card contains. headerTemplate(), footerTemplate() and imageTemplate() are there too if the default title bar is not what you want.

import {Et2Portlet} from "../../api/js/etemplate/Et2Portlet/Et2Portlet";
import {html} from "lit";

export class Et2PortletExample extends Et2Portlet
{
    bodyTemplate()
    {
        return html`<p>${this.settings?.message ?? "Nothing configured yet"}</p>`;
    }
}

customElements.define("et2-portlet-example", Et2PortletExample);

Letting the user configure it

portletProperties is the list of settings the Configure dialog shows - the same shape as a preference definition, one entry per thing the user can change. The base class already contributes color; add yours to what super returns rather than replacing it.

get portletProperties()
{
    return [
        ...super.portletProperties,
        {name: "message", label: "Message", type: "et2-textbox"},
        {
            name: "size", label: "Size", type: "et2-select",
            select_options: [{value: "s", label: "Small"}, {value: "l", label: "Large"}]
        }
    ];
}

What the user picks lands in settings, which is persisted for that user and handed back to the portlet the next time Home is opened. editTemplate points at the eTemplate used to render that dialog, and defaults to Home’s generic one - set it only if your portlet needs a hand-built configuration form.

Actions

Every portlet gets Configure and Remove for free. Anything you set on actions is merged on top of those, so you can add your own entries and override the defaults, but you do not have to re-declare them.

this.set_actions({
    refresh: {caption: "Refresh", icon: "reload", group: "portlet", onExecute: () => this.load()}
});

Size and position

width and height are in grid cells, not pixels, and row and col place the card on the Home grid. They are normally not written by hand - the user drags the card, and the new values are saved through the same settings mechanism as everything else.

<et2-portlet-example id="example" title="Example" row="1" col="1" width="2" height="2"/>

An eTemplate inside a portlet

If a portlet’s body is a whole eTemplate rather than a bit of markup, it is loaded with the portlet’s own id. The base class looks it up by that id when the card is resized and tells it to lay itself out again, so anything inside follows the new size.

Properties

Name Description Reflects Type Default
color Set the portlet color string -
editTemplate Custom etemplate used to customize / set up the portlet string -
portletProperties
Get a list of user-configurable properties { name : string, type : string, label : string, select_options? : SelectOption[] }[] -
settings Array of customization settings, similar in structure to preference settings object -
title Give a title Goes in the header at the top with the icons string -

Learn more about attributes and properties.

Inherited properties (18)

Et2Widget

Name Description
accesskey Accesskey provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character.
actions Set Actions on the widget Each action is defined as an object: move: { type: “drop”, acceptedTypes: “mail”, icon: “move”, caption: “Move to” onExecute: javascript:mail_move” } This will turn the widget into a drop target for “mail” drag types. When “mail” drag types are dropped, the global function mail_move(egwAction action, egwActionObject sender) will be called. The ID of the dragged “mail” will be in sender.id, some information about the sender will be in sender.context. The etemplate2 widget involved can typically be found in action.parent.data.widget, so your handler can operate in the widget context easily. The location varies depending on your action though. It might be action.parent.parent.data.widget To customise how the actions are handled for a particular widget, override _link_actions(). It handles the more widget-specific parts.
align Used by Et2Box to determine alignment. Allowed values are left, right
class CSS Class. This class is applied to the outside, on the web component itself. Due to how WebComponents work, this might not change anything inside the component.
data Set the dataset from a CSV
deferredProperties Any attribute that refers to row content cannot be resolved immediately, but some like booleans cannot stay a string because it’s a boolean attribute. We store them for later, and parse when they’re fully in their row. If you are creating a widget that can go in a nextmatch row, and it has boolean attributes that can change for each row, add those attributes into deferredProperties
disabled Defines whether this widget is visibly disabled. The widget is still visible, but clearly cannot be interacted with. Widgets disabled in the template will not return a value to the application code, even if re-enabled via javascript before submitting. To allow a disabled widget to be re-enabled and return a value, disable via javascript in the app’s et2_ready() instead of an attribute in the template file.
dom_id Get the actual DOM ID, which has been prefixed to make sure it’s unique.
hidden The widget is not visible. As far as the user is concerned, the widget does not exist. Widgets hidden with an attribute in the template may not be created in the DOM, and will not return a value. Widgets can be hidden after creation, and they may return a value if hidden this way.
id Get the ID of the widget
label The label of the widget This is usually displayed in some way. It’s also important for accessability. This is defined in the parent somewhere, and re-defining it causes labels to disappear
noLang Disable any translations for the widget
parentId Parent is different than what is specified in the template / hierarchy. Widget ID of another node to insert this node into instead of the normal location
statustext Tooltip which is shown for this element on hover
styles WebComponent *
options Get property-values as object
supportedWidgetClasses et2_widget compatability

LitElement

Name Description
updateComplete A read-only promise that resolves when the component has finished updating.

Methods

Name Description Arguments
edit_settings() Create & show a dialog for customizing this portlet Properties for customization are sent in the ‘settings’ attribute -
set_actions() Overriden from parent to add in default actions actions:
_onMoveResize() Handle moving and resizing event: InteractEvent
_onMoveResizeEnd() Move or resize has completed. Now into parent grid and update settings. event: InteractEvent
_setupMoveResize() Set up moving & resizing -

Learn more about methods.

Inherited methods (22)

Et2Widget

Name Description
checkCreateNamespace() Checks whether a namespace exists for this element in the content array. If yes, an own perspective of the content array is created. If not, the parent content manager is used. Constructor attributes are passed in case a child needs to make decisions
clone() Creates a copy of this widget.
createElementFromNode() Create a et2_widget from an XML node. First the type and attributes are read from the node. Then the readonly & modifications arrays are checked for changes specific to the loaded data. Then the appropriate constructor is called. After the constructor returns, the widget has a chance to further initialize itself from the XML node when the widget’s loadFromXML() method is called with the node.
getArrayMgr() Returns the array manager object for the given part
getArrayMgrs() Returns an associative array containing the top-most array managers.
getChildren() Get child widgets Use .children to get web component children
getInstanceManager() Returns the instance manager
getPath() Returns the path into the data array. By default, array manager takes care of this, but some extensions need to override this
getRoot() Returns the base widget Usually this is the same as getInstanceManager().widgetContainer
loadFromXML() Loads the widget tree from an XML node
loadingFinished() Needed for legacy compatability.
parseXMLAttrs() The parseXMLAttrs function takes an XML DOM attributes object and adds the given attributes to the _target associative array. This function also parses the legacyOptions. N.B. This is only used for legacy widgets. WebComponents use transformAttributes() and do their own handling of attributes.
set_label() NOT the setter, since we cannot add to the DOM before connectedCallback() TODO: This is not best practice. Should just set property, DOM modification should be done in render https://lit-element.polymer-project.org/guide/templates#design-a-performant-template
setArrayMgr() Sets the array manager for the given part
setArrayMgrs() Sets all array manager objects - this function can be used to set the root array managers of the container object.
setInstanceManager() Set the instance manager Normally this is not needed as it’s set on the top-level container, and we just return that reference
transformAttributes() Load further details from content Normal load & attribute assign will cast our settings object to a string
_handleClick() Click handler calling custom handler set via onclick attribute to this.onclick
destroy() et2_widget compatability
set_class() Set the widget class
set_disabled() Wrapper on this.disabled because legacy had it.
set_statustext() supports legacy set_statustext