How can I receive all Portlet(dynamically created) in the AnchorLayout

  1. #1

    How can I receive all Portlet(dynamically created) in the AnchorLayout

    Hi,

    I am trying to get all portlet(dynamically created) in the AnchorLayout with code below.

                   
                    <ext:Button ID="BtnShowModules" AutoPostBack="true" &#111;nclick="BtnShowModules_Click" runat="server" Text="Show Page Modules"/>
                    <ext:Button ID="BtnSavePositions" Visible="false" runat="server" Text="Save the position">
                        <AjaxEvents>
                            <Click OnEvent="BtnSavePositions_Click">
                                <EventMask ShowMask="true" />
                                
                                <ExtraParams>
                                    <ext:Parameter Name="Message" Value="Positions are saved successfully." />
                                </ExtraParams>
                                
                            </Click>
                        </AjaxEvents>                
                    </ext:Button>                
    
    
                    <ext:LayoutColumn ColumnWidth=".10">
                        <ext:PortalColumn  Title="Modules" ID="PortalColumnModules" runat="server" StyleSpec="padding:10px 0 10px 10px" >
                            <Body>
                                <ext:AnchorLayout ID="AnchorLayoutModules" runat="server">
                                    <ext:Anchor Horizontal="100%">
                                        <ext:Portlet ID="Portlet2" runat="server" Title="Portlet Modules">
                                        </ext:Portlet>
                                    </ext:Anchor>
                                </ext:AnchorLayout>
                            </Body>
                        </ext:PortalColumn>
                    </ext:LayoutColumn>
    
    
            //function for creating dynamic portlet   
            public void GetModulesByPageID(int PageID)
            {
                using (MYEntities db = new MYEntities())
                {
    
                    var pageModules2 = from mdl in db.TRM_Pages_Modules
                                       where mdl.TRM_Pages.ID == PageID orderby mdl.TRM_Locations.ID,mdl.Sequence
                                       select new { ID = mdl.TRM_Modules.ID, ModuleName = mdl.TRM_Modules.Name, LocationID = mdl.TRM_Locations.ID, Sequence=mdl.Sequence };
    
    
    
                    foreach (var modules in pageModules2.ToList())
                    {
                        Anchor ModulesAnchor = new Anchor();
                        Portlet ModulesPortlet = new Portlet();
    
                        ModulesPortlet.Title = modules.ModuleName;
                        ModulesPortlet.ID = modules.ID.ToString();
    
                        ModulesAnchor.Items.Add(ModulesPortlet);
                        AnchorLayoutModules.Anchors.Add(ModulesAnchor);
                    }
    
                }
    
            }
    
    
            //after Clicking BtnSavePositions button <br style="font-weight: bold;">
            protected void BtnSavePositions_Click(object sender, AjaxEventArgs e)
            {
    
                AnchorLayout PortalColumnLeftObj = ControlUtils.FindControl<AnchorLayout>(this.Page, "AnchorLayoutLeft");
                //Save left part
                int position = 0;
                foreach (var item in PortalColumnLeftObj.Items)
                {
                    string moduleId = item.ID;
                    string moduleName = item.ProductName;
                }
                
                  
                Ext.Msg.Alert("Save Position", string.Format("{0}", e.ExtraParams["Message"])).Show();
            }
    
            //create portlet dynamically
    
            protected void BtnShowModules_Click(object sender, EventArgs e)
            {
                int selectedItemInt;
                bool chkSelecttedItem = Int32.TryParse(ComboWebSites.SelectedItem.Value, out selectedItemInt);
    
                if (chkSelecttedItem)
                {
                    GetModulesByPageID(selectedItemInt);
                }
    
                BtnSavePositions.Visible = true;
                //GetAllModules();
            }
    I can see all portlet on the screen but I cannot get them(by clicking button) even by drop event(in the Portal) like this

        <ext:Portal ID="Portal1" runat="server" Title="Portal" >
    
            <AjaxEvents>
            
            <Drop OnEvent="Drop">
                <ExtraParams>
                    <ext:Parameter Name="id" Value="e.panel.id" Mode="Raw" />
                    <ext:Parameter Name="parentID" Value="e.portal.id" Mode="Raw" />
                    <ext:Parameter Name="index" Value="e.columnIndex" Mode="Raw" />
                    <ext:Parameter Name="pos" Value="e.position" Mode="Raw" />
                </ExtraParams> 
            </Drop>
            
            </AjaxEvents>
    
    [AjaxMethod]
            public void Drop(object sender, AjaxEventArgs e)
            {
                
                //I can see the all parameters right.
                string id = e.ExtraParams["id"].ToString();
                string portalID = e.ExtraParams["parentID"].ToString();
                string cindex = e.ExtraParams["index"].ToString();
                string postion = e.ExtraParams["pos"].ToString();
                this.PortletMiddle.Html = "id:" + id + " PID:" + portalID + " Column:" + cindex + " pos:" + postion;
    
                //Just one Portlet is coming which is Portlet1 (this is not being created dynamically)
                
                AnchorLayout PortalColumnLeftObj = ControlUtils.FindControl<AnchorLayout>(this.Page, "AnchorLayoutLeft");
                //Save left part
                int position = 0;
                foreach (var item in PortalColumnLeftObj.Items)
                {
                    string moduleId = item.ID;
                    string moduleName = item.ProductName;
                }
    
    
            }
    Actually, it will be enough to get it by DROP EVENT




    All suggestions are welcome.

    Thank you in advance
















  2. #2

    RE: How can I receive all Portlet(dynamically created) in the AnchorLayout

    Hello Latif,

    I have a similar problem about saving the position
    of dynamically created portlet/panel.

    Have you found a solution?

    Regards,
    Stefan
  3. #3

    RE: How can I receive all Portlet(dynamically created) in the AnchorLayout


    Hi Stefan,

    Yes I have solved the problem.

    I got all portlet's IDs by ExtJS(with clicking a button) at the client side then I send them to a function(.net) with JSON format so I saved all my portlet IDs to DB in the function.

    Regards,
    Latif
  4. #4

    RE: How can I receive all Portlet(dynamically created) in the AnchorLayout

    Thanks Latif,

    I solved the problem that way.


    Regards,
    Stefan
  5. #5

    RE: How can I receive all Portlet(dynamically created) in the AnchorLayout

    Hi Latif and Cacovsky,
    have you a sample code for this operation ?
    I need to do the same...

    Thanks in advance

  6. #6

    RE: How can I receive all Portlet(dynamically created) in the AnchorLayout

    Hi Polo,



    See the sample below.


    
    
    <script type="text/javascript">
            function SendPortlets() {
                var mystr;
                var portal = Ext.getCmp("<%=Portal1.ClientID %>");
    
    
                var portalHeader = Ext.getCmp("<%=PortalPageHeader.ClientID %>");
                var myStrHeader;
                var portletHeaderCheck = 0;
                //debugger;            
                var ModuleID;
                mystr = '{"menu": {';
                
                //FOR HEADER MODULES
                if (typeof (portalHeader) != 'undefined') {
                    for (i = 0; i < portalHeader.items.items.length; i++) {
                        mystr += ' "' + (i + 4) + '": {';
                        mystr += ' "menuitem": [';
                        for (j = 0; j < portalHeader.items.items[i].items.items.length; j++) {
                            //ctl00_cphMiddle1_ModulePlace1_2 - we should split this
                            ModuleID = portalHeader.items.items[i].items.items[j].id.split("_");
                            mystr += ' {"moduleID": "' + ModuleID[3] + '", "title": "' + portalHeader.items.items[i].items.items[j].title + '"}';
                            if (j != portalHeader.items.items[i].items.items.length - 1) mystr += ',';
                            portletHeaderCheck = 1;
                        }
                        mystr += ']';
                        mystr += '}';
                        if (i != portalHeader.items.items.length - 1) mystr += ',';
                    }
                } else {
                    mystr += '"4": { "menuitem": []}'; 
                }
    
    
    
    
                if ((portal.items.items.length > 0)) {
                    mystr += ',';
                }
                
                var portletCheck = 0;
                for (i = 0; i < portal.items.items.length; i++) {
                    mystr += ' "' + i + '": {';
                    mystr += ' "menuitem": [';
                    for (j = 0; j < portal.items.items[i].items.items.length; j++) {
                        //ctl00_cphMiddle1_ModulePlace1_2 - we should split this
                        ModuleID = portal.items.items[i].items.items[j].id.split("_");
                        mystr += ' {"moduleID": "' + ModuleID[3] + '", "title": "' + portal.items.items[i].items.items[j].title + '"}';
                        if (j != portal.items.items[i].items.items.length - 1) mystr += ',';
                        portletCheck = 1;
                    }
                    mystr += ']';
                    mystr += '}';
                    if (i != portal.items.items.length - 1) mystr += ',';
                }
                mystr += '}}';
    
    
                if (portletCheck == 0) {
                    Ext.Msg.alert('Alert', 'There is no portlet to save!'); 
                } else {
                
                eval("Coolite.AjaxMethods." + "<%=this.ClientID %>" + ".SavePositions(mystr);");
                }
            }
    </script>
    
    
    
    
    
                    <ext:Button ID="BtnSavePositions" Hidden="true"  runat="server" Text="Save the position">
                        <Listeners>
                             <Click Handler="SendPortlets();" />
                        </Listeners>
                    </ext:Button>
    
    
    
    
    
     <ext:Portal ID="PortalPageHeader" Visible="false" runat="server" Title="Project Header">
            <Body>
                <ext:ColumnLayout  ID="ColumnLayout1" runat="server">
                    <%--All Modules--%>
                    <ext:LayoutColumn ColumnWidth=".100">
                        <ext:PortalColumn  Title="Modules" ID="PortalColumnPageHeader" runat="server" StyleSpec="padding:10px 0 10px 10px" >
                            <Body>
                                <ext:AnchorLayout ID="AnchorLayoutHeader" runat="server">
                                               
                                </ext:AnchorLayout>
                            </Body>
                        </ext:PortalColumn>
                    </ext:LayoutColumn>
                                    
                </ext:ColumnLayout>
            </Body>
        </ext:Portal>
         
        
        <ext:Portal AutoScroll="true" StyleSpec="overflow:auto; background-color: transparent; height: 600px;"   ID="Portal1" runat="server" Title="Page View" >
            
            <Body>
                
                    
                <ext:ColumnLayout  ID="ColumnLayoutMain" runat="server">
                    <%--All Modules--%>
                    <ext:LayoutColumn ColumnWidth=".20">
                        <ext:PortalColumn  Title="Modules" ID="PortalColumnModules" runat="server" StyleSpec="padding:10px 0 10px 10px;" >
                            
                            <Body>
                                
                                <ext:AnchorLayout ID="AnchorLayoutModules" runat="server">
                                               
                                </ext:AnchorLayout>
                            </Body>
                        </ext:PortalColumn>
                    </ext:LayoutColumn>
                    <%--left side of the page--%>
                    <ext:LayoutColumn ColumnWidth=".15">
                        <ext:PortalColumn ID="PortalColumnLeft" runat="server" StyleSpec="padding:10px 0 10px 10px" >
                            
                            <Body>
                                <ext:AnchorLayout ID="AnchorLayoutLeft" runat="server">
    
    
                                </ext:AnchorLayout>
                            </Body>
                        </ext:PortalColumn>
                    </ext:LayoutColumn>
                    <%--middle side of the page--%>
                    <ext:LayoutColumn ColumnWidth=".40">
                        <ext:PortalColumn ID="PortalColumnMiddle" runat="server" StyleSpec="padding:10px 0 10px 10px" >
                            <Body>
                                <ext:AnchorLayout ID="AnchorLayoutMiddle" runat="server">
    
    
                                </ext:AnchorLayout>
                            </Body>
                        </ext:PortalColumn>
                    </ext:LayoutColumn>
                    <%--Right side of the page--%>
                    <ext:LayoutColumn ColumnWidth=".25">
                        <ext:PortalColumn ID="PortalColumnRight" runat="server" StyleSpec="padding:10px 0 10px 10px" >
                            
                            <Body>
                                <ext:AnchorLayout ID="AnchorLayoutRight" runat="server">
    
    
                                </ext:AnchorLayout>
                            </Body>
                        </ext:PortalColumn>
                    </ext:LayoutColumn>                
                                    
                </ext:ColumnLayout>
            </Body>
        </ext:Portal>







            public void GetAllModules()
            {
                using (invoicetest25052007Entities db = new invoicetest25052007Entities())
                {
                    foreach (var modules in db.TRM_Modules.ToList())
                    {
                        Anchor ModulesAnchor = new Anchor();
                        Portlet ModulesPortlet = new Portlet();
    
    
                        ModulesPortlet.Title = modules.Name;
                        ModulesPortlet.ID = modules.ID.ToString();
    
    
                        ModulesAnchor.Items.Add(ModulesPortlet);
                        AnchorLayoutModules.Anchors.Add(ModulesAnchor);
                    }
                }
            }
    
    
    
    
    
    
    
           public void SavePositions(string positions)
            {
                JObject positionsInJson = JObject.Parse(positions);
                JArray portletPositions = (JArray)positionsInJson["menuitem"];
    	}

Similar Threads

  1. Replies: 0
    Last Post: Sep 06, 2011, 6:33 PM
  2. Dynamically created panel content
    By reiben in forum 1.x Help
    Replies: 0
    Last Post: Jun 14, 2011, 7:07 AM
  3. Replies: 2
    Last Post: Dec 25, 2010, 11:07 AM
  4. Create portlet dynamically
    By vimaln in forum 1.x Help
    Replies: 3
    Last Post: Mar 13, 2009, 7:59 PM
  5. How to Create a portlet dynamically?
    By mohan.kantipudi in forum 1.x Help
    Replies: 0
    Last Post: Jan 16, 2009, 2:11 AM

Posting Permissions