Promotic

Przykład: Wytworzy okno PmForm ustawione do wprowadzania czasu (od/do)

W jednym skrypcie (np. po naciśnięciu przycisku w zdarzeniu onButtonUp) zostanie wytworzone okno do ustawienia daty i czasu. Wstępnie ustawiony czas można ustawić w skrypcie za komentarzem "Initial Time". Wartość czasu opracowywuje funkcja "onViewClose".
JavaScriptWybierz oraz skopiuj do schowka

//#pragma variable sTxtFrom=Macro("$.text('sys','from')");
//#pragma variable sTxtTo=Macro("$.text('sys','to')");
//#pragma variable sTxtDate=Macro("$.text('sys','date')");
//#pragma variable sTxtTime=Macro("$.text('sys','time')");
//#pragma variable sTxtSec=Macro("$.text('sys','second')");
//#pragma variable sTxtMin=Macro("$.text('sys','minute')");
//#pragma variable sTxtHour=Macro("$.text('sys','hour')");
//#pragma variable sTxtDay=Macro("$.text('sys','day')");
//#pragma variable sTxtMonth=Macro("$.text('sys','month')");
//#pragma variable sTxtYear=Macro("$.text('sys','year')");
var oFrom, oTo, oYear, oMonth, oDay, oHour, oMinut, oSec, oActF, oActT;
function onViewLoad(ev)
{
// Initial Time
var InitTime = Pm.CreatePmDateObject(Pm.Time - 2/24);
InitTime.SetHour(InitTime.GetHour(), 0, 0, 0);
var InitTime2 = Pm.CreatePmDateObject();
// *******************************

var oForm = ev.Form;
oForm.Title = sTxtFrom + " - " + sTxtTo + " (" + sTxtDate + "/" + sTxtTime + ")";

// From - text + check
var oLay0 = oForm.CreateItem("layout", "iF", null, "Subtype:horz;");
oFrom = oLay0.CreateItem("string", "Dt", sTxtFrom, "BodyWidthIni:10;BodyWidthMode:const;ValueHorzAlign:right;");
oFrom.Value = InitTime.Format("%Y.%m.%d %H:%M:%S");
oFrom.AddEvent("onEditAccept", "ChangeFrom", onChangeDt);
oActF = oLay0.CreateItem("bool", "id_boolF", null, "TitlePos:right;");
oActF.AddEvent("onEditAccept", "ChangeActF", onChangeActF);
oActF.Value = 1;

// To - text + check
var oLay1 = oForm.CreateItem("layout", "iT", null, "Subtype:horz;");
oTo = oLay1.CreateItem("string", "Dt2", sTxtTo, "BodyWidthIni:10;BodyWidthMode:const;ValueHorzAlign:right;");
oTo.Value = InitTime2.Format("%Y.%m.%d %H:%M:%S");
oTo.AddEvent("onEditAccept", "ChangeTo", onChangeDt);
oActT = oLay1.CreateItem("bool", "id_boolT", null, "TitlePos:right;");
oActT.AddEvent("onEditAccept", "ChangeActT", onChangeActT);

oForm.CreateItem("separ", "", null, "Subtype:line;");

// TitleDate
var oLay2 = oForm.CreateItem("layout", "iTDate", null, "Subtype:horz;");
var oIt = oLay2.CreateItem("string", "s1", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtYear + ";");
oIt = oLay2.CreateItem("string", "s2", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtMonth + ";");
oIt = oLay2.CreateItem("string", "s3", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtDay + ";");

// Date
var oLay3 = oForm.CreateItem("layout", "iFr", null, "Subtype:horz;");
oYear = oLay3.CreateItem("number", "yearF", null, "BodyWidthIni:5;");
oYear.AddEvent("onEditAccept", "ChangeYear", onChange);
oMonth = oLay3.CreateItem("number", "monthF", null, "BodyWidthIni:5;Min:1;Max:12;");
oMonth.AddEvent("onEditAccept", "ChangeMonth", onChangeMonth);
oDay = oLay3.CreateItem("number", "dayF", null, "BodyWidthIni:5;Min:1;Max:31;");
oDay.AddEvent("onEditAccept", "ChangeDay", onChange);

// TitleTime
var oLay4 = oForm.CreateItem("layout", "iTTime", null, "Subtype:horz;");
oIt = oLay4.CreateItem("string", "s4", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtHour + ";");
oIt = oLay4.CreateItem("string", "s5", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtMin + ";");
oIt = oLay4.CreateItem("string", "s6", "", "Subtype:static;BodyWidthIni:5;TitlePos:no;Value:" + sTxtSec + ";");

// Time
var oLay5 = oForm.CreateItem("layout", "iFr2", null, "Subtype:horz;");
oHour = oLay5.CreateItem("number", "hourF", null, "BodyWidthIni:5;Min:0;Max:23;");
oHour.AddEvent("onEditAccept", "ChangeHour", onChange);
oMinut = oLay5.CreateItem("number", "minF", null, "BodyWidthIni:5;Min:0;Max:59;");
oMinut.AddEvent("onEditAccept", "ChangeMinute", onChange);
oSec = oLay5.CreateItem("number", "secF", null, "BodyWidthIni:5;Min:0;Max:59;");
oSec.AddEvent("onEditAccept", "ChangeSec", onChange);

onChangeDt();
onChangeMonth();
}


function onChangeActF(ev)
{
oActT.Value = ! oActF.Value;
onChangeDt(ev);
}

function onChangeActT(ev)
{
oActF.Value = ! oActT.Value;
onChangeDt(ev);
}

function onChangeMonth(ev)
{
var nMonth = oMonth.Value;
switch (nMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
oDay.Max = 31;
break;
case 2:
oDay.Max = 29;
break;
case 4:
case 6:
case 9:
case 11:
oDay.Max = 30;
break;
}
onChange();
}

function onChange(ev)
{
var tDateTime = Pm.CreateDate(oYear.Value, oMonth.Value, oDay.Value, oHour.Value, oMinut.Value, oSec.Value, 0);
var sDateTime = Pm.CreatePmDateObject(tDateTime).Format("%Y.%m.%d %H:%M:%S");
if (oActF.Value)
{
oFrom.Value = sDateTime;
}
else
{
oTo.Value = sDateTime;
}
}

function onChangeDt(ev)
{
if (oActF.Value)
{
var nTime = Pm.ScanDate(oFrom.Value, 1);
}
else
{
var nTime = Pm.ScanDate(oTo.Value, 1);
}
var oTime = Pm.CreatePmDateObject(nTime);
oYear.Value = oTime.GetYear();
oMonth.Value = oTime.GetMonth();
oDay.Value = oTime.GetDay();
oHour.Value = oTime.GetHour();
oMinut.Value = oTime.GetMinute();
oSec.Value = oTime.GetSecond();
}

function onViewClose(ev)
{
if (ev.CloseReason == "ok")
{
var tTimeF = Pm.ScanDate(oFrom.Value, 1);
var tTimeT = Pm.ScanDate(oTo.Value, 1);
// return values
}
}

// Wytworzy PmViewCreator - Obiekt umożliwia otwarcie różnego rodzaju przeglądarek
var oCreator = Pm.CreateView(null, "/#glob/form", "", "target:_blank;modal:1;");
oCreator.View.onLoad = onViewLoad;
oCreator.View.onClose = onViewClose;

// Otworzy formularz w oknie modalnym:
oCreator.Open();
© MICROSYS, spol. s r.o.