How to work with modal windows

This chapter describes the creation and usage of modal windows in the PROMOTIC system.
Modal window is a window that blocks access and control of all other application windows while open so the user can interact only with this window. After the modal window is closed the control is returned back to the window from which the modal window was opened.

The modal window is usually used for data entry (editing). The user is entering the entries and before the proces is completed the user is prevented from "leaving the window".

While the modal window is open, access the rest of the application is blocked, therefore it is necessary to think well before using such window. It is recommended to use such window only for simple data entry so it is not open for a long time.


How to create modal window

Asuming there is a graphic panel (PmPanel object), that contains one edit item PmiWCombo, PmiWCheck and PmiWEdit and two control buttons PmiButton (OK and Cancel).
1) In the onPanelStartEnd event of the PmiRoot object it is possible to read the Arguments property and display it in the editing graphic items:
Example for JavaScript language:
var aArgm = pMe.Arguments;
pMe.Items("/WCombo").SelectedIndex = aArg.GetItem(0);
pMe.Items("/WCheck").Value = aArg.GetItem(1);
pMe.Items("/WEdit").Value = aArg.GetItem(2);
Example for VBScript language:
Dim aArgm
aArgm = pMe.Arguments
pMe.Items("/WCombo").SelectedIndex = aArg(0)
pMe.Items("/WCheck").Value = aArg(1)
pMe.Items("/WEdit").Value = aArg(2)

2) In the onButtonUp event of the OK button close the window with "ok" attribute.
Example for JavaScript language:
Example for VBScript language:

3) In the onButtonUp event of the Cancel button close the window with no attribute.
Example for JavaScript language:
Example for VBScript language:

4) In the onPanelStopEnd event of the PmiRoot object it is possible to use the ReturnValue property in order to send back the value read from the editing graphic items.
Example for JavaScript language:
if (pEvent.Reason == "ok")
   var v1 = pMe.Items("/WCombo").SelectedIndex;
   var v2 = pMe.Items("/WCheck").Value;
   var v3 = pMe.Items("/WEdit").Value;
   var aVal = Pm.CreatePmArray().Create(3);
   aVal.SetItem(v1, 0);
   aVal.SetItem(v2 = v2 ? -1 : 0, 1);
   aVal.SetItem(v3, 2);
   pMe.ReturnValue = aVal;
Example for VBScript language:
If pEvent.Reason = "ok" Then
   Dim aVal(2), val1
   aVal(0) = pMe.Items("/WCombo").SelectedIndex
   val1 = pMe.Items("/WCheck").Value
   If val1 Then
     val1 = -1
     val1 = 0
   End If
   aVal(1) = val1
   aVal(2) = pMe.Items("/WEdit").Value
   pMe.ReturnValue = aVal

How to open modal window and process the entered values once it is closed

Asuming there is a button (PmiButton) in the parent panel that opens the modal window. The example below describes the recommended way of using the PmMap and PmAction objects in order to receive the value from modal window.

Create the oExtra variable representing the PmMap type object and then:

- enter the input value of the modal window into the oExtra.Arguments property.
- enter an action that calls the user method "ClosePanel" (when the window is closed) into the oExtra.onClose property.

Then the modal window is opened. Once the window is closed its value is processed in the "ClosePanel" method.

1) Script in the onButtonUp event of the button:
Example for JavaScript language:
arr.SetItem(2, 0);
arr.SetItem(-1, 1);
arr.SetItem("Promotic", 2);
var oExtra = Pm.CreatePmMap();
oExtra.onClose = Pm.CreatePmAction(1, pMe, "ClosePanel");
pMe.PmPanel.OpenView("/ModalDlg", "target:_blank;modal:1;", "", oExtra);
Example for VBScript language:
Dim oExtra, val0, val1, val2
val0 = 2
val1 = true
val2 = "Promotic"
Set oExtra = Pm.CreatePmMap()
oExtra.mapSetValueAt "Arguments", Array(val0,val1,val2)
oExtra.mapSetValueAt "onClose", Pm.CreatePmAction(1, pMe, "ClosePanel")
pMe.PmPanel.OpenView "/ModalDlg", "target:_blank;modal:1;", "", oExtra

2) In the button on the Methods page it is necessary to create a user method "ClosePanel" with parameters oSystem and oPrivate. The method script content is:
Example for JavaScript language:
var aVal = oSystem.ReturnValue;
  var val0 = aVal.GetItem(0);
  var val1 = aVal.GetItem(1);
  var val2 = aVal.GetItem(2);
  Pm.Debug("val0=" + val0 + ", val1=" + val1 + ", val2=" + val2);
Example for VBScript language:
Dim aVal
aVal = oSystem.ReturnValue
If Pm.IsValid(aVal) Then
  Dim val0, val1, val2
  val0 = aVal(0)
  val1 = aVal(1)
  val2 = aVal(2)
  Pm.Debug "val0=" & val0 & ", val1=" & val1 & ", val2=" & val2
End If

Obsolete and therefore not recommended approach of modal window opening by the OpenViewModal method. If this method is used then the modal window is opened synchronously and therefore the script waits until the window is closed by the user. If the window is enabled as Web component then problems may occure since some Web browsers do not support such approach (Chrome, Opera).

PROMOTIC 8.3.20 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