Beispiel #1
0
        private void RenderDiagnosticMetadataAttributesForListMenuItem(ListMenuRenderingContext renderingContext, WebMenuItem menuItem)
        {
            if (!string.IsNullOrEmpty(menuItem.ItemID))
            {
                renderingContext.Writer.AddAttribute(DiagnosticMetadataAttributes.ItemID, menuItem.ItemID);
            }

            if (!string.IsNullOrEmpty(menuItem.Text))
            {
                renderingContext.Writer.AddAttribute(DiagnosticMetadataAttributes.Content, HtmlUtility.StripHtmlTags(menuItem.Text));
            }
        }
Beispiel #2
0
        private void RegisterMenuItems(ListMenuRenderingContext renderingContext)
        {
            if (!renderingContext.Control.HasClientScript)
            {
                return;
            }

            WebMenuItem[] groupedListMenuItems = renderingContext.Control.MenuItems.GroupMenuItems(false);

            string key = renderingContext.Control.UniqueID + "_MenuItems";

            if (!renderingContext.Control.Page.ClientScript.IsStartupScriptRegistered(typeof(ListMenuRenderer), key))
            {
                StringBuilder script = new StringBuilder();
                script.AppendFormat("ListMenu_AddMenuInfo (document.getElementById ('{0}'), \r\n\t", renderingContext.Control.ClientID);
                script.AppendFormat("new ListMenu_MenuInfo ('{0}', new Array (\r\n", renderingContext.Control.ClientID);
                bool isFirstItemInGroup = true;

                for (int idxItems = 0; idxItems < groupedListMenuItems.Length; idxItems++)
                {
                    WebMenuItem currentItem = groupedListMenuItems[idxItems];
                    if (!currentItem.EvaluateVisible())
                    {
                        continue;
                    }

                    if (isFirstItemInGroup)
                    {
                        isFirstItemInGroup = false;
                    }
                    else
                    {
                        script.AppendFormat(",\r\n");
                    }
                    AppendListMenuItem(renderingContext, script, currentItem);
                }
                script.Append(" )");      // Close Array
                script.Append(" )");      // Close new MenuInfo
                script.Append(" );\r\n"); // Close AddMenuInfo

                script.Append(renderingContext.Control.GetUpdateScriptReference("null"));

                renderingContext.Control.Page.ClientScript.RegisterStartupScriptBlock(
                    renderingContext.Control,
                    typeof(ListMenuRenderer),
                    key,
                    script.ToString());
            }
        }
Beispiel #3
0
        private void RenderListMenuItem(ListMenuRenderingContext renderingContext, WebMenuItem menuItem, int index)
        {
            bool showIcon = menuItem.Style == WebMenuItemStyle.Icon || menuItem.Style == WebMenuItemStyle.IconAndText;
            bool showText = menuItem.Style == WebMenuItemStyle.Text || menuItem.Style == WebMenuItemStyle.IconAndText;

            renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Id, GetMenuItemClientID(renderingContext, index));
            renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Class, "listMenuItem");
            if (IsDiagnosticMetadataRenderingEnabled)
            {
                RenderDiagnosticMetadataAttributesForListMenuItem(renderingContext, menuItem);
            }
            renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Span);

            var command = !menuItem.IsDisabled ? menuItem.Command : new Command(CommandType.None)
            {
                OwnerControl = menuItem.OwnerControl
            };

            if (string.IsNullOrEmpty(command.ItemID))
            {
                command.ItemID = "MenuItem_" + index + "_Command";
            }

            command.RenderBegin(
                renderingContext.Writer,
                RenderingFeatures,
                renderingContext.Control.Page.ClientScript.GetPostBackClientHyperlink(renderingContext.Control, index.ToString()),
                new[] { index.ToString() },
                "",
                null);

            if (showIcon && menuItem.Icon.HasRenderingInformation)
            {
                menuItem.Icon.Render(renderingContext.Writer, renderingContext.Control);
                if (showText)
                {
                    renderingContext.Writer.Write(c_whiteSpace);
                }
            }
            if (showText)
            {
                renderingContext.Writer.Write(menuItem.Text); // Do not HTML encode.
            }
            command.RenderEnd(renderingContext.Writer);
            renderingContext.Writer.RenderEndTag();
        }
Beispiel #4
0
        private IEnumerable <IEnumerable <WebMenuItem> > GetVisibleMenuItemsInGroups(ListMenuRenderingContext renderingContext)
        {
            var menuItems  = renderingContext.Control.MenuItems.GroupMenuItems(false).Where(mi => mi.EvaluateVisible());
            var lineBreaks = renderingContext.Control.LineBreaks;

            switch (lineBreaks)
            {
            case ListMenuLineBreaks.All:
                return(menuItems.Select(mi => new[] { mi }.AsEnumerable()));

            case ListMenuLineBreaks.BetweenGroups:
                return(menuItems.GroupBy(mi => mi.Category).Select(g => g.AsEnumerable()));

            case ListMenuLineBreaks.None:
                return(new[] { menuItems });

            default:
                throw new InvalidOperationException(string.Format("'{0}' is not a valid option for ListMenuLineBreaks enum.", lineBreaks));
            }
        }
Beispiel #5
0
        public void Render(ListMenuRenderingContext renderingContext)
        {
            ArgumentUtility.CheckNotNull("renderingContext", renderingContext);

            RegisterMenuItems(renderingContext);

            renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Id, renderingContext.Control.ClientID);
            renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
            renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
            renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
            renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Class, CssClassListMenu);
            if (IsDiagnosticMetadataRenderingEnabled)
            {
                AddDiagnosticMetadataAttributes(renderingContext);
            }
            renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Table);

            var groupedMenuItems = GetVisibleMenuItemsInGroups(renderingContext);

            foreach (var menuItemsInGroup in groupedMenuItems)
            {
                renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                renderingContext.Writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
                renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Class, "listMenuRow");
                renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Td);

                foreach (var menuItem in menuItemsInGroup)
                {
                    RenderListMenuItem(renderingContext, menuItem, renderingContext.Control.MenuItems.IndexOf(menuItem));
                }

                renderingContext.Writer.RenderEndTag();
                renderingContext.Writer.RenderEndTag();
            }
            //WebMenuItem[] groupedListMenuItems = renderingContext.Control.MenuItems.GroupMenuItems (false).Where (mi=>mi.EvaluateVisible()).ToArray();
            //bool isFirstItem = true;
            //for (int idxItems = 0; idxItems < groupedListMenuItems.Length; idxItems++)
            //{
            //  WebMenuItem currentItem = groupedListMenuItems[idxItems];

            //  bool isLastItem = (idxItems == (groupedListMenuItems.Length - 1));
            //  bool isFirstCategoryItem = (isFirstItem || (groupedListMenuItems[idxItems - 1].Category != currentItem.Category));
            //  bool isLastCategoryItem = (isLastItem || (groupedListMenuItems[idxItems + 1].Category != currentItem.Category));
            //  bool hasAlwaysLineBreaks = (renderingContext.Control.LineBreaks == ListMenuLineBreaks.All);
            //  bool hasCategoryLineBreaks = (renderingContext.Control.LineBreaks == ListMenuLineBreaks.BetweenGroups);

            //  if (hasAlwaysLineBreaks || (hasCategoryLineBreaks && isFirstCategoryItem) || isFirstItem)
            //  {
            //    renderingContext.Writer.RenderBeginTag (HtmlTextWriterTag.Tr);
            //    renderingContext.Writer.AddStyleAttribute (HtmlTextWriterStyle.Width, "100%");
            //    renderingContext.Writer.AddAttribute (HtmlTextWriterAttribute.Class, "listMenuRow");
            //    renderingContext.Writer.RenderBeginTag (HtmlTextWriterTag.Td);
            //  }
            //  RenderListMenuItem (renderingContext, currentItem, renderingContext.Control.MenuItems.IndexOf (currentItem));
            //  if (hasAlwaysLineBreaks || (hasCategoryLineBreaks && isLastCategoryItem) || isLastItem)
            //  {
            //    renderingContext.Writer.RenderEndTag ();
            //    renderingContext.Writer.RenderEndTag ();
            //  }

            //  if (isFirstItem)
            //    isFirstItem = false;
            //}
            renderingContext.Writer.RenderEndTag();
        }
Beispiel #6
0
 private string GetMenuItemClientID(ListMenuRenderingContext renderingContext, int menuItemIndex)
 {
     return(renderingContext.Control.ClientID + "_" + menuItemIndex);
 }
Beispiel #7
0
        private void AppendListMenuItem(ListMenuRenderingContext renderingContext, StringBuilder stringBuilder, WebMenuItem menuItem)
        {
            int    menuItemIndex    = renderingContext.Control.MenuItems.IndexOf(menuItem);
            string href             = "null";
            string target           = "null";
            bool   isCommandEnabled = true;

            if (menuItem.Command != null)
            {
                bool isActive = menuItem.Command.Show == CommandShow.Always ||
                                renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.ReadOnly ||
                                !renderingContext.Control.IsReadOnly && menuItem.Command.Show == CommandShow.EditMode;

                isCommandEnabled = isActive && menuItem.Command.Type != CommandType.None;
                if (isCommandEnabled)
                {
                    bool isPostBackCommand = menuItem.Command.Type == CommandType.Event ||
                                             menuItem.Command.Type == CommandType.WxeFunction;
                    if (isPostBackCommand)
                    {
                        // Clientside script creates an anchor with href="#" and onclick=function
                        string argument = menuItemIndex.ToString();
                        href = renderingContext.Control.Page.ClientScript.GetPostBackClientHyperlink(renderingContext.Control, argument) + ";";
                        href = ScriptUtility.EscapeClientScript(href);
                        href = "'" + href + "'";
                    }
                    else if (menuItem.Command.Type == CommandType.Href)
                    {
                        href   = menuItem.Command.HrefCommand.FormatHref(menuItemIndex.ToString(), menuItem.ItemID);
                        href   = "'" + renderingContext.Control.ResolveClientUrl(href) + "'";
                        target = "'" + menuItem.Command.HrefCommand.Target + "'";
                    }
                }
            }

            bool   showIcon = menuItem.Style == WebMenuItemStyle.Icon || menuItem.Style == WebMenuItemStyle.IconAndText;
            bool   showText = menuItem.Style == WebMenuItemStyle.Text || menuItem.Style == WebMenuItemStyle.IconAndText;
            string icon     = "null";

            if (showIcon && menuItem.Icon.HasRenderingInformation)
            {
                icon = "'" + renderingContext.Control.ResolveClientUrl(menuItem.Icon.Url) + "'";
            }
            string disabledIcon = "null";

            if (showIcon && menuItem.DisabledIcon.HasRenderingInformation)
            {
                disabledIcon = "'" + renderingContext.Control.ResolveClientUrl(menuItem.DisabledIcon.Url) + "'";
            }
            string text = showText ? "'" + menuItem.Text + "'" : "null";

            bool isDisabled = !renderingContext.Control.Enabled ||
                              !menuItem.EvaluateEnabled() ||
                              !isCommandEnabled;

            stringBuilder.AppendFormat(
                "\t\tnew ListMenuItemInfo ('{0}', '{1}', {2}, {3}, {4}, {5}, {6}, {7}, {8})",
                GetMenuItemClientID(renderingContext, menuItemIndex),
                menuItem.Category,
                text,
                icon,
                disabledIcon,
                (int)menuItem.RequiredSelection,
                isDisabled ? "true" : "false",
                href,
                target);
        }