Promotic
WikipediaLinkedInYoutubeTwitterFacebook

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:
 
JavaScriptVBScriptSelect and copy to clipboard

var aArgm = pMe.Arguments;
pMe.Items("/WCombo").SelectedIndex = aArgm.GetItem(0);
pMe.Items("/WCheck").Value = aArgm.GetItem(1);
pMe.Items("/WEdit").Value = aArgm.GetItem(2);

2) In the onButtonUp event of the OK button close the window with "ok" attribute.
 
JavaScriptVBScriptSelect and copy to clipboard

pMe.Root.Close("ok");

3) In the onButtonUp event of the Cancel button close the window with no attribute.
 
JavaScriptVBScriptSelect and copy to clipboard

pMe.Root.Close("");

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.
 
JavaScriptVBScriptSelect and copy to clipboard

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;
}
 

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 call the designer's 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:
 
JavaScriptVBScriptSelect and copy to clipboard

var arr = Pm.CreatePmArray().Create(3);
arr.SetItem(2, 0);
arr.SetItem(-1, 1);
arr.SetItem("Promotic", 2);

var oExtra = Pm.CreatePmMap();
oExtra.Arguments = arr;
oExtra.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 method "ClosePanel" with parameters oSystem and oPrivate. The method script content is:
 
JavaScriptVBScriptSelect and copy to clipboard

var aVal = oSystem.ReturnValue;
if (Pm.IsValid(aVal))
{
  var val0 = aVal.GetItem(0);
  var val1 = aVal.GetItem(1);
  var val2 = aVal.GetItem(2);
  Pm.Debug("val0=" + val0 + ", val1=" + val1 + ", val2=" + val2);
}
 
Note

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.22 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