/// <summary>
    /// Method for adding panel to group cell.
    /// </summary>
    /// <param name="tabGroupCell">Table cell to be added to</param>
    /// <param name="panelIndex">Index of panel to be added</param>
    private void AddPanelTo(TableCell tabGroupCell, int panelIndex)
    {
        int startIndex = (panelIndex * MaximumItems);

        // Create new instance of panel
        CMSPanel outerPanel = new CMSPanel();

        outerPanel.EnableViewState = false;
        outerPanel.ID      = "pnlOuter" + panelIndex;
        outerPanel.ShortID = "po" + panelIndex;

        // In case of horizontal layout
        if (HorizontalLayout)
        {
            // Stack panels side-by-side
            outerPanel.Style.Add("float", CultureHelper.IsUICultureRTL() ? "right" : "left");
        }
        else
        {
            // Stack panels underneath
            outerPanel.Style.Add("clear", "both");
        }

        // Add panel to collection of panels
        tabGroupCell.Controls.Add(outerPanel);

        // Add buttons to panel
        for (int buttonIndex = startIndex; buttonIndex < startIndex + MaximumItems; buttonIndex++)
        {
            if (Buttons.Count > buttonIndex)
            {
                AddButtonTo(outerPanel, buttonIndex);
            }
        }
    }
示例#2
0
    /// <summary>
    /// Generate apropriate icons if source folder is changed.
    /// </summary>
    /// <param name="folderName">Name of selected folder</param>
    /// <param name="defaultValue">Determine default value which should be checked</param>
    private void HandleChangeFolderAction(string folderName, string defaultValue)
    {
        try
        {
            DirectoryInfo di            = DirectoryInfo.New(DirectoryHelper.CombinePath(FullIconFolderPath, folderName));
            string        directoryName = di.Name;
            ArrayList     iconList      = GetIconsInFolder(di);
            string        defaultIcon   = (iconList.Contains(defaultValue)) ? defaultValue : String.Empty;

            foreach (string fileInfo in iconList)
            {
                string path = GetImagePath(IconsFolder + "/" + directoryName + "/" + fileInfo);

                // Size caption
                LocalizedLabel lblIcon = new LocalizedLabel
                {
                    ResourceString  = "iconcaption." + fileInfo.Remove(fileInfo.LastIndexOfCSafe('.')),
                    EnableViewState = false
                };

                // Icon image
                CMSImage imgIcon = new CMSImage
                {
                    ImageUrl        = UIHelper.ResolveImageUrl(path),
                    AlternateText   = fileInfo,
                    EnableViewState = false
                };

                // Icon panel
                CMSPanel pnlIcon = new CMSPanel
                {
                    CssClass        = "iconItem",
                    EnableViewState = false
                };
                pnlIcon.Attributes.Add("onclick", string.Format("SelectItem_{0}(this);SetAction_{0}('select','{1}');RaiseHiddenPostBack_{0}();", ClientID, fileInfo));
                pnlIcon.Controls.Add(imgIcon);
                pnlIcon.Controls.Add(lblIcon);


                // Check for selected value
                if ((defaultIcon == String.Empty) || (fileInfo.ToLowerCSafe() == defaultValue.ToLowerCSafe()))
                {
                    defaultIcon = fileInfo;
                    pnlIcon.AddCssClass("selected");
                }

                // Add controls
                pnlChild.Controls.Add(pnlIcon);
            }
            CurrentIcon = defaultIcon;
        }
        catch (Exception ex)
        {
            lblError.Text += "[IconSelector.HandleChangeFolderAction]: Error getting icons in selected icon folder. Original exception: " + ex.Message;
        }
        CurrentIconFolder = folderName;
        pnlUpdateIcons.Update();
    }
    /// <summary>
    /// Geterates CMSPanel for right icon
    /// </summary>
    /// <param name="identifierId">Identifier id</param>
    private CMSPanel CreateRightIconPanel(int identifierId)
    {
        CMSPanel pnlRightIcon = new CMSPanel();

        pnlRightIcon.ID       = "pnlRightIcon";
        pnlRightIcon.ShortID  = "pri" + identifierId;
        pnlRightIcon.CssClass = "Icon IconRight";
        return(pnlRightIcon);
    }
    /// <summary>
    /// Method for adding submenu.
    /// </summary>
    /// <param name="button">Menu item button</param>
    /// <param name="cssClass">Button css class</param>
    /// <param name="identifier">Button identifier</param>
    private CMSPanel CreateSubMenu(MenuItem button, string cssClass, int identifier)
    {
        // Generate sub items container
        var pnlSubItems = new CMSPanel();

        pnlSubItems.ID       = "pnlSubItems" + identifier;
        pnlSubItems.ShortID  = "ps" + identifier;
        pnlSubItems.CssClass = "SubMenuItems ContextMenu";

        // Forward scroll button
        Panel pnlForward = new Panel
        {
            ID       = "pnlForward",
            CssClass = "ForwardScroller"
        };

        // Backward scroll button
        Panel pnlBackward = new Panel
        {
            ID       = "pnlBackward",
            CssClass = "BackwardScroller"
        };

        // Scrollable area
        ScrollPanel pnlMenu = new ScrollPanel
        {
            ID                        = "pnlCultureList",
            ShortID                   = "pcl" + identifier,
            CssClass                  = "ContextMenuContainer",
            ScrollAreaCssClass        = "PortalContextMenu UniMenuContextMenu",
            Layout                    = RepeatDirection.Vertical,
            InnerItemClass            = "Item",
            ForwardScrollerControlID  = pnlForward.ID,
            BackwardScrollerControlID = pnlBackward.ID,
            ScrollStep                = 200
        };

        pnlSubItems.Controls.Add(pnlForward);
        pnlSubItems.Controls.Add(pnlBackward);
        pnlSubItems.Controls.Add(pnlMenu);

        // Add menu items
        int subIdentifier = 0;

        foreach (SubMenuItem item in button.SubItems)
        {
            AddSubMenuItem(pnlMenu, item, cssClass, subIdentifier);
            subIdentifier++;
        }

        return(pnlSubItems);
    }
    /// <summary>
    /// Get html for icon.
    /// </summary>
    /// <param name="name">Name</param>
    /// <param name="icon">CMSIcon</param>
    /// <param name="jsHandler">Handler for on click event.</param>
    private static string GetIconHtml(string name, CMSIcon icon, string jsHandler)
    {
        var label = new Label();

        label.Text = name;

        var panel = new CMSPanel();

        panel.Controls.Add(icon);
        panel.Controls.Add(label);
        panel.Attributes.Add("onclick", jsHandler + "return false;");
        string iconHtml = panel.GetRenderedHTML();

        return(iconHtml);
    }
示例#6
0
    /// <summary>
    /// Creates group panel from group.
    /// </summary>
    /// <param name="group">Definition of group</param>
    /// <param name="identifier">Identifier of panel</param>
    private CMSPanel CreateGroupPanelWith(Group group, int identifier)
    {
        Panel    innerPanel = GetContent(group.Control, group.UIElementID, group.Caption);
        CMSPanel groupPanel = null;

        if (innerPanel != null)
        {
            groupPanel = new CMSPanel()
            {
                ID      = "pnlGroup" + identifier,
                ShortID = "g" + identifier
            };

            groupPanel.Controls.Add(GetLeftBorder());
            groupPanel.Controls.Add(innerPanel);
            groupPanel.Controls.Add(GetRightBorder());
            groupPanel.CssClass = group.CssClass;
        }

        return(groupPanel);
    }
示例#7
0
    /// <summary>
    /// Render Folder icon preview HTML.
    /// </summary>
    /// <param name="defaultValue">Determine default value which should be checked</param>
    private void GetFolderIconPreview(string defaultValue)
    {
        foreach (string[] folderInfo in GetPredefinedIconFoldersSet())
        {
            string dirName  = folderInfo[0];
            string iconName = folderInfo[1];
            string path     = GetImagePath(IconsFolder + "/" + dirName + "/" + iconName);

            // Icon image
            CMSImage imgFolder = new CMSImage
            {
                ImageUrl        = UIHelper.ResolveImageUrl(path),
                AlternateText   = iconName,
                EnableViewState = false
            };

            // Icon panel
            CMSPanel pnlFolder = new CMSPanel
            {
                EnableViewState = false
            };
            pnlFolder.AddCssClass("iconItem");
            pnlFolder.Controls.Add(imgFolder);
            pnlFolder.Attributes.Add("onclick", string.Format("SelectItem_{0}(this);SetAction_{0}('changefolder','{1}');RaiseHiddenPostBack_{0}();", ClientID, dirName));

            // Check for selected value
            if ((defaultValue == String.Empty) || (dirName.ToLowerCSafe() == defaultValue.ToLowerCSafe()))
            {
                defaultValue = dirName;
                pnlFolder.AddCssClass("selected");
            }

            // Add controls
            pnlMain.Controls.Add(pnlFolder);
        }

        // Actualize value of current icon folder
        CurrentIconFolder = defaultValue;
    }
示例#8
0
    /// <summary>
    /// Generates div with right border.
    /// </summary>
    /// <param name="captionText">Caption of group</param>
    /// <returns>Panel with right border</returns>
    protected Panel GetCaption(string captionText)
    {
        // Create literal with caption
        Literal caption = new Literal()
        {
            ID = "ltlCaption" + identifier,
            EnableViewState = false,
            Text            = captionText
        };

        // Create panel and add caption literal
        CMSPanel captionPanel = new CMSPanel()
        {
            ID              = "pnlCaption" + identifier,
            ShortID         = "cp" + identifier,
            EnableViewState = false,
            CssClass        = "UniMenuDescription"
        };

        captionPanel.Controls.Add(caption);

        return(captionPanel);
    }
示例#9
0
    /// <summary>
    /// Generates panel with buttons loaded from given UI Element.
    /// </summary>
    /// <param name="uiElementId">ID of the UI Element</param>
    private Panel GetButtons(int uiElementId)
    {
        const int bigButtonMinimalWidth   = 40;
        const int smallButtonMinimalWidth = 66;

        // Load the buttons manually from UI Element
        IEnumerable <UIElementInfo> elements = UIElementInfoProvider.GetChildUIElements(uiElementId);

        // When no child found
        if (!elements.Any())
        {
            // Try to use group element as button
            elements = UIElementInfo.Provider.Get()
                       .WhereEquals("ElementID", uiElementId);

            var groupElement = elements.FirstOrDefault();
            if (groupElement != null)
            {
                // Use group element as button only if it has URL specified
                if (String.IsNullOrEmpty(groupElement.ElementTargetURL))
                {
                    elements = Enumerable.Empty <UIElementInfo>();
                }
            }
        }

        // Filter the dataset according to UI Profile
        var filteredElements = FilterElements(elements).ToList();

        int small = 0;
        int count = filteredElements.Count;

        // No buttons, render nothing
        if (count == 0)
        {
            return(null);
        }

        // Prepare the panel
        var pnlButtons = new Panel();

        pnlButtons.CssClass = "ActionButtons";

        // Prepare the table
        Table    tabGroup    = new Table();
        TableRow tabGroupRow = new TableRow();

        tabGroup.CellPadding        = 0;
        tabGroup.CellSpacing        = 0;
        tabGroup.EnableViewState    = false;
        tabGroupRow.EnableViewState = false;
        tabGroup.Rows.Add(tabGroupRow);

        List <Panel> panels = new List <Panel>();

        for (int i = 0; i < count; i++)
        {
            // Get current and next button
            UIElementInfo uiElement = filteredElements[i];

            UIElementInfo sel = UIContextHelper.CheckSelectedElement(uiElement, UIContext);
            if (sel != null)
            {
                String selectionSuffix = ValidationHelper.GetString(UIContext["selectionSuffix"], String.Empty);
                StartingPage  = UIContextHelper.GetElementUrl(sel, UIContext) + selectionSuffix;
                HighlightItem = uiElement.ElementName;
            }

            // Raise button creating event
            OnButtonCreating?.Invoke(this, new UniMenuArgs {
                UIElement = uiElement
            });

            UIElementInfo uiElementNext = null;
            if (i < count - 1)
            {
                uiElementNext = filteredElements[i + 1];
            }

            // Set the first button
            if (mFirstUIElement == null)
            {
                mFirstUIElement = uiElement;
            }

            // Get the sizes of current and next button. Button is large when it is the only in the group
            bool isSmall     = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (count > 1);
            bool isResized   = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (!isSmall);
            bool isNextSmall = (uiElementNext != null) && (uiElementNext.ElementSize == UIElementSizeEnum.Regular);

            // Set the CSS class according to the button size
            string cssClass    = (isSmall ? "SmallButton" : "BigButton");
            string elementName = uiElement.ElementName;

            // Display only caption - do not substitute with Display name when empty
            string elementCaption = ResHelper.LocalizeString(uiElement.ElementCaption, ResourceCulture);

            // Create main button panel
            CMSPanel pnlButton = new CMSPanel
            {
                ID      = "pnlButton" + elementName,
                ShortID = "b" + elementName
            };

            pnlButton.Attributes.Add("name", elementName);
            pnlButton.CssClass = cssClass;

            // Remember the first button
            if (firstPanel == null)
            {
                firstPanel = pnlButton;
            }

            // Remember the selected button
            if ((preselectedPanel == null) && elementName.EqualsCSafe(HighlightItem, true))
            {
                preselectedPanel = pnlButton;

                // Set the selected button
                if (mHighlightedUIElement == null)
                {
                    mHighlightedUIElement = uiElement;
                }
            }

            // URL or behavior
            string url = uiElement.ElementTargetURL;

            if (!string.IsNullOrEmpty(url) && url.StartsWithCSafe("javascript:", true))
            {
                pnlButton.Attributes["onclick"] = url.Substring("javascript:".Length);
            }
            else
            {
                url = UIContextHelper.GetElementUrl(uiElement, UIContext);

                if (url != String.Empty)
                {
                    string buttonSelection = (RememberSelectedItem ? "SelectButton(this);" : "");

                    // Ensure hash code if required
                    url = MacroResolver.Resolve(URLHelper.EnsureHashToQueryParameters(url));

                    if (!String.IsNullOrEmpty(TargetFrameset))
                    {
                        if (uiElement.ElementType == UIElementTypeEnum.PageTemplate)
                        {
                            url = URLHelper.UpdateParameterInUrl(url, "displaytitle", "false");
                        }

                        String target = UseIFrame ? String.Format("frames['{0}']", TargetFrameset) : String.Format("parent.frames['{0}']", TargetFrameset);
                        pnlButton.Attributes["onclick"] = String.Format("{0}{1}.location.href = '{2}';", buttonSelection, target, UrlResolver.ResolveUrl(url));
                    }
                    else
                    {
                        pnlButton.Attributes["onclick"] = String.Format("{0}self.location.href = '{1}';", buttonSelection, UrlResolver.ResolveUrl(url));
                    }
                }
            }

            // Tooltip
            if (!String.IsNullOrEmpty(uiElement.ElementDescription))
            {
                pnlButton.ToolTip = ResHelper.LocalizeString(uiElement.ElementDescription, ResourceCulture);
            }
            else
            {
                pnlButton.ToolTip = elementCaption;
            }
            pnlButton.EnableViewState = false;

            // Ensure correct grouping of small buttons
            if (isSmall && (small == 0))
            {
                small++;

                Panel pnlSmallGroup = new Panel
                {
                    ID = "pnlGroupSmall" + uiElement.ElementName
                };
                if (IsRTL)
                {
                    pnlSmallGroup.Style.Add("float", "right");
                    pnlSmallGroup.Style.Add("text-align", "right");
                }
                else
                {
                    pnlSmallGroup.Style.Add("float", "left");
                    pnlSmallGroup.Style.Add("text-align", "left");
                }

                pnlSmallGroup.EnableViewState = false;
                pnlSmallGroup.Controls.Add(pnlButton);
                panels.Add(pnlSmallGroup);
            }

            // Generate button link
            HyperLink buttonLink = new HyperLink
            {
                ID = "lnkButton" + uiElement.ElementName,
                EnableViewState = false
            };

            // Generate button image
            Image buttonImage = new Image
            {
                ID              = "imgButton" + uiElement.ElementName,
                ImageAlign      = (isSmall ? ImageAlign.AbsMiddle : ImageAlign.Top),
                AlternateText   = elementCaption,
                EnableViewState = false
            };

            // Use icon path
            if (!string.IsNullOrEmpty(uiElement.ElementIconPath))
            {
                string iconPath = GetImagePath(uiElement.ElementIconPath);

                // Check if element size was changed
                if (isResized)
                {
                    // Try to get larger icon
                    string largeIconPath = iconPath.Replace("list.png", "module.png");
                    if (FileHelper.FileExists(largeIconPath))
                    {
                        iconPath = largeIconPath;
                    }
                }

                buttonImage.ImageUrl = GetImageUrl(iconPath);
                buttonLink.Controls.Add(buttonImage);
            }
            // Use Icon class
            else if (!string.IsNullOrEmpty(uiElement.ElementIconClass))
            {
                var icon = new CMSIcon
                {
                    ID = string.Format("ico_{0}_{1}", identifier, i),
                    EnableViewState = false,
                    ToolTip         = pnlButton.ToolTip,
                    CssClass        = "cms-icon-80 " + uiElement.ElementIconClass
                };
                buttonLink.Controls.Add(icon);
            }
            // Load default module icon if ElementIconPath is not specified
            else
            {
                buttonImage.ImageUrl = GetImageUrl("CMSModules/module.png");
                buttonLink.Controls.Add(buttonImage);
            }

            // Generate caption text
            Literal captionLiteral = new Literal
            {
                ID              = "ltlCaption" + uiElement.ElementName,
                Text            = (isSmall ? "\n" : "<br />") + elementCaption,
                EnableViewState = false
            };
            buttonLink.Controls.Add(captionLiteral);

            //Generate button table (IE7 issue)
            Table     tabButton     = new Table();
            TableRow  tabRow        = new TableRow();
            TableCell tabCellLeft   = new TableCell();
            TableCell tabCellMiddle = new TableCell();
            TableCell tabCellRight  = new TableCell();

            tabButton.CellPadding = 0;
            tabButton.CellSpacing = 0;

            tabButton.EnableViewState     = false;
            tabRow.EnableViewState        = false;
            tabCellLeft.EnableViewState   = false;
            tabCellMiddle.EnableViewState = false;
            tabCellRight.EnableViewState  = false;

            tabButton.Rows.Add(tabRow);
            tabRow.Cells.Add(tabCellLeft);
            tabRow.Cells.Add(tabCellMiddle);
            tabRow.Cells.Add(tabCellRight);

            // Generate left border
            Panel pnlLeft = new Panel
            {
                ID              = "pnlLeft" + uiElement.ElementName,
                CssClass        = "Left" + cssClass,
                EnableViewState = false
            };

            // Generate middle part of button
            Panel pnlMiddle = new Panel
            {
                ID       = "pnlMiddle" + uiElement.ElementName,
                CssClass = "Middle" + cssClass
            };
            pnlMiddle.Controls.Add(buttonLink);
            Panel pnlMiddleTmp = new Panel
            {
                EnableViewState = false
            };
            if (isSmall)
            {
                pnlMiddle.Style.Add("min-width", smallButtonMinimalWidth + "px");
                // IE7 issue with min-width
                pnlMiddleTmp.Style.Add("width", smallButtonMinimalWidth + "px");
                pnlMiddle.Controls.Add(pnlMiddleTmp);
            }
            else
            {
                pnlMiddle.Style.Add("min-width", bigButtonMinimalWidth + "px");
                // IE7 issue with min-width
                pnlMiddleTmp.Style.Add("width", bigButtonMinimalWidth + "px");
                pnlMiddle.Controls.Add(pnlMiddleTmp);
            }
            pnlMiddle.EnableViewState = false;

            // Generate right border
            Panel pnlRight = new Panel
            {
                ID              = "pnlRight" + uiElement.ElementName,
                CssClass        = "Right" + cssClass,
                EnableViewState = false
            };

            // Add inner controls
            tabCellLeft.Controls.Add(pnlLeft);
            tabCellMiddle.Controls.Add(pnlMiddle);
            tabCellRight.Controls.Add(pnlRight);

            pnlButton.Controls.Add(tabButton);

            // If there were two small buttons in a row end the grouping div
            if ((small == 2) || (isSmall && !isNextSmall))
            {
                small = 0;

                // Add the button to the small buttons grouping panel
                panels[panels.Count - 1].Controls.Add(pnlButton);
            }
            else
            {
                if (small == 0)
                {
                    // Add the generated button into collection
                    panels.Add(pnlButton);
                }
            }
            if (small == 1)
            {
                small++;
            }

            // Raise button created event
            OnButtonCreated?.Invoke(this, new UniMenuArgs {
                UIElement = uiElement, TargetUrl = url, ButtonControl = pnlButton, ImageControl = buttonImage
            });
        }

        // Add all panels to control
        foreach (Panel panel in panels)
        {
            TableCell tabGroupCell = new TableCell
            {
                VerticalAlign   = VerticalAlign.Top,
                EnableViewState = false
            };

            tabGroupCell.Controls.Add(panel);
            tabGroupRow.Cells.Add(tabGroupCell);
        }

        pnlButtons.Controls.Add(tabGroup);

        return(pnlButtons);
    }
    /// <summary>
    /// Creates group panel from group.
    /// </summary>
    /// <param name="group">Definition of group</param>
    /// <param name="identifier">Identifier of panel</param>
    private CMSPanel CreateGroupPanelWith(Group group, int identifier)
    {
        Panel innerPanel = GetContent(group.Control, group.UIElementID, group.Caption);
        CMSPanel groupPanel = null;

        if (innerPanel != null)
        {
            groupPanel = new CMSPanel()
            {
                ID = "pnlGroup" + identifier,
                ShortID = "g" + identifier
            };

            groupPanel.Controls.Add(GetLeftBorder());
            groupPanel.Controls.Add(innerPanel);
            groupPanel.Controls.Add(GetRightBorder());
            groupPanel.CssClass = group.CssClass;
        }

        return groupPanel;
    }
    /// <summary>
    /// Method for adding submenu.
    /// </summary>
    /// <param name="button">Menu item button</param>
    /// <param name="cssClass">Button css class</param>
    /// <param name="identifier">Button identifier</param>
    private CMSPanel CreateSubMenu(MenuItem button, string cssClass, int identifier)
    {
        // Generate sub items container
        var pnlSubItems = new CMSPanel();
        pnlSubItems.ID = "pnlSubItems" + identifier;
        pnlSubItems.ShortID = "ps" + identifier;
        pnlSubItems.CssClass = "SubMenuItems ContextMenu";

        // Forward scroll button
        Panel pnlForward = new Panel
        {
            ID = "pnlForward",
            CssClass = "ForwardScroller"
        };

        // Backward scroll button
        Panel pnlBackward = new Panel
        {
            ID = "pnlBackward",
            CssClass = "BackwardScroller"
        };

        // Scrollable area
        ScrollPanel pnlMenu = new ScrollPanel
        {
            ID = "pnlCultureList",
            ShortID = "pcl" + identifier,
            CssClass = "ContextMenuContainer",
            ScrollAreaCssClass = "PortalContextMenu UniMenuContextMenu",
            Layout = RepeatDirection.Vertical,
            InnerItemClass = "Item",
            ForwardScrollerControlID = pnlForward.ID,
            BackwardScrollerControlID = pnlBackward.ID,
            ScrollStep = 200
        };

        pnlSubItems.Controls.Add(pnlForward);
        pnlSubItems.Controls.Add(pnlBackward);
        pnlSubItems.Controls.Add(pnlMenu);

        // Add menu items
        int subIdentifier = 0;
        foreach (SubMenuItem item in button.SubItems)
        {
            AddSubMenuItem(pnlMenu, item, cssClass, subIdentifier);
            subIdentifier++;
        }

        return pnlSubItems;
    }
 /// <summary>
 /// Geterates CMSPanel for right icon
 /// </summary>
 /// <param name="identifierId">Identifier id</param>
 private CMSPanel CreateRightIconPanel(int identifierId)
 {
     CMSPanel pnlRightIcon = new CMSPanel();
     pnlRightIcon.ID = "pnlRightIcon";
     pnlRightIcon.ShortID = "pri" + identifierId;
     pnlRightIcon.CssClass = "Icon IconRight";
     return pnlRightIcon;
 }
    /// <summary>
    /// Method for adding sub menu item into menu.
    /// </summary>
    /// <param name="pnlMenu">Menu container control</param>
    /// <param name="item">Sub menu item definition</param>
    /// <param name="cssClass">Button css class</param>
    /// <param name="subIdentifier">Button identifier</param>
    private void AddSubMenuItem(CMSPanel pnlMenu, SubMenuItem item, string cssClass, int subIdentifier)
    {
        if (String.IsNullOrEmpty(item.ControlPath))
        {
            // Generate sub item
            CMSPanel pnlItem = new CMSPanel();
            pnlItem.ID = "pnlSubItem" + subIdentifier;
            pnlItem.ShortID = "pi" + subIdentifier;
            pnlItem.CssClass = "Item ItemPadding";
            pnlItem.ToolTip = item.Tooltip;

            if (!String.IsNullOrEmpty(item.OnClientClick))
            {
                pnlItem.Attributes["onclick"] = item.OnClientClick.Replace("##BUTTON##", "$cmsj(this).parents('." + cssClass + "').get(0)");
            }

            if (!String.IsNullOrEmpty(item.ImagePath))
            {
                string altText = String.IsNullOrEmpty(item.ImageAltText) ? item.Text : item.ImageAltText;

                // Generate sub items text
                CMSPanel pnlIcon = new CMSPanel();
                pnlIcon.ID = "pnlIcon";
                pnlIcon.ShortID = "pii" + subIdentifier;
                pnlIcon.CssClass = "Icon";
                Literal subItemImage = new Literal();
                subItemImage.ID = "ltlSubItemImage" + subIdentifier;
                subItemImage.EnableViewState = false;
                subItemImage.Text = String.Format("<img src=\"{0}\" alt=\"{1}\" />&nbsp;",
                        ResolveUrl(item.ImagePath),
                        GetString(altText));

                pnlIcon.Controls.Add(subItemImage);
                pnlItem.Controls.Add(pnlIcon);
            }

            // Add custom HTML attributes
            foreach (var htmlAttribute in item.HtmlAttributes)
            {
                pnlItem.Attributes[htmlAttribute.Key] = HTMLHelper.HTMLEncode(htmlAttribute.Value);
            }

            // Generate sub items text
            CMSPanel pnlText = new CMSPanel();
            pnlText.ID = "pnlText";
            pnlText.ShortID = "pt" + subIdentifier;
            pnlText.CssClass = "Name";
            Label subItemText = new Label();
            subItemText.ID = "ltlSubItem" + subIdentifier;
            subItemText.EnableViewState = false;
            subItemText.Text = GetString(item.Text);

            pnlText.Controls.Add(subItemText);
            pnlItem.Controls.Add(pnlText);

            if (!String.IsNullOrEmpty(item.RightImagePath))
            {
                string altText = String.IsNullOrEmpty(item.RightImageAltText) ? item.Text : item.RightImageAltText;

                // Generate sub item right icon
                Literal subRightItemImage = new Literal();
                subRightItemImage.ID = "ltlSubRightItemImage" + subIdentifier;
                subRightItemImage.EnableViewState = false;
                subRightItemImage.Text = String.Format("<img class=\"RightIcon\" src=\"{0}\" alt=\"{1}\" />&nbsp;",
                        ResolveUrl(item.RightImagePath),
                        GetString(altText));

                CMSPanel pnlRightIcon = CreateRightIconPanel(subIdentifier);
                pnlRightIcon.Controls.Add(subRightItemImage);
                pnlItem.Controls.Add(pnlRightIcon);
            }
            else if (!string.IsNullOrEmpty(item.RightImageIconClass))
            {
                string altText = String.IsNullOrEmpty(item.RightImageAltText) ? item.Text : item.RightImageAltText;

                var icon = new CMSIcon
                {
                    ID = "ico" + subIdentifier,
                    EnableViewState = false,
                    ToolTip = GetString(altText),
                    CssClass = "cms-icon-80 " + item.RightImageIconClass
                };

                CMSPanel pnlRightIcon = CreateRightIconPanel(subIdentifier);
                pnlRightIcon.Controls.Add(icon);
                pnlItem.Controls.Add(pnlRightIcon);
            }

            pnlMenu.Controls.Add(pnlItem);
        }
        else
        {
            // Load menu item control
            Control ctrl = LoadUserControl(item.ControlPath);
            if (ctrl != null)
            {
                pnlMenu.Controls.Add(ctrl);
            }
        }
    }
示例#14
0
    /// <summary>
    /// Method for adding button to controls.
    /// </summary>
    /// <param name="outerPanel">Panel to be added to</param>
    /// <param name="identifier">Index of button</param>
    private void AddButtonTo(CMSPanel outerPanel, int identifier)
    {
        MenuItem   button      = Buttons[identifier];
        string     caption     = button.Text;
        string     tooltip     = button.Tooltip;
        string     cssClass    = button.CssClass;
        string     onClick     = button.OnClientClick;
        string     redirectUrl = button.RedirectUrl;
        string     imagePath   = button.ImagePath;
        string     alt         = button.ImageAltText;
        int        minWidth    = button.MinimalWidth;
        ImageAlign imageAlign  = GetImageAlign(button.ImageAlign);

        // Generate button image
        Image buttonImage = new Image();

        buttonImage.ID              = "img" + identifier;
        buttonImage.CssClass        = "MenuButtonImage";
        buttonImage.EnableViewState = false;
        buttonImage.AlternateText   = alt ?? caption;
        if (!string.IsNullOrEmpty(imagePath))
        {
            buttonImage.ImageUrl = ResolveUrl(imagePath);
        }
        buttonImage.ImageAlign = imageAlign;

        // Generate button text
        Literal captionLiteral = new Literal();

        captionLiteral.ID = "ltlCaption" + identifier;
        captionLiteral.EnableViewState = false;
        string separator = (imageAlign == ImageAlign.Top) ? "<br />" : "\n";

        captionLiteral.Text = String.Format("{0}<span class=\"MenuButtonText\">{1}</span>", separator, caption);

        CMSPanel pnlSubItems = null;

        if (button.SubItems.Count > 0)
        {
            // Ensure jQuery tool is loaded
            ScriptHelper.RegisterJQueryTools(Page);

            // Append submenu toogle script
            onClick = "CMSUniMenu.ToogleSubMenu(this);" + onClick;

            // Append arrow down image for idication sub menu
            captionLiteral.Text += "&nbsp;<img style=\"width:8px; height:8px;\" src=\"" + GetImageUrl("Design/Controls/UniMenu/ArrowDown.png") + "\" alt=\"Sub menu items\" class=\"SubItemsArrow\" />";

            // Create submenu
            CreateSubMenu(button, ref pnlSubItems, cssClass, identifier);
        }

        // Generate button link
        HyperLink buttonLink = new HyperLink();

        buttonLink.ID = "btn" + identifier;
        buttonLink.EnableViewState = false;

        buttonLink.Controls.Add(buttonImage);
        buttonLink.Controls.Add(captionLiteral);

        if (!string.IsNullOrEmpty(redirectUrl))
        {
            buttonLink.NavigateUrl = ResolveUrl(redirectUrl);
        }

        // Generate left border
        CMSPanel pnlLeft = new CMSPanel();

        pnlLeft.ID      = "pnlLeft" + identifier;
        pnlLeft.ShortID = "pl" + identifier;

        pnlLeft.EnableViewState = false;
        pnlLeft.CssClass        = "Left" + cssClass;

        // Generate middle part of button
        CMSPanel pnlMiddle = new CMSPanel();

        pnlMiddle.ID      = "pnlMiddle" + identifier;
        pnlMiddle.ShortID = "pm" + identifier;

        pnlMiddle.EnableViewState = false;
        pnlMiddle.CssClass        = "Middle" + cssClass;
        pnlMiddle.Controls.Add(buttonLink);
        if (minWidth > 0)
        {
            pnlMiddle.Style.Add("min-width", minWidth + "px");

            // IE7 issue with min-width
            CMSPanel pnlMiddleTmp = new CMSPanel();
            pnlMiddleTmp.EnableViewState = false;
            pnlMiddleTmp.Style.Add("width", minWidth + "px");
            pnlMiddle.Controls.Add(pnlMiddleTmp);
        }

        // Add sub items if exists
        if (pnlSubItems != null)
        {
            pnlMiddle.Controls.Add(pnlSubItems);
        }

        // Generate right border
        CMSPanel pnlRight = new CMSPanel();

        pnlRight.ID      = "pnlRight" + identifier;
        pnlRight.ShortID = "pr" + identifier;

        pnlRight.EnableViewState = false;
        pnlRight.CssClass        = "Right" + cssClass;

        // Generate whole button
        CMSPanel pnlButton = new CMSPanel();

        pnlButton.ID      = "pnlButton" + identifier;
        pnlButton.ShortID = BUTTON_PANEL_SHORTID + identifier;

        pnlButton.EnableViewState = false;
        if ((AllowSelection && identifier == SelectedIndex) || (button.AllowToggle && button.IsToggled))
        {
            cssClass += SelectedSuffix;
        }

        pnlButton.CssClass = cssClass;

        if (button.AllowToggle)
        {
            pnlButton.CssClass += " Toggle";
            EnsureAllowToggleScript();
        }

        //Generate button table (IE7 issue)
        Table     tabButton     = new Table();
        TableRow  tabRow        = new TableRow();
        TableCell tabCellLeft   = new TableCell();
        TableCell tabCellMiddle = new TableCell();
        TableCell tabCellRight  = new TableCell();

        tabButton.CellPadding = 0;
        tabButton.CellSpacing = 0;

        tabButton.Rows.Add(tabRow);
        tabRow.Cells.Add(tabCellLeft);
        tabRow.Cells.Add(tabCellMiddle);
        tabRow.Cells.Add(tabCellRight);

        // Add inner controls
        tabCellLeft.Controls.Add(pnlLeft);
        tabCellMiddle.Controls.Add(pnlMiddle);
        tabCellRight.Controls.Add(pnlRight);

        pnlButton.Controls.Add(tabButton);

        pnlButton.ToolTip = tooltip ?? caption;

        outerPanel.Controls.Add(pnlButton);

        if (AllowDraggable)
        {
            mStartupScript.Append(String.Format("$j( '#{0}' ).draggable({{ helper:{1}, scope:'{2}' }});", pnlButton.ClientID, GetDraggableHandler(button.DraggableTemplateHandler), button.DraggableScope));
        }
        if (AllowSelection)
        {
            onClick = "SelectButton(this);" + onClick;
        }
        else if (button.AllowToggle)
        {
            onClick = "ToggleButton(this);" + onClick;
        }

        pnlButton.Attributes["onclick"] = CheckChanges ? "if (CheckChanges()) {" + onClick + "}" : onClick;

        // In case of horizontal layout
        if (HorizontalLayout)
        {
            // Stack buttons underneath
            pnlButton.Style.Add("clear", "both");
        }
        else
        {
            // Stack buttons side-by-side
            pnlButton.Style.Add("float", "left");
        }
    }
示例#15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Groups != null)
        {
            ScriptHelper.RegisterJQuery(Page);
            ScriptHelper.RegisterScriptFile(Page, "jquery/jquery-tools.js");
            ScriptHelper.RegisterScriptFile(Page, "~/CMSAdminControls/UI/UniMenu/UniMenu.js");

            if (RememberSelectedItem)
            {
                StringBuilder selectionScript = new StringBuilder();
                selectionScript.AppendLine("function SelectButton(elem)");
                selectionScript.AppendLine("{");
                selectionScript.AppendLine("    var selected = 'Selected';");
                selectionScript.AppendLine("    var jElem =$j(elem);");
                selectionScript.AppendFormat("    $j('#{0}').find('.'+selected).removeClass(selected);\n", pnlControls.ClientID);
                selectionScript.AppendLine("    jElem.addClass(selected);");
                selectionScript.AppendLine("}");
                ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "UIToolbarSelectionScript", ScriptHelper.GetScript(selectionScript.ToString()));
            }

            // Generate script for activating menu buttons by script
            string        buttonSelection       = (RememberSelectedItem ? "SelectButton(this);" : "");
            StringBuilder remoteSelectionScript = new StringBuilder();
            remoteSelectionScript.AppendLine("var SelectedItemID = null;");
            remoteSelectionScript.AppendLine("function SelectItem(elementID, elementUrl, forceSelection)");
            remoteSelectionScript.AppendLine("{");
            remoteSelectionScript.AppendLine("  if(forceSelection === undefined) forceSelection = true;");
            remoteSelectionScript.AppendLine("  if(SelectedItemID == elementID && !forceSelection) { return; }");
            remoteSelectionScript.AppendLine("    SelectedItemID = elementID;");
            remoteSelectionScript.AppendLine("    var selected = 'Selected';");
            remoteSelectionScript.AppendFormat("    $j(\"#{0} .\"+selected).removeClass(selected);\n", pnlControls.ClientID);
            remoteSelectionScript.AppendFormat("    $j(\"#{0} div[name='\"+elementID+\"']\").addClass(selected);\n", pnlControls.ClientID);
            remoteSelectionScript.AppendLine("    if(elementUrl != null && elementUrl != '') {");
            if (!String.IsNullOrEmpty(TargetFrameset))
            {
                remoteSelectionScript.AppendLine(String.Format("{0}parent.frames['{1}'].location.href = elementUrl;", buttonSelection, TargetFrameset));
            }
            else
            {
                remoteSelectionScript.AppendLine(buttonSelection + "self.location.href = elementUrl;");
            }
            remoteSelectionScript.AppendLine("    }");
            remoteSelectionScript.AppendLine("}");
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "UIToolbarRemoteSelectionScript", ScriptHelper.GetScript(remoteSelectionScript.ToString()));

            ArrayList controlsList = new ArrayList();
            int       groupsCount  = Groups.GetUpperBound(0) + 1;
            InnerControls = new List <CMSUserControl>(groupsCount);

            // Process the groups
            for (identifier = 0; identifier < groupsCount; identifier++)
            {
                // Check array dimensions
                if (Groups.GetUpperBound(1) < 2)
                {
                    if (ShowErrors)
                    {
                        Controls.Add(GetError(GetString("unimenu.wrongdimensions")));
                    }
                    continue;
                }

                string captionText        = Groups[identifier, 0];
                string contentControlPath = Groups[identifier, 1];
                string cssClass           = Groups[identifier, 2];
                int    uiElementId        = (Groups.GetUpperBound(1) == 3 ? ValidationHelper.GetInteger(Groups[identifier, 3], 0) : 0);

                // Caption and path to content control have to be entered
                if (string.IsNullOrEmpty(captionText))
                {
                    if (ShowErrors)
                    {
                        Controls.Add(GetError(GetString("unimenu.captionempty")));
                    }
                    continue;
                }
                if (string.IsNullOrEmpty(contentControlPath) && (uiElementId <= 0))
                {
                    if (ShowErrors)
                    {
                        Controls.Add(GetError(GetString("unimenu.pathempty")));
                    }
                    continue;
                }

                CMSPanel groupPanel = new CMSPanel()
                {
                    ID      = "pnlGroup" + identifier,
                    ShortID = "g" + identifier
                };

                // Add controls to main panel
                groupPanel.Controls.Add(GetLeftBorder());

                bool createGroup = false;

                if (!string.IsNullOrEmpty(contentControlPath))
                {
                    CMSUserControl contentControl = null;
                    try
                    {
                        // Try to load content control
                        contentControl         = (CMSUserControl)Page.LoadControl(contentControlPath);
                        contentControl.ID      = "ctrlContent" + identifier;
                        contentControl.ShortID = "c" + identifier;
                    }
                    catch
                    {
                        Controls.Add(GetError(GetString("unimenu.errorloadingcontrol")));
                        continue;
                    }
                    Panel innerPanel = GetContent(contentControl, 0, captionText);
                    if (innerPanel != null)
                    {
                        groupPanel.Controls.Add(innerPanel);
                        createGroup = true;
                    }

                    InnerControls.Insert(identifier, (CMSUserControl)contentControl);
                }
                else if (uiElementId > 0)
                {
                    Panel innerPanel = GetContent(null, uiElementId, captionText);
                    if (innerPanel != null)
                    {
                        groupPanel.Controls.Add(innerPanel);
                        createGroup = true;
                    }
                }

                groupPanel.Controls.Add(GetRightBorder());

                groupPanel.CssClass = cssClass;

                // Add group panel to list of controls
                if (createGroup)
                {
                    mMenuEmpty = false;
                    controlsList.Add(groupPanel);

                    // Insert separator after group
                    if (groupsCount > 1)
                    {
                        controlsList.Add(GetGroupSeparator());
                    }
                }
            }

            // Handle the preselection
            if (preselectedPanel != null)
            {
                // Add the selected class to the preselected button
                preselectedPanel.CssClass += " Selected";
            }
            else if ((firstPanel != null) && HighlightFirstItem)
            {
                // Add the selected class to the first button
                firstPanel.CssClass += " Selected";
            }

            // Add group panels to to the control
            foreach (Control control in controlsList)
            {
                pnlControls.Controls.Add(control);
            }
        }
        else
        {
            Controls.Add(GetError(GetString("unimenu.wrongdimensions")));
        }
    }
示例#16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            if (Buttons != null)
            {
                if (AllowSelection)
                {
                    ScriptHelper.RegisterJQuery(Page);
                    StringBuilder selectionScript = new StringBuilder();
                    selectionScript.AppendLine("function SelectButton(elem)");
                    selectionScript.AppendLine("{");
                    selectionScript.AppendLine("    var selected = '" + SelectedSuffix + "';");
                    selectionScript.AppendLine("    var jElem =$j(elem);");
                    // Get first parent table
                    selectionScript.AppendLine("    var parentTable = jElem.parents('table').get(0);");
                    selectionScript.AppendLine("    if (parentTable != null) {");
                    // Remove selected class from current group of buttons
                    selectionScript.AppendLine("        $j(parentTable).find('.' + elem.className).removeClass(selected);");
                    selectionScript.AppendLine("    }");
                    selectionScript.AppendLine("    jElem.addClass(selected);");
                    selectionScript.AppendLine("}");
                    ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "selectionScript", ScriptHelper.GetScript(selectionScript.ToString()));

                    StringBuilder indexSelection = new StringBuilder();
                    indexSelection.AppendLine("function SelectButtonIndex_" + ClientID + "(index)");
                    indexSelection.AppendLine("{");
                    indexSelection.AppendLine("    var elem = document.getElementById('" + ClientID + "_" + BUTTON_PANEL_SHORTID + "'+index);");
                    indexSelection.AppendLine("    SelectButton(elem);");
                    indexSelection.AppendLine("");
                    indexSelection.AppendLine("}");
                    ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "indexSelection_" + ClientID, ScriptHelper.GetScript(indexSelection.ToString()));
                }

                if (AllowToggle)
                {
                    // Toggle script
                    StringBuilder toggleScript = new StringBuilder();
                    toggleScript.AppendLine("function ToggleButton(elem)");
                    toggleScript.AppendLine("{");
                    toggleScript.AppendLine("    var selected = '" + SelectedSuffix.Trim() + "';");
                    toggleScript.AppendLine("    var jElem =$j(elem);");
                    // Get first parent table
                    toggleScript.AppendLine("    jElem.toggleClass(selected);");
                    toggleScript.AppendLine("}");
                    ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "toggleScript", ScriptHelper.GetScript(toggleScript.ToString()));
                }

                int buttonsCount = Buttons.GetUpperBound(0) + 1;
                InnerControls = new List <Panel>(buttonsCount);
                for (identifier = 0; identifier < buttonsCount; identifier++)
                {
                    // Check array dimensions
                    if (Buttons.GetUpperBound(1) != 8)
                    {
                        Controls.Add(GetError(GetString("unimenubuttons.wrongdimensions")));
                        continue;
                    }

                    string     caption     = Buttons[identifier, 0];
                    string     tooltip     = Buttons[identifier, 1];
                    string     cssClass    = Buttons[identifier, 2];
                    string     onClick     = Buttons[identifier, 3];
                    string     redirectUrl = Buttons[identifier, 4];
                    string     imagePath   = Buttons[identifier, 5];
                    string     alt         = Buttons[identifier, 6];
                    string     align       = Buttons[identifier, 7];
                    string     minWidth    = Buttons[identifier, 8];
                    ImageAlign imageAlign  = ParseImageAlign(align);

                    // Generate button image
                    Image buttonImage = new Image();
                    buttonImage.ID = "img" + identifier;
                    buttonImage.EnableViewState = false;
                    buttonImage.AlternateText   = alt ?? caption;
                    if (!string.IsNullOrEmpty(imagePath))
                    {
                        buttonImage.ImageUrl = ResolveUrl(imagePath);
                    }
                    buttonImage.ImageAlign = imageAlign;

                    // Generate button text
                    Literal captionLiteral = new Literal();
                    captionLiteral.ID = "ltlCaption" + identifier;
                    captionLiteral.EnableViewState = false;
                    string separator = (imageAlign == ImageAlign.Top) ? "<br />" : "\n";
                    captionLiteral.Text = separator + caption;

                    // Generate button link
                    HyperLink buttonLink = new HyperLink();
                    buttonLink.ID = "btn" + identifier;
                    buttonLink.EnableViewState = false;

                    buttonLink.Controls.Add(buttonImage);
                    buttonLink.Controls.Add(captionLiteral);

                    if (!string.IsNullOrEmpty(redirectUrl))
                    {
                        buttonLink.NavigateUrl = ResolveUrl(redirectUrl);
                    }

                    // Generate left border
                    CMSPanel pnlLeft = new CMSPanel();
                    pnlLeft.ID      = "pnlLeft" + identifier;
                    pnlLeft.ShortID = "pl" + identifier;

                    pnlLeft.EnableViewState = false;
                    pnlLeft.CssClass        = "Left" + cssClass;

                    // Generate middle part of button
                    CMSPanel pnlMiddle = new CMSPanel();
                    pnlMiddle.ID      = "pnlMiddle" + identifier;
                    pnlMiddle.ShortID = "pm" + identifier;

                    pnlMiddle.EnableViewState = false;
                    pnlMiddle.CssClass        = "Middle" + cssClass;
                    pnlMiddle.Controls.Add(buttonLink);
                    if (!string.IsNullOrEmpty(minWidth))
                    {
                        pnlMiddle.Style.Add("min-width", minWidth + "px");

                        // IE7 issue with min-width
                        CMSPanel pnlMiddleTmp = new CMSPanel();
                        pnlMiddleTmp.EnableViewState = false;
                        pnlMiddleTmp.Style.Add("width", minWidth + "px");
                        pnlMiddle.Controls.Add(pnlMiddleTmp);
                    }

                    // Generate right border
                    CMSPanel pnlRight = new CMSPanel();
                    pnlRight.ID      = "pnlRight" + identifier;
                    pnlRight.ShortID = "pr" + identifier;

                    pnlRight.EnableViewState = false;
                    pnlRight.CssClass        = "Right" + cssClass;

                    // Generate whole button
                    CMSPanel pnlButton = new CMSPanel();
                    pnlButton.ID      = "pnlButton" + identifier;
                    pnlButton.ShortID = BUTTON_PANEL_SHORTID + identifier;

                    pnlButton.EnableViewState = false;
                    if ((AllowSelection || AllowToggle) && (identifier == SelectedIndex))
                    {
                        cssClass += SelectedSuffix;
                    }

                    pnlButton.CssClass = cssClass;

                    if (AllowToggle)
                    {
                        pnlButton.CssClass += " Toggle";
                    }

                    //Generate button table (IE7 issue)
                    Table     tabButton     = new Table();
                    TableRow  tabRow        = new TableRow();
                    TableCell tabCellLeft   = new TableCell();
                    TableCell tabCellMiddle = new TableCell();
                    TableCell tabCellRight  = new TableCell();

                    tabButton.CellPadding = 0;
                    tabButton.CellSpacing = 0;

                    tabButton.Rows.Add(tabRow);
                    tabRow.Cells.Add(tabCellLeft);
                    tabRow.Cells.Add(tabCellMiddle);
                    tabRow.Cells.Add(tabCellRight);

                    // Add inner controls
                    tabCellLeft.Controls.Add(pnlLeft);
                    tabCellMiddle.Controls.Add(pnlMiddle);
                    tabCellRight.Controls.Add(pnlRight);

                    pnlButton.Controls.Add(tabButton);

                    pnlButton.ToolTip = tooltip ?? caption;

                    if (AllowSelection)
                    {
                        onClick = "SelectButton(this);" + onClick;
                    }
                    else if (AllowToggle)
                    {
                        onClick = "ToggleButton(this);" + onClick;
                    }

                    pnlButton.Attributes["onclick"] = CheckChanges ? "if (CheckChanges()) {" + onClick + "}" : onClick;

                    // In case of horizontal layout
                    if (HorizontalLayout)
                    {
                        // Stack buttons underneath
                        pnlButton.Style.Add("clear", "both");
                    }
                    else
                    {
                        // Stack buttons side-by-sode
                        pnlButton.Style.Add("float", "left");
                    }

                    // Fill collection of buttons
                    InnerControls.Insert(identifier, pnlButton);
                }

                // Calculate number of needed panels
                int panelCount = InnerControls.Count / MaximumItems;
                if ((InnerControls.Count % MaximumItems) > 0)
                {
                    panelCount++;
                }

                // Initialize list of panels
                List <Panel> panels = new List <Panel>();

                Table    tabGroup    = new Table();
                TableRow tabGroupRow = new TableRow();

                tabGroup.CellPadding = 0;
                tabGroup.CellSpacing = 0;
                tabGroup.Rows.Add(tabGroupRow);

                // Fill each panel
                for (int panelIndex = 0; panelIndex < panelCount; panelIndex++)
                {
                    // Create new instance of panel
                    CMSPanel outerPanel = new CMSPanel();
                    outerPanel.EnableViewState = false;
                    outerPanel.ID      = "pnlOuter" + panelIndex;
                    outerPanel.ShortID = "po" + panelIndex;

                    // In case of horizontal layout
                    if (HorizontalLayout)
                    {
                        // Stack panels side-by-side
                        outerPanel.Style.Add("float", "left");
                    }
                    else
                    {
                        // Stack panels underneath
                        outerPanel.Style.Add("clear", "both");
                    }
                    // Add buttons to panel
                    for (int buttonIndex = (panelIndex * MaximumItems); buttonIndex < (panelCount * MaximumItems) + panelCount; buttonIndex++)
                    {
                        if (((buttonIndex % MaximumItems) < MaximumItems) && (InnerControls.Count > buttonIndex))
                        {
                            outerPanel.Controls.Add(InnerControls[buttonIndex]);
                        }
                    }
                    // Add panel to collection of panels
                    panels.Add(outerPanel);
                }

                // Add all panels to control
                foreach (Panel panel in panels)
                {
                    TableCell tabGroupCell = new TableCell();
                    tabGroupCell.VerticalAlign = VerticalAlign.Top;

                    tabGroupCell.Controls.Add(panel);
                    tabGroupRow.Cells.Add(tabGroupCell);
                }

                Controls.Add(tabGroup);
            }
            else
            {
                Controls.Add(GetError(GetString("unimenubuttons.wrongdimensions")));
            }
        }
    }
示例#17
0
    /// <summary>
    /// Generates panel with buttons loaded from given UI Element.
    /// </summary>
    /// <param name="uiElementId">ID of the UI Element</param>
    protected Panel GetButtons(int uiElementId)
    {
        const int bigButtonMinimalWidth   = 40;
        const int smallButtonMinimalWidth = 66;

        Panel pnlButtons = null;

        // Load the buttons manually from UI Element
        DataSet ds = UIElementInfoProvider.GetChildUIElements(uiElementId);

        // When no child found
        if (DataHelper.DataSourceIsEmpty(ds))
        {
            // Try to use group element as button
            ds = UIElementInfoProvider.GetUIElements("ElementID = " + uiElementId, null);

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                DataRow dr  = ds.Tables[0].Rows[0];
                string  url = ValidationHelper.GetString(dr["ElementTargetURL"], "");

                // Use group element as button only if it has URL specified
                if (string.IsNullOrEmpty(url))
                {
                    ds = null;
                }
            }
        }

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            // Filter the dataset according to UI Profile
            FilterElements(ds);

            int small = 0;
            int count = ds.Tables[0].Rows.Count;

            // No buttons, render nothing
            if (count == 0)
            {
                return(null);
            }

            // Prepare the panel
            pnlButtons          = new Panel();
            pnlButtons.CssClass = "ActionButtons";

            // Prepare the table
            Table    tabGroup    = new Table();
            TableRow tabGroupRow = new TableRow();

            tabGroup.CellPadding        = 0;
            tabGroup.CellSpacing        = 0;
            tabGroup.EnableViewState    = false;
            tabGroupRow.EnableViewState = false;
            tabGroup.Rows.Add(tabGroupRow);

            List <Panel> panels = new List <Panel>();

            for (int i = 0; i < count; i++)
            {
                // Get current and next button
                UIElementInfo uiElement     = new UIElementInfo(ds.Tables[0].Rows[i]);
                UIElementInfo uiElementNext = null;
                if (i < count - 1)
                {
                    uiElementNext = new UIElementInfo(ds.Tables[0].Rows[i + 1]);
                }

                // Set the first button
                if (mFirstUIElement == null)
                {
                    mFirstUIElement = uiElement;
                }

                // Get the sizes of current and next button. Button is large when it is the only in the group
                bool isSmall     = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (count > 1);
                bool isResized   = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (!isSmall);
                bool isNextSmall = (uiElementNext != null) && (uiElementNext.ElementSize == UIElementSizeEnum.Regular);

                // Set the CSS class according to the button size
                string cssClass    = (isSmall ? "SmallButton" : "BigButton");
                string elementName = uiElement.ElementName;

                // Create main button panel
                CMSPanel pnlButton = new CMSPanel()
                {
                    ID      = "pnlButton" + elementName,
                    ShortID = "b" + elementName
                };

                pnlButton.Attributes.Add("name", elementName);
                pnlButton.CssClass = cssClass;

                // Remember the first button
                if (firstPanel == null)
                {
                    firstPanel = pnlButton;
                }

                // Remember the selected button
                if ((preselectedPanel == null) && elementName.Equals(HighlightItem, StringComparison.InvariantCultureIgnoreCase))
                {
                    preselectedPanel = pnlButton;

                    // Set the selected button
                    if (mHighlightedUIElement == null)
                    {
                        mHighlightedUIElement = uiElement;
                    }
                }

                // URL or behavior
                string url = uiElement.ElementTargetURL;

                if (!string.IsNullOrEmpty(url) && url.StartsWith("javascript:", StringComparison.InvariantCultureIgnoreCase))
                {
                    pnlButton.Attributes["onclick"] = url.Substring("javascript:".Length);
                }
                else if (!string.IsNullOrEmpty(url) && !url.StartsWith("javascript:", StringComparison.InvariantCultureIgnoreCase))
                {
                    string buttonSelection = (RememberSelectedItem ? "SelectButton(this);" : "");

                    // Ensure hash code if required
                    string targetUrl = CMSContext.ResolveMacros(URLHelper.EnsureHashToQueryParameters(url));

                    if (!String.IsNullOrEmpty(TargetFrameset))
                    {
                        pnlButton.Attributes["onclick"] = String.Format("{0}parent.frames['{1}'].location.href = '{2}';", buttonSelection, TargetFrameset, URLHelper.ResolveUrl(targetUrl));
                    }
                    else
                    {
                        pnlButton.Attributes["onclick"] = String.Format("{0}self.location.href = '{1}';", buttonSelection, URLHelper.ResolveUrl(targetUrl));
                    }

                    if (OnButtonCreated != null)
                    {
                        OnButtonCreated(uiElement, targetUrl);
                    }
                }

                // Tooltip
                if (!string.IsNullOrEmpty(uiElement.ElementDescription))
                {
                    pnlButton.ToolTip = ResHelper.LocalizeString(uiElement.ElementDescription);
                }
                else
                {
                    pnlButton.ToolTip = ResHelper.LocalizeString(uiElement.ElementCaption);
                }
                pnlButton.EnableViewState = false;

                // Ensure correct grouping of small buttons
                if (isSmall && (small == 0))
                {
                    small++;

                    Panel pnlSmallGroup = new Panel()
                    {
                        ID = "pnlGroupSmall" + uiElement.ElementName
                    };
                    if (IsRTL)
                    {
                        pnlSmallGroup.Style.Add("float", "right");
                        pnlSmallGroup.Style.Add("text-align", "right");
                    }
                    else
                    {
                        pnlSmallGroup.Style.Add("float", "left");
                        pnlSmallGroup.Style.Add("text-align", "left");
                    }

                    pnlSmallGroup.EnableViewState = false;
                    pnlSmallGroup.Controls.Add(pnlButton);
                    panels.Add(pnlSmallGroup);
                }

                // Generate button image
                Image buttonImage = new Image()
                {
                    ID         = "imgButton" + uiElement.ElementName,
                    ImageAlign = (isSmall ? ImageAlign.AbsMiddle : ImageAlign.Top)
                };
                if (!string.IsNullOrEmpty(uiElement.ElementIconPath))
                {
                    string iconPath = GetImageUrl(uiElement.ElementIconPath);

                    // Check if element size was changed
                    if (isResized)
                    {
                        // Try to get larger icon
                        string largeIconPath = iconPath.Replace("list.png", "module.png");
                        try
                        {
                            if (CMS.IO.File.Exists(MapPath(largeIconPath)))
                            {
                                iconPath = largeIconPath;
                            }
                        }
                        catch { }
                    }

                    buttonImage.ImageUrl = iconPath;
                }
                else
                {
                    // Load defaul module icon if ElementIconPath is not specified
                    buttonImage.ImageUrl = GetImageUrl("CMSModules/module.png");
                }
                buttonImage.EnableViewState = false;

                // Generate button text
                Literal captionLiteral = new Literal()
                {
                    ID              = "ltlCaption" + uiElement.ElementName,
                    Text            = (isSmall ? "\n" : "<br />") + ResHelper.LocalizeString(uiElement.ElementCaption),
                    EnableViewState = false
                };

                // Generate button link
                HyperLink buttonLink = new HyperLink()
                {
                    ID = "lnkButton" + uiElement.ElementName
                };
                buttonLink.Controls.Add(buttonImage);
                buttonLink.Controls.Add(captionLiteral);
                buttonLink.EnableViewState = false;

                //Generate button table (IE7 issue)
                Table     tabButton     = new Table();
                TableRow  tabRow        = new TableRow();
                TableCell tabCellLeft   = new TableCell();
                TableCell tabCellMiddle = new TableCell();
                TableCell tabCellRight  = new TableCell();

                tabButton.CellPadding = 0;
                tabButton.CellSpacing = 0;

                tabButton.EnableViewState     = false;
                tabRow.EnableViewState        = false;
                tabCellLeft.EnableViewState   = false;
                tabCellMiddle.EnableViewState = false;
                tabCellRight.EnableViewState  = false;

                tabButton.Rows.Add(tabRow);
                tabRow.Cells.Add(tabCellLeft);
                tabRow.Cells.Add(tabCellMiddle);
                tabRow.Cells.Add(tabCellRight);

                // Generate left border
                Panel pnlLeft = new Panel()
                {
                    ID              = "pnlLeft" + uiElement.ElementName,
                    CssClass        = "Left" + cssClass,
                    EnableViewState = false
                };

                // Generate middle part of button
                Panel pnlMiddle = new Panel()
                {
                    ID       = "pnlMiddle" + uiElement.ElementName,
                    CssClass = "Middle" + cssClass
                };
                pnlMiddle.Controls.Add(buttonLink);
                Panel pnlMiddleTmp = new Panel()
                {
                    EnableViewState = false
                };
                if (isSmall)
                {
                    pnlMiddle.Style.Add("min-width", smallButtonMinimalWidth + "px");
                    // IE7 issue with min-width
                    pnlMiddleTmp.Style.Add("width", smallButtonMinimalWidth + "px");
                    pnlMiddle.Controls.Add(pnlMiddleTmp);
                }
                else
                {
                    pnlMiddle.Style.Add("min-width", bigButtonMinimalWidth + "px");
                    // IE7 issue with min-width
                    pnlMiddleTmp.Style.Add("width", bigButtonMinimalWidth + "px");
                    pnlMiddle.Controls.Add(pnlMiddleTmp);
                }
                pnlMiddle.EnableViewState = false;

                // Generate right border
                Panel pnlRight = new Panel()
                {
                    ID              = "pnlRight" + uiElement.ElementName,
                    CssClass        = "Right" + cssClass,
                    EnableViewState = false
                };

                // Add inner controls
                tabCellLeft.Controls.Add(pnlLeft);
                tabCellMiddle.Controls.Add(pnlMiddle);
                tabCellRight.Controls.Add(pnlRight);

                pnlButton.Controls.Add(tabButton);

                // If there were two small buttons in a row end the grouping div
                if ((small == 2) || (isSmall && !isNextSmall))
                {
                    small = 0;

                    // Add the button to the small buttons grouping panel
                    panels[panels.Count - 1].Controls.Add(pnlButton);
                }
                else
                {
                    if (small == 0)
                    {
                        // Add the generated button into collection
                        panels.Add(pnlButton);
                    }
                }
                if (small == 1)
                {
                    small++;
                }
            }

            // Add all panels to control
            foreach (Panel panel in panels)
            {
                TableCell tabGroupCell = new TableCell()
                {
                    VerticalAlign   = VerticalAlign.Top,
                    EnableViewState = false
                };

                tabGroupCell.Controls.Add(panel);
                tabGroupRow.Cells.Add(tabGroupCell);
            }

            pnlButtons.Controls.Add(tabGroup);
        }

        return(pnlButtons);
    }
    /// <summary>
    /// Render Folder icon preview HTML.
    /// </summary>
    /// <param name="defaultValue">Determine default value which should be checked</param>
    private void GetFolderIconPreview(string defaultValue)
    {
        foreach (string[] folderInfo in GetPredefinedIconFoldersSet())
        {
            string dirName = folderInfo[0];
            string iconName = folderInfo[1];
            string path = GetImagePath(IconsFolder + "/" + dirName + "/" + iconName);

            // Icon image
            CMSImage imgFolder = new CMSImage
            {
                ImageUrl = UIHelper.ResolveImageUrl(path),
                AlternateText = iconName,
                EnableViewState = false
            };

            // Icon panel
            CMSPanel pnlFolder = new CMSPanel
            {
                EnableViewState = false
            };
            pnlFolder.AddCssClass("iconItem");
            pnlFolder.Controls.Add(imgFolder);
            pnlFolder.Attributes.Add("onclick", string.Format("SelectItem_{0}(this);SetAction_{0}('changefolder','{1}');RaiseHiddenPostBack_{0}();", ClientID, dirName));

            // Check for selected value
            if ((defaultValue == String.Empty) || (dirName.ToLowerCSafe() == defaultValue.ToLowerCSafe()))
            {
                defaultValue = dirName;
                pnlFolder.AddCssClass("selected");
            }

            // Add controls
            pnlMain.Controls.Add(pnlFolder);
        }

        // Actualize value of current icon folder
        CurrentIconFolder = defaultValue;
    }
示例#19
0
    /// <summary>
    /// Method for adding sub menu item into menu.
    /// </summary>
    /// <param name="pnlMenu">Menu container control</param>
    /// <param name="item">Sub menu item definition</param>
    /// <param name="cssClass">Button css class</param>
    /// <param name="subIdentifier">Button identifier</param>
    private void AddSubMenuItem(CMSPanel pnlMenu, SubMenuItem item, string cssClass, int subIdentifier)
    {
        if (String.IsNullOrEmpty(item.ControlPath))
        {
            // Generate sub item
            CMSPanel pnlItem = new CMSPanel();
            pnlItem.ID       = "pnlSubItem" + subIdentifier;
            pnlItem.ShortID  = "pi" + subIdentifier;
            pnlItem.CssClass = "Item ItemPadding";
            pnlItem.ToolTip  = item.Tooltip;

            if (!String.IsNullOrEmpty(item.OnClientClick))
            {
                pnlItem.Attributes["onclick"] = item.OnClientClick.Replace("##BUTTON##", "$cmsj(this).parents('." + cssClass + "').get(0)");
            }

            if (!String.IsNullOrEmpty(item.ImagePath))
            {
                string altText = String.IsNullOrEmpty(item.ImageAltText) ? item.Text : item.ImageAltText;

                // Generate sub items text
                CMSPanel pnlIcon = new CMSPanel();
                pnlIcon.ID       = "pnlIcon";
                pnlIcon.ShortID  = "pii" + subIdentifier;
                pnlIcon.CssClass = "Icon";
                Literal subItemImage = new Literal();
                subItemImage.ID = "ltlSubItemImage" + subIdentifier;
                subItemImage.EnableViewState = false;
                subItemImage.Text            = String.Format("<img src=\"{0}\" alt=\"{1}\" />&nbsp;",
                                                             ResolveUrl(item.ImagePath),
                                                             GetString(altText));

                pnlIcon.Controls.Add(subItemImage);
                pnlItem.Controls.Add(pnlIcon);
            }

            // Add custom HTML attributes
            foreach (var htmlAttribute in item.HtmlAttributes)
            {
                pnlItem.Attributes[htmlAttribute.Key] = HTMLHelper.HTMLEncode(htmlAttribute.Value);
            }

            // Generate sub items text
            CMSPanel pnlText = new CMSPanel();
            pnlText.ID       = "pnlText";
            pnlText.ShortID  = "pt" + subIdentifier;
            pnlText.CssClass = "Name";
            Label subItemText = new Label();
            subItemText.ID = "ltlSubItem" + subIdentifier;
            subItemText.EnableViewState = false;
            subItemText.Text            = GetString(item.Text);

            pnlText.Controls.Add(subItemText);
            pnlItem.Controls.Add(pnlText);

            if (!String.IsNullOrEmpty(item.RightImagePath))
            {
                string altText = String.IsNullOrEmpty(item.RightImageAltText) ? item.Text : item.RightImageAltText;

                // Generate sub item right icon
                Literal subRightItemImage = new Literal();
                subRightItemImage.ID = "ltlSubRightItemImage" + subIdentifier;
                subRightItemImage.EnableViewState = false;
                subRightItemImage.Text            = String.Format("<img class=\"RightIcon\" src=\"{0}\" alt=\"{1}\" />&nbsp;",
                                                                  ResolveUrl(item.RightImagePath),
                                                                  GetString(altText));

                CMSPanel pnlRightIcon = CreateRightIconPanel(subIdentifier);
                pnlRightIcon.Controls.Add(subRightItemImage);
                pnlItem.Controls.Add(pnlRightIcon);
            }
            else if (!string.IsNullOrEmpty(item.RightImageIconClass))
            {
                string altText = String.IsNullOrEmpty(item.RightImageAltText) ? item.Text : item.RightImageAltText;

                var icon = new CMSIcon
                {
                    ID = "ico" + subIdentifier,
                    EnableViewState = false,
                    ToolTip         = GetString(altText),
                    CssClass        = "cms-icon-80 " + item.RightImageIconClass
                };

                CMSPanel pnlRightIcon = CreateRightIconPanel(subIdentifier);
                pnlRightIcon.Controls.Add(icon);
                pnlItem.Controls.Add(pnlRightIcon);
            }

            pnlMenu.Controls.Add(pnlItem);
        }
        else
        {
            // Load menu item control
            Control ctrl = LoadUserControl(item.ControlPath);
            if (ctrl != null)
            {
                pnlMenu.Controls.Add(ctrl);
            }
        }
    }
    /// <summary>
    /// Generate apropriate icons if source folder is changed.
    /// </summary>
    /// <param name="folderName">Name of selected folder</param>
    /// <param name="defaultValue">Determine default value which should be checked</param>
    private void HandleChangeFolderAction(string folderName, string defaultValue)
    {
        try
        {
            DirectoryInfo di = DirectoryInfo.New(DirectoryHelper.CombinePath(FullIconFolderPath, folderName));
            string directoryName = di.Name;
            ArrayList iconList = GetIconsInFolder(di);
            string defaultIcon = (iconList.Contains(defaultValue)) ? defaultValue : String.Empty;

            foreach (string fileInfo in iconList)
            {
                string path = GetImagePath(IconsFolder + "/" + directoryName + "/" + fileInfo);

                // Size caption
                LocalizedLabel lblIcon = new LocalizedLabel
                {
                    ResourceString = "iconcaption." + fileInfo.Remove(fileInfo.LastIndexOfCSafe('.')),
                    EnableViewState = false
                };

                // Icon image
                CMSImage imgIcon = new CMSImage
                {
                    ImageUrl = UIHelper.ResolveImageUrl(path),
                    AlternateText = fileInfo,
                    EnableViewState = false
                };

                // Icon panel
                CMSPanel pnlIcon = new CMSPanel
                {
                    CssClass = "iconItem",
                    EnableViewState = false
                };
                pnlIcon.Attributes.Add("onclick", string.Format("SelectItem_{0}(this);SetAction_{0}('select','{1}');RaiseHiddenPostBack_{0}();", ClientID, fileInfo));
                pnlIcon.Controls.Add(imgIcon);
                pnlIcon.Controls.Add(lblIcon);

                // Check for selected value
                if ((defaultIcon == String.Empty) || (fileInfo.ToLowerCSafe() == defaultValue.ToLowerCSafe()))
                {
                    defaultIcon = fileInfo;
                    pnlIcon.AddCssClass("selected");
                }

                // Add controls
                pnlChild.Controls.Add(pnlIcon);
            }
            CurrentIcon = defaultIcon;
        }
        catch (Exception ex)
        {
            lblError.Text += "[IconSelector.HandleChangeFolderAction]: Error getting icons in selected icon folder. Original exception: " + ex.Message;
        }
        CurrentIconFolder = folderName;
        pnlUpdateIcons.Update();
    }
示例#21
0
    /// <summary>
    /// Method for adding button to controls.
    /// </summary>
    /// <param name="outerPanel">Panel to be added to</param>
    /// <param name="identifier">Index of button</param>
    private void AddButtonTo(CMSPanel outerPanel, int identifier)
    {
        MenuItem   button      = Buttons[identifier];
        string     caption     = button.Text;
        string     tooltip     = button.Tooltip;
        string     cssClass    = button.CssClass;
        string     onClick     = button.OnClientClick;
        string     redirectUrl = button.RedirectUrl;
        string     imagePath   = button.ImagePath;
        string     iconClass   = button.IconClass;
        string     alt         = button.ImageAltText;
        int        minWidth    = button.MinimalWidth;
        ImageAlign imageAlign  = GetImageAlign(button.ImageAlign);

        // Generate button image
        WebControl image = null;

        if (!string.IsNullOrEmpty(imagePath))
        {
            var buttonImage = new Image
            {
                ID              = "img" + identifier,
                CssClass        = "MenuButtonImage",
                EnableViewState = false,
                AlternateText   = alt ?? caption,
                ImageAlign      = imageAlign,
                ImageUrl        = ResolveUrl(imagePath)
            };
            image = buttonImage;
        }
        else if (!string.IsNullOrEmpty(iconClass))
        {
            var icon = new CMSIcon
            {
                ID = "ico" + identifier,
                EnableViewState = false,
                ToolTip         = tooltip,
                CssClass        = "cms-icon-80 " + iconClass
            };
            image = icon;
        }

        // Generate button text
        Literal captionLiteral = new Literal();

        captionLiteral.ID = "ltlCaption" + identifier;
        captionLiteral.EnableViewState = false;
        string separator = (imageAlign == ImageAlign.Top) ? "<br />" : "\n";

        captionLiteral.Text = String.Format("{0}<span class=\"MenuButtonText\">{1}</span>", separator, caption);

        CMSPanel pnlSubItems = null;

        if (button.SubItems.Count > 0)
        {
            // Ensure jQuery tool is loaded
            ScriptHelper.RegisterJQueryTools(Page);

            // Register support script
            ScriptHelper.RegisterScriptFile(Page, "~/CMSAdminControls/UI/UniMenu/UniMenu.js");

            // Append sub-menu toggle script
            onClick = "CMSUniMenu.ToogleSubMenu(this);" + onClick;

            // Append arrow down image for indication sub menu
            captionLiteral.Text += @"<i aria-hidden=""true"" class=""icon-caret-right-down cms-icon-30""></i>";

            // Create submenu
            pnlSubItems = CreateSubMenu(button, cssClass, identifier);
        }

        // Generate button link
        HyperLink buttonLink = new HyperLink();

        buttonLink.ID = "btn" + identifier;
        buttonLink.EnableViewState = false;

        if (image != null)
        {
            buttonLink.Controls.Add(image);
        }
        buttonLink.Controls.Add(captionLiteral);

        if (!string.IsNullOrEmpty(redirectUrl))
        {
            buttonLink.NavigateUrl = ResolveUrl(redirectUrl);
        }

        // Generate left border
        CMSPanel pnlLeft = new CMSPanel();

        pnlLeft.ID      = "pnlLeft" + identifier;
        pnlLeft.ShortID = "pl" + identifier;

        pnlLeft.EnableViewState = false;
        pnlLeft.CssClass        = "Left" + cssClass;

        // Generate middle part of button
        CMSPanel pnlMiddle = new CMSPanel();

        pnlMiddle.ID      = "pnlMiddle" + identifier;
        pnlMiddle.ShortID = "pm" + identifier;

        pnlMiddle.EnableViewState = false;
        pnlMiddle.CssClass        = "Middle" + cssClass;
        pnlMiddle.Controls.Add(buttonLink);
        if (minWidth > 0)
        {
            pnlMiddle.Style.Add("min-width", minWidth + "px");

            // IE7 issue with min-width
            CMSPanel pnlMiddleTmp = new CMSPanel();
            pnlMiddleTmp.EnableViewState = false;
            pnlMiddleTmp.Style.Add("width", minWidth + "px");
            pnlMiddle.Controls.Add(pnlMiddleTmp);
        }

        // Add sub items if exists
        if (pnlSubItems != null)
        {
            pnlMiddle.Controls.Add(pnlSubItems);
        }

        // Generate right border
        CMSPanel pnlRight = new CMSPanel();

        pnlRight.ID      = "pnlRight" + identifier;
        pnlRight.ShortID = "pr" + identifier;

        pnlRight.EnableViewState = false;
        pnlRight.CssClass        = "Right" + cssClass;

        // Generate whole button
        CMSPanel pnlButton = new CMSPanel();

        pnlButton.ID      = "pnlButton" + identifier;
        pnlButton.ShortID = BUTTON_PANEL_SHORTID + identifier;

        // Propagate attributes to panel for JavaScript use
        foreach (var entry in button.Attributes)
        {
            pnlButton.Attributes.Add(entry.Key, entry.Value);
        }

        pnlButton.EnableViewState = false;

        if (button.AllowToggle && button.IsToggled)
        {
            cssClass += SelectedSuffix;
        }

        pnlButton.CssClass = cssClass;

        if (button.AllowToggle)
        {
            pnlButton.CssClass += " Toggle";
            EnsureAllowToggleScript();
        }

        //Generate button table (IE7 issue)
        Table     tabButton     = new Table();
        TableRow  tabRow        = new TableRow();
        TableCell tabCellLeft   = new TableCell();
        TableCell tabCellMiddle = new TableCell();
        TableCell tabCellRight  = new TableCell();

        tabButton.CellPadding = 0;
        tabButton.CellSpacing = 0;

        tabButton.Rows.Add(tabRow);
        tabRow.Cells.Add(tabCellLeft);
        tabRow.Cells.Add(tabCellMiddle);
        tabRow.Cells.Add(tabCellRight);

        // Add inner controls
        tabCellLeft.Controls.Add(pnlLeft);
        tabCellMiddle.Controls.Add(pnlMiddle);
        tabCellRight.Controls.Add(pnlRight);

        pnlButton.Controls.Add(tabButton);

        pnlButton.ToolTip = tooltip ?? caption;

        outerPanel.Controls.Add(pnlButton);

        if (AllowDraggable)
        {
            mStartupScript.Append(String.Format("$cmsj( '#{0}' ).draggable({{ helper:{1}, scope:'{2}' }});", pnlButton.ClientID, GetDraggableHandler(button.DraggableTemplateHandler), button.DraggableScope));
        }

        if (!AllowSelection && button.AllowToggle)
        {
            onClick = "ToggleButton(this);" + onClick;
        }

        pnlButton.Attributes["onclick"] = CheckChanges ? "if (CheckChanges()) {" + onClick + "}" : onClick;

        // In case of horizontal layout
        if (HorizontalLayout)
        {
            // Stack buttons underneath
            pnlButton.Style.Add("clear", "both");
        }
        else
        {
            // Stack buttons side-by-side
            pnlButton.Style.Add("float", "left");
        }

        if (button.IsSelectable)
        {
            // Collect panel client IDs for JavaScript
            mElemsIds += "#" + pnlButton.ClientID + ",";
            if (AllowSelection && (identifier == SelectedIndex))
            {
                // Button should be selected by default, remember its ClientID for JavaScript
                defaultSelectedClientID = "#" + pnlButton.ClientID;
            }
        }
    }
示例#22
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Groups.Count > 0)
        {
            pnlScrollControls.IsRTL          = IsRTL;
            pnlScrollControls.InnerItemClass = "MiddleBigButton";

            if (RememberSelectedItem)
            {
                RegisterRememberSelectedItemScript();
                RegisterSelectItemScript("SelectButton(this);");
            }
            RegisterSelectItemScript("");

            InnerControls = new List <CMSUserControl>(Groups.Count);

            // Process the groups
            for (identifier = 0; identifier < Groups.Count; identifier++)
            {
                Group group = Groups[identifier];

                if (!string.IsNullOrEmpty(group.ControlPath) && (group.Control == null))
                {
                    group.Control = TryToCreateGroupControlBy(group.ControlPath, identifier);
                }
                if (group.Control != null)
                {
                    int index = identifier;
                    if (InnerControls.Count < index)
                    {
                        index = InnerControls.Count;
                    }

                    InnerControls.Insert(index, group.Control);
                }

                CMSPanel groupPanel = CreateGroupPanelWith(group, identifier);

                if (groupPanel != null)
                {
                    mMenuEmpty = false;
                    CurrentPanelControl.Controls.Add(groupPanel);

                    // Insert separator after group
                    if (Groups.Count > 1)
                    {
                        CurrentPanelControl.Controls.Add(GetGroupSeparator(group));
                    }
                }
            }

            // Handle the pre-selection
            if (preselectedPanel != null)
            {
                // Add the selected class to the preselected button
                preselectedPanel.CssClass += " Selected";
            }
            else if ((firstPanel != null) && HighlightFirstItem)
            {
                // Add the selected class to the first button
                firstPanel.CssClass += " Selected";
            }

            if (!HorizontalLayout)
            {
                CurrentPanelControl.CssClass = "Vertical";
                if (Width > 0)
                {
                    CurrentPanelControl.Attributes.Add("style", "width:" + Width + "px");
                }
            }
        }

        if (DisableScrollPanel)
        {
            pnlScrollControls.Visible = false;
            pnlLeftScroller.Visible   = false;
            pnlRightScroller.Visible  = false;
        }
        else
        {
            pnlControls.Visible = false;
        }
    }
    /// <summary>
    /// Get html for icon.
    /// </summary>
    /// <param name="name">Name</param>
    /// <param name="icon">CMSIcon</param>
    /// <param name="jsHandler">Handler for on click event.</param>
    private static string GetIconHtml(string name, CMSIcon icon, string jsHandler)
    {
        var label = new Label();
        label.Text = name;

        var panel = new CMSPanel();
        panel.Controls.Add(icon);
        panel.Controls.Add(label);
        panel.Attributes.Add("onclick", jsHandler + "return false;");
        string iconHtml = panel.GetRenderedHTML();
        return iconHtml;
    }
    /// <summary>
    /// Generates div with right border.
    /// </summary>
    /// <param name="captionText">Caption of group</param>
    /// <returns>Panel with right border</returns>
    protected Panel GetCaption(string captionText)
    {
        // Create literal with caption
        Literal caption = new Literal()
        {
            ID = "ltlCaption" + identifier,
            EnableViewState = false,
            Text = captionText
        };

        // Create panel and add caption literal
        CMSPanel captionPanel = new CMSPanel()
        {
            ID = "pnlCaption" + identifier,
            ShortID = "cp" + identifier,
            EnableViewState = false,
            CssClass = "UniMenuDescription"
        };
        captionPanel.Controls.Add(caption);

        return captionPanel;
    }
    /// <summary>
    /// Method for adding sub menu item into menu.
    /// </summary>
    /// <param name="pnlMenu">Menu container control</param>
    /// <param name="item">Sub menu item definition</param>
    /// <param name="cssClass">Button css class</param>
    /// <param name="subIdentifier">Button identifier</param>
    private void AddSubMenuItem(CMSPanel pnlMenu, SubMenuItem item, string cssClass, int subIdentifier)
    {
        if (String.IsNullOrEmpty(item.ControlPath))
        {
            // Generate sub item
            CMSPanel pnlItem = new CMSPanel();
            pnlItem.ID = "pnlSubItem" + subIdentifier;
            pnlItem.ShortID = "pi" + subIdentifier;
            pnlItem.CssClass = "Item ItemPadding";
            pnlItem.ToolTip = item.Tooltip;

            if (!String.IsNullOrEmpty(item.OnClientClick))
            {
                pnlItem.Attributes["onclick"] = item.OnClientClick.Replace("##BUTTON##", "$j(this).parents('." + cssClass + "').get(0)");
            }

            if (!String.IsNullOrEmpty(item.ImagePath))
            {
                string altText = String.IsNullOrEmpty(item.ImageAltText) ? item.Text : item.ImageAltText;

                // Generate sub items text
                CMSPanel pnlIcon = new CMSPanel();
                pnlIcon.ID = "pnlIcon";
                pnlIcon.ShortID = "pii" + subIdentifier;
                pnlIcon.CssClass = "Icon";
                Literal subItemImage = new Literal();
                subItemImage.ID = "ltlSubItemImage" + subIdentifier;
                subItemImage.EnableViewState = false;
                subItemImage.Text = String.Format("<img src=\"{0}\" alt=\"{1}\" />&nbsp;",
                        ResolveUrl(item.ImagePath),
                        GetString(altText));

                pnlIcon.Controls.Add(subItemImage);
                pnlItem.Controls.Add(pnlIcon);
            }

            // Generate sub items text
            CMSPanel pnlText = new CMSPanel();
            pnlText.ID = "pnlText";
            pnlText.ShortID = "pt" + subIdentifier;
            pnlText.CssClass = "Name";
            Label subItemText = new Label();
            subItemText.ID = "ltlSubItem" + subIdentifier;
            subItemText.EnableViewState = false;
            subItemText.Text = GetString(item.Text);

            pnlText.Controls.Add(subItemText);
            pnlItem.Controls.Add(pnlText);

            if (!String.IsNullOrEmpty(item.RightImagePath))
            {
                string altText = String.IsNullOrEmpty(item.RightImageAltText) ? item.Text : item.RightImageAltText;

                // Generate sub item right icon
                CMSPanel pnlRightIcon = new CMSPanel();
                pnlRightIcon.ID = "pnlRightIcon";
                pnlRightIcon.ShortID = "pri" + subIdentifier;
                pnlRightIcon.CssClass = "Icon IconRight";
                Literal subRightItemImage = new Literal();
                subRightItemImage.ID = "ltlSubRightItemImage" + subIdentifier;
                subRightItemImage.EnableViewState = false;
                subRightItemImage.Text = String.Format("<img class=\"RightIcon\" src=\"{0}\" alt=\"{1}\" />&nbsp;",
                        ResolveUrl(item.RightImagePath),
                        GetString(altText));

                pnlRightIcon.Controls.Add(subRightItemImage);
                pnlItem.Controls.Add(pnlRightIcon);
            }

            pnlMenu.Controls.Add(pnlItem);
        }
        else
        {
            // Load menu item control
            Control ctrl = this.LoadUserControl(item.ControlPath);
            if (ctrl != null)
            {
                pnlMenu.Controls.Add(ctrl);
            }
        }
    }
示例#26
0
    /// <summary>
    /// Method for adding sub menu item into menu.
    /// </summary>
    /// <param name="pnlMenu">Menu container control</param>
    /// <param name="item">Sub menu item definition</param>
    /// <param name="cssClass">Button css class</param>
    /// <param name="subIdentifier">Button identifier</param>
    private void AddSubMenuItem(CMSPanel pnlMenu, SubMenuItem item, string cssClass, int subIdentifier)
    {
        if (String.IsNullOrEmpty(item.ControlPath))
        {
            // Generate sub item
            CMSPanel pnlItem = new CMSPanel();
            pnlItem.ID       = "pnlSubItem" + subIdentifier;
            pnlItem.ShortID  = "pi" + subIdentifier;
            pnlItem.CssClass = "Item ItemPadding";
            pnlItem.ToolTip  = item.Tooltip;

            if (!String.IsNullOrEmpty(item.OnClientClick))
            {
                pnlItem.Attributes["onclick"] = item.OnClientClick.Replace("##BUTTON##", "$j(this).parents('." + cssClass + "').get(0)");
            }

            if (!String.IsNullOrEmpty(item.ImagePath))
            {
                string altText = String.IsNullOrEmpty(item.ImageAltText) ? item.Text : item.ImageAltText;

                // Generate sub items text
                CMSPanel pnlIcon = new CMSPanel();
                pnlIcon.ID       = "pnlIcon";
                pnlIcon.ShortID  = "pii" + subIdentifier;
                pnlIcon.CssClass = "Icon";
                Literal subItemImage = new Literal();
                subItemImage.ID = "ltlSubItemImage" + subIdentifier;
                subItemImage.EnableViewState = false;
                subItemImage.Text            = String.Format("<img src=\"{0}\" alt=\"{1}\" />&nbsp;",
                                                             ResolveUrl(item.ImagePath),
                                                             GetString(altText));

                pnlIcon.Controls.Add(subItemImage);
                pnlItem.Controls.Add(pnlIcon);
            }

            // Generate sub items text
            CMSPanel pnlText = new CMSPanel();
            pnlText.ID       = "pnlText";
            pnlText.ShortID  = "pt" + subIdentifier;
            pnlText.CssClass = "Name";
            Label subItemText = new Label();
            subItemText.ID = "ltlSubItem" + subIdentifier;
            subItemText.EnableViewState = false;
            subItemText.Text            = GetString(item.Text);

            pnlText.Controls.Add(subItemText);
            pnlItem.Controls.Add(pnlText);

            if (!String.IsNullOrEmpty(item.RightImagePath))
            {
                string altText = String.IsNullOrEmpty(item.RightImageAltText) ? item.Text : item.RightImageAltText;

                // Generate sub item right icon
                CMSPanel pnlRightIcon = new CMSPanel();
                pnlRightIcon.ID       = "pnlRightIcon";
                pnlRightIcon.ShortID  = "pri" + subIdentifier;
                pnlRightIcon.CssClass = "Icon IconRight";
                Literal subRightItemImage = new Literal();
                subRightItemImage.ID = "ltlSubRightItemImage" + subIdentifier;
                subRightItemImage.EnableViewState = false;
                subRightItemImage.Text            = String.Format("<img class=\"RightIcon\" src=\"{0}\" alt=\"{1}\" />&nbsp;",
                                                                  ResolveUrl(item.RightImagePath),
                                                                  GetString(altText));

                pnlRightIcon.Controls.Add(subRightItemImage);
                pnlItem.Controls.Add(pnlRightIcon);
            }

            pnlMenu.Controls.Add(pnlItem);
        }
        else
        {
            // Load menu item control
            Control ctrl = this.LoadUserControl(item.ControlPath);
            if (ctrl != null)
            {
                pnlMenu.Controls.Add(ctrl);
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            if (Buttons != null)
            {
                if (AllowSelection)
                {
                    ScriptHelper.RegisterJQuery(Page);
                    StringBuilder selectionScript = new StringBuilder();
                    selectionScript.AppendLine("function SelectButton(elem)");
                    selectionScript.AppendLine("{");
                    selectionScript.AppendLine("    var selected = '" + SelectedSuffix + "';");
                    selectionScript.AppendLine("    var jElem =$j(elem);");
                    // Get first parent table
                    selectionScript.AppendLine("    var parentTable = jElem.parents('table').get(0);");
                    selectionScript.AppendLine("    if (parentTable != null) {");
                    // Remove selected class from current group of buttons
                    selectionScript.AppendLine("        $j(parentTable).find('.' + elem.className).removeClass(selected);");
                    selectionScript.AppendLine("    }");
                    selectionScript.AppendLine("    jElem.addClass(selected);");
                    selectionScript.AppendLine("}");
                    ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "selectionScript", ScriptHelper.GetScript(selectionScript.ToString()));

                    StringBuilder indexSelection = new StringBuilder();
                    indexSelection.AppendLine("function SelectButtonIndex_" + ClientID + "(index)");
                    indexSelection.AppendLine("{");
                    indexSelection.AppendLine("    var elem = document.getElementById('" + ClientID + "_" + BUTTON_PANEL_SHORTID + "'+index);");
                    indexSelection.AppendLine("    SelectButton(elem);");
                    indexSelection.AppendLine("");
                    indexSelection.AppendLine("}");
                    ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "indexSelection_" + ClientID, ScriptHelper.GetScript(indexSelection.ToString()));
                }

                if (AllowToggle)
                {
                    // Toggle script
                    StringBuilder toggleScript = new StringBuilder();
                    toggleScript.AppendLine("function ToggleButton(elem)");
                    toggleScript.AppendLine("{");
                    toggleScript.AppendLine("    var selected = '" + SelectedSuffix.Trim() + "';");
                    toggleScript.AppendLine("    var jElem =$j(elem);");
                    // Get first parent table
                    toggleScript.AppendLine("    jElem.toggleClass(selected);");
                    toggleScript.AppendLine("}");
                    ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "toggleScript", ScriptHelper.GetScript(toggleScript.ToString()));
                }

                int buttonsCount = Buttons.GetUpperBound(0) + 1;
                InnerControls = new List<Panel>(buttonsCount);
                for (identifier = 0; identifier < buttonsCount; identifier++)
                {
                    // Check array dimensions
                    if (Buttons.GetUpperBound(1) != 8)
                    {
                        Controls.Add(GetError(GetString("unimenubuttons.wrongdimensions")));
                        continue;
                    }

                    string caption = Buttons[identifier, 0];
                    string tooltip = Buttons[identifier, 1];
                    string cssClass = Buttons[identifier, 2];
                    string onClick = Buttons[identifier, 3];
                    string redirectUrl = Buttons[identifier, 4];
                    string imagePath = Buttons[identifier, 5];
                    string alt = Buttons[identifier, 6];
                    string align = Buttons[identifier, 7];
                    string minWidth = Buttons[identifier, 8];
                    ImageAlign imageAlign = ParseImageAlign(align);

                    // Generate button image
                    Image buttonImage = new Image();
                    buttonImage.ID = "img" + identifier;
                    buttonImage.EnableViewState = false;
                    buttonImage.AlternateText = alt ?? caption;
                    if (!string.IsNullOrEmpty(imagePath))
                    {
                        buttonImage.ImageUrl = ResolveUrl(imagePath);
                    }
                    buttonImage.ImageAlign = imageAlign;

                    // Generate button text
                    Literal captionLiteral = new Literal();
                    captionLiteral.ID = "ltlCaption" + identifier;
                    captionLiteral.EnableViewState = false;
                    string separator = (imageAlign == ImageAlign.Top) ? "<br />" : "\n";
                    captionLiteral.Text = separator + caption;

                    // Generate button link
                    HyperLink buttonLink = new HyperLink();
                    buttonLink.ID = "btn" + identifier;
                    buttonLink.EnableViewState = false;

                    buttonLink.Controls.Add(buttonImage);
                    buttonLink.Controls.Add(captionLiteral);

                    if (!string.IsNullOrEmpty(redirectUrl))
                    {
                        buttonLink.NavigateUrl = ResolveUrl(redirectUrl);
                    }

                    // Generate left border
                    CMSPanel pnlLeft = new CMSPanel();
                    pnlLeft.ID = "pnlLeft" + identifier;
                    pnlLeft.ShortID = "pl" + identifier;

                    pnlLeft.EnableViewState = false;
                    pnlLeft.CssClass = "Left" + cssClass;

                    // Generate middle part of button
                    CMSPanel pnlMiddle = new CMSPanel();
                    pnlMiddle.ID = "pnlMiddle" + identifier;
                    pnlMiddle.ShortID = "pm" + identifier;

                    pnlMiddle.EnableViewState = false;
                    pnlMiddle.CssClass = "Middle" + cssClass;
                    pnlMiddle.Controls.Add(buttonLink);
                    if (!string.IsNullOrEmpty(minWidth))
                    {
                        pnlMiddle.Style.Add("min-width", minWidth + "px");

                        // IE7 issue with min-width
                        CMSPanel pnlMiddleTmp = new CMSPanel();
                        pnlMiddleTmp.EnableViewState = false;
                        pnlMiddleTmp.Style.Add("width", minWidth + "px");
                        pnlMiddle.Controls.Add(pnlMiddleTmp);
                    }

                    // Generate right border
                    CMSPanel pnlRight = new CMSPanel();
                    pnlRight.ID = "pnlRight" + identifier;
                    pnlRight.ShortID = "pr" + identifier;

                    pnlRight.EnableViewState = false;
                    pnlRight.CssClass = "Right" + cssClass;

                    // Generate whole button
                    CMSPanel pnlButton = new CMSPanel();
                    pnlButton.ID = "pnlButton" + identifier;
                    pnlButton.ShortID = BUTTON_PANEL_SHORTID + identifier;

                    pnlButton.EnableViewState = false;
                    if ((AllowSelection || AllowToggle) && (identifier == SelectedIndex))
                    {
                        cssClass += SelectedSuffix;
                    }

                    pnlButton.CssClass = cssClass;

                    if (AllowToggle)
                    {
                        pnlButton.CssClass += " Toggle";
                    }

                    //Generate button table (IE7 issue)
                    Table tabButton = new Table();
                    TableRow tabRow = new TableRow();
                    TableCell tabCellLeft = new TableCell();
                    TableCell tabCellMiddle = new TableCell();
                    TableCell tabCellRight = new TableCell();

                    tabButton.CellPadding = 0;
                    tabButton.CellSpacing = 0;

                    tabButton.Rows.Add(tabRow);
                    tabRow.Cells.Add(tabCellLeft);
                    tabRow.Cells.Add(tabCellMiddle);
                    tabRow.Cells.Add(tabCellRight);

                    // Add inner controls
                    tabCellLeft.Controls.Add(pnlLeft);
                    tabCellMiddle.Controls.Add(pnlMiddle);
                    tabCellRight.Controls.Add(pnlRight);

                    pnlButton.Controls.Add(tabButton);

                    pnlButton.ToolTip = tooltip ?? caption;

                    if (AllowSelection)
                    {
                        onClick = "SelectButton(this);" + onClick;
                    }
                    else if (AllowToggle)
                    {
                        onClick = "ToggleButton(this);" + onClick;
                    }

                    pnlButton.Attributes["onclick"] = CheckChanges ? "if (CheckChanges()) {" + onClick + "}" : onClick;

                    // In case of horizontal layout
                    if (HorizontalLayout)
                    {
                        // Stack buttons underneath
                        pnlButton.Style.Add("clear", "both");
                    }
                    else
                    {
                        // Stack buttons side-by-sode
                        pnlButton.Style.Add("float", "left");
                    }

                    // Fill collection of buttons
                    InnerControls.Insert(identifier, pnlButton);
                }

                // Calculate number of needed panels
                int panelCount = InnerControls.Count / MaximumItems;
                if ((InnerControls.Count % MaximumItems) > 0)
                {
                    panelCount++;
                }

                // Initialize list of panels
                List<Panel> panels = new List<Panel>();

                Table tabGroup = new Table();
                TableRow tabGroupRow = new TableRow();

                tabGroup.CellPadding = 0;
                tabGroup.CellSpacing = 0;
                tabGroup.Rows.Add(tabGroupRow);

                // Fill each panel
                for (int panelIndex = 0; panelIndex < panelCount; panelIndex++)
                {
                    // Create new instance of panel
                    CMSPanel outerPanel = new CMSPanel();
                    outerPanel.EnableViewState = false;
                    outerPanel.ID = "pnlOuter" + panelIndex;
                    outerPanel.ShortID = "po" + panelIndex;

                    // In case of horizontal layout
                    if (HorizontalLayout)
                    {
                        // Stack panels side-by-side
                        outerPanel.Style.Add("float", "left");
                    }
                    else
                    {
                        // Stack panels underneath
                        outerPanel.Style.Add("clear", "both");
                    }
                    // Add buttons to panel
                    for (int buttonIndex = (panelIndex * MaximumItems); buttonIndex < (panelCount * MaximumItems) + panelCount; buttonIndex++)
                    {
                        if (((buttonIndex % MaximumItems) < MaximumItems) && (InnerControls.Count > buttonIndex))
                        {
                            outerPanel.Controls.Add(InnerControls[buttonIndex]);
                        }
                    }
                    // Add panel to collection of panels
                    panels.Add(outerPanel);
                }

                // Add all panels to control
                foreach (Panel panel in panels)
                {
                    TableCell tabGroupCell = new TableCell();
                    tabGroupCell.VerticalAlign = VerticalAlign.Top;

                    tabGroupCell.Controls.Add(panel);
                    tabGroupRow.Cells.Add(tabGroupCell);
                }

                Controls.Add(tabGroup);
            }
            else
            {
                Controls.Add(GetError(GetString("unimenubuttons.wrongdimensions")));
            }
        }
    }
    /// <summary>
    /// Method for adding button to controls.
    /// </summary>
    /// <param name="outerPanel">Panel to be added to</param>
    /// <param name="identifier">Index of button</param>
    private void AddButtonTo(CMSPanel outerPanel, int identifier)
    {
        MenuItem button = Buttons[identifier];
        string caption = button.Text;
        string tooltip = button.Tooltip;
        string cssClass = button.CssClass;
        string onClick = button.OnClientClick;
        string redirectUrl = button.RedirectUrl;
        string imagePath = button.ImagePath;
        string iconClass = button.IconClass;
        string alt = button.ImageAltText;
        int minWidth = button.MinimalWidth;
        ImageAlign imageAlign = GetImageAlign(button.ImageAlign);

        // Generate button image
        WebControl image = null;
        if (!string.IsNullOrEmpty(imagePath))
        {
            var buttonImage = new Image
            {
                ID = "img" + identifier,
                CssClass = "MenuButtonImage",
                EnableViewState = false,
                AlternateText = alt ?? caption,
                ImageAlign = imageAlign,
                ImageUrl = ResolveUrl(imagePath)
            };
            image = buttonImage;
        }
        else if (!string.IsNullOrEmpty(iconClass))
        {
            var icon = new CMSIcon
            {
                ID = "ico" + identifier,
                EnableViewState = false,
                ToolTip = tooltip,
                CssClass = "cms-icon-80 " + iconClass
            };
            image = icon;
        }

        // Generate button text
        Literal captionLiteral = new Literal();
        captionLiteral.ID = "ltlCaption" + identifier;
        captionLiteral.EnableViewState = false;
        string separator = (imageAlign == ImageAlign.Top) ? "<br />" : "\n";
        captionLiteral.Text = String.Format("{0}<span class=\"MenuButtonText\">{1}</span>", separator, caption);

        CMSPanel pnlSubItems = null;
        if (button.SubItems.Count > 0)
        {
            // Ensure jQuery tool is loaded
            ScriptHelper.RegisterJQueryTools(Page);

            // Register support script
            ScriptHelper.RegisterScriptFile(Page, "~/CMSAdminControls/UI/UniMenu/UniMenu.js");

            // Append sub-menu toggle script
            onClick = "CMSUniMenu.ToogleSubMenu(this);" + onClick;

            // Append arrow down image for indication sub menu
            captionLiteral.Text += @"<i aria-hidden=""true"" class=""icon-caret-right-down cms-icon-30""></i>";

            // Create submenu
            pnlSubItems = CreateSubMenu(button, cssClass, identifier);
        }

        // Generate button link
        HyperLink buttonLink = new HyperLink();
        buttonLink.ID = "btn" + identifier;
        buttonLink.EnableViewState = false;

        if (image != null)
        {
            buttonLink.Controls.Add(image);
        }
        buttonLink.Controls.Add(captionLiteral);

        if (!string.IsNullOrEmpty(redirectUrl))
        {
            buttonLink.NavigateUrl = ResolveUrl(redirectUrl);
        }

        // Generate left border
        CMSPanel pnlLeft = new CMSPanel();
        pnlLeft.ID = "pnlLeft" + identifier;
        pnlLeft.ShortID = "pl" + identifier;

        pnlLeft.EnableViewState = false;
        pnlLeft.CssClass = "Left" + cssClass;

        // Generate middle part of button
        CMSPanel pnlMiddle = new CMSPanel();
        pnlMiddle.ID = "pnlMiddle" + identifier;
        pnlMiddle.ShortID = "pm" + identifier;

        pnlMiddle.EnableViewState = false;
        pnlMiddle.CssClass = "Middle" + cssClass;
        pnlMiddle.Controls.Add(buttonLink);
        if (minWidth > 0)
        {
            pnlMiddle.Style.Add("min-width", minWidth + "px");

            // IE7 issue with min-width
            CMSPanel pnlMiddleTmp = new CMSPanel();
            pnlMiddleTmp.EnableViewState = false;
            pnlMiddleTmp.Style.Add("width", minWidth + "px");
            pnlMiddle.Controls.Add(pnlMiddleTmp);
        }

        // Add sub items if exists
        if (pnlSubItems != null)
        {
            pnlMiddle.Controls.Add(pnlSubItems);
        }

        // Generate right border
        CMSPanel pnlRight = new CMSPanel();
        pnlRight.ID = "pnlRight" + identifier;
        pnlRight.ShortID = "pr" + identifier;

        pnlRight.EnableViewState = false;
        pnlRight.CssClass = "Right" + cssClass;

        // Generate whole button
        CMSPanel pnlButton = new CMSPanel();
        pnlButton.ID = "pnlButton" + identifier;
        pnlButton.ShortID = BUTTON_PANEL_SHORTID + identifier;

        // Propagate attributes to panel for JavaScript use
        foreach (var entry in button.Attributes)
        {
            pnlButton.Attributes.Add(entry.Key, entry.Value);
        }

        pnlButton.EnableViewState = false;

        if (button.AllowToggle && button.IsToggled)
        {
            cssClass += SelectedSuffix;
        }

        pnlButton.CssClass = cssClass;

        if (button.AllowToggle)
        {
            pnlButton.CssClass += " Toggle";
            EnsureAllowToggleScript();
        }

        //Generate button table (IE7 issue)
        Table tabButton = new Table();
        TableRow tabRow = new TableRow();
        TableCell tabCellLeft = new TableCell();
        TableCell tabCellMiddle = new TableCell();
        TableCell tabCellRight = new TableCell();

        tabButton.CellPadding = 0;
        tabButton.CellSpacing = 0;

        tabButton.Rows.Add(tabRow);
        tabRow.Cells.Add(tabCellLeft);
        tabRow.Cells.Add(tabCellMiddle);
        tabRow.Cells.Add(tabCellRight);

        // Add inner controls
        tabCellLeft.Controls.Add(pnlLeft);
        tabCellMiddle.Controls.Add(pnlMiddle);
        tabCellRight.Controls.Add(pnlRight);

        pnlButton.Controls.Add(tabButton);

        pnlButton.ToolTip = tooltip ?? caption;

        outerPanel.Controls.Add(pnlButton);

        if (AllowDraggable)
        {
            mStartupScript.Append(String.Format("$cmsj( '#{0}' ).draggable({{ helper:{1}, scope:'{2}' }});", pnlButton.ClientID, GetDraggableHandler(button.DraggableTemplateHandler), button.DraggableScope));
        }

        if (!AllowSelection && button.AllowToggle)
        {
            onClick = "ToggleButton(this);" + onClick;
        }

        pnlButton.Attributes["onclick"] = CheckChanges ? "if (CheckChanges()) {" + onClick + "}" : onClick;

        // In case of horizontal layout
        if (HorizontalLayout)
        {
            // Stack buttons underneath
            pnlButton.Style.Add("clear", "both");
        }
        else
        {
            // Stack buttons side-by-side
            pnlButton.Style.Add("float", "left");
        }

        if (button.IsSelectable)
        {
            // Collect panel client IDs for JavaScript
            mElemsIds += "#" + pnlButton.ClientID + ",";
            if (AllowSelection && (identifier == SelectedIndex))
            {
                // Button should be selected by default, remember its ClientID for JavaScript
                defaultSelectedClientID = "#" + pnlButton.ClientID;
            }
        }
    }
    /// <summary>
    /// Generates panel with buttons loaded from given UI Element.
    /// </summary>
    /// <param name="uiElementId">ID of the UI Element</param>
    protected Panel GetButtons(int uiElementId)
    {
        const int bigButtonMinimalWidth = 40;
        const int smallButtonMinimalWidth = 66;

        Panel pnlButtons = null;

        // Load the buttons manually from UI Element
        DataSet ds = UIElementInfoProvider.GetChildUIElements(uiElementId);

        // When no child found
        if (DataHelper.DataSourceIsEmpty(ds))
        {
            // Try to use group element as button
            ds = UIElementInfoProvider.GetUIElements("ElementID = " + uiElementId, null);

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                DataRow dr = ds.Tables[0].Rows[0];
                string url = ValidationHelper.GetString(dr["ElementTargetURL"], "");

                // Use group element as button only if it has URL specified
                if (string.IsNullOrEmpty(url))
                {
                    ds = null;
                }
            }
        }

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            // Filter the dataset according to UI Profile
            FilterElements(ds);

            int small = 0;
            int count = ds.Tables[0].Rows.Count;

            // No buttons, render nothing
            if (count == 0)
            {
                return null;
            }

            // Prepare the panel
            pnlButtons = new Panel();
            pnlButtons.CssClass = "ActionButtons";

            // Prepare the table
            Table tabGroup = new Table();
            TableRow tabGroupRow = new TableRow();

            tabGroup.CellPadding = 0;
            tabGroup.CellSpacing = 0;
            tabGroup.EnableViewState = false;
            tabGroupRow.EnableViewState = false;
            tabGroup.Rows.Add(tabGroupRow);

            List<Panel> panels = new List<Panel>();

            for (int i = 0; i < count; i++)
            {
                // Get current and next button
                UIElementInfo uiElement = new UIElementInfo(ds.Tables[0].Rows[i]);
                UIElementInfo uiElementNext = null;
                if (i < count - 1)
                {
                    uiElementNext = new UIElementInfo(ds.Tables[0].Rows[i + 1]);
                }

                // Set the first button
                if (mFirstUIElement == null)
                {
                    mFirstUIElement = uiElement;
                }

                // Get the sizes of current and next button. Button is large when it is the only in the group
                bool isSmall = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (count > 1);
                bool isResized = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (!isSmall);
                bool isNextSmall = (uiElementNext != null) && (uiElementNext.ElementSize == UIElementSizeEnum.Regular);

                // Set the CSS class according to the button size
                string cssClass = (isSmall ? "SmallButton" : "BigButton");
                string elementName = uiElement.ElementName;

                // Create main button panel
                CMSPanel pnlButton = new CMSPanel()
                {
                    ID = "pnlButton" + elementName,
                    ShortID = "b" + elementName
                };

                pnlButton.Attributes.Add("name", elementName);
                pnlButton.CssClass = cssClass;

                // Remember the first button
                if (firstPanel == null)
                {
                    firstPanel = pnlButton;
                }

                // Remember the selected button
                if ((preselectedPanel == null) && elementName.Equals(HighlightItem, StringComparison.InvariantCultureIgnoreCase))
                {
                    preselectedPanel = pnlButton;

                    // Set the selected button
                    if (mHighlightedUIElement == null)
                    {
                        mHighlightedUIElement = uiElement;
                    }
                }

                // URL or behavior
                string url = uiElement.ElementTargetURL;

                if (!string.IsNullOrEmpty(url) && url.StartsWith("javascript:", StringComparison.InvariantCultureIgnoreCase))
                {
                    pnlButton.Attributes["onclick"] = url.Substring("javascript:".Length);
                }
                else if (!string.IsNullOrEmpty(url) && !url.StartsWith("javascript:", StringComparison.InvariantCultureIgnoreCase))
                {
                    string buttonSelection = (RememberSelectedItem ? "SelectButton(this);" : "");

                    // Ensure hash code if required
                    string targetUrl = CMSContext.ResolveMacros(URLHelper.EnsureHashToQueryParameters(url));

                    if (!String.IsNullOrEmpty(TargetFrameset))
                    {
                        pnlButton.Attributes["onclick"] = String.Format("{0}parent.frames['{1}'].location.href = '{2}';", buttonSelection, TargetFrameset, URLHelper.ResolveUrl(targetUrl));
                    }
                    else
                    {
                        pnlButton.Attributes["onclick"] = String.Format("{0}self.location.href = '{1}';", buttonSelection, URLHelper.ResolveUrl(targetUrl));
                    }

                    if (OnButtonCreated != null)
                    {
                        OnButtonCreated(uiElement, targetUrl);
                    }
                }

                // Tooltip
                if (!string.IsNullOrEmpty(uiElement.ElementDescription))
                {
                    pnlButton.ToolTip = ResHelper.LocalizeString(uiElement.ElementDescription);
                }
                else
                {
                    pnlButton.ToolTip = ResHelper.LocalizeString(uiElement.ElementCaption);
                }
                pnlButton.EnableViewState = false;

                // Ensure correct grouping of small buttons
                if (isSmall && (small == 0))
                {
                    small++;

                    Panel pnlSmallGroup = new Panel()
                    {
                        ID = "pnlGroupSmall" + uiElement.ElementName
                    };
                    if (IsRTL)
                    {
                        pnlSmallGroup.Style.Add("float", "right");
                        pnlSmallGroup.Style.Add("text-align", "right");
                    }
                    else
                    {
                        pnlSmallGroup.Style.Add("float", "left");
                        pnlSmallGroup.Style.Add("text-align", "left");
                    }

                    pnlSmallGroup.EnableViewState = false;
                    pnlSmallGroup.Controls.Add(pnlButton);
                    panels.Add(pnlSmallGroup);

                }

                // Generate button image
                Image buttonImage = new Image()
                {
                    ID = "imgButton" + uiElement.ElementName,
                    ImageAlign = (isSmall ? ImageAlign.AbsMiddle : ImageAlign.Top)
                };
                if (!string.IsNullOrEmpty(uiElement.ElementIconPath))
                {
                    string iconPath = GetImageUrl(uiElement.ElementIconPath);

                    // Check if element size was changed
                    if(isResized)
                    {
                        // Try to get larger icon
                        string largeIconPath = iconPath.Replace("list.png", "module.png");
                        try
                        {
                            if (CMS.IO.File.Exists(MapPath(largeIconPath)))
                            {
                                iconPath = largeIconPath;
                            }
                        }
                        catch { }
                    }

                    buttonImage.ImageUrl = iconPath;
                }
                else
                {
                    // Load defaul module icon if ElementIconPath is not specified
                    buttonImage.ImageUrl = GetImageUrl("CMSModules/module.png");
                }
                buttonImage.EnableViewState = false;

                // Generate button text
                Literal captionLiteral = new Literal()
                {
                    ID = "ltlCaption" + uiElement.ElementName,
                    Text = (isSmall ? "\n" : "<br />") + ResHelper.LocalizeString(uiElement.ElementCaption),
                    EnableViewState = false
                };

                // Generate button link
                HyperLink buttonLink = new HyperLink()
                {
                    ID = "lnkButton" + uiElement.ElementName
                };
                buttonLink.Controls.Add(buttonImage);
                buttonLink.Controls.Add(captionLiteral);
                buttonLink.EnableViewState = false;

                //Generate button table (IE7 issue)
                Table tabButton = new Table();
                TableRow tabRow = new TableRow();
                TableCell tabCellLeft = new TableCell();
                TableCell tabCellMiddle = new TableCell();
                TableCell tabCellRight = new TableCell();

                tabButton.CellPadding = 0;
                tabButton.CellSpacing = 0;

                tabButton.EnableViewState = false;
                tabRow.EnableViewState = false;
                tabCellLeft.EnableViewState = false;
                tabCellMiddle.EnableViewState = false;
                tabCellRight.EnableViewState = false;

                tabButton.Rows.Add(tabRow);
                tabRow.Cells.Add(tabCellLeft);
                tabRow.Cells.Add(tabCellMiddle);
                tabRow.Cells.Add(tabCellRight);

                // Generate left border
                Panel pnlLeft = new Panel()
                {
                    ID = "pnlLeft" + uiElement.ElementName,
                    CssClass = "Left" + cssClass,
                    EnableViewState = false
                };

                // Generate middle part of button
                Panel pnlMiddle = new Panel()
                {
                    ID = "pnlMiddle" + uiElement.ElementName,
                    CssClass = "Middle" + cssClass
                };
                pnlMiddle.Controls.Add(buttonLink);
                Panel pnlMiddleTmp = new Panel()
                {
                    EnableViewState = false
                };
                if (isSmall)
                {
                    pnlMiddle.Style.Add("min-width", smallButtonMinimalWidth + "px");
                    // IE7 issue with min-width
                    pnlMiddleTmp.Style.Add("width", smallButtonMinimalWidth + "px");
                    pnlMiddle.Controls.Add(pnlMiddleTmp);
                }
                else
                {
                    pnlMiddle.Style.Add("min-width", bigButtonMinimalWidth + "px");
                    // IE7 issue with min-width
                    pnlMiddleTmp.Style.Add("width", bigButtonMinimalWidth + "px");
                    pnlMiddle.Controls.Add(pnlMiddleTmp);
                }
                pnlMiddle.EnableViewState = false;

                // Generate right border
                Panel pnlRight = new Panel()
                {
                    ID = "pnlRight" + uiElement.ElementName,
                    CssClass = "Right" + cssClass,
                    EnableViewState = false
                };

                // Add inner controls
                tabCellLeft.Controls.Add(pnlLeft);
                tabCellMiddle.Controls.Add(pnlMiddle);
                tabCellRight.Controls.Add(pnlRight);

                pnlButton.Controls.Add(tabButton);

                // If there were two small buttons in a row end the grouping div
                if ((small == 2) || (isSmall && !isNextSmall))
                {
                    small = 0;

                    // Add the button to the small buttons grouping panel
                    panels[panels.Count - 1].Controls.Add(pnlButton);
                }
                else
                {
                    if (small == 0)
                    {
                        // Add the generated button into collection
                        panels.Add(pnlButton);
                    }
                }
                if (small == 1)
                {
                    small++;
                }
            }

            // Add all panels to control
            foreach (Panel panel in panels)
            {
                TableCell tabGroupCell = new TableCell()
                {
                    VerticalAlign = VerticalAlign.Top,
                    EnableViewState = false
                };

                tabGroupCell.Controls.Add(panel);
                tabGroupRow.Cells.Add(tabGroupCell);
            }

            pnlButtons.Controls.Add(tabGroup);
        }

        return pnlButtons;
    }
    /// <summary>
    /// Method for adding panel to group cell.
    /// </summary>
    /// <param name="tabGroupCell">Table cell to be added to</param>
    /// <param name="panelIndex">Index of panel to be added</param>
    private void AddPanelTo(TableCell tabGroupCell, int panelIndex)
    {
        int startIndex = (panelIndex * MaximumItems);

        // Create new instance of panel
        CMSPanel outerPanel = new CMSPanel();
        outerPanel.EnableViewState = false;
        outerPanel.ID = "pnlOuter" + panelIndex;
        outerPanel.ShortID = "po" + panelIndex;

        // In case of horizontal layout
        if (HorizontalLayout)
        {
            // Stack panels side-by-side
            outerPanel.Style.Add("float", CultureHelper.IsUICultureRTL() ? "right" : "left");
        }
        else
        {
            // Stack panels underneath
            outerPanel.Style.Add("clear", "both");
        }

        // Add panel to collection of panels
        tabGroupCell.Controls.Add(outerPanel);

        // Add buttons to panel
        for (int buttonIndex = startIndex; buttonIndex < startIndex + MaximumItems; buttonIndex++)
        {
            if (Buttons.Count > buttonIndex)
            {
                AddButtonTo(outerPanel, buttonIndex);
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Groups != null)
        {
            ScriptHelper.RegisterJQuery(Page);
            ScriptHelper.RegisterScriptFile(Page, "jquery/jquery-tools.js");
            ScriptHelper.RegisterScriptFile(Page, "~/CMSAdminControls/UI/UniMenu/UniMenu.js");

            if (RememberSelectedItem)
            {
                StringBuilder selectionScript = new StringBuilder();
                selectionScript.AppendLine("function SelectButton(elem)");
                selectionScript.AppendLine("{");
                selectionScript.AppendLine("    var selected = 'Selected';");
                selectionScript.AppendLine("    var jElem =$j(elem);");
                selectionScript.AppendFormat("    $j('#{0}').find('.'+selected).removeClass(selected);\n", pnlControls.ClientID);
                selectionScript.AppendLine("    jElem.addClass(selected);");
                selectionScript.AppendLine("}");
                ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "UIToolbarSelectionScript", ScriptHelper.GetScript(selectionScript.ToString()));
            }

            // Generate script for activating menu buttons by script
            string buttonSelection = (RememberSelectedItem ? "SelectButton(this);" : "");
            StringBuilder remoteSelectionScript = new StringBuilder();
            remoteSelectionScript.AppendLine("var SelectedItemID = null;");
            remoteSelectionScript.AppendLine("function SelectItem(elementID, elementUrl, forceSelection)");
            remoteSelectionScript.AppendLine("{");
            remoteSelectionScript.AppendLine("  if(forceSelection === undefined) forceSelection = true;");
            remoteSelectionScript.AppendLine("  if(SelectedItemID == elementID && !forceSelection) { return; }");
            remoteSelectionScript.AppendLine("    SelectedItemID = elementID;");
            remoteSelectionScript.AppendLine("    var selected = 'Selected';");
            remoteSelectionScript.AppendFormat("    $j(\"#{0} .\"+selected).removeClass(selected);\n", pnlControls.ClientID);
            remoteSelectionScript.AppendFormat("    $j(\"#{0} div[name='\"+elementID+\"']\").addClass(selected);\n", pnlControls.ClientID);
            remoteSelectionScript.AppendLine("    if(elementUrl != null && elementUrl != '') {");
            if (!String.IsNullOrEmpty(TargetFrameset))
            {
                remoteSelectionScript.AppendLine(String.Format("{0}parent.frames['{1}'].location.href = elementUrl;", buttonSelection, TargetFrameset));
            }
            else
            {
                remoteSelectionScript.AppendLine(buttonSelection + "self.location.href = elementUrl;");
            }
            remoteSelectionScript.AppendLine("    }");
            remoteSelectionScript.AppendLine("}");
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "UIToolbarRemoteSelectionScript", ScriptHelper.GetScript(remoteSelectionScript.ToString()));

            ArrayList controlsList = new ArrayList();
            int groupsCount = Groups.GetUpperBound(0) + 1;
            InnerControls = new List<CMSUserControl>(groupsCount);

            // Process the groups
            for (identifier = 0; identifier < groupsCount; identifier++)
            {
                // Check array dimensions
                if (Groups.GetUpperBound(1) < 2)
                {
                    if (ShowErrors)
                    {
                        Controls.Add(GetError(GetString("unimenu.wrongdimensions")));
                    }
                    continue;
                }

                string captionText = Groups[identifier, 0];
                string contentControlPath = Groups[identifier, 1];
                string cssClass = Groups[identifier, 2];
                int uiElementId = (Groups.GetUpperBound(1) == 3 ? ValidationHelper.GetInteger(Groups[identifier, 3], 0) : 0);

                // Caption and path to content control have to be entered
                if (string.IsNullOrEmpty(captionText))
                {
                    if (ShowErrors)
                    {
                        Controls.Add(GetError(GetString("unimenu.captionempty")));
                    }
                    continue;
                }
                if (string.IsNullOrEmpty(contentControlPath) && (uiElementId <= 0))
                {
                    if (ShowErrors)
                    {
                        Controls.Add(GetError(GetString("unimenu.pathempty")));
                    }
                    continue;
                }

                CMSPanel groupPanel = new CMSPanel()
                {
                    ID = "pnlGroup" + identifier,
                    ShortID = "g" + identifier
                };

                // Add controls to main panel
                groupPanel.Controls.Add(GetLeftBorder());

                bool createGroup = false;

                if (!string.IsNullOrEmpty(contentControlPath))
                {
                    CMSUserControl contentControl = null;
                    try
                    {
                        // Try to load content control
                        contentControl = (CMSUserControl)Page.LoadControl(contentControlPath);
                        contentControl.ID = "ctrlContent" + identifier;
                        contentControl.ShortID = "c" + identifier;
                    }
                    catch
                    {
                        Controls.Add(GetError(GetString("unimenu.errorloadingcontrol")));
                        continue;
                    }
                    Panel innerPanel = GetContent(contentControl, 0, captionText);
                    if (innerPanel != null)
                    {
                        groupPanel.Controls.Add(innerPanel);
                        createGroup = true;
                    }

                    InnerControls.Insert(identifier, (CMSUserControl)contentControl);
                }
                else if (uiElementId > 0)
                {
                    Panel innerPanel = GetContent(null, uiElementId, captionText);
                    if (innerPanel != null)
                    {
                        groupPanel.Controls.Add(innerPanel);
                        createGroup = true;
                    }
                }

                groupPanel.Controls.Add(GetRightBorder());

                groupPanel.CssClass = cssClass;

                // Add group panel to list of controls
                if (createGroup)
                {
                    mMenuEmpty = false;
                    controlsList.Add(groupPanel);

                    // Insert separator after group
                    if (groupsCount > 1)
                    {
                        controlsList.Add(GetGroupSeparator());
                    }
                }
            }

            // Handle the preselection
            if (preselectedPanel != null)
            {
                // Add the selected class to the preselected button
                preselectedPanel.CssClass += " Selected";
            }
            else if ((firstPanel != null) && HighlightFirstItem)
            {
                // Add the selected class to the first button
                firstPanel.CssClass += " Selected";
            }

            // Add group panels to to the control
            foreach (Control control in controlsList)
            {
                pnlControls.Controls.Add(control);
            }
        }
        else
        {
            Controls.Add(GetError(GetString("unimenu.wrongdimensions")));
        }
    }
    /// <summary>
    /// Method for adding button to controls.
    /// </summary>
    /// <param name="outerPanel">Panel to be added to</param>
    /// <param name="identifier">Index of button</param>
    private void AddButtonTo(CMSPanel outerPanel, int identifier)
    {
        MenuItem button = Buttons[identifier];
        string caption = button.Text;
        string tooltip = button.Tooltip;
        string cssClass = button.CssClass;
        string onClick = button.OnClientClick;
        string redirectUrl = button.RedirectUrl;
        string imagePath = button.ImagePath;
        string alt = button.ImageAltText;
        int minWidth = button.MinimalWidth;
        ImageAlign imageAlign = GetImageAlign(button.ImageAlign);

        // Generate button image
        Image buttonImage = new Image();
        buttonImage.ID = "img" + identifier;
        buttonImage.CssClass = "MenuButtonImage";
        buttonImage.EnableViewState = false;
        buttonImage.AlternateText = alt ?? caption;
        if (!string.IsNullOrEmpty(imagePath))
        {
            buttonImage.ImageUrl = ResolveUrl(imagePath);
        }
        buttonImage.ImageAlign = imageAlign;

        // Generate button text
        Literal captionLiteral = new Literal();
        captionLiteral.ID = "ltlCaption" + identifier;
        captionLiteral.EnableViewState = false;
        string separator = (imageAlign == ImageAlign.Top) ? "<br />" : "\n";
        captionLiteral.Text = String.Format("{0}<span class=\"MenuButtonText\">{1}</span>", separator, caption);

        CMSPanel pnlSubItems = null;
        if (button.SubItems.Count > 0)
        {
            // Ensure jQuery tool is loaded
            ScriptHelper.RegisterJQueryTools(Page);

            // Append submenu toogle script
            onClick = "CMSUniMenu.ToogleSubMenu(this);" + onClick;

            // Append arrow down image for idication sub menu
            captionLiteral.Text += "&nbsp;<img style=\"width:8px; height:8px;\" src=\"" + GetImageUrl("Design/Controls/UniMenu/ArrowDown.png") + "\" alt=\"Sub menu items\" class=\"SubItemsArrow\" />";

            // Create submenu
            CreateSubMenu(button, ref pnlSubItems, cssClass, identifier);
        }

        // Generate button link
        HyperLink buttonLink = new HyperLink();
        buttonLink.ID = "btn" + identifier;
        buttonLink.EnableViewState = false;

        buttonLink.Controls.Add(buttonImage);
        buttonLink.Controls.Add(captionLiteral);

        if (!string.IsNullOrEmpty(redirectUrl))
        {
            buttonLink.NavigateUrl = ResolveUrl(redirectUrl);
        }

        // Generate left border
        CMSPanel pnlLeft = new CMSPanel();
        pnlLeft.ID = "pnlLeft" + identifier;
        pnlLeft.ShortID = "pl" + identifier;

        pnlLeft.EnableViewState = false;
        pnlLeft.CssClass = "Left" + cssClass;

        // Generate middle part of button
        CMSPanel pnlMiddle = new CMSPanel();
        pnlMiddle.ID = "pnlMiddle" + identifier;
        pnlMiddle.ShortID = "pm" + identifier;

        pnlMiddle.EnableViewState = false;
        pnlMiddle.CssClass = "Middle" + cssClass;
        pnlMiddle.Controls.Add(buttonLink);
        if (minWidth > 0)
        {
            pnlMiddle.Style.Add("min-width", minWidth + "px");

            // IE7 issue with min-width
            CMSPanel pnlMiddleTmp = new CMSPanel();
            pnlMiddleTmp.EnableViewState = false;
            pnlMiddleTmp.Style.Add("width", minWidth + "px");
            pnlMiddle.Controls.Add(pnlMiddleTmp);
        }

        // Add sub items if exists
        if (pnlSubItems != null)
        {
            pnlMiddle.Controls.Add(pnlSubItems);
        }

        // Generate right border
        CMSPanel pnlRight = new CMSPanel();
        pnlRight.ID = "pnlRight" + identifier;
        pnlRight.ShortID = "pr" + identifier;

        pnlRight.EnableViewState = false;
        pnlRight.CssClass = "Right" + cssClass;

        // Generate whole button
        CMSPanel pnlButton = new CMSPanel();
        pnlButton.ID = "pnlButton" + identifier;
        pnlButton.ShortID = BUTTON_PANEL_SHORTID + identifier;

        pnlButton.EnableViewState = false;
        if ((AllowSelection && identifier == SelectedIndex ) || (button.AllowToggle && button.IsToggled))
        {
            cssClass += SelectedSuffix;
        }

        pnlButton.CssClass = cssClass;

        if (button.AllowToggle)
        {
            pnlButton.CssClass += " Toggle";
            EnsureAllowToggleScript();
        }

        //Generate button table (IE7 issue)
        Table tabButton = new Table();
        TableRow tabRow = new TableRow();
        TableCell tabCellLeft = new TableCell();
        TableCell tabCellMiddle = new TableCell();
        TableCell tabCellRight = new TableCell();

        tabButton.CellPadding = 0;
        tabButton.CellSpacing = 0;

        tabButton.Rows.Add(tabRow);
        tabRow.Cells.Add(tabCellLeft);
        tabRow.Cells.Add(tabCellMiddle);
        tabRow.Cells.Add(tabCellRight);

        // Add inner controls
        tabCellLeft.Controls.Add(pnlLeft);
        tabCellMiddle.Controls.Add(pnlMiddle);
        tabCellRight.Controls.Add(pnlRight);

        pnlButton.Controls.Add(tabButton);

        pnlButton.ToolTip = tooltip ?? caption;

        outerPanel.Controls.Add(pnlButton);

        if (AllowDraggable)
        {
            mStartupScript.Append(String.Format("$j( '#{0}' ).draggable({{ helper:{1}, scope:'{2}' }});", pnlButton.ClientID, GetDraggableHandler(button.DraggableTemplateHandler), button.DraggableScope));
        }
        if (AllowSelection)
        {
            onClick = "SelectButton(this);" + onClick;
        }
        else if (button.AllowToggle)
        {
            onClick = "ToggleButton(this);" + onClick;
        }

        pnlButton.Attributes["onclick"] = CheckChanges ? "if (CheckChanges()) {" + onClick + "}" : onClick;

        // In case of horizontal layout
        if (HorizontalLayout)
        {
            // Stack buttons underneath
            pnlButton.Style.Add("clear", "both");
        }
        else
        {
            // Stack buttons side-by-side
            pnlButton.Style.Add("float", "left");
        }
    }