예제 #1
0
 private MvcHtmlString GenerateJqAjaxPagerElement(PagerItem item, int designOrPublish)
 {
     //if (item.Disabled)
     //    return CreateWrappedPagerElement(item, String.Format("<a disabled=\"disabled\">{0}</a>", item.Text));
     return(CreateWrappedPagerElement(item, GenerateAnchor(item, designOrPublish)));
 }
예제 #2
0
        private MvcHtmlString CreateWrappedPagerElement(PagerItem item, string el)
        {
            string navStr = el;

            switch (item.Type)
            {
            case PagerItemType.FirstPage:
                if ((!string.IsNullOrEmpty(_pagerOptions.FirstItemWrapperCss) ||
                     !string.IsNullOrEmpty(_pagerOptions.PagerItemWrapperCss)))
                {
                    if (item.Disabled)
                    {
                        navStr =
                            string.Format("<span{0}>{1}</span>", string.Format(" class=\"{0} {1}\"",
                                                                               _pagerOptions.FirstItemWrapperCss ??
                                                                               _pagerOptions.PagerItemWrapperCss, _pagerOptions.DisabledCss), item.Text);
                    }
                    else
                    {
                        navStr =
                            string.Format("<span class=\"{0}\">{1}</span>",
                                          _pagerOptions.FirstItemWrapperCss ??
                                          _pagerOptions.PagerItemWrapperCss, el);
                    }
                }
                break;

            case PagerItemType.LastPage:
                if ((!string.IsNullOrEmpty(_pagerOptions.LastItemWrapperCss) ||
                     !string.IsNullOrEmpty(_pagerOptions.PagerItemWrapperCss)))
                {
                    if (item.Disabled)
                    {
                        navStr =
                            string.Format("<span{0}>{1}</span>", string.Format(" class=\"{0} {1}\"",
                                                                               _pagerOptions.LastItemWrapperCss ??
                                                                               _pagerOptions.PagerItemWrapperCss, _pagerOptions.DisabledCss), item.Text);
                    }
                    else
                    {
                        navStr =
                            string.Format("<span class=\"{0}\">{1}</span>",
                                          _pagerOptions.LastItemWrapperCss ??
                                          _pagerOptions.PagerItemWrapperCss, el);
                    }
                }
                break;

            case PagerItemType.NextPage:
                if ((!string.IsNullOrEmpty(_pagerOptions.NextItemWrapperCss) ||
                     !string.IsNullOrEmpty(_pagerOptions.PagerItemWrapperCss)))
                {
                    if (item.Disabled)
                    {
                        navStr =
                            string.Format("<span{0}>{1}</span>", string.Format(" class=\"{0} {1}\"",
                                                                               _pagerOptions.NextItemWrapperCss ??
                                                                               _pagerOptions.PagerItemWrapperCss, _pagerOptions.DisabledCss), item.Text);
                    }
                    else
                    {
                        navStr =
                            string.Format("<span class=\"{0}\">{1}</span>",
                                          _pagerOptions.NextItemWrapperCss ??
                                          _pagerOptions.PagerItemWrapperCss, el);
                    }
                }
                break;

            case PagerItemType.PrevPage:
                if ((!string.IsNullOrEmpty(_pagerOptions.PrevItemWrapperCss) ||
                     !string.IsNullOrEmpty(_pagerOptions.PagerItemWrapperCss)))
                {
                    if (item.Disabled)
                    {
                        navStr =
                            string.Format("<span{0}>{1}</span>", string.Format(" class=\"{0} {1}\"",
                                                                               _pagerOptions.PrevItemWrapperCss ??
                                                                               _pagerOptions.PagerItemWrapperCss, _pagerOptions.DisabledCss), item.Text);
                    }
                    else
                    {
                        navStr =
                            string.Format("<span class=\"{0}\">{1}</span>",
                                          _pagerOptions.PrevItemWrapperCss ??
                                          _pagerOptions.PagerItemWrapperCss, el);
                    }
                }
                break;

            case PagerItemType.MorePage:
                if ((!string.IsNullOrEmpty(_pagerOptions.MorePagerItemWrapperCss) ||
                     !string.IsNullOrEmpty(_pagerOptions.PagerItemWrapperCss)))
                {
                    navStr =
                        string.Format("<span class=\"{0}\">{1}</span>",
                                      _pagerOptions.MorePagerItemWrapperCss ??
                                      _pagerOptions.PagerItemWrapperCss, el);
                }
                break;

            case PagerItemType.NumericPage:
                if (item.PageIndex == _pageIndex &&
                    (!string.IsNullOrEmpty(_pagerOptions.CurrentPagerItemWrapperCss) ||
                     !string.IsNullOrEmpty(_pagerOptions.PagerItemWrapperCss)))     //current page
                {
                    navStr =
                        string.Format("<span{0}>{1}</span>", string.Format(" class=\"{0} {1}\"",
                                                                           _pagerOptions.CurrentPagerItemWrapperCss ??
                                                                           _pagerOptions.PagerItemWrapperCss, _pagerOptions.DisabledCss), item.Text);
                }
                else if (!string.IsNullOrEmpty(_pagerOptions.NumericPagerItemWrapperCss) ||
                         !string.IsNullOrEmpty(_pagerOptions.PagerItemWrapperCss))
                {
                    navStr =
                        string.Format("<span class=\"{0}\">{1}</span>",
                                      _pagerOptions.NumericPagerItemWrapperCss ??
                                      _pagerOptions.PagerItemWrapperCss, el);
                }
                break;
            }
            return(MvcHtmlString.Create(navStr + _pagerOptions.SeparatorHtml));
        }
예제 #3
0
        private string GenerateAnchor(PagerItem item, int designOrPublish)
        {
            if (_msAjaxPaging)
            {
                var routeValues = GetCurrentRouteValues(_ajax.ViewContext);
                if (item.PageIndex == 0)
                {
                    routeValues[_pagerOptions.PageIndexParameterName] = ScriptPageIndexName;
                }
                else
                {
                    routeValues[_pagerOptions.PageIndexParameterName] = item.PageIndex;
                }
                if (!string.IsNullOrEmpty(_routeName))
                {
                    return(_ajax.RouteLink(item.Text, _routeName, routeValues, _ajaxOptions).ToString());
                }
                return(_ajax.RouteLink(item.Text, routeValues, _ajaxOptions).ToString());
            }
            /**region 使用当前页面-zhenhua.du 2012.2.9**/
            string url = _pagerOptions.UseCurrentPageUrl ? GetCurrentPageUrl(item.PageIndex, designOrPublish) : GenerateUrl(item.PageIndex);

            if (_pagerOptions.UseJqueryAjax)
            {
                StringBuilder ehBuilder = new StringBuilder();
                //ignore OnSuccess property
                if (!string.IsNullOrEmpty(_ajaxOptions.OnFailure) || !string.IsNullOrEmpty(_ajaxOptions.OnBegin))
                {
                    ehBuilder.Append("$.ajax({url:$(this).attr(\'href\'),success:function(data,status,xhr){$(\'#");
                    ehBuilder.Append(_ajaxOptions.UpdateTargetId).Append("\').html(data);}");
                    if (!string.IsNullOrEmpty(_ajaxOptions.OnFailure))
                    {
                        ehBuilder.Append(",error:").Append(HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnFailure));
                    }
                    if (!string.IsNullOrEmpty(_ajaxOptions.OnBegin))
                    {
                        ehBuilder.Append(",beforeSend:").Append(HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnBegin));
                    }
                    if (!string.IsNullOrEmpty(_ajaxOptions.OnComplete))
                    {
                        ehBuilder.Append(",complete:").Append(
                            HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnComplete));
                    }
                    ehBuilder.Append("});return false;");
                }
                else if (!string.IsNullOrEmpty(_ajaxOptions.OnSuccess) && string.IsNullOrEmpty(_ajaxOptions.OnComplete) && string.IsNullOrEmpty(_ajaxOptions.UpdateTargetId))
                {
                    /**使用自定义**/
                    string callback = _ajaxOptions.OnSuccess.Replace("%_PageIndex_%", item.PageIndex.ToString());
                    ehBuilder.AppendFormat("{0};return false;", callback);
                }
                else
                {
                    ehBuilder.Append("$(\'#").Append(_ajaxOptions.UpdateTargetId);
                    ehBuilder.Append("\').load($(this).attr(\'href\')");
                    if (!string.IsNullOrEmpty(_ajaxOptions.OnComplete))
                    {
                        ehBuilder.Append(",").Append(HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnComplete));
                    }
                    ehBuilder.Append(");return false;");
                }
                return(string.IsNullOrEmpty(url)
                           ? _html.Encode(item.Text)
                           : String.Format(CultureInfo.InvariantCulture,
                                           "<a href=\"{0}\" onclick=\"{1}\">{2}</a>",
                                           GenerateUrl(item.PageIndex), ehBuilder, item.Text));
            }
            return("<a href=\"" + url +
                   "\" onclick=\"window.open(this.attributes.getNamedItem('href').value,'_self')\"></a>");
        }