예제 #1
0
        /// <summary>
        /// Header
        /// </summary>
        /// <param name="htmlHelper">Html header</param>
        /// <param name="header">header</param>
        /// <returns>Hearder</returns>
        private static string Header(HtmlHelper htmlHelper, ContentBoxHeader header)
        {
            var builder = new TagBuilder("div");
            var h3      = new TagBuilder("h3");
            var clear   = new TagBuilder("div");

            clear.AddCssClass("clear");

            h3.SetInnerText(header.Title);

            if (header.Required)
            {
                var span = new TagBuilder("span");
                span.AddCssClass("required");
                span.SetInnerText("*");

                h3.InnerHtml += "&nbsp;";
                h3.InnerHtml += span;
            }

            builder.AddCssClass("content-box-header");
            builder.InnerHtml += h3.ToString();

            CreateHeaderLoading(header, builder, htmlHelper);
            CreateHeaderTabs(header, builder);
            CreateHeaderButtons(header, builder, htmlHelper);

            builder.InnerHtml += clear.ToString();

            return(builder.ToString());
        }
예제 #2
0
        /// <summary>
        /// Create header tabs
        /// </summary>
        /// <param name="header">Header</param>
        /// <param name="builder">Builder</param>
        private static void CreateHeaderTabs(ContentBoxHeader header, TagBuilder builder)
        {
            if (header.Tabs == null || header.Tabs.Count <= 0)
            {
                return;
            }

            var ul = new TagBuilder("ul");
            int i  = 0;

            ul.AddCssClass("content-box-tabs");

            foreach (ContentBoxHeaderTab tab in header.Tabs)
            {
                var li   = new TagBuilder("li");
                var link = new TagBuilder("a");

                if (tab.Current)
                {
                    link.AddCssClass("default-tab current");
                }

                link.Attributes.Add("href", "#tab" + i);
                link.Attributes.Add("title", tab.Title);
                link.InnerHtml = tab.Text;

                li.InnerHtml  = link.ToString();
                ul.InnerHtml += li.ToString();

                i++;
            }

            builder.InnerHtml += ul.ToString();
        }
예제 #3
0
        /// <summary>
        /// Create header loading
        /// </summary>
        /// <param name="header">Header</param>
        /// <param name="builder">Builder</param>
        /// <param name="htmlHelper">Html helper</param>
        private static void CreateHeaderLoading(ContentBoxHeader header, TagBuilder builder, HtmlHelper htmlHelper)
        {
            if (header.Loading == null)
            {
                return;
            }

            var    loading = new TagBuilder("div");
            string url     = UrlHelper.GenerateContentUrl(header.Loading.ImagePath, htmlHelper.ViewContext.HttpContext);

            loading.AddCssClass(header.Loading.Class);
            loading.Attributes.Add("id", header.Loading.Id);
            loading.InnerHtml = "<img src=\"" + url + "\" alt=\"\" />";

            builder.InnerHtml += loading.ToString();
        }
예제 #4
0
        /// <summary>
        /// Create header buttons
        /// </summary>
        /// <param name="header">Header</param>
        /// <param name="builder">Builder</param>
        /// <param name="htmlHelper">Html helper</param>
        private static void CreateHeaderButtons(ContentBoxHeader header, TagBuilder builder, HtmlHelper htmlHelper)
        {
            if (header.Buttons == null || header.Buttons.Count.Equals(0))
            {
                return;
            }

            var ul = new TagBuilder("ul");

            ul.AddCssClass("content-box-tabs content-box-tabs-button");

            foreach (var button in header.Buttons)
            {
                var li   = new TagBuilder("li");
                var link = new TagBuilder("a");
                var url  = UrlHelper.GenerateContentUrl(button.Url, htmlHelper.ViewContext.HttpContext);

                if (button.HtmlAttributes != null)
                {
                    if (button.HtmlAttributes is Dictionary <string, object> )
                    {
                        link.MergeAttributes((Dictionary <string, object>)button.HtmlAttributes);
                    }
                    else
                    {
                        link.MergeAttributes(new RouteValueDictionary(button.HtmlAttributes));
                    }
                }
                else
                {
                    link.MergeAttributes(new RouteValueDictionary());
                }

                link.MergeAttribute("class", button.Class);
                link.MergeAttribute("href", url, true);
                link.MergeAttribute("title", button.Title, true);
                link.InnerHtml = button.Text;

                li.InnerHtml  = link.ToString();
                ul.InnerHtml += li.ToString();
            }

            builder.InnerHtml += ul.ToString();
        }
예제 #5
0
        /// <summary>
        /// Content box helper
        /// </summary>
        /// <param name="htmlHelper">Html helper</param>
        /// <param name="header">Header</param>
        /// <param name="htmlAttributes">Html attributes</param>
        /// <returns>MvcContentBox</returns>
        private static MvcContentBox ContentBoxHelper(this HtmlHelper htmlHelper, ContentBoxHeader header, object htmlAttributes)
        {
            var textWriter = htmlHelper.ViewContext.Writer;
            var contentBox = new TagBuilder("div");

            if (htmlAttributes != null)
            {
                if (htmlAttributes is Dictionary <string, object> )
                {
                    contentBox.MergeAttributes((Dictionary <string, object>)htmlAttributes);
                }
                else
                {
                    contentBox.MergeAttributes(new RouteValueDictionary(htmlAttributes));
                }
            }
            else
            {
                contentBox.MergeAttributes(new RouteValueDictionary());
            }

            if (contentBox.Attributes.ContainsKey("class"))
            {
                contentBox.Attributes["class"] = "content-box " + contentBox.Attributes["class"];
            }
            else
            {
                contentBox.AddCssClass("content-box");
            }

            textWriter.Write(contentBox.ToString(TagRenderMode.StartTag));
            textWriter.Write(Header(htmlHelper, header));
            textWriter.Write(Content());

            return(new MvcContentBox(htmlHelper.ViewContext));
        }
        /// <summary>
        /// Header
        /// </summary>
        /// <param name="htmlHelper">Html header</param>
        /// <param name="header">header</param>
        /// <returns>Hearder</returns>
        private static string Header(HtmlHelper htmlHelper, ContentBoxHeader header)
        {
            var builder = new TagBuilder("div");
            var h3 = new TagBuilder("h3");
            var clear = new TagBuilder("div");

            clear.AddCssClass("clear");

            h3.SetInnerText(header.Title);

            if (header.Required)
            {
                var span = new TagBuilder("span");
                span.AddCssClass("required");
                span.SetInnerText("*");

                h3.InnerHtml += "&nbsp;";
                h3.InnerHtml += span;
            }

            builder.AddCssClass("content-box-header");
            builder.InnerHtml += h3.ToString();

            CreateHeaderLoading(header, builder, htmlHelper);
            CreateHeaderTabs(header, builder);
            CreateHeaderButtons(header, builder, htmlHelper);

            builder.InnerHtml += clear.ToString();

            return builder.ToString();
        }
        /// <summary>
        /// Create header tabs
        /// </summary>
        /// <param name="header">Header</param>
        /// <param name="builder">Builder</param>
        private static void CreateHeaderTabs(ContentBoxHeader header, TagBuilder builder)
        {
            if (header.Tabs == null || header.Tabs.Count <= 0) return;

            var ul = new TagBuilder("ul");
            int i = 0;

            ul.AddCssClass("content-box-tabs");

            foreach (ContentBoxHeaderTab tab in header.Tabs)
            {
                var li = new TagBuilder("li");
                var link = new TagBuilder("a");

                if (tab.Current)
                {
                    link.AddCssClass("default-tab current");
                }

                link.Attributes.Add("href", "#tab" + i);
                link.Attributes.Add("title", tab.Title);
                link.InnerHtml = tab.Text;

                li.InnerHtml = link.ToString();
                ul.InnerHtml += li.ToString();

                i++;
            }

            builder.InnerHtml += ul.ToString();
        }
        /// <summary>
        /// Create header loading
        /// </summary>
        /// <param name="header">Header</param>
        /// <param name="builder">Builder</param>
        /// <param name="htmlHelper">Html helper</param>
        private static void CreateHeaderLoading(ContentBoxHeader header, TagBuilder builder, HtmlHelper htmlHelper)
        {
            if (header.Loading == null) return;

            var loading = new TagBuilder("div");
            string url = UrlHelper.GenerateContentUrl(header.Loading.ImagePath, htmlHelper.ViewContext.HttpContext);

            loading.AddCssClass(header.Loading.Class);
            loading.Attributes.Add("id", header.Loading.Id);
            loading.InnerHtml = "<img src=\"" + url + "\" alt=\"\" />";

            builder.InnerHtml += loading.ToString();
        }
        /// <summary>
        /// Create header buttons
        /// </summary>
        /// <param name="header">Header</param>
        /// <param name="builder">Builder</param>
        /// <param name="htmlHelper">Html helper</param>
        private static void CreateHeaderButtons(ContentBoxHeader header, TagBuilder builder, HtmlHelper htmlHelper)
        {
            if (header.Buttons == null || header.Buttons.Count.Equals(0)) return;

            var ul = new TagBuilder("ul");

            ul.AddCssClass("content-box-tabs content-box-tabs-button");

            foreach (var button in header.Buttons)
            {
                var li = new TagBuilder("li");
                var link = new TagBuilder("a");
                var url = UrlHelper.GenerateContentUrl(button.Url, htmlHelper.ViewContext.HttpContext);

                if (button.HtmlAttributes != null)
                {
                    if(button.HtmlAttributes is Dictionary<string, object>)
                    {
                        link.MergeAttributes((Dictionary<string, object>)button.HtmlAttributes);
                    }
                    else
                    {
                        link.MergeAttributes(new RouteValueDictionary(button.HtmlAttributes));
                    }
                }
                else
                {
                    link.MergeAttributes(new RouteValueDictionary());
                }

                link.MergeAttribute("class", button.Class);
                link.MergeAttribute("href", url, true);
                link.MergeAttribute("title", button.Title, true);
                link.InnerHtml = button.Text;

                li.InnerHtml = link.ToString();
                ul.InnerHtml += li.ToString();
            }

            builder.InnerHtml += ul.ToString();
        }
        /// <summary>
        /// Content box helper
        /// </summary>
        /// <param name="htmlHelper">Html helper</param>
        /// <param name="header">Header</param>
        /// <param name="htmlAttributes">Html attributes</param>
        /// <returns>MvcContentBox</returns>
        private static MvcContentBox ContentBoxHelper(this HtmlHelper htmlHelper, ContentBoxHeader header, object htmlAttributes)
        {
            var textWriter = htmlHelper.ViewContext.Writer;
            var contentBox = new TagBuilder("div");

            if (htmlAttributes != null)
            {
                if (htmlAttributes is Dictionary<string, object>)
                {
                    contentBox.MergeAttributes((Dictionary<string, object>)htmlAttributes);
                }
                else
                {
                    contentBox.MergeAttributes(new RouteValueDictionary(htmlAttributes));
                }
            }
            else
            {
                contentBox.MergeAttributes(new RouteValueDictionary());
            }

            if(contentBox.Attributes.ContainsKey("class"))
            {
                contentBox.Attributes["class"] = "content-box " + contentBox.Attributes["class"];
            }
            else
            {
                contentBox.AddCssClass("content-box");
            }

            textWriter.Write(contentBox.ToString(TagRenderMode.StartTag));
            textWriter.Write(Header(htmlHelper, header));
            textWriter.Write(Content());

            return new MvcContentBox(htmlHelper.ViewContext);
        }