Promotic

Příklad: V objektu PmgForm vytvoří strom

Příklad na vytvoření stromu ve skriptu události onFormLoad objektu PmgForm.
JavaScriptVyber a zkopíruj do schránky

// ------------ FORM ---------------------------
var oForm = pMe.Form;
// ----------- Buttons -----------------
oForm.SysLayoutPos = "bottom";
var oButtLay = oForm.GetItem("$sys", 1);
// button add
var oButt = oButtLay.CreateItem("button", "buttAdd");
oButt.Value = "Add";
oButt.AddEvent("onAction", "butAdd", AddItem);
// button remove
var oButt = oButtLay.CreateItem("button", "buttRemove");
oButt.Value = "Remove";
oButt.AddEvent("onAction", "butRemove", RemoveItem);
// button colapse
var oButt = oButtLay.CreateItem("button", "buttColapse");
oButt.Value = "Colapse";
oButt.AddEvent("onAction", "butColapse", ColapseItems);

// ----------- Tree -------------------
var oTree = oForm.CreateItem("tree", "Tree", null, "");

// tree settings
oTree.BgColor = "#fafafa";
oTree.TextColor = "#0000ff";
oTree.TreeRootVisible = 1;
oTree.BodyFont = "normal normal 700 13px 'Microsoft Sans Serif'";

// tree root
var oRoot = oTree.TreeRoot;
oRoot.Title = "Root";
// oRoot.SetExpanded(1, 1);

// tree items
var oItemA = oRoot.CreateItem("itemA");
var oItemB = oRoot.CreateItem("itemB");
var oItemA1 = oItemA.CreateItem("oItemA1");
var oItemA2 = oItemA.CreateItem("oItemA2");
oItemA2.TextColor = "#ff00ff";

// ---------- Functions ----------
function AddItem(ev)
{
if (ev.Action == "main")
{
var oItem = oRoot.GetSel(0);
if (Pm.IsValid(oItem))
{
var oCreator2 = Pm.CreateView(null, "/#glob/form", "", "target:_blank;pos:top,center;modal:1;");
oCreator2.View.onLoad = function(evLoad)
{
var oFormDlg = evLoad.Form;
oFormDlg.Title = "Create item";
var oStrId = oFormDlg.CreateItem("string", "txtid", "id", "BodyWidthIni:25;");
oStrId.Value = "itemC";
var oStrTitle = oFormDlg.CreateItem("string", "txttitle", "Title", "BodyWidthIni:25;");
oStrTitle.Value = "title";
var oStrProps = oFormDlg.CreateItem("string", "txtprops", "Property", "BodyWidthIni:25;");
oStrProps.Value = "TextColor:#0000ff;";
oFormDlg.AddEvent("onClose", "formclose", function(evClose) { if (evClose.CloseReason == "ok") { oItem.CreateItem(oStrId.Value, oStrTitle.Value, oStrProps.Value, "pos:last;"); } });
};
oCreator2.Open();
}
}
}

function RemoveItem(ev)
{
if (ev.Action == "main")
{
var oItem = oRoot.GetSel(0);
if (Pm.IsValid(oItem))
{
oItem.RemoveItem(0);
}
}
}

function ColapseItems(ev)
{
if (ev.Action == "main")
{
oRoot.SetExpanded(0, 1);
}
}
© MICROSYS, spol. s r.o.