Represent as a single item in a paged list pager.
        /// <summary>
        ///     Generate the html content for a pager item.
        /// </summary>
        /// <param name="item">The pager item for rendering.</param>
        /// <returns>The generated <see cref="IHtmlContent" /> for the <paramref name="item" />.</returns>
        protected static IHtmlContent GeneratePagerItem(PagerRenderingItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            // Container
            var itemTag = new TagBuilder("li");

            TagBuilder linkTag;

            // Generate <a> or <span> according to its state
            if (item.State == PagerRenderingItemState.Active)
            {
                itemTag.AddCssClass("active");                 // active CSS class
                linkTag = new TagBuilder("span");
            }
            else if (CanLink(item))
            {
                linkTag = new TagBuilder("a");
                linkTag.Attributes["href"] = item.Link;
            }
            else
            {
                itemTag.AddCssClass("disabled");                 // Disabled core CSS class
                linkTag = new TagBuilder("span");
            }

            // Add Bootstrap v4 classes, this is not confict with bootstrap v3. However user may choose to diable it manually.
            if (!string.Equals(item.Settings.GetValueOfDefault("disble-bootstrap-v4-class"), "true",
                               StringComparison.OrdinalIgnoreCase))
            {
                itemTag.AddCssClass("page-item");
                linkTag.AddCssClass("page-link");
            }

            // Append father settings
            AppendAdditionalAttributes(itemTag, item.List.Settings, ItemAttributeSettingKeyPrefix);
            AppendAdditionalAttributes(linkTag, item.List.Settings, LinkAttributeSettingKeyPrefix);

            // Append all additional attributes
            AppendAdditionalAttributes(itemTag, item.Settings, ItemAttributeSettingKeyPrefix);
            AppendAdditionalAttributes(linkTag, item.Settings, LinkAttributeSettingKeyPrefix);

            // Set real content and merge elements
            linkTag.InnerHtml.SetHtmlContent(item.Content);
            itemTag.InnerHtml.SetHtmlContent(linkTag);
            return(itemTag);
        }
예제 #2
0
        /// <summary>
        ///     Generate the html content for a pager item.
        /// </summary>
        /// <param name="item">The pager item for rendering.</param>
        /// <returns>The generated <see cref="IHtmlContent" /> for the <paramref name="item" />.</returns>
        protected static IHtmlContent GeneratePagerItem(PagerRenderingItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            // Container
            var itemTag = new TagBuilder("li");

            TagBuilder linkTag;

            // Generate <a> or <span> according to its state
            if (item.State == PagerRenderingItemState.Active)
            {
                itemTag.AddCssClass("active");                 // active CSS class
                linkTag = new TagBuilder("span");
            }
            else if (CanLink(item))
            {
                linkTag = new TagBuilder("a");
                linkTag.Attributes["href"] = item.Link;
            }
            else
            {
                itemTag.AddCssClass("disabled");                 // Disabled core CSS class
                linkTag = new TagBuilder("span");
            }


            // Append father settings
            AppendAdditionalAttributes(itemTag, item.List.Settings, ItemAttributeSettingKeyPrefix);
            AppendAdditionalAttributes(linkTag, item.List.Settings, LinkAttributeSettingKeyPrefix);

            // Append all additional attributes
            AppendAdditionalAttributes(itemTag, item.Settings, ItemAttributeSettingKeyPrefix);
            AppendAdditionalAttributes(linkTag, item.Settings, LinkAttributeSettingKeyPrefix);

            // Set real content and merge elements
            linkTag.InnerHtml.SetHtmlContent(item.Content);
            itemTag.InnerHtml.SetHtmlContent(linkTag);
            return(itemTag);
        }
예제 #3
0
 /// <summary>
 ///     Determine if a <see cref="PagerRenderingItem" /> has a valid link.
 /// </summary>
 /// <param name="item">The <see cref="PagerRenderingItem" /> object.</param>
 /// <returns>
 ///     If the <paramref name="item" /> has a valid link and is not disabled, returns <c>true</c>; otherwise, return
 ///     <c>false</c>.
 /// </returns>
 private static bool CanLink(PagerRenderingItem item)
 {
     return(item.State != PagerRenderingItemState.Disabled && !string.IsNullOrEmpty(item.Link));
 }