private void RegisterMenuItems(DropDownMenuRenderingContext renderingContext) { string key = renderingContext.Control.UniqueID; if (renderingContext.Control.Enabled && !renderingContext.Control.Page.ClientScript.IsStartupScriptRegistered(typeof(DropDownMenuQuirksModeRenderer), key)) { StringBuilder script = new StringBuilder(); script.Append("DropDownMenu_AddMenuInfo" + " (\r\n\t"); script.AppendFormat("new DropDownMenu_MenuInfo ('{0}', new Array (\r\n", renderingContext.Control.ClientID); bool isFirstItem = true; WebMenuItem[] menuItems; if (renderingContext.Control.EnableGrouping) { menuItems = renderingContext.Control.MenuItems.GroupMenuItems(true); } else { menuItems = renderingContext.Control.MenuItems.ToArray(); } string category = null; bool isCategoryVisible = false; for (int i = 0; i < menuItems.Length; i++) { WebMenuItem menuItem = menuItems[i]; if (renderingContext.Control.EnableGrouping && category != menuItem.Category) { category = menuItem.Category; isCategoryVisible = false; } if (!menuItem.EvaluateVisible()) { continue; } if (renderingContext.Control.EnableGrouping && menuItem.IsSeparator && !isCategoryVisible) { continue; } if (renderingContext.Control.EnableGrouping) { isCategoryVisible = true; } if (isFirstItem) { isFirstItem = false; } else { script.AppendFormat(",\r\n"); } AppendMenuItem(renderingContext, script, menuItem, renderingContext.Control.MenuItems.IndexOf(menuItem)); } script.Append(" )"); // Close Array script.Append(" )"); // Close new MenuInfo script.Append(" );"); // Close AddMenuInfo renderingContext.Control.Page.ClientScript.RegisterStartupScriptBlock(renderingContext.Control, typeof(DropDownMenuQuirksModeRenderer), key, script.ToString()); } }
public void EvaluateTrue_FromTrueAndWithCommandSetNull() { WebMenuItem menuItem = CreateWebMenuItemWithoutCommand(); menuItem.IsVisible = true; bool isVisible = menuItem.EvaluateVisible(); Assert.That(isVisible, Is.True); }
public void EvaluateFalse_FromFalseAndWithCommandSetNull() { WebMenuItem menuItem = CreateWebMenuItemWithoutCommand(); menuItem.IsVisible = false; bool isVisible = menuItem.EvaluateVisible(); Assert.That(isVisible, Is.False); }
public void EvaluateFalse_FromFalse() { WebMenuItem menuItem = CreateWebMenuItem(); menuItem.IsVisible = false; _mocks.ReplayAll(); bool isVisible = menuItem.EvaluateVisible(); _mocks.VerifyAll(); Assert.That(isVisible, Is.False); }
public void EvaluateFalse_FromTrueAndWithAccessDenied() { WebMenuItem menuItem = CreateWebMenuItem(); menuItem.IsVisible = true; Expect.Call(_mockCommand.HasAccess(_mockSecurableObject)).Return(false); _mocks.ReplayAll(); bool isVisible = menuItem.EvaluateVisible(); _mocks.VerifyAll(); Assert.That(isVisible, Is.False); }
public void EvaluateFalse_FromFalseAndWithMissingPermissionBehaviorSetToDisabled() { WebMenuItem menuItem = CreateWebMenuItem(); menuItem.MissingPermissionBehavior = MissingPermissionBehavior.Disabled; menuItem.IsVisible = false; Expect.Call(_mockCommand.HasAccess(_mockSecurableObject)).Repeat.Never(); _mocks.ReplayAll(); bool isVisible = menuItem.EvaluateVisible(); _mocks.VerifyAll(); Assert.That(isVisible, Is.False); }
public void Render(ListMenuRenderingContext renderingContext) { ArgumentUtility.CheckNotNull("renderingContext", renderingContext); RegisterMenuItems(renderingContext); WebMenuItem[] groupedListMenuItems = renderingContext.Control.MenuItems.GroupMenuItems(false).Where(mi => mi.EvaluateVisible()).ToArray(); 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.RenderBeginTag(HtmlTextWriterTag.Table); bool isFirstItem = true; for (int idxItems = 0; idxItems < groupedListMenuItems.Length; idxItems++) { WebMenuItem currentItem = groupedListMenuItems[idxItems]; if (!currentItem.EvaluateVisible()) { continue; } 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(); }
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()); } }