Creating a New Branding Element
To create a new branding element:
-
Create an application class definition that extends the PTBR_BRANDING:Elements:BaseElement class.
Use the PTBR_BRANDING:Elements:Basic* class definitions as examples.
-
Implement the following methods in the new class:
-
The class constructor to initialize the object. If the class includes additional attributes, ensure that the constructor also sets an initial value for these attributes.
MyElement(ID as string) -
clone to create an exact copy of the current object.
clone() Returns PTBR_BRANDING:Elements:BaseElement -
getHTML to return an HTML code fragment representing the object.
getHTML(preview as boolean) Returns string
-
-
Optionally, implement the getStyleDefinitions method to return style definitions for the object as an in-line style definition block or an external style sheet link:
getStyleDefinitions() Returns string -
If the element includes additional attributes, implement the following:
-
A get property of type
PTBR_BRANDING:Attributes:attr_type. The value of attr_type will depend on the type of attribute (text, image, HTML, and so on)—for example,PTBR_BRANDING:Attributes:TextAttribute. -
getAttributeByID to return the additional attribute by ID.
getAttributeByID(ID as string, create as boolean) Returns PTBR_BRANDING:Attributes:BaseAttribute
-
-
Create a new element type definition.
Example
The following example provides the implementation of the PTBR_BRANDING:Elements:BasicText class.
import PTPP_PORTAL:UTILITY:Collection;
import PTBR_BRANDING:Attributes:BaseAttribute;
import PTBR_BRANDING:Attributes:TextAttribute;
import PTBR_BRANDING:Elements:BaseElement;
/**
* BasicText Class
*/
class BasicText extends PTBR_BRANDING:Elements:BaseElement
/* --- Properties --- */
property PTBR_BRANDING:Attributes:TextAttribute Text get;
/* --- Methods --- */
method BasicText(&pId As string);
method clone() Returns PTBR_BRANDING:Elements:BaseElement;
method getAttributeByID(&pId As string, &pCreate As boolean) Returns PTBR_BRANDING:Attributes:BaseAttribute;
method getHTML(&pPreview As boolean) Returns string;
private
/* --- Private Properties --- */
Constant &cstText = ".text";
/* --- Private Methods --- */
end-class;
/**
* Constructor
*
* @param pId ID of the object.
*
*/
method BasicText
/+ &pId as String +/
%Super = create PTBR_BRANDING:Elements:BaseElement(&pId);
%This.setElementType("BasicText");
rem %this.setAdvancedOptionsPage (Page.);
/* Initialize attributes */
%This.StyleClass = "PSTEXT";
%This.Text.setText("");
end-method;
/**
* Make an exact copy of this object.
* NOTE: Only create the object here, do not copy any class properties.
* If there are new class properties, override the copyProperties
* method and do it there. Should invoke the %Super.copyProperties
* in that method though.
*
* @return BaseElement New object exactly matching this object.
*
*/
method clone
/+ Returns PTBR_BRANDING:Elements:BaseElement +/
/+ Extends/implements PTBR_BRANDING:Elements:BaseElement.clone +/
Local PTBR_BRANDING:Elements:BasicText &newObj = create PTBR_BRANDING:Elements:BasicText(%This.ID);
/* Call the copy properties function */
%This.copyProperties(&newObj);
Return &newObj;
end-method;
/**
* Get Attribute By ID
*
* @param pId ID of the attribute.
* @param pCreate True - create the attribute when not exist.
*
* @return BaseAttribute - Attribute object
*
*/
method getAttributeByID
/+ &pId as String, +/
/+ &pCreate as Boolean +/
/+ Returns PTBR_BRANDING:Attributes:BaseAttribute +/
/+ Extends/implements PTBR_BRANDING:Elements:BaseElement.getAttributeByID +/
Local PTBR_BRANDING:Attributes:BaseAttribute &getAttributeByID = %Super.getAttributeByID(&pId, &pCreate);
Local PTBR_BRANDING:Attributes:TextAttribute &TextAttribute;
If ((&getAttributeByID = Null) And
&pCreate) Then
Evaluate &pId
When &cstText
&TextAttribute = create PTBR_BRANDING:Attributes:TextAttribute(&pId);
&TextAttribute.Label = MsgGetText(219, 7509, "Text");
&TextAttribute.setText("");
&TextAttribute.IsVisible = True;
&getAttributeByID = &TextAttribute;
Break;
End-Evaluate;
If (&getAttributeByID <> Null) Then
%This.Attributes.insert(&getAttributeByID);
End-If;
End-If;
Return &getAttributeByID;
end-method;
/**
* Get HTML of the element
*
* @param pPreview True - preview mode.
*
* @return String - HTML
*
*/
method getHTML
/+ &pPreview as Boolean +/
/+ Returns String +/
/+ Extends/implements PTBR_BRANDING:Elements:BaseElement.getHTML +/
Local string &getHTML = "";
&getHTML = GetHTMLText(HTML.PTBR_ELM_CONTAINER_SPAN, EscapeHTML(%This.ID), EscapeHTML(%This.StyleClass), EscapeHTML(%This.Text.getRuntimeValue()));
Return &getHTML;
end-method;
/*****************************
* Get/Set method pairs
*****************************/
/**
* Text Property
*
*/
get Text
/+ Returns PTBR_BRANDING:Attributes:TextAttribute +/
Return (%This.getAttributeByID(&cstText, True) As PTBR_BRANDING:Attributes:TextAttribute);
end-get;