Exemple #1
0
        protected string RenderPageButton(string name, string textOrUrl, int page,
                                          PageButtonStyle pageButtonStyle, IDictionary <string, object> htmlAttributes = null, bool encoded = true)
        {
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }

            string buttonId = null;

            if (!string.IsNullOrEmpty(fieldName))
            {
                buttonId = BasicHtmlHelper.IdFromName(
                    BasicHtmlHelper.AddField(fieldName, name));
            }
            else
            {
                if (string.IsNullOrWhiteSpace(controllerName))
                {
                    buttonId = BasicHtmlHelper.IdFromName(
                        BasicHtmlHelper.AddField("CurrentController_" + actionName + "_" + parameterName, name));
                }
                else
                {
                    buttonId = BasicHtmlHelper.IdFromName(
                        BasicHtmlHelper.AddField(controllerName + "_" + actionName + "_" + parameterName, name));
                }
            }

            string pageUrl = string.Empty;

            if (parameterName != null)
            {
                System.Web.Routing.RouteValueDictionary routeDictionary = null;
                if (otherParameters != null)
                {
                    routeDictionary = otherParameters as System.Web.Routing.RouteValueDictionary;
                    if (routeDictionary == null)
                    {
                        routeDictionary = new System.Web.Routing.RouteValueDictionary(otherParameters);
                    }
                }
                else
                {
                    routeDictionary = new System.Web.Routing.RouteValueDictionary();
                }
                if (page < 0)
                {
                    routeDictionary.Add(parameterName, templateSymbol);
                }
                else
                {
                    routeDictionary.Add(parameterName, page);
                }
                pageUrl = UrlHelper.GenerateUrl(
                    routeName,
                    actionName,
                    controllerName,
                    protocol,
                    hostname,
                    fragment,
                    routeDictionary,
                    htmlHelper.RouteCollection,
                    htmlHelper.ViewContext.RequestContext,
                    true);
            }

            htmlAttributes["id"] = buttonId;
            string res;

            BasicHtmlHelper.SetDefaultStyle(htmlAttributes, "cursor", "pointer");
            switch (pageButtonStyle)
            {
            case PageButtonStyle.Button:
                htmlAttributes["type"]  = "button";
                htmlAttributes["value"] = htmlHelper.Encode(textOrUrl);
                return
                    (string.Format(buttonSchema,
                                   BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                   fieldName,
                                   pageString(page),
                                   buttonId,
                                   clientUrl(page, pageUrl),
                                   targetIdName,
                                   validationType));

            case PageButtonStyle.Link:
                htmlAttributes["href"] = "javascript:void(0);";

                if (htmlAttributes.ContainsKey("disabled") && htmlAttributes["disabled"].ToString() == "disabled" ||
                    htmlAttributes.ContainsKey("data-selected-page") && htmlAttributes["data-selected-page"].ToString() == "selected")
                {
                    string prevstyle = BasicHtmlHelper.SetStyle(htmlAttributes, "color", "gray");
                    res =
                        string.Format(linkSchemaDisabled,
                                      BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                      fieldName,
                                      page,
                                      buttonId,
                                      encoded ? htmlHelper.Encode(textOrUrl) : textOrUrl,
                                      pageUrl,
                                      targetIdName,
                                      validationType);
                    BasicHtmlHelper.SetAttribute(htmlAttributes, "style", prevstyle);
                }
                else
                {
                    if (pageUrl.Length != 0 && targetIdName.Length == 0 && page >= 0)
                    {
                        htmlAttributes["href"] = pageUrl;
                        res = string.Format(linkSchemaGet, BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                            encoded ? htmlHelper.Encode(textOrUrl) : textOrUrl);
                    }
                    else
                    {
                        res =
                            string.Format(linkSchema,
                                          BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                          fieldName,
                                          pageString(page),
                                          buttonId,
                                          encoded ? htmlHelper.Encode(textOrUrl) : textOrUrl,
                                          clientUrl(page, pageUrl),
                                          targetIdName,
                                          validationType);
                    }
                }
                return(res);

            default:
                htmlAttributes["src"] = textOrUrl;

                if (htmlAttributes.ContainsKey("disabled") && htmlAttributes["disabled"].ToString() == "disabled")
                {
                    string prevstyle = BasicHtmlHelper.SetStyle(htmlAttributes, "color", "gray");
                    res =
                        string.Format(imgSchemaDisabled,
                                      BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                      fieldName,
                                      page,
                                      buttonId,
                                      pageUrl,
                                      targetIdName,
                                      validationType);
                    BasicHtmlHelper.SetAttribute(htmlAttributes, "style", prevstyle);
                }
                else
                {
                    res =
                        string.Format(imgSchema,
                                      BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                      fieldName,
                                      pageString(page),
                                      buttonId,
                                      clientUrl(page, pageUrl),
                                      targetIdName,
                                      validationType);
                }
                return(res);
            }
        }