Promotic
WikipediaLinkedInYoutubeTwitterFacebook

Opening the viewer for option selection (/#glob/list)

The window for option selection from a list is opened by the Pm.CreateView method. In the parameter sViewPath the global path "/#glob/list" is entered.
Viewer parameters:
initValue[optional] (String) Initial selection (Identifier).
list(Array) 2-dimensional array with optionsi, where the rows represent each option and the columns the option items. See (Col,Row) - 2-dimensional array meaning an array of rows.
The first column (index 0) is not displayed by the menu (it is invisible) and contains the identifiers of each option. The next columns are displayed in the menu. The menu has a table layout, having one column less than the used 2-dimensional data array.
The first row may (not necessarily) contain the header with column titles (localized user names) in the menu. If the first row is to contain the header, then in the first column (invisible, reserved for identifiers) there must be a string with $title value.
autoselect[optional] (Long) (Long) It allows to use the mode which is not requesting user input unless necessary. The window is not displayed.
0 (default) - the window will always be displayed.
1 - The window will be displayed only if there are at least two possible options.
If only a single option is available, then it is selected automatically and the method returns value of the String type (selected option identifier).
If there is no option available then the method returns: null for JavaScript or Empty pro VBScript (it can be tested by the Pm.IsValid method).
grid[optional] (Long) Specifies whether the cells of displayed table will have borders.
0 (default) - have no borders.
1 - have borders.
title[optional] (String) Window header, if the window is displayed including header (for target:_blank;)
onChange[optional] (Function) The event function for managing the event of viewer modification.

For JavaScript the object function is entered.

For VBScript the object PmAction is entered.

The function has a single parameter ev containing information regarding the corresponding event.

ev.value - (String) Currently selected option (Identifier).
onClose[optional] (Function) The event function for managing the event of viewer closing.

For JavaScript the object function is entered.

For VBScript the object PmAction is entered.

The function has a single parameter ev containing information regarding the corresponding event.

ev.CloseReason - (String) Identifier of the window closing type. The value "ok" represents a valid selection. The values "cancel" or "" represent cancelled selection.
ev.ReturnValue - (String) Final selected option (Identifier).
The viewer parameters are in the form of the PmMap object that is filled from value of the sView parameter (of the KeyVal type) in the Pm.CreateView method.

By filling from the KeyVal value all the parameters are initially stored as string. The content of the PmMap object can be then modified as needed - the items can be modified, added and deleted.

The PmMap object can also contain other embedded PmMap objects (Submap). The PmMap.mapSetSubmapAt method can be used in order to create a new PmMap or make one accessible.

Example1:
Selection from an array of values
JavaScriptSelect and copy to clipboard

var arr = Pm.CreatePmArray().Create(2,3);
arr.SetItem("id1", 0, 0);
arr.SetItem("Test 1", 1, 0);
arr.SetItem("id2", 0, 1);
arr.SetItem("Test 2", 1, 1);
arr.SetItem("id3", 0, 2);
arr.SetItem("Test 3", 1, 2);

function onViewClose(ev)
{
if (ev.CloseReason == "ok")
{
switch (ev.ReturnValue)
{
case "id1":
Pm.Debug("Run test 1");
break;
case "id2":
Pm.Debug("Run test 2");
break;
case "id3":
Pm.Debug("Run test 3");
break;
}
}
}

var oCreator = Pm.CreateView(pMe.PmPanel, "/#glob/list", "autoselect:0;grid:1;title:Selection;", "target:_blank;modal:1;pos:view," + pMe.ViewX + "," + pMe.ViewY + ";");
oCreator.View.list = arr;
oCreator.View.initValue = "id2";
oCreator.View.onClose = onViewClose;
oCreator.Open();
Example2:
Selection from a list of panels. (Based on the selection, the method returns FindViewers)
JavaScriptSelect and copy to clipboard

function onViewClose(ev)
{
if (ev.CloseReason == "ok")
{
var sViewer = ev.ReturnValue;
if (Pm.IsValid(sViewer))
Pm.CreateView(pMe, sViewer, "", "target:main;").Open();
}
}

var aList = Pm.FindViewers("groups:menu;viewers:panel;","", "columns:path,title;");
var oCreator = Pm.CreateView(pMe.PmPanel, "/#glob/list", "autoselect:0;grid:1;title:Selection;", "target:_blank;modal:1;pos:view," + pMe.ViewX + "," + pMe.ViewY + ";");
oCreator.View.list = aList;
oCreator.View.onClose = onViewClose;
oCreator.Open();

History:
Pm9.00.09: Created
PROMOTIC 9.0.9 SCADA system documentation - MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice