コード例 #1
0
ファイル: DataGridItem.cs プロジェクト: nomada2/MvcKompAppGit
        protected void GetItemContainerTags(
            ItemContainerType itemContainerType,
            int index,
            Func <TItem, int, string> getDynamicContainer,
            IDictionary <string, object> htmlattributes,
            string prefix,
            bool hidden,
            out string openTag,
            out string closureTag
            )
        {
            if (htmlattributes == null)
            {
                htmlattributes = new Dictionary <string, object>();
            }
            BasicHtmlHelper.SetAttribute(htmlattributes, "id", BasicHtmlHelper.IdFromName(prefix) + "_Container");

            if (hidden)
            {
                BasicHtmlHelper.SetDefaultStyle(htmlattributes, "display", "none");
            }
            switch (itemContainerType)
            {
            case ItemContainerType.div:
                openTag    = string.Format("<div {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes));
                closureTag = "</div>";
                break;

            case ItemContainerType.span:
                openTag    = string.Format("<span {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes));
                closureTag = "</span>";
                break;

            case ItemContainerType.tr:
                openTag    = string.Format("<tr {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes));
                closureTag = "</tr>";
                break;

            case ItemContainerType.td:
                openTag    = string.Format("<td {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes));
                closureTag = "</td>";
                break;

            case ItemContainerType.li:
                openTag    = string.Format("<li {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes));
                closureTag = "</li>";
                break;

            case ItemContainerType.section:
                openTag    = string.Format("<section {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes));
                closureTag = "</section>";
                break;

            case ItemContainerType.article:
                openTag    = string.Format("<article {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes));
                closureTag = "</article>";
                break;

            case ItemContainerType.p:
                openTag    = string.Format("<p {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes));
                closureTag = "</p>";
                break;

            default:
                if (getDynamicContainer != null)
                {
                    string tagName = getDynamicContainer(Item.OldValue, index);
                    openTag    = string.Format("<{1} {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes), tagName);
                    closureTag = string.Format("</{0}>", tagName);
                }
                else
                {
                    openTag    = string.Format("<div {0}>", BasicHtmlHelper.GetAttributesString(htmlattributes));
                    closureTag = "</div>";
                }
                break;
            }
        }
コード例 #2
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);
            }
        }