Promotic
Login logon

Opening the viewer for file/folder selection (/#glob/filepath)

The window for selecting the file/folder is opened by the Pm.CreateView method. In the sViewPath parameter the global path "/#glob/filepath" is entered.
This viewer is not functional in Web panels.
Syntax:
JavaScriptVBScriptSelect and copy to clipboard

var oCreator = Pm.CreateView(oFrom, "/#glob/filepath", sViewPars, sFramePars);
oCreator.Open();
Parameters of the Pm.CreateView method:
oFrom(Object) The object, which will mediate the opening of the viewer.
The object specifies the origin of the path, the relative position of the window, the parent, etc.
- The null value means the usage of:
- the PmaPanel object if CreateView method is called in the script of the Pmg object.
- active PmaWorkspace, if CreateView method is called in the script of the Pma object.
- If the the PmgFrame object is entered here (in the script of the Pmg object), then the viewer opens in this frame.
- If the the PmaPanel object is entered here (in the script of the Pma object), then the viewer opens in this selected object.

See the PmViewCreator.From property.
sViewPars(String) Viewer parameters (they differ for various viewer types).
See the PmViewCreator.View property.
Entries are in the KeyVal format. For example "title:App files;initValue:#app:MyApp.log;mode:1;hide:1;defaultExt:ini;".

Properties and events in the PmViewCreator.View object:
initValue[optional] (String) Initial selection of file/folder, preferably as PROMOTIC path to files or folders.
mode[optional] (Long) (Long) Selection mode. Specifies whether the result is a path to the file or to folder.
1 (default) - File selection.
2 - Folder selection.
roots[optional] (PmMap) A list of selection origins (root) (logic folders, physical discs, …) in the form of embedded map (Submap). In order to easily create/set an embedded map (Submap) in another map's item the PmMap.mapSetSubmapAt method can be used. This method ensures creation of the submap in the item and can add multiple items from a string in the KeyVal format.
 
Each selection origin (root) is constituted by a pair of values: description (titleN) and value (valueN), where N is the index (zero-based index). The titles (titleN) are optional. For example in the original KeyVal notation before transfering into the PmMap object, the entry could look as follows: "title0:Boiler1;value0:#data:Boiler1/;title1:Boiler2;value1:#data:Boiler2/;"
If not set, then there will be only a single selection origin defined by initValue.
 
The allowed values (valueN) of selection origins (root) are:
#xx - Origins of PROMOTIC paths, e.g. "value0:#pmres;value1:#appres;"
#xx:yy/zz - PROMOTIC paths including the subfolders, e.g. "value0:#pmres:Img/;value1:#appres:Img/;"
disk: - Devices as drive letters, e.g. "value0:c:;value1:d:;"
disk:yy/zz - Paths as drive letters including subfolders, e.g. "value0:c:\Temp\;value0:d:\Data\;"
$disks - All mapped physical drive devices (drive letters) are added automatically, e.g. "value0:$disks;"
hide[optional] (Long) Allows to set what is to be hidden.
0 (default) - Show all.
1 - Hide subfolders.
2 - Hide files.
existence[optional] (Long) Allows to set whether the selected file/folder (non)existence is tested.
0 (default) - Not tested.
1 - Confirmation if the selected file/folder already exists.
10 - The selected file/folder must exist.
11 - The selected file/folder must not exist.
defaultExt[optional] (String) Default new file extension if if not defined otherwise. For example "csv".
filter[optional] (PmMap) A list of displayed file filters in the form of embedded map (Submap). In order to easily create/set an embedded map (Submap) in another map's item the PmMap.mapSetSubmapAt method can be used. This method ensures creation of the submap in the item and can add multiple items from a string in the KeyVal format.
 
Each filter is constituted by a pair of values: description (titleN) and value (valueN), where N is the index (zero-based index). The titles (titleN) are optional. For example in the original KeyVal notation before transfering into the PmMap object, the entry could look as follows: "title0:Images;value0:*.jpg,*.png,*.bmp;title1:All files;value1:*.*;"
 
If not set, then there will only be a single filter in the selection for all files.
title[optional] (String) Window header, if the window with header is displayed (for target:_blank;)
onChange[optional] (Function) The event function for managing the event of viewer modification.
For JavaScript the function is entered.
For VBScript the PmAction object is entered.
 
The function has a single parameter ev containing information regarding the corresponding event.
ev.value - (String) Currently selected path to the file/folder.
onClose[optional] (Function) The event function for managing the event of viewer closing.
For JavaScript the function is entered.
For VBScript the PmAction object 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" means a valid selection.
The value "cancel" or "" represent cancelled selection.
ev.ReturnValue - (String) Resulting selected file/folder.
sFramePars(String) Parameters for the frame where the viewer will be displayed.
See the PmViewCreator.Frame property.
Entries are in the KeyVal format, for example "target:_blank;".
The viewer parameters are in the form of the PmMap object that is filled from value of the sViewPars 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 - 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 of file that is located only in the application folder (only ini, log or all files)
JavaScriptSelect and copy to clipboard

var oCreator = Pm.CreateView(null, "/#glob/filepath", "title:App files;initValue:#app:MyApp.log;mode:1;hide:1;defaultExt:ini;", "target:_blank;modal:1;");
var oView = oCreator.View;
oView.mapSetSubmapAt("filter", "", "title0:Setting log;value0:*.ini,*.log;title1:All files;value1:*.*;");
oView.onClose = function(ev)
{
Pm.Debug("onClose ReturnValue=" + ev.ReturnValue);
};
oCreator.Open();
Example2:
Selection of the path to the folder located in this application (#app:). The return value is then processed in the function onClose.
JavaScriptSelect and copy to clipboard

function onClose(ev)
{
if (ev.CloseReason == "ok")
{
Pm.Debug("onClose ReturnValue=" + ev.ReturnValue);
}
}

var oCreator = Pm.CreateView(null, "/#glob/filepath", "title:PmAppFiles,initValue:#app:;mode:2;", "target:_blank;modal:1;");
oCreator.View.onClose = onClose;
oCreator.Open();
Example3:
Saving the text into a new or selected txt file in the Data folder (#data:). The return value is then processed in function onClose.
While processing, it is supposed that there is a designer "SaveFile" method present in the panel, that receives the parameters and use the FileTextWrite method to save the file and sends back the saving result.
JavaScriptSelect and copy to clipboard

function onClose(ev)
{
if (ev.CloseReason == "ok")
{
var sFilePath = ev.ReturnValue;
if (sFilePath != "")
{
var sText = "Hello world!";
var bDone = pMe.PmPanel.Methods.SaveFile(sFilePath, sText);
Pm.Debug("Save text to file=" + sFilePath + " is " + bDone);
}
}
}

var oCreator = Pm.CreateView(null, "/#glob/filepath", "title:Create File;initValue:#data:;mode:1;defaultExt:txt;", "target:_blank;modal:1;");
oCreator.View.onClose = onClose;
oCreator.Open();

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

Send page remark Contact responsible person
© MICROSYS, spol. s r.o.Update cookies preferences