public static void PrimeXml(MainMenuItem[] items) { // This is only supposed to be used once, to prime the initial menu XmlSerializer serializer = new XmlSerializer(typeof (MainMenuItem[])); using (TextWriter writer = new StreamWriter("C:\\Windows\\Temp\\temp.xml")) { serializer.Serialize(writer, items); } }
public static MainMenuItem Submenu(string resourceKey, int userLevel, string permissions) { MainMenuItem result = new MainMenuItem() { Permissions = permissions, ResourceKey = resourceKey, UserLevel = userLevel, Type = MenuItemType.Submenu }; return result; }
public static MainMenuItem Disabled(string image, string resourceKey, int userLevel, string permissions) { MainMenuItem result = new MainMenuItem() { ImageUrl = image, Permissions = permissions, ResourceKey = resourceKey, UserLevel = userLevel, Type = MenuItemType.Disabled }; return result; }
public static MainMenuItem Link(string image, string navUrl, string resourceKey, int userLevel, string permissions) { MainMenuItem result = new MainMenuItem() { ImageUrl = image, NavigateUrl = navUrl, Permissions = permissions, ResourceKey = resourceKey, UserLevel = userLevel, Type = MenuItemType.Link }; return result; }
private void WriteMenuItem(MainMenuItem menuItem, HtmlTextWriter output) { output.Write("<li class=\"{0}\">", menuItem.Type.ToString()); string localizedText = "RESOURCE NOT FOUND"; if (!String.IsNullOrEmpty(menuItem.ResourceKey)) { object resourceObject = GetGlobalResourceObject("Menu5", "Menu5_" + menuItem.ResourceKey); if (resourceObject != null) { localizedText = resourceObject.ToString(); } } localizedText = Server.HtmlEncode(localizedText); // muy importante string iconSize = "40px"; if (File.Exists(Server.MapPath("~/Images/PageIcons/" + menuItem.ImageUrl + "-20px.png"))) { iconSize = "20px"; } switch (menuItem.Type) { // TODO: More types here, and check with the CSS. Some work to get good looking // MEH forcing build case MenuItemType.Link: output.Write("<a href=\"{1}\"><img src=\"/Images/PageIcons/{0}-{3}.png\" height=\"20\" width=\"20\" />{2}</a>", menuItem.ImageUrl, menuItem.NavigateUrl, localizedText, iconSize); break; case MenuItemType.Disabled: string imageUrl = "/Images/PageIcons/" + menuItem.ImageUrl + "-" + iconSize + ".png"; if (String.IsNullOrEmpty(menuItem.ImageUrl)) { imageUrl = "/Images/PageIcons/transparency-16px.png"; // doesn't matter in slightest if browser resizes to 20px } output.Write("<a href='#disabled'><img src=\"{0}\" height=\"20\" width=\"20\" />{1}</a>", imageUrl, localizedText); break; case MenuItemType.Submenu: output.Write("<a href='#'>" + localizedText + "</a>"); break; case MenuItemType.Separator: output.Write(" <hr/>"); break; default: throw new NotImplementedException(); } if (menuItem.Children.Length > 0) { output.Write("<ul>"); foreach (MainMenuItem child in menuItem.Children) { WriteMenuItem(child, output); } output.Write("</ul>"); } output.Write("</li>"); }
public MainMenuItem() { Children = new MainMenuItem[0]; }
public static void PrimeNewMenuFile() { MainMenuItem todoItem = MainMenuItem.Disabled(string.Empty, "Placeholder_Todo", 1, string.Empty); MainMenuItem[] todoItemArray = new MainMenuItem[] {todoItem}; MainMenuItem peopleItem = MainMenuItem.Submenu("People", 1, string.Empty); peopleItem.Children = todoItemArray; MainMenuItem commsItem = MainMenuItem.Submenu("Communications", 1, string.Empty); peopleItem.Children = todoItemArray; MainMenuItem claimRefundItem = MainMenuItem.Link("iconshock-moneyback", "/Pages/v5/Financial/FileExpenseClaim.aspx", "Financial_ClaimExpense", 2, String.Empty); MainMenuItem separatorItem = MainMenuItem.Separator; MainMenuItem[] financialChildren = new[] {claimRefundItem, separatorItem}; MainMenuItem financialItem = MainMenuItem.Submenu("Financial", 2, string.Empty); financialItem.Children = financialChildren; MainMenuItem[] protoMenu = new[] {peopleItem, commsItem, financialItem}; PrimeXml(protoMenu); }