Exemple #1
0
        /// <summary>
        /// Creates the global navigation links.
        /// </summary>
        /// <param name="isSecureConnection">The flag indicating whether the HTTP connection uses secure sockets.</param>
        /// <returns>The control that represents the global navigation links.</returns>
        private Control CreateGlobalNavigation(bool isSecureConnection)
        {
            ControlList        links = null;
            HyperLink          link  = null;
            HyperLink          link2 = null;
            HtmlGenericControl ul    = null;
            HtmlGenericControl ul2   = null;
            HtmlGenericControl li    = null;
            HtmlGenericControl li2   = null;

            try
            {
                if (m_ModernTheme)
                {
                    ul = new HtmlGenericControl("ul");
                    ul.Attributes["class"] = "nav pull-right";
                }
                else
                {
                    links = new ControlList();
                }

                Micajah.Common.Bll.ActionCollection items = ActionProvider.GlobalNavigationLinks.FindByActionId(ActionProvider.GlobalNavigationLinksActionId).GetAvailableChildActions(m_ActionIdList, m_IsFrameworkAdmin, m_IsAuthenticated);

                if (m_ModernTheme)
                {
                    li = (HtmlGenericControl)CreateApplicationLogoListItem("Al");

                    ul.Controls.Add(li);
                }
                else
                {
                    Micajah.Common.Bll.Action item = items.FindByActionId(ActionProvider.MyAccountMenuGlobalNavigationLinkActionId);

                    if (item != null)
                    {
                        Micajah.Common.Bll.ActionCollection items2 = item.GetAvailableChildActions(m_ActionIdList, m_IsFrameworkAdmin, m_IsAuthenticated);

                        items.AddRange(items2);

                        items.Sort();
                    }
                }

                foreach (Micajah.Common.Bll.Action item in items)
                {
                    link             = new HyperLink();
                    link.NavigateUrl = item.CustomAbsoluteNavigateUrl;
                    link.ToolTip     = item.Description;

                    if (m_ModernTheme)
                    {
                        li = new HtmlGenericControl("li");

                        string iconUrl  = null;
                        string text     = item.CustomName;
                        string cssClass = "Icon";

                        if (item.ActionId == ActionProvider.MyAccountMenuGlobalNavigationLinkActionId)
                        {
                            iconUrl = string.Format(CultureInfo.InvariantCulture, "{0}{1}www.gravatar.com/avatar/{2}?s=24"
                                                    , (isSecureConnection ? Uri.UriSchemeHttps : Uri.UriSchemeHttp), Uri.SchemeDelimiter, Support.CalculateMD5Hash(m_UserContext.Email.ToLowerInvariant()));

                            cssClass += " Avtr";
                        }
                        else
                        {
                            if (item.ActionId == ActionProvider.PageHelpGlobalNavigationLinkActionId)
                            {
                                if (!m_MasterPage.VisibleHelpLink)
                                {
                                    continue;
                                }

                                link.Attributes["onclick"] = m_MasterPage.HelpLinkOnClick;
                            }

                            if (!string.IsNullOrEmpty(item.IconUrl))
                            {
                                iconUrl = item.IconUrl;
                                if (iconUrl.IndexOf("glyphicon", StringComparison.OrdinalIgnoreCase) == -1)
                                {
                                    iconUrl = CustomUrlProvider.CreateApplicationAbsoluteUrl(iconUrl);
                                }
                                else
                                {
                                    using (Label label = new Label())
                                    {
                                        label.CssClass = "glyphicon " + iconUrl;

                                        if (string.IsNullOrEmpty(text))
                                        {
                                            label.CssClass += " no-margin";
                                        }

                                        link.Controls.Add(label);
                                    }

                                    iconUrl = null;
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(iconUrl))
                        {
                            using (Image image = new Image())
                            {
                                image.ImageUrl = iconUrl;
                                image.CssClass = cssClass;

                                link.Controls.Add(image);
                            }
                        }

                        if (!string.IsNullOrEmpty(text))
                        {
                            using (LiteralControl literal = new LiteralControl(text))
                            {
                                link.Controls.Add(literal);
                            }
                        }

                        li.Controls.Add(link);
                        ul.Controls.Add(li);

                        ActionCollection childActions = item.GetAvailableChildActions(m_ActionIdList, m_IsFrameworkAdmin, m_IsAuthenticated);
                        if (childActions.Count > 0)
                        {
                            link.CssClass = "dropdown-toggle";
                            link.Attributes["data-toggle"] = "dropdown";

                            using (Label label = new Label())
                            {
                                label.CssClass = "caret";
                                link.Controls.Add(label);
                            }

                            ul2 = new HtmlGenericControl("ul");
                            ul2.Attributes["class"] = "dropdown-menu blue";

                            foreach (Micajah.Common.Bll.Action item2 in childActions)
                            {
                                li2 = new HtmlGenericControl("li");

                                link2             = new HyperLink();
                                link2.Text        = item2.CustomName;
                                link2.NavigateUrl = item2.CustomAbsoluteNavigateUrl;
                                link2.ToolTip     = item2.Description;

                                li2.Controls.Add(link2);
                                ul2.Controls.Add(li2);
                            }

                            li.Attributes["class"] = "dropdown";
                            li.Controls.Add(ul2);
                        }
                    }
                    else
                    {
                        if (item.ActionId == ActionProvider.MyAccountMenuGlobalNavigationLinkActionId)
                        {
                            if ((m_UserContext != null) && (m_UserContext.OrganizationId == Guid.Empty))
                            {
                                continue;
                            }
                        }

                        link.Text = item.CustomName;

                        links.Add(link);
                    }
                }

                if (m_ModernTheme)
                {
                    return(ul);
                }
                else
                {
                    return((links.Count > 0) ? links : null);
                }
            }
            finally
            {
                if (ul2 != null)
                {
                    ul2.Dispose();
                }
                if (li2 != null)
                {
                    li2.Dispose();
                }
                if (ul != null)
                {
                    ul.Dispose();
                }
                if (li != null)
                {
                    li.Dispose();
                }
                if (link != null)
                {
                    link.Dispose();
                }
                if (links != null)
                {
                    links.Dispose();
                }
            }
        }