Promotic

onPageModify - event of the PmaWebDir object

Description:
The event is triggered for the possibility to change the sent text document.
Is triggered after all changes of the document has been finish (including automatic replacing of keywords) and before sending the document into the Web browser.
Parameters:
pMe(Object) Reference to the PmaWebDir object where the event rises.
pEvent(Object) Reference to the object describing detailed information about the specific event.
pEvent.User - (Object) [for reading] The PmUser object that represents authorized user, who called the request for this page.
pEvent.Params - (String) [for reading] Text string that contains parameters in the URL.
This string has the form, for example "a=13&b=xyz". It means that "a" has the value "13" and "b" has the value "xyz".
It is possible to separate individual values from this string by the Pm.HTTPGetFormValue method.
pEvent.Method - (String) [for reading] Name of the HTTP method by which the parameters were sent:
"POST" - Sending parameters from the HTML form
"GET" - Sending parameters as a part of the required new page
pEvent.FilePath - (String) [for reading] Relative path to the file that is requested from the Web browser.
pEvent.PageString - (String) [for read and write] Text string that contains the whole required HTML/XML document in the text form after the automatic replacing of keywords has been made. If the required file isn't a HTML/XML document, then this string is empty. The algorithm can change the content of the document by writing into this property.
pEvent.Modify - (Boolean) [for read and write] If the pEvent.PageString property has been changed, then the value of the property must be set to true. Otherwise changes will not be accepted.
If Data source = Text set into the pEvent.PageString property in the onPageModify event, then the pEvent.Modify property is preset to true.
pEvent.MimeType - (String) [for read and write] Text string containing MIME type, determined from the extension of the requested page.
The MIME type is specified in HTTP response headers.
Changing the type to another may be convenient for example if the browser is required not to display the content of the page when referring to it, but instead offer to download the file (for example by changing to MIME type application/octet-stream).
Note:
The event is triggered only for the following types of documents: *.XML, *.HTM, *.JSON, *.CSV, *.TXT and *.JS.
 
- If set Data source = Text set into the pEvent.PageString property in the onPageModify event, then using this event is recommended only for special cases.
Because this event is triggered after replacing the keywords in the document, it is needless to change the keywords here.
More simple way to change the sent document is by the onPageLoad event, which is triggered just before keywords replacing.
See also Example1.
- If is Data source = Text set into the pEvent.PageString property in the onPageModify event, then this event is the only option to fill in the sent data.
Example1:
Suppose we have a user HTML page on the disk (Page.html) where we require the _(XXXXX)_ keyword to be replaced in the text, for example by the user name. The replacement is performed by the StringReplace method.

Text in HTML page:
<title>_(XXXXX)_</title>
  
Script in the onPageModify event:
JavaScriptVBScriptSelect and copy to clipboard

if (pEvent.FilePath == "Page.htm")
{
var sReplaced = Pm.StringReplace(pEvent.PageString, "xxxxx", pEvent.User.Name);
pEvent.Modify = true;
pEvent.PageString = sReplaced;
}
Example2:
Example of sending very simple HTML pages dynamically created directly in the script of this event. The "Data source" configurator must be set to "Text set into the pEvent.PageString property in the onPageModify event".
JavaScriptVBScriptSelect and copy to clipboard

var s;
if ("GET" == pEvent.Method)
{
switch (pEvent.FilePath)
{
case "abc.htm":
s = "<html><head><title>abc</title></head>";
s += "<body><p>Temperature = ";
s += pMe.Pm("/Data/#vars/temperature").Value;
s += "</p></body></html>";
break;
case "fff.htm":
// ...
break;
default:
// ...
break;
}
pEvent.PageString = s;
}

History:
Pm9.00.20: New pEvent.Method parameter.
Pm9.00.19:
- New pEvent.Params parameter with parameters in the URL.
- New pEvent.MimeType parameter containing MIME type of HTML page.
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.