How vcan i add menu item in start menu (desktop) dynamically?

  1. #1

    How vcan i add menu item in start menu (desktop) dynamically?

    I am trying to generate the start menu item dynamically. But i fails. My target is to generate the menu item, which will come from database.

    Database table is like:

    Menu ID Menu Name Parent Menu ID
    ============== ============== ==============
    M1 Group1 #
    M2 Group2 #
    M3 Sub1 M1
    M4 Sub2 M1
    M5 Sub3 M2
    M6 Sub4 M2


    It will like this :

    All
    |
    Group1
    |______Sub1
    |______Sub2
    Group2

    |______Sub3

    |______Sub4


    Please help.

    Sadeque


  2. #2

    RE: How vcan i add menu item in start menu (desktop) dynamically?

    I got the solution. Within next week i will post a blog at my blog site about this.
  3. #3

    RE: How vcan i add menu item in start menu (desktop) dynamically?

    Hi Sadeque

    Can you please post the code for the dynamic load or give me your blog address

    Thanks
    Richardt
  4. #4

    RE: How vcan i add menu item in start menu (desktop) dynamically?

    Hi Richardt,

    I am writing step by step wise. Please follow it:

    Step:1 -- Create Table In Database
    =========================

    create table as MENU by using following column

    Column Name
    ==========
    UserId
    vMenuID
    vMenuName
    vMenuCaption
    vPageName
    vParent
    iOrderBy
    iWidth
    iHeight
    iPageX
    iPageY

    Step:2 -- Create a aspx file and copy the following code.
    =======================================

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Desktop.aspx.cs" Inherits="HRIS.Restricted.Desktop" %>
    <%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Human Resource Information System</title>
        <style type="text/css">        
            .start-button {
                background-image:url(../Images/vista_start_button.gif) !important;
            }
            
            .shortcut-icon {
                width:48px;
                height:48px;
                filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../Images/window.png", sizingMethod="scale");
            }
            
            .icon-grid48 {
                background-image: url(../Images/grid48x48.png) !important;
                filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../Images/grid48x48.png", sizingMethod="scale");
            }
            
            .icon-user48 {
                background-image: url(../Images/Report1.png) !important;
                filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../Images/Report1.png", sizingMethod="scale");
            }
            
            .icon-window48 {
                background-image: url(../Images/window48x48.png) !important;
                filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../Images/window48x48.png", sizingMethod="scale");
            }
            
            .desktopEl {
                position:absolute !important;
            }
        </style>
        <script type="text/javascript">
            var alignPanels = function () {
                pnlSample.getEl().alignTo(Ext.getBody(), "tr", [-505, 5], false)
            }
    
            var template = '{1}';
    
            var change = function (value) {
                return String.format(template, (value > 0) ? 'green' : 'red', value);
            }
    
            var pctChange = function (value) {
                return String.format(template, (value > 0) ? 'green' : 'red', value + '%');
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server">
                <Listeners>
                    <DocumentReady Handler="alignPanels();" />
                    <WindowResize Handler="alignPanels();" />
                </Listeners>
            </ext:ScriptManager>
    
            <ext:Desktop ID="HRISDesktop" runat="server" BackgroundColor="Black" ShortcutTextColor="White" Wallpaper="../Images/desktop.gif">
                <StartButton Text="Start" IconCls="start-button" />
                <%-- NOTE: Body Controls must be added to a container with position:absolute --%>
                <Body>
            
                </Body>
                <Modules>
                    <ext:DesktopModule ModuleID="DesktopModule1" WindowID="ReportWindow1" AutoRun="false">
                    </ext:DesktopModule>
                </Modules>  
                
                <Shortcuts>
                    <ext:DesktopShortcut ModuleID="DesktopModule1" Text="Report Window" IconCls="shortcut-icon icon-user48" />
                </Shortcuts>
                
                <StartMenu Width="325" Height="300" ToolsWidth="125">
                    <ToolItems>
                        <ext:MenuItem Text="Settings" Icon="Wrench">
                            <Menu>
                                <ext:Menu ID="menuTheme" runat="server">
                                    <Items>
                                        <ext:MenuItem Text="Themes" Icon="Theme">
                                            <Menu>
                                                <ext:Menu ID="InternTheme" runat="server">
                                                    <Items>
                                                        <ext:MenuItem ID="menuDefault" Text="Default">
                                                            <Listeners>
                                                                <Click Handler="Coolite.Ext.setTheme('/extjs/resources/css/ext-all-embedded-css/coolite.axd');" />
                                                            </Listeners>
                                                        </ext:MenuItem>
                                                        <ext:MenuItem ID="MenuItem1" Text="Gray">
                                                            <Listeners>
                                                                <Click Handler="Coolite.Ext.setTheme('/extjs/resources/css/xtheme-gray-embedded-css/coolite.axd');" />
                                                            </Listeners>
                                                        </ext:MenuItem>
                                                        <ext:MenuItem ID="MenuItem2" Text="Slate">
                                                            <Listeners>
                                                                <Click Handler="Coolite.Ext.setTheme('/extjs/resources/css/xtheme-slate-embedded-css/coolite.axd');" />
                                                            </Listeners>
                                                        </ext:MenuItem>
                                                    </Items>
                                                </ext:Menu>
                                            </Menu>
                                        </ext:MenuItem>
                                        <ext:MenuItem Text="Change Password" Icon="User" runat="server">
                                        </ext:MenuItem>
                                    </Items>
                                </ext:Menu>
                            </Menu>
                        </ext:MenuItem>
                        <ext:MenuItem Text="Logout" Icon="Disconnect">
                            <AjaxEvents>
                                <Click OnEvent="Logout_Click">
                                    <EventMask ShowMask="true" Msg="Good Bye..." MinDelay="0" />
                                </Click>
                            </AjaxEvents>
                        </ext:MenuItem>
                    </ToolItems>
                    <Items>
                        <ext:MenuItem ID="MainMenu" runat="server" Text="All" Icon="Folder">
                        <Plugins>
                        <ext:TabCloseMenu ID="tab">
                        </ext:TabCloseMenu>
                        </Plugins>
                        </ext:MenuItem>
                    </Items>
                    <Items>
                        <ext:MenuItem ID="Support" runat="server" Text="Support" Icon="Help">
                        </ext:MenuItem>
                        <ext:MenuItem ID="Feedback" runat="server" Text="Feedback" Icon="Information">
                        </ext:MenuItem>
                        <ext:MenuItem ID="Developer" runat="server" Text="Developer" Icon="Information">
                        </ext:MenuItem>
                    </Items>
                </StartMenu>
            </ext:Desktop>
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        </form>
    </body>
    </html>

    and copy the following code in code behind file

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;
    using Coolite.Ext.Web;
    using System.IO;
    
    namespace HRIS.Restricted
    {
        public partial class Desktop : System.Web.UI.Page
        {
            int menuValue = 1;
            int incValue = 1;
            protected void Page_Load(object sender, EventArgs e)
            {
                buildMenu();
            }
    
            private void buildMenu()
            {
                Coolite.Ext.Web.Menu SubMenu = new Coolite.Ext.Web.Menu();
                Coolite.Ext.Web.MenuItem SubMenuFolder;
    
                string ConnectionString = ConfigurationManager.ConnectionStrings["SecurityConnection"].ConnectionString;
                SqlConnection con = new SqlConnection(ConnectionString);
                string sqlstatment = "select * from Menu where UserName = '" + User.Identity.Name.ToString()  + "' order by iOrderBy";
    
                SqlDataAdapter adapter = new SqlDataAdapter(sqlstatment, con);
                DataSet ds = new DataSet();
                adapter.Fill(ds, "vw_menu");
    
                if (ds.Tables[0].Rows.Count > 0)
                {
                    SubMenu.ID = "SubMenu";
                    MainMenu.Menu.Add(SubMenu);
                }
    
                ds.Relations.Add("NodeRelation", ds.Tables[0].Columns["vMenuID"], ds.Tables[0].Columns["vParent"]);
                foreach (DataRow dbRow in ds.Tables[0].Rows)
                {
                    if (dbRow.IsNull("vParent"))
                    {
                        SubMenuFolder = new Coolite.Ext.Web.MenuItem();
                        SubMenuFolder.ID = dbRow["vMenuName"].ToString();
                        SubMenuFolder.Icon = Icon.Folder;
                        SubMenuFolder.Text = dbRow["vMenuCaption"].ToString();
                        SubMenu.Items.Add(SubMenuFolder);
                        
                        incValue = 1;
                        this.PopulateSubItem(dbRow, SubMenuFolder);
                    }
                }
            }
    
            private void PopulateSubItem(DataRow dbRow, Coolite.Ext.Web.MenuItem itm)
            {
                Coolite.Ext.Web.MenuItem childitm;
                Coolite.Ext.Web.Menu SubSubMenu = new Coolite.Ext.Web.Menu();
                foreach (DataRow childRow in dbRow.GetChildRows("NodeRelation"))
                {
                    if ((int)childRow["vType"] == 0)
                    {
                        SubSubMenu.ID = "SubSubMenu" + menuValue.ToString();
                        itm.Menu.Add(SubSubMenu);
    
                        childitm = new Coolite.Ext.Web.MenuItem();
                        childitm.ID = childRow["vMenuName"].ToString();
                        childitm.Icon = Icon.Folder;
                        childitm.Text = childRow["vMenuCaption"].ToString();
                        SubSubMenu.Items.Add(childitm);
    
                        incValue = 1;
                    }
                    else
                    {
                        if (incValue == 1)
                        {
                            SubSubMenu.ID = "SubSubMenu" + menuValue.ToString();
                            itm.Menu.Add(SubSubMenu);
                        }
    
                        Coolite.Ext.Web.DesktopWindow deskWindow = new Coolite.Ext.Web.DesktopWindow();
                        deskwindow.ID = childRow["vMenuName"].ToString() + "1";
                        deskwindow.Title = childRow["vMenuCaption"].ToString();
                        deskwindow.Icon = Icon.User;
                        deskwindow.Width = (int)childRow["iWidth"];
                        deskwindow.Height = (int)childRow["iHeight"];
                        deskwindow.PageX = (int)childRow["iPageX"];
                        deskwindow.PageY = (int)childRow["iPageY"];
                        deskwindow.AutoLoad.Url = childRow["vPageName"].ToString();
                        deskwindow.AutoLoad.Mode = LoadMode.IFrame;
                        deskwindow.Maximizable = true;
                        deskwindow.Resizable = true;
                        deskwindow.CenterOnLoad = true;
                        PlaceHolder1.Controls.Add(deskWindow);
    
                        childitm = new Coolite.Ext.Web.MenuItem();
                        childitm.ID = childRow["vMenuName"].ToString();
                        childitm.Icon = Icon.User;
                        childitm.Text = childRow["vMenuCaption"].ToString();
                        childitm.Listeners.Click.Handler = "#{" + childRow["vMenuName"].ToString() + "1" + "}.show();#{" + childRow["vMenuName"].ToString() + "1" + "}.reload();";
                        SubSubMenu.Items.Add(childitm);
    
                        incValue = 0;
                    }
                    
                    menuValue += menuValue;
                    this.PopulateSubItem(childRow, childitm);
                }
            }
    
            protected void Logout_Click(object sender, AjaxEventArgs e)
            {
                FormsAuthentication.SignOut();
                Response.Redirect("Login.aspx");
            }
        }
    }

    Have any confusion please inform me.

    Thanks,

    Sadeque Sharif
    Freelance Developer

    Mail: sadeque.sharif@yahoo.com
    Web: www.crea8ivecode.net
  5. #5

    RE: How vcan i add menu item in start menu (desktop) dynamically?

    Hi Sadeque

    Thanks a lot

    Richardt
  6. #6

    RE: How vcan i add menu item in start menu (desktop) dynamically?

    Hi Sadeque

    Can you please explain the iorder by field. All the others I understand.

    Thanks
    Richardt
  7. #7

    RE: How vcan i add menu item in start menu (desktop) dynamically?

    Hi Richardt,

    I used iOrderBy column to show the menu order by. Like:

    Menu Name Order By
    =================== ==========
    Personal Information 1
    Official Information 2
    Department Information 11
    Section Information 21


    Have any confusion please informe me.


    Thanks,

    Sadeque Sharif
    Freelance Developer

    Mail: sadeque.sharif@yahoo.com
    Web: www.crea8ivecode.net






    <h2><a &#111;nmouseover="window.status = window.location;return true;" &#111;nmouseout="window.status='';return true;" title="View Richardt's Profile..." id="ctl10_ctlTopic_ctlPanelBar_ctlTopicsRepeater_c tl09_smAuthorName" href="void('');">
    </a></h2>
  8. #8

    RE: How vcan i add menu item in start menu (desktop) dynamically?

    Hi Sadeque




    It works like a bomb.

    I have added some extra functionality to the click handler, so that the same window cannot be opened twice and if a screen needs to be maximized on load.

    I added a field called maxi to the table which has a value of M = maximize and N = normal which handles the maximize.

    
    
    
    
    childitm.Listeners.Click.Handler = "var desk = MyDesktop.getDesktop(); var windows = desk.getManager().getBy(function() { return true; }); var y = 0; var i = 0; for (i = 0; i <= windows.length - 1; i++) { if (windows[i].id == '" &amp; childRow("vMenuName").ToString() + "1" &amp; "') {windows[i].show(); y = 1; } }; #{" + childRow("vMenuName").ToString() + "1" + "}.show(); if(y == 0){if ('" &amp; childRow("Maxi").ToString() &amp; "' == 'M') { #{" + childRow("vMenuName").ToString() + "1" + "}.maximize(); };}" '#{" + childRow("vMenuName").ToString() + "1" + "}.reload();
    Thanks again for the code
    Richardt
  9. #9

    Hi there i need some help

    Hi
    I wanna ask u about StartButton it doesn't work in v2.0 i need to change icon and text <another thing is :how to change direction to be Right to lift if it possible

    and thanx

    Ahmad
    the error is :Type 'Ext.Net.Desktop' does not have a public property named 'StartButton'
    Last edited by ASA; Jul 29, 2012 at 11:01 AM. Reason: extend

Similar Threads

  1. Replies: 2
    Last Post: May 28, 2012, 1:54 PM
  2. Replies: 2
    Last Post: Apr 02, 2012, 7:48 AM
  3. [CLOSED] Menu inside Component menu item
    By tansu in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 15, 2010, 2:32 PM
  4. [CLOSED] [1.0] Desktop start menu styles issue
    By Labyrinth in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 27, 2010, 9:27 AM
  5. access to item of menu in Coolite desktop
    By mono in forum 1.x Help
    Replies: 0
    Last Post: Aug 10, 2009, 11:50 AM

Posting Permissions