コード例 #1
0
ファイル: Module.cs プロジェクト: moayyaed/YetaWF-Modules
        /// <summary>
        /// Renders a complete module menu.
        /// </summary>
        /// <param name="mod">The module for which the module menu is rendered.</param>
        /// <returns>Returns the complete module menu as HTML.</returns>
        public async Task <string> RenderModuleMenuAsync(ModuleDefinition mod)
        {
            HtmlBuilder hb = new HtmlBuilder();

            MenuList moduleMenu = await mod.GetModuleMenuListAsync(ModuleAction.RenderModeEnum.NormalMenu, ModuleAction.ActionLocationEnum.ModuleMenu);

            string menuContents = (await RenderMenuAsync(moduleMenu, null, Globals.CssModuleMenu));

            if (!string.IsNullOrWhiteSpace(menuContents))
            {
                //await Manager.ScriptManager.AddKendoUICoreJsFile("kendo.popup.min.js"); // is now a prereq of kendo.window (2017.2.621)
                await KendoUICore.AddFileAsync("kendo.menu.min.js");

                await Manager.AddOnManager.AddAddOnNamedAsync(Package.AreaName, "ModuleMenu");   // module menu support

                await Manager.AddOnManager.AddAddOnNamedAsync(Package.AreaName, "Modules");      // various module support

                await Manager.AddOnManager.AddAddOnNamedAsync(Package.AreaName, "jquery-color"); // for color change when entering module edit menu

                // <div class= >
                YTagBuilder divTag = new YTagBuilder("div");
                divTag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(Globals.CssModuleMenuEditIcon));
                divTag.Attributes.Add("style", "display:none");
                hb.Append(divTag.ToString(YTagRenderMode.StartTag));

                hb.Append(ImageHTML.BuildKnownIcon("#ModuleMenuEdit", sprites: Info.PredefSpriteIcons, title: null /*no tooltip here as it's useless */));

                // <div>
                YTagBuilder div2Tag = new YTagBuilder("div");
                div2Tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(Globals.CssModuleMenuContainer));
                hb.Append(div2Tag.ToString(YTagRenderMode.StartTag));

                // <ul><li> menu
                hb.Append(menuContents);

                // </div>
                hb.Append(div2Tag.ToString(YTagRenderMode.EndTag));

                // </div>
                hb.Append(divTag.ToString(YTagRenderMode.EndTag));
            }
            return(hb.ToString());
        }
コード例 #2
0
ファイル: PanelInfo.cs プロジェクト: moayyaed/YetaWF-Modules
        public async Task <string> RenderAsync(PanelInfo model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            hb.Append($@"
<div class='yt_panels_panelinfo t_display' id='{ControlId}'>");

            if (model.Style == PanelInfo.PanelStyleEnum.Tabs)
            {
                UI ui = new UI {
                    TabsDef = new TabsDefinition {
                        ActiveTabIndex = model._ActiveTab,
                    }
                };

                for (int panelIndex = 0; panelIndex < model.Panels.Count; ++panelIndex)
                {
                    if (model.Panels[panelIndex].IsAuthorizedAsync().Result)
                    {
                        string caption = model.Panels[panelIndex].Caption;
                        if (string.IsNullOrWhiteSpace(caption))
                        {
                            caption = this.__ResStr("noCaption", "(no caption)");
                        }
                        string toolTip = model.Panels[panelIndex].ToolTip;
                        if (string.IsNullOrWhiteSpace(toolTip))
                        {
                            toolTip = null;
                        }
                        ui.TabsDef.Tabs.Add(new TabEntry {
                            Caption         = caption,
                            ToolTip         = toolTip,
                            PaneCssClasses  = "t_panel",
                            RenderPaneAsync = async(int tabIndex) => {
                                HtmlBuilder hbt = new HtmlBuilder();
                                if (await model.Panels[tabIndex].IsAuthorizedAsync())
                                {
                                    ModuleDefinition mod = await model.Panels[tabIndex].GetModuleAsync();
                                    if (mod != null)
                                    {
                                        mod.ShowTitle         = false;
                                        mod.UsePartialFormCss = false;
                                        hbt.Append(await mod.RenderModuleAsync(HtmlHelper));
                                    }
                                    else
                                    {
                                        hbt.Append($@"<div>{this.__ResStr("noModule", "(no module defined)")}</div>");
                                    }
                                }
                                return(hbt.ToString());
                            },
                        });
                    }
                }
                hb.Append($@"
    <div class='t_panels t_acctabs' id='{DivId}'>
        {await HtmlHelper.ForDisplayAsync(ui, nameof(ui.TabsDef), HtmlAttributes: new { __NoTemplate = true })}
    </div>");
            }
            else if (model.Style == PanelInfo.PanelStyleEnum.AccordionjQuery)
            {
                hb.Append($@"
    <div class='t_panels t_accjquery' id='{DivId}'>");

                int panelIndex = 0;

                for (panelIndex = 0; panelIndex < model.Panels.Count; ++panelIndex)
                {
                    if (await model.Panels[panelIndex].IsAuthorizedAsync())
                    {
                        string caption = model.Panels[panelIndex].Caption;
                        if (string.IsNullOrWhiteSpace(caption))
                        {
                            caption = this.__ResStr("noCaption", "(no caption)");
                        }
                        hb.Append($@"<h3>{Utility.HtmlEncode(caption)}</h3>");
                        ModuleDefinition mod = model.Panels[panelIndex].GetModuleAsync().Result;
                        if (mod != null)
                        {
                            mod.ShowTitle         = false;
                            mod.UsePartialFormCss = false;
                            hb.Append(await mod.RenderModuleAsync(HtmlHelper));
                        }
                        else
                        {
                            hb.Append($@"<div>{this.__ResStr("noModule", "(no module defined)")}</div>");
                        }
                    }
                }
                hb.Append($@"
    </div>");

                Manager.ScriptManager.AddLast($@"
$('#{DivId}').accordion({{
    collapsible: true,
    heightStyle: 'content',
    activate: function (ev, ui) {{
        if (ui.newPanel[0])
            $YetaWF.processActivateDivs([ui.newPanel[0]]);
    }}
}});");
            }
            else if (model.Style == PanelInfo.PanelStyleEnum.AccordionKendo)
            {
                hb.Append($@"
    <ul class='t_panels t_acckendo' id='{DivId}'>");

                int panelIndex = 0;
                int tabIndex   = 0;

                for (panelIndex = 0; panelIndex < model.Panels.Count; ++panelIndex)
                {
                    if (model.Panels[panelIndex].IsAuthorizedAsync().Result)
                    {
                        string caption = model.Panels[panelIndex].Caption;
                        if (string.IsNullOrWhiteSpace(caption))
                        {
                            caption = this.__ResStr("noCaption", "(no caption)");
                        }

                        hb.Append($@"
        <li class='{(model._ActiveTab == tabIndex ? "k-state-active" : "")}'>
            <span class='{(model._ActiveTab == tabIndex ? "k-link k-state-selected" : "")}'>{Utility.HtmlEncode(caption)}</span>
            <div class='t_panel-kendo' style='display:none'>");

                        ModuleDefinition mod = await model.Panels[panelIndex].GetModuleAsync();
                        if (mod != null)
                        {
                            mod.ShowTitle         = false;
                            mod.UsePartialFormCss = false;
                            hb.Append(await mod.RenderModuleAsync(HtmlHelper));
                        }
                        else
                        {
                            hb.Append(this.__ResStr("noModule", "(no module defined)"));
                        }
                        hb.Append($@"
            </div>
        </li>");

                        ++tabIndex;
                    }
                }
                hb.Append($@"
    </ul>
</div>");

                await KendoUICore.AddFileAsync("kendo.data.min.js");

                await KendoUICore.AddFileAsync("kendo.panelbar.min.js");

                Manager.ScriptManager.AddLast($@"
$('#{DivId}').kendoPanelBar({{
    expandMode: 'single',
    activate: function(ev) {{
        if (ev.item[0])
            $YetaWF.processActivateDivs([ev.item[0]]);
    }}
}});
var $panelBar = $('#{DivId}').kendoPanelBar().data('kendoPanelBar');
$panelBar.select();");
            }

            Manager.ScriptManager.AddLast($@"
{BeginDocumentReady(ControlId)}
    $YetaWF.processActivateDivs([$YetaWF.getElementById('{ControlId}')]);
{EndDocumentReady()} ");

            return(hb.ToString());
        }