Example #1
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var buttons = new StringBuilder("[");
            var id      = output.Attributes["id"]?.Value;

            if (HasSave)
            {
                buttons.Append($"{{ text:'{SaveButtonName}', iconCls:'icon-ok', handler:function(){{ {OnSave} }} }},");
            }
            if (HasClose)
            {
                buttons.Append($"{{ text:'{CloseButtonName}', iconCls:'icon-cancel', handler:function(){{ {(id != null ? $"$('#{id}').window('close')" : "")} }} }},");
            }


            buttons.Append("]");

            Options.AddIf(OnClose.IsNotNullOrWhiteSpace(), EasyuiConsts.Dialog_OnClose, GetJavaScriptString($"function(){{ {OnClose} }}"));

            Options.AddIf(IsMax, EasyuiConsts.Dialog_IsMax, IsMax);

            Options.Add(EasyuiConsts.Dialog_Buttons, GetJavaScriptString(buttons.ToString()));

            output.Attributes.Add(EasyuiConsts.Dialog_Closed, Closed.ToString().ToCamelCase());

            if (Closed)
            {
                var style = output.Attributes["style"]?.ToString() ?? "";
                if (style.IsNotNullOrWhiteSpace() && !style.EndsWith(";"))
                {
                    style += ";";
                }
                style += "display: none;";
                output.Attributes.SetAttribute("style", style);
            }

            await base.ProcessAsync(context, output);
        }
Example #2
0
        protected override void InitOption(TagHelperContext context, TagHelperOutput output)
        {
            var content = output.Content.GetContent(HtmlEncoder.Default);

            if (Url.IsNotNullOrWhiteSpace())
            {
                Type    = DialogType.Frame;
                content = Url;
            }
            else if (!content.IsNotNullOrWhiteSpace())
            {
                Type = DialogType.Page;
            }

            Options.Add("type", Type);
            Options.AddIf(Title.IsNotNullOrWhiteSpace(), "title", Title);
            Options.AddIf(content.IsNotNullOrWhiteSpace(), LayuiConsts.Dialog_Content, content);
            Options.AddIf(Area.IsNotNullOrWhiteSpace(), "area", Area);
            if (HasSave)
            {
                Options.Add("btn", new[] { SaveButtonName });
                if (OnSave.IsNotNullOrWhiteSpace())
                {
                    Options.Add("yes", GetJavaScriptString($"function(){{ {OnSave} }} }}"));
                }
            }

            Options.AddIf(OnClose.IsNotNullOrWhiteSpace(), LayuiConsts.Dialog_OnClose, GetJavaScriptString($"function(){{ {OnClose} }}"));
            Options.AddIf(OnShow.IsNotNullOrWhiteSpace(), LayuiConsts.Dialog_OnShow, GetJavaScriptString($"function(){{ {OnShow} }}"));
            Options.AddIf(IsMax, LayuiConsts.Dialog_IsMax, IsMax);
            Options.AddIf(ShowMaxMin, LayuiConsts.Dialog_IsMaxMin, true);
            Options.AddIf(MaxWidth > 0, "maxWidth", MaxWidth);
            Options.AddIf(MaxHeight > 0, "maxHeight", MaxHeight);

            base.InitOption(context, output);
        }