Promotic
WikipediaLinkedInYoutubeTwitterFacebook

Example: Creates a PmForm window configured as multi-select from a list of items

In a single script (e.g. after pressing the button in the onButtonUp event). At the beginning there are variables that define the titles of the window and tables. Then the aList variable that represents a list of items to be selected from. Each item has a value and a text to be displayed (emulated in the example). Tre is also the aSelect variable that can be used to define which items will be preselected. The onViewClose function then defines fow the selected list of items is processed.
JavaScriptSelect and copy to clipboard

//****** Setting values ********
var sTitle = "Select n items from the list";
var sTitleL = "List of items";
var sTitleR = "Selected items";
var nTabColWidth = 18;
var oTableL, oTableR, oRowL, oRowR, i, j, e, oArea11L, oArea12L, oBtnToRight, oBtnToLeft, oArea11R, oArea12R;

//aList = PmArray a two-dimensional field, where 1 column represents the identifier and the second text for display
var aList = Pm.CreatePmArray().Create(16, 2);
for (i = 0; i < aList.GetSize(1); i++)
{
aList.SetItem("id" + i, i, 0);
aList.SetItem("text" + i, i, 1);
}

//aSelect = one-dimensional array of preselected identifiers
var aSelect = Pm.CreatePmArray().Array1("id2", "id7");

//close the form with the OK button
function onViewClose(ev)
{
if (ev.CloseReason == "ok")  //****** END Setting parameters ********
{
var nRows = oArea11R.RowCount;
var aSel = Pm.CreatePmArray().Create(nRows);
for (i = 0; i < nRows; i++)
aSel.SetItem(oArea11R.GetRow(i).PrivateData, i);

//RETURN Array ID selected
Pm.Debug(aSel, 1);
}
}
//****** END Setting parameters ********


//******* LOAD FORM ***********************
var nBodyRowL = aList.GetSize(1);
var nBodyRowR = aSelect.GetSize(1);
nBodyRowL = nBodyRowL - nBodyRowR;

function onViewLoad(ev)
{
var oForm = ev.Form;
oForm.Title = sTitle;
oForm.BgColor = "#c0dcc0";

var oLay = oForm.CreateItem("layout", "Lay", null, "Subtype:horz;BodyHeightMode:resize;BodyWidthMode:resize;");

//XXXXXXXXXX init LEFT table XXXXXXXXXXXXXXXXXXX
oTableL = oLay.CreateItem("table", "id_tableL", null, "BodyHeightMode:resize;BodyWidthMode:resize;");
oTableL.InitRows(nBodyRowL, 1, 0);
oTableL.InitCols(1, 0);
oTableL.SetColWidth(nTabColWidth, 1, -1);  //Table Column width
oTableL.SetSel(0, 0);  //Table Set active row

oArea12L = oTableL.GetArea(12);  //TableArea 12=MainHead
oArea12L.BgColor = "#c0dcc0";
oArea12L.GetRow(0).GetCell(0).Value = sTitleL;

oArea11L = oTableL.GetArea(11);  //TableArea 11=MainBody
oArea11L.BgColor = "#ffffff";
oArea11L.HorzAlign = "left";

// XXXXXXXXXX CENTER buttons XXXXXXXXXXX
var oLayC = oLay.CreateItem("layout", "LayC", null, "Subtype:vert;");  //layer for center buttons
oBtnToRight = oLayC.CreateItem("button", "id_butt_add");
oBtnToRight.Value = ">>";
oBtnToRight.AddEvent("onAction", onRight);

oBtnToLeft = oLayC.CreateItem("button", "id_butt_clear");
oBtnToLeft.Value = "<<";
oBtnToLeft.AddEvent("onAction", onLeft);

// XXXXXXXXXX init RIGHT table XXXXXXXXXXXXXX
oTableR = oLay.CreateItem("table", "id_tableR", null, "BodyHeightMode:resize;BodyWidthMode:resize;");
oTableR.InitRows(0, 1, 0);
oTableR.InitCols(1, 0);
oTableR.SetColWidth(nTabColWidth, 1, -1);  //Table Column width
oTableR.SetSel(0, 0);  //Table Set active row

oArea12R = oTableR.GetArea(12);  //TableArea 12=MainHead
oArea12R.BgColor = "#c0dcc0";
oArea12R.GetRow(0).GetCell(0).Value = sTitleL;

oArea11R = oTableR.GetArea(11);  //TableArea 11=MainBody
oArea11R.BgColor = "#ffffff";
oArea11R.HorzAlign = "left";

onFillData();
}

function onFillData(ev)
{
e = 0;
nBodyRowR = aSelect.GetSize(1);
oTableR.DeleteRow(1, 0, -1);
for (i = 0; i < aList.GetSize(1); i++)
{
var bSel = 0;
for (j = 0; j < nBodyRowR; j++)
{
if (aList.GetItem(i, 0) == aSelect.GetItem(j))
bSel = 1;
}
if (!bSel)
{
oRowL = oArea11L.GetRow(e);
oRowL.GetCell(0).Value = aList.GetItem(i, 1);
oRowL.PrivateData = aList.GetItem(i, 0);
e++;
}
else
{
oTableR.InsertRow(1, -1);
oRowR = oArea11R.GetRow(-1);
oRowR.GetCell(0).Value = aList.GetItem(i, 1);
oRowR.PrivateData = aList.GetItem(i, 0);
}
}
}

//move the highlighted left item to the right
function onRight(ev)
{
var oRow = oTableL.GetSel(0);
if (oRow != null)
{
oRowL = oArea11L.GetRow(oRow.Row);
aSelect.Insert(-2, oRowL.PrivateData);
oTableL.DeleteRow(1, -1);
onFillData();
}
}

//move the highlighted right item to the left
function onLeft(ev)
{
var oRow = oTableR.GetSel(0);
if (oRow != null)
{
oRowR = oArea11R.GetRow(oRow.Row);
for (i = 0; i < aSelect.GetSize(1); i++)
{
if (oRowR.PrivateData == aSelect.GetItem(i))
{
aSelect.Remove(i, 1);
break;
}
}
oTableL.InsertRow(1, -1);
onFillData();
}
}

//Creates PmViewCreator - This object allows opening the various viewers
var oCreator = Pm.CreateView(pMe.PmPanel, "/#glob/form", "", "target:_blank;modal:1;pos:view," + pMe.ViewX + "," + pMe.ViewY + ";size:640,350;");
oCreator.View.onLoad = onViewLoad;
oCreator.View.onClose = onViewClose;

//Opens form in modal window:
oCreator.Open();
PROMOTIC 9.0.13 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