PDA

View Full Version : [CLOSED] bulid TreePanel dynamic, ItemClick is not work?



gs_user
Aug 13, 2013, 2:19 AM
when i bulid TreePanel in dynamic
itemclick is not work, why?

chang another road..
how to add Listeners in dynamic?
Is TreePanel1.AddListener("ItemClick", "addTab(#{tpMain}, record)");
it is not work..?




<%@ Page Language="C#" Inherits="BasePage" %>

<%@ Import Namespace="Ext.Net.Utilities" %>
<%@ Import Namespace="System.Data"%>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack && !X.IsAjaxRequest)
{
this.BuildTree(TreePanel1.Root);
//TreePanel1.AddListener("ItemClick", "addTab(#{tpMain}, record)");
}

foreach (Portlet portlet in ControlUtils.FindControls<Portlet>(this.Page))
{
portlet.DirectEvents.Hide.Event += Portlet_Hide;
portlet.DirectEvents.Hide.EventMask.ShowMask = true;
portlet.DirectEvents.Hide.EventMask.Msg = "Saving...";
portlet.DirectEvents.Hide.EventMask.MinDelay = 500;

portlet.DirectEvents.Hide.ExtraParams.Add(new Ext.Net.Parameter("ID", portlet.ClientID));
}
}

private Ext.Net.NodeCollection BuildTree(Ext.Net.NodeCollection nodes)
{
if (nodes == null)
{
nodes = new Ext.Net.NodeCollection();
}

Ext.Net.Node root = new Ext.Net.Node();
root.Text = "Root";
root.Expanded = true;
nodes.Add(root);

Ext.Net.Node node1 = new Ext.Net.Node();
node1.Text = "基本資料維護";
node1.Icon = Icon.Database;
node1.Expanded = true;
root.Children.Add(node1);


node1.Children.Add(
new Ext.Net.Node() {
Text = "結算週期維護",
Icon = Icon.Database,
Expanded=true,
NodeID = "SettleParam.aspx?page=SettleParam.aspx"
}
);

node1.Children.Add(
new Ext.Net.Node()
{
Text = "基本參數設定",
Icon = Icon.Database,
Expanded = true,
NodeID = "Basic.aspx?page=Basic.aspx"
}
);

node1.Children.Add(
new Ext.Net.Node()
{
Text = "班別資料維護",
Icon = Icon.Database,
Expanded = true,
NodeID = "Shift.aspx?page=Shift.aspx"
}
);

node1.Children.Add(
new Ext.Net.Node()
{
Text = "卡鐘轉入參數設定",
Icon = Icon.Database,
Expanded = true,
NodeID = "TranParam.aspx?page=TranParam.aspx"
}
);

node1.Children.Add(
new Ext.Net.Node()
{
Text = "假別代碼維護",
Icon = Icon.Database,
Expanded = true,
NodeID = "LeaveCode.aspx?page=LeaveCode.aspx"
}
);

node1.Children.Add(
new Ext.Net.Node()
{
Text = "例假日&加班倍率維護",
Icon = Icon.Database,
Expanded = true,
NodeID = "Holiday.aspx?page=Holiday.aspx"
}
);

node1.Children.Add(
new Ext.Net.Node()
{
Text = "例假日&個人班別維護",
Icon = Icon.Database,
Expanded = true,
NodeID = "p_shift.aspx?page=p_shift.aspx"
}
);



Ext.Net.Node node2 = new Ext.Net.Node();
node2.Text = "日常維護";
node2.Icon = Icon.ApplicationEdit;
node2.Expanded = true;
root.Children.Add(node2);

Ext.Net.Node node3 = new Ext.Net.Node();
node3.Text = "查詢作業";
node3.Icon = Icon.Report;
node3.Expanded = true;
root.Children.Add(node3);


return nodes;
}



protected void Portlet_Hide(object sender, DirectEventArgs e)
{
X.Msg.Alert("Status", e.ExtraParams["ID"] + " Hidden").Show();
}

protected void btLogout_Click(object sender, DirectEventArgs e)
{
Session["gen01"] = "";
Session["lang"] = "";
Response.Cookies["Attendance"]["gen01"] = "";
Response.Cookies["Attendance"]["lang"] = "";
Response.Cookies["Attendance"].Expires = DateTime.Now.AddDays(-1);
UdfEpm.langData = null;
Response.Redirect("Default.aspx");
}

[DirectMethod]
public void ckDelete(string s1)
{
Response.Cookies["page"][s1] = "";
Response.Cookies["page"].Expires = DateTime.Now.AddDays(-1);
}
</script>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">

var addTab = function (tabPanel, record) {
if (record.isLeaf()) {
var tab = tabPanel.getComponent(record.getId());
if (!tab) {
tab = tabPanel.add({
id: record.getId(),
title: record.get('text'),
closable: true,
loader: {
url: record.getId(),
renderer: "frame",
loadMask: {
showMask: true,
msg: "Loading " + record.get('text') + "..."
},
}
});
tab.on("close", function () {
var url = record.getId();
var filename = url.substring(url.lastIndexOf('/')+1,url.lastIndexOf('.aspx')+5);
App.direct.ckDelete(filename);
}, this);
}
tabPanel.setActiveTab(tab);
}
}

// var reLogin = function(){
// document.location.href="Default.aspx";
// }


var addSendTab = function (tabPanel) {
var tab = tabPanel.getComponent('inbox');
if (!tab) {
tab = tabPanel.add({
id: "inbox",
title: "inbox",
closable: true,
loader: {
url: "inbox.aspx",
renderer: "frame",
loadMask: {
showMask: true,
msg: "Loading inbox..."
},
}
});
}
tabPanel.setActiveTab(tab);
// tab.load('inbox.aspx');
}



</script>
<style>
.x-column-padding{
padding : 10px 0px 10px 10px;
}

.x-column-padding1{
padding : 10px;
}
.test2
{
color: Black;
font-size: 17px;
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Neptune" ShowWarningOnAjaxFailure="false"/>
<ext:Hidden ID="hGen01" runat="server" />
<ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
<Items>
<ext:Panel ID="Panel2" runat="server" Region="North" Height="40" Border="false" Split="true" Collapsible="true" Header="false" CollapseMode="Mini" >
<Items>

</Items>
</ext:Panel>
<ext:TreePanel
ID="TreePanel1"
runat="server"
Width="200"
Region="West" Lines="false"
Collapsible="true"
Split="true" Header="false"
AutoScroll="true"
MarginSpec="5 0 5 5"
RootVisible="false" >
<TopBar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button ID="Button1" runat="server" Text="全部展開">
<Listeners>
<Click Handler="#{TreePanel1}.expandAll();" />
</Listeners>
</ext:Button>
<ext:Button ID="Button2" runat="server" Text="全部縮合">
<Listeners>
<Click Handler="#{TreePanel1}.collapseAll();" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Listeners>
<ItemClick Handler="addTab(#{tpMain}, record);" />
</Listeners>
<Plugins>
<ext:TabCloseMenu ID="TabCloseMenu1" runat="server" />
</Plugins>
</ext:TreePanel>
<ext:TabPanel ID="tpMain"
runat="server"
Region="Center"
ActiveTabIndex="0"
MarginSpec="5 5 5 0">
<Items>
<ext:Panel ID="Panel4" runat="server" Title="首頁" Layout="Fit">
<Items>
<ext:Portal ID="Portal1" runat="server" Border="false">
<Items>
<ext:PortalColumn ID="PortalColumn1"
runat="server"
Cls="x-column-padding">
<Items>
<ext:Portlet ID="Portlet1" runat="server" Title="Another Panel 1" Icon="Accept" Html="未完成" />
</Items>
</ext:PortalColumn>
<ext:PortalColumn ID="PortalColumn2"
runat="server"
Cls="x-column-padding">
<Items>
<ext:Portlet ID="Portlet2" runat="server" Title="Panel 2" Html="未完成" />
<ext:Portlet ID="Portlet3" runat="server" Title="Another Panel 2" Html="未完成" />
</Items>
</ext:PortalColumn>
<ext:PortalColumn ID="PortalColumn3"
runat="server"
Cls="x-column-padding1">
<Items>
<ext:Portlet ID="Portlet4" runat="server" Title="Panel 3" Html="未完成" />
<ext:Portlet ID="Portlet5" runat="server" Title="Another Panel 3" Html="未完成" />
</Items>
</ext:PortalColumn>
</Items>
</ext:Portal>
</Items>
</ext:Panel>

</Items>
<Plugins>
<ext:TabCloseMenu ID="TabCloseMenu2" runat="server" />
</Plugins>
</ext:TabPanel>
</Items>
</ext:Viewport>
</form>
</body>
</html>

Daniil
Aug 13, 2013, 3:57 AM
Hi @gs_user,

Please use this during Page_Load.

this.TreePanel1.Listeners.ItemClick.Handler = "addTab(#{tpMain}, record);";

The AddListener method please use during a DirectEvent/DirectMethod only.

gs_user
Aug 13, 2013, 5:08 AM
Thanks,it'is work