Exemple #1
0
        public static String BuildActionsMenu(ActionContainerHolder actions, String callbackName, Boolean IsLeft = true, String style = "btn btn-primary btn-sm", String type = "button", String ClickScript = "", String ClassName = "actions", String Glyphicon = "glyphicon-star")
        {
            StringBuilder result = new StringBuilder();

            if (!IsLeft)
            {
                style += " pull-right";
            }

            if (actions.Menu.Items.Count > 0)
            {
                result.AppendFormat("<div class='{0}'>", ClassName);

                Helpers.ContentHelper.ObjectActions = new List <MenuAction>();
                var menuItems = Helpers.GetMenuActions(actions.Menu);

                /// Reversing for pull-right correct visibility
                if (!IsLeft)
                {
                    menuItems = menuItems.Reverse().ToList();
                }

                foreach (XafMenuItem menuItem in menuItems)
                {
                    var  action      = (menuItem.ActionProcessor as MenuActionItemBase).Action as ActionBase;
                    bool usePostBack = action.Model.GetValue <bool>("IsPostBackRequired");
                    if (!(Helpers.GenerateSingleChoiceAction(ref result, menuItem, IsLeft, style, callbackName, type, ClickScript)))
                    {
                        result.Append(Helpers.GetFormattedActionString(menuItem, ClickScript + ";" + Helpers.ContentHelper.GetScript(callbackName, String.Format("\"Action={0}\"", menuItem.Name), menuItem, usePostBack).Replace("'", "\""), style, type, Glyphicon));
                    }
                }
                result.Append("</div>");
            }

            return(result.ToString());
        }
        public void GenerateMenuItems(ChoiceActionItemCollection collection)
        {
            Helpers.ContentHelper.ClearMenu();
            var ULText = "";
            var style  = @"style=""" + (String.Concat(XAFBootstrapConfiguration.Instance.GetMenuTextColor()) != "" ? "font-size: 11px; color: " + XAFBootstrapConfiguration.Instance.GetMenuTextColor() + "; " : "font-size: 11px; color: #666;") + @"""";

            XafApplication App             = (WebApplication.Instance as XafApplication);
            IModelNode     NavigationItems = App.Model.GetNode("NavigationItems").GetNode("Items");

            IList <ChoiceActionItem> LeftItems  = new List <ChoiceActionItem>();
            IList <ChoiceActionItem> RightItems = new List <ChoiceActionItem>();

            for (int i = 0; i < collection.Count; i++)
            {
                var RootItem = collection[i];
                if (!RootItem.Active || !RootItem.Enabled)
                {
                    continue;
                }

                if (RootItem.Model.GetValue <XAFBootstrapMenuAlign>("MenuAlign") == XAFBootstrapMenuAlign.Right)
                {
                    RightItems.Add(RootItem);
                }
                else
                {
                    LeftItems.Add(RootItem);
                }
            }

            if (XAFBootstrapConfiguration.Instance.Menu == MenuType.Default || XAFBootstrapConfiguration.Instance.Menu == MenuType.xbMegaMenu)
            {
                #region xb menu

                if (LeftItems.Count > 0)
                {
                    var xbMenu = "";
                    foreach (var RootItem in LeftItems)
                    {
                        xbMenu += GeneratexbSubMenu(RootItem, true, false, style);
                    }
                    foreach (var RootItem in RightItems)
                    {
                        xbMenu += GeneratexbSubMenu(RootItem, true, true, style);
                    }

                    var Settings   = "";
                    var SettingsLi = "";
                    Settings += String.Format(@"
                        <li aria-haspopup=""true"" class=""right"">
					        <a {0} href=""javascript:;"">&nbsp;<span class=""glyphicon glyphicon-cog""></span>&nbsp;</a>
                            <div class=""grid-container4"">                                        
                                <ul>", style);

                    StringBuilder tempRes = new StringBuilder();
                    foreach (XafMenuItem menuItem in Helpers.GetMenuActions(SAC))
                    {
                        String glyphiconString = "glyphicon-star";
                        if (menuItem.ActionProcessor != null && menuItem.ActionProcessor.Action != null && menuItem.ActionProcessor.Action.Model != null && !String.IsNullOrEmpty(menuItem.ActionProcessor.Action.Model.GetValue <String>("Glyphicon")))
                        {
                            glyphiconString = menuItem.ActionProcessor.Action.Model.GetValue <String>("Glyphicon");
                        }
                        if (!(Helpers.GenerateSingleChoiceAction(ref tempRes, menuItem, true, "", SAC.UniqueID + "_Callback")))
                        {
                            SettingsLi += String.Format("<li><a islink=\"true\" class=\"xb-mega-menu-li-a\" href='javascript:;' onclick='$(\".xb-mega-menu.mobile li\").removeClass(\"hover\"); if ($(\"#settingsCollapseButton\").is(\":visible\")) $(\"#settingsCollapseButton\").click();{2}'><span class='glyphicon {4}'></span> {0}</a></li>"
                                                        , menuItem.Text
                                                        , menuItem.Name
                                                        , Helpers.ContentHelper.GetScript(SAC.UniqueID + "_Callback", String.Format("\"Action={0}\"", menuItem.Name)).Replace("'", "\"")
                                                        , ""
                                                        , glyphiconString
                                                        , style);
                        }
                        else
                        {
                            var choiceAction = (menuItem.ActionProcessor as MenuActionItemBase).Action as SingleChoiceAction;
                            SettingsLi += String.Format(@"<li class=""dropdown-header"">{0}</li>", choiceAction.Caption);
                            SettingsLi += String.Join("", choiceAction.Items.Select(f =>
                                                                                    String.Format("<li><a islink=\"true\" class=\"xb-mega-menu-li-a\" href=\"javascript:;\" onclick='$(\".xb-mega-menu.mobile li\").removeClass(\"hover\"); if ($(\"#settingsCollapseButton\").is(\":visible\")) $(\"#settingsCollapseButton\").click();{2}'><span class=\"glyphicon {1}\"></span> {0}</a></li>"
                                                                                                  , f.Caption
                                                                                                  , glyphiconString
                                                                                                  , Helpers.ContentHelper.GetScript(SAC.UniqueID + "_Callback", String.Format("\"Action={0},{1}\"", menuItem.Name, f.Id)).Replace("'", "\"")
                                                                                                  , style
                                                                                                  )
                                                                                    ));
                        }
                    }
                    Settings += SettingsLi;
                    Settings += @"</ul>
                            <div>
                        </li>";

                    xbMenu += Settings;

                    ULText = String.Format(
                        @"<div style='position: relative'>
                        <div class=""hidden-xs hidden-sm"">
                            <ul class=""xb-mega-menu desktop xb-mega-menu-anim-scale xb-mega-menu-response-to-icons"" style=""{2}"">
                            {0}
                            </ul>
                        </div>
                        <div class=""hidden-md hidden-lg"">
                            <ul class=""xb-mega-menu mobile xb-mega-menu-anim-scale xb-mega-menu-response-to-icons"" style=""{2}"">
                                <li aria-haspopup=""true"" class=""right"">
					                <a href=""javascript:;"">
                                        &nbsp;<span class=""glyphicon glyphicon-th-list"" style=""font-size: 13pt; margin-top: 10px; {3}""></span>&nbsp;                                    
                                    </a>
                                    <div class=""grid-container4"">                                        
                                        <ul style=""{2}"">{1}</ul>
                                    </div>
                                </li>
                            </ul>
                        </div>
                        <div class=""progress loading-progress"" style=""display: none; position: absolute; bottom: 0px; z-index: 1000; width: 100%;"" id=""loadingProgress"">
                            <div class=""progress-bar progress-bar-info progress-bar-striped active"" role=""progressbar"" aria-valuenow=""100"" aria-valuemin=""0"" aria-valuemax=""100"" style=""width: 100%""></div>
                        </div>
                    </div>"
                        , xbMenu
                        , xbMenu
                        , String.Concat(XAFBootstrapConfiguration.Instance.GetMenuBackgroundColor()) != "" ? "background: " + XAFBootstrapConfiguration.Instance.GetMenuBackgroundColor() + ";" : ""
                        , String.Concat(XAFBootstrapConfiguration.Instance.GetMenuTextColor()) != "" ? "color: " + XAFBootstrapConfiguration.Instance.GetMenuTextColor() + ";" : ""
                        );
                }

                xbMegaMenu.EncodeHtml = false;
                xbMegaMenu.Text       = ULText;
                #endregion
            }
            else
            {
                #region Bootstrap menu
                if (LeftItems.Count > 0)
                {
                    ULText += "<ul class='nav navbar-nav'>";
                    foreach (var RootItem in LeftItems)
                    {
                        if (RootItem.Items.Count > 0)
                        {
                            ULText += String.Format(
                                @"<li class='dropdown'>
                                <a href='javascript:;' class='dropdown-toggle' data-toggle='dropdown'>{2} <span>{0}</span> <span class='caret'></span>
                                </a>
                                <ul class='dropdown-menu' role='menu'>{1}</ul></li>
                               "
                                , RootItem.Caption
                                , GenerateSubMenu(RootItem, true)
                                , String.Concat(RootItem.Model.GetValue <String>("Glyphicon")) != ""
                                     ? FormatGlyphicon(String.Concat(RootItem.Model.GetValue <String>("Glyphicon"))) : ""
                                );
                        }
                        else
                        {
                            ULText += GetMenuItem(RootItem);
                        }
                    }
                    ULText += "</ul>";
                }

                var Settings   = "";
                var SettingsLi = "";
                Settings += @"
                        <li class='dropdown hidden-xs' style='position: absolute; right: 10px;'>
                          <a href='#' class='dropdown-toggle' data-toggle='dropdown'><span class='glyphicon glyphicon-cog settings-button'></span></a>
                          <ul class='dropdown-menu' role='menu'>";

                StringBuilder tempRes = new StringBuilder();
                foreach (XafMenuItem menuItem in Helpers.GetMenuActions(SAC))
                {
                    String glyphiconString = "glyphicon-star";
                    if (menuItem.ActionProcessor != null && menuItem.ActionProcessor.Action != null && menuItem.ActionProcessor.Action.Model != null && !String.IsNullOrEmpty(menuItem.ActionProcessor.Action.Model.GetValue <String>("Glyphicon")))
                    {
                        glyphiconString = menuItem.ActionProcessor.Action.Model.GetValue <String>("Glyphicon");
                    }
                    if (!(Helpers.GenerateSingleChoiceAction(ref tempRes, menuItem, true, "", SAC.UniqueID + "_Callback")))
                    {
                        SettingsLi += String.Format("<li><a href='javascript:;' onclick='if ($(\"#settingsCollapseButton\").is(\":visible\")) $(\"#settingsCollapseButton\").click();{2}'><span class='glyphicon {4}'></span> {0}</a></li>"
                                                    , menuItem.Text
                                                    , menuItem.Name
                                                    , Helpers.ContentHelper.GetScript(SAC.UniqueID + "_Callback", String.Format("\"Action={0}\"", menuItem.Name)).Replace("'", "\"")
                                                    , ""
                                                    , glyphiconString);
                    }
                    else
                    {
                        var choiceAction = (menuItem.ActionProcessor as MenuActionItemBase).Action as SingleChoiceAction;
                        SettingsLi += String.Format(@"<li class=""dropdown-header"">{0}</li>", choiceAction.Caption);
                        SettingsLi += String.Join("", choiceAction.Items.Select(f =>
                                                                                String.Format("<li><a href=\"javascript:;\" onclick='if ($(\"#settingsCollapseButton\").is(\":visible\")) $(\"#settingsCollapseButton\").click();{2}'><span class=\"glyphicon {1}\"></span> {0}</a></li>"
                                                                                              , f.Caption
                                                                                              , glyphiconString
                                                                                              , Helpers.ContentHelper.GetScript(SAC.UniqueID + "_Callback", String.Format("\"Action={0},{1}\"", menuItem.Name, f.Id)).Replace("'", "\""))
                                                                                ));
                    }
                }
                Settings += SettingsLi;
                Settings +=
                    @"</ul>
                      </li>";


                //if (RightItems.Count > 0)
                {
                    ULText += "<ul class='nav navbar-nav navbar-right'>";

                    ULText += Settings;

                    foreach (var RootItem in RightItems)
                    {
                        if (RootItem.Items.Count > 0)
                        {
                            ULText += String.Format(
                                @"<li class='dropdown'>
                                <a href='#' class='dropdown-toggle' data-toggle='dropdown'>{0} <span class='caret'></span></a>
                                <ul class='dropdown-menu' role='menu'>{1}</ul></li>"
                                , RootItem.Caption
                                , GenerateSubMenu(RootItem, true)
                                , String.Concat(RootItem.Model.GetValue <String>("Glyphicon")) != ""
                                     ? FormatGlyphicon(String.Concat(RootItem.Model.GetValue <String>("Glyphicon"))) : ""
                                );
                        }
                        else
                        {
                            ULText += String.Format("<li><a href='#about'>{0}</a></li>", GetMenuItem(RootItem));
                        }
                    }
                    ULText += "</ul>";
                }

                TopMenu.EncodeHtml = false;
                TopMenu.Text       = String.Format(@"
                    <div class='navbar navbar-default navbar-fixed-top {3}' role='navigation' id='navbar'>
                      <div>
                        <div class='navbar-header'>                        
                          <button type='button' id='menuCollapseButton' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#mainMenu'>
                            <span class='sr-only'>Toggle navigation</span>
                            <span class='icon-bar'></span>
                            <span class='icon-bar'></span>
                            <span class='icon-bar'></span>
                          </button>
                          <button type='button' id='settingsCollapseButton' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#settingsMenu'>
                            <span class='sr-only'>Toggle navigation</span>
                            <span class='glyphicon glyphicon-cog text-info settings-button'></span>
                          </button>                    
                          <a class='navbar-brand' href='#'>{1}</a>
                        </div>                    
                        <div class='navbar-collapse collapse' id='mainMenu'>
                            <div class='container'>
                                {0}
                            </div>
                        </div>
                        <div class='navbar-collapse collapse' id='settingsMenu'>
                            <ul class='nav hidden-sm hidden-md hidden-lg navbar-nav'>
                                {2}
                            </ul>
                        </div>
                      </div>
                    
                      <div class=""progress loading-progress"" style=""display: none"" id=""loadingProgress"">
                        <div class=""progress-bar progress-bar-info progress-bar-striped active"" role=""progressbar"" aria-valuenow=""100"" aria-valuemin=""0"" aria-valuemax=""100"" style=""width: 100%""></div>
                      </div>

                    </div>"
                                                   , ULText
                                                   , (File.Exists(MapPath("~/images/logo.png")) ? "<img style='max-height: 30px; max-width: 160px; margin-top: -5px;' src='images/logo.png'>" : App.Model.Title)
                                                   , SettingsLi
                                                   , XAFBootstrapConfiguration.Instance != null && XAFBootstrapConfiguration.Instance.InverseNavBar ? "navbar-inverse" : "");
                #endregion
            }
        }
Exemple #3
0
        public void GenerateMenuItems(ChoiceActionItemCollection collection)
        {
            Helpers.ContentHelper.ClearMenu();
            var ULText = "";

            XafApplication App             = (WebApplication.Instance as XafApplication);
            IModelNode     NavigationItems = App.Model.GetNode("NavigationItems").GetNode("Items");

            IList <ChoiceActionItem> LeftItems  = new List <ChoiceActionItem>();
            IList <ChoiceActionItem> RightItems = new List <ChoiceActionItem>();

            for (int i = 0; i < collection.Count; i++)
            {
                var RootItem = collection[i];
                if (!RootItem.Active || !RootItem.Enabled)
                {
                    continue;
                }
                if (RootItem.Model is IModelMenuAlign)
                {
                    if ((RootItem.Model as IModelMenuAlign).MenuAlign == XAFBootstrapMenuAlign.Right)
                    {
                        RightItems.Add(RootItem);
                    }
                    else
                    {
                        LeftItems.Add(RootItem);
                    }
                }
                else
                {
                    LeftItems.Add(RootItem);
                }
            }

            if (LeftItems.Count > 0)
            {
                ULText += "<ul class='nav navbar-nav'>";
                foreach (var RootItem in LeftItems)
                {
                    if (RootItem.Items.Count > 0)
                    {
                        ULText += String.Format(
                            @"<li class='dropdown'>
                            <a href='javascript:;' class='dropdown-toggle' data-toggle='dropdown'>{2} <span>{0}</span> <span class='caret'></span>
                            </a>
                            <ul class='dropdown-menu' role='menu'>{1}</ul></li>
                           "
                            , RootItem.Caption
                            , GenerateSubMenu(RootItem, true)
                            , RootItem.Model is IModelGlyphicon && String.Concat((RootItem.Model as IModelGlyphicon).Glyphicon) != ""
                                 ? String.Format("<span class='glyphicon glyphicon-{0}'></span> ", (RootItem.Model as IModelGlyphicon).Glyphicon) : ""
                            );
                    }
                    else
                    {
                        ULText += GetMenuItem(RootItem);
                    }
                }
                ULText += "</ul>";
            }

            var Settings   = "";
            var SettingsLi = "";

            Settings += @"
                    <li class='dropdown hidden-xs' style='position: absolute; right: 10px;'>
                      <a href='#' class='dropdown-toggle' data-toggle='dropdown'><span class='glyphicon glyphicon-cog settings-button'></span></a>
                      <ul class='dropdown-menu' role='menu'>";

            StringBuilder tempRes = new StringBuilder();

            foreach (XafMenuItem menuItem in Helpers.GetMenuActions(SAC))
            {
                if (!(Helpers.GenerateSingleChoiceAction(ref tempRes, menuItem, true, "", SAC.UniqueID + "_Callback")))
                {
                    SettingsLi += String.Format("<li><a href='javascript:;' onclick='if ($(\"#settingsCollapseButton\").is(\":visible\")) $(\"#settingsCollapseButton\").click();{2}'><span class='glyphicon glyphicon-star'></span> {0}</a></li>"
                                                , menuItem.Text
                                                , menuItem.Name
                                                , Helpers.ContentHelper.GetScript(SAC.UniqueID + "_Callback", String.Format("\"Action={0}\"", menuItem.Name)).Replace("'", "\""), "");
                }
                else
                {
                    var choiceAction = (menuItem.ActionProcessor as MenuActionItemBase).Action as SingleChoiceAction;
                    SettingsLi += String.Format(@"<li class=""dropdown-header"">{0}</li>", choiceAction.Caption);
                    SettingsLi += String.Join("", choiceAction.Items.Select(f =>
                                                                            String.Format("<li><a href=\"javascript:;\" onclick='if ($(\"#settingsCollapseButton\").is(\":visible\")) $(\"#settingsCollapseButton\").click();{1}'><span class=\"glyphicon glyphicon-star\"></span> {0}</a></li>"
                                                                                          , f.Caption
                                                                                          , Helpers.ContentHelper.GetScript(SAC.UniqueID + "_Callback", String.Format("\"Action={0},{1}\"", menuItem.Name, f.Id)).Replace("'", "\""))
                                                                            ));
                }
            }
            Settings += SettingsLi;
            Settings +=
                @"</ul>
                  </li>";


            //if (RightItems.Count > 0)
            {
                ULText += "<ul class='nav navbar-nav navbar-right'>";

                ULText += Settings;

                foreach (var RootItem in RightItems)
                {
                    if (RootItem is IModelMenuAlign)
                    {
                    }
                    if (RootItem.Items.Count > 0)
                    {
                        ULText += String.Format(
                            @"<li class='dropdown'>
                            <a href='#' class='dropdown-toggle' data-toggle='dropdown'>{0} <span class='caret'></span></a>
                            <ul class='dropdown-menu' role='menu'>{1}</ul></li>"
                            , RootItem.Caption
                            , GenerateSubMenu(RootItem, true)
                            , RootItem.Model is IModelGlyphicon && String.Concat((RootItem.Model as IModelGlyphicon).Glyphicon) != ""
                                 ? String.Format("<span class='glyphicon glyphicon-{0}'></span> ", (RootItem.Model as IModelGlyphicon).Glyphicon) : ""
                            );
                    }
                    else
                    {
                        ULText += String.Format("<li><a href='#about'>{0}</a></li>", GetMenuItem(RootItem));
                    }
                }
                ULText += "</ul>";
            }

            TopMenu.EncodeHtml = false;
            TopMenu.Text       = String.Format(@"
                <div class='navbar navbar-default navbar-fixed-top {3}' role='navigation' id='navbar'>
                  <div class='container'>
                    <div class='navbar-header'>                        
                      <button type='button' id='menuCollapseButton' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#mainMenu'>
                        <span class='sr-only'>Toggle navigation</span>
                        <span class='icon-bar'></span>
                        <span class='icon-bar'></span>
                        <span class='icon-bar'></span>
                      </button>
                      <button type='button' id='settingsCollapseButton' class='navbar-toggle collapsed' data-toggle='collapse' data-target='#settingsMenu'>
                        <span class='sr-only'>Toggle navigation</span>
                        <span class='glyphicon glyphicon-cog text-info settings-button'></span>
                      </button>                    
                      <a class='navbar-brand' href='#'>{1}</a>
                    </div>                    
                    <div class='navbar-collapse collapse' id='mainMenu'>
                        {0}
                    </div>
                    <div class='navbar-collapse collapse' id='settingsMenu'>
                        <ul class='nav hidden-sm hidden-md hidden-lg navbar-nav'>
                            {2}
                        </ul>
                    </div>
                  </div>
                    
                  <div class=""progress loading-progress"" style=""display: none"" id=""loadingProgress"">
                    <div class=""progress-bar progress-bar-info progress-bar-striped active"" role=""progressbar"" aria-valuenow=""100"" aria-valuemin=""0"" aria-valuemax=""100"" style=""width: 100%""></div>
                  </div>

                </div>"
                                               , ULText
                                               , (File.Exists(MapPath("~/images/logo.png")) ? "<img style='max-height: 30px; max-width: 160px; margin-top: -5px;' src='images/logo.png'>" : App.Model.Title)
                                               , SettingsLi
                                               , XAFBootstrapConfiguration.Instance != null && XAFBootstrapConfiguration.Instance.InverseNavBar ? "navbar-inverse" : "");
        }