Ejemplo n.º 1
0
        protected MvcHtmlString BaseButton(string displayName,
                                           ManipulationButtonStyle buttonStyle, IDictionary <string, object> htmlAttributes)
        {
            switch (buttonStyle)
            {
            case ManipulationButtonStyle.Button:
                return(MvcHtmlString.Create
                       (
                           string.Format("<input type=\"button\" value=\"{0}\" {1} />",
                                         CurrHtmlHelper.Encode(displayName),
                                         BasicHtmlHelper.GetAttributesString(htmlAttributes))
                       ));

            case ManipulationButtonStyle.Image:
                htmlAttributes["src"] = displayName;
                BasicHtmlHelper.SetDefaultStyle(htmlAttributes, "cursor", "pointer");
                return(MvcHtmlString.Create
                       (
                           string.Format("<img {1} />",
                                         displayName,
                                         BasicHtmlHelper.GetAttributesString(htmlAttributes))
                       ));

            default:
                htmlAttributes["href"] = "javascript:void(0);";
                return(MvcHtmlString.Create
                       (
                           string.Format("<a {1}>{0}</a>",
                                         CurrHtmlHelper.Encode(displayName),
                                         BasicHtmlHelper.GetAttributesString(htmlAttributes))
                       ));
            }
        }
Ejemplo n.º 2
0
        protected string RenderPageButton(string textOrUrl, string disabledTexOrUrl, int index,
                                          PageButtonStyle pageButtonStyle, PageButtonType?pageButtonType, IDictionary <string, object> htmlAttributes = null, bool encoded = true)
        {
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }
            string buttonType = getPageButtonClass(pageButtonType);
            string buttonId   = fieldId + "_" + buttonType;

            if (!pageButtonType.HasValue)
            {
                if (index < 0)
                {
                    buttonId = buttonId + "_" + (-index).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    buttonId = buttonId + index.ToString(CultureInfo.InvariantCulture);
                }
                htmlAttributes["data-pager-index"] = index.ToString(CultureInfo.InvariantCulture);
            }
            htmlAttributes["id"] = buttonId;
            htmlAttributes["data-pager-button"] = buttonType;
            BasicHtmlHelper.AddClass(htmlAttributes, fieldId + "_class");
            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)));

            case PageButtonStyle.Image:
                htmlAttributes["src"] = textOrUrl;
                if (disabledTexOrUrl != null)
                {
                    htmlAttributes["data-disabled-src"] = disabledTexOrUrl;
                    htmlAttributes["data-enabled-src"]  = textOrUrl;
                }
                return(string.Format(imgSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes)));

            default:
                htmlAttributes["href"] = "javascript:void(0);";
                return(string.Format(linkSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes), encoded ? htmlHelper.Encode(textOrUrl): textOrUrl));
            }
        }
Ejemplo n.º 3
0
        public static MvcHtmlString ManipulationButton <VM>(
            this HtmlHelper <VM> htmlHelper,
            ManipulationButtonType manipulationButtonType,
            string textOrUrl,
            string targetName,
            string name = null,
            ManipulationButtonStyle manipulationButtonStyle = ManipulationButtonStyle.Button,
            IDictionary <string, object> htmlAttributes     = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = getManipulationButtonClass(manipulationButtonType);
            }
            if (textOrUrl == null)
            {
                throw new ArgumentNullException("textOrUrl");
            }
            if (targetName == null)
            {
                throw new ArgumentNullException("targetName");
            }

            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }

            string buttonId = BasicHtmlHelper.IdFromName(
                BasicHtmlHelper.AddField(htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix, name));

            htmlAttributes["id"] = buttonId;
            switch (manipulationButtonStyle)
            {
            case ManipulationButtonStyle.Button:
                htmlAttributes["type"]  = "button";
                htmlAttributes["value"] = htmlHelper.Encode(textOrUrl);
                return(MvcHtmlString.Create(
                           string.Format(buttonSchema,
                                         BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                         processTarget(manipulationButtonType, targetName),
                                         getManipulationButtonClass(manipulationButtonType),
                                         buttonId)));

            case ManipulationButtonStyle.Link:
                htmlAttributes["href"] = "javascript:void(0);";
                return(MvcHtmlString.Create(
                           string.Format(linkSchema,
                                         BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                         processTarget(manipulationButtonType, targetName),
                                         getManipulationButtonClass(manipulationButtonType),
                                         buttonId,
                                         htmlHelper.Encode(textOrUrl))));

            default:
                htmlAttributes["src"] = textOrUrl;
                BasicHtmlHelper.SetDefaultStyle(htmlAttributes, "cursor", "pointer");
                return(MvcHtmlString.Create(
                           string.Format(imgSchema,
                                         BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                         processTarget(manipulationButtonType, targetName),
                                         getManipulationButtonClass(manipulationButtonType),
                                         buttonId)));
            }
        }/*
Ejemplo n.º 4
0
        public MvcHtmlString Time(bool dateHidden = false, IDictionary <string, object> htmlAttributes = null, CultureInfo culture = null)
        {
            if (timeRendered)
            {
                return(MvcHtmlString.Create(string.Empty));
            }
            timeRendered    = true;
            this.dateHidden = dateHidden;
            if (culture == null)
            {
                culture = CultureInfo.CurrentUICulture;
            }
            string newPrefix = BasicHtmlHelper.AddField(prefix, "$");

            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }
            htmlAttributes["data-elementispart"] = "true";
            DateTime?min = currMin;
            DateTime?max = currMax;

            StringBuilder sb = new StringBuilder();

            sb.Append(RenderBasicScripts(culture));
            htmlAttributes["maxlength"] = "2";
            BasicHtmlHelper.SetDefaultStyle(htmlAttributes, "text-align", "right");
            if (dateHidden)
            {
                sb.Append(htmlHelper.Hidden(
                              BasicHtmlHelper.AddField(newPrefix, "Year"), Year).ToString());
                sb.Append(htmlHelper.Hidden(
                              BasicHtmlHelper.AddField(newPrefix, "Month"), Month).ToString());
                sb.Append(htmlHelper.Hidden(
                              BasicHtmlHelper.AddField(newPrefix, "Day"), Day).ToString());
            }


            string separator = culture.DateTimeFormat.TimeSeparator;

            bool applyRestrictionsMin = min != null && min.HasValue &&
                                        min.Value.Year == curr.Value.Year && min.Value.Month == curr.Value.Month &&
                                        min.Value.Day == curr.Value.Day;

            bool applyRestrictionsMax = max != null && max.HasValue &&
                                        curr.Value.Year == max.Value.Year && curr.Value.Month == max.Value.Month &&
                                        curr.Value.Day == max.Value.Day;

            int minHour = 0;
            int maxHour = 23;

            if (applyRestrictionsMin)
            {
                if (min.Value.Hour > minHour)
                {
                    minHour = min.Value.Hour;
                }
            }
            else
            {
                applyRestrictionsMin = false;
            }
            if (applyRestrictionsMax)
            {
                if (max.Value.Hour < maxHour)
                {
                    maxHour = max.Value.Hour;
                }
            }
            else
            {
                applyRestrictionsMax = false;
            }

            List <SelectListItem> allHours = new List <SelectListItem>(1);

            for (int hour = Hours; hour <= Hours; hour++)
            {
                allHours.Add(new SelectListItem()
                {
                    Value    = hour.ToString(),
                    Text     = hour.ToString("00"),
                    Selected = Hours == hour
                });
            }
            //AddFunctions(ref htmlAttributes, false);
            sb.Append(htmlHelper.DropDownList(
                          BasicHtmlHelper.AddField(newPrefix, "Hours"),
                          allHours,
                          htmlAttributes).ToString());
            sb.Append(string.Format("<span class='{0}'>{1}</span>", htmlAttributes["style"].ToString(), separator));
            int minMinute = 0;
            int maxMinute = 59;

            if (applyRestrictionsMin)
            {
                if (min.Value.Minute > minMinute)
                {
                    minMinute = min.Value.Minute;
                }
            }
            else
            {
                applyRestrictionsMin = false;
            }

            if (applyRestrictionsMax)
            {
                if (max.Value.Minute < maxMinute)
                {
                    maxMinute = max.Value.Minute;
                }
            }
            else
            {
                applyRestrictionsMax = false;
            }

            List <SelectListItem> allMinutes = new List <SelectListItem>(1);

            for (int minute = Minutes; minute <= Minutes; minute++)
            {
                allMinutes.Add(new SelectListItem()
                {
                    Value    = minute.ToString(),
                    Text     = minute.ToString("00"),
                    Selected = Minutes == minute
                });
            }
            //AddFunctions(ref htmlAttributes, false);
            sb.Append(htmlHelper.DropDownList(
                          BasicHtmlHelper.AddField(newPrefix, "Minutes"),
                          allMinutes,
                          htmlAttributes).ToString());

            sb.Append(string.Format("<span class='{0}'>{1}</span>", htmlAttributes["style"].ToString(), separator));
            int minSecond = 0;
            int maxSecond = 59;

            if (applyRestrictionsMin)
            {
                if (min.Value.Second > minSecond)
                {
                    minSecond = min.Value.Second;
                }
            }
            else
            {
                applyRestrictionsMin = false;
            }

            if (applyRestrictionsMax)
            {
                if (max.Value.Second < maxSecond)
                {
                    maxSecond = max.Value.Second;
                }
            }
            else
            {
                applyRestrictionsMax = false;
            }

            List <SelectListItem> allSeconds = new List <SelectListItem>(1);

            for (int second = Seconds; second <= Seconds; second++)
            {
                allSeconds.Add(new SelectListItem()
                {
                    Value    = second.ToString(),
                    Text     = second.ToString("00"),
                    Selected = Seconds == second
                });
            }
            //AddFunctions(ref htmlAttributes, true);
            sb.Append(htmlHelper.DropDownList(
                          BasicHtmlHelper.AddField(newPrefix, "Seconds"),
                          allSeconds,
                          htmlAttributes).ToString());

            return(MvcHtmlString.Create(sb.ToString()));
        }
Ejemplo n.º 5
0
        public MvcHtmlString Date(bool useTextBoxForYear = false, IDictionary <string, object> htmlAttributes = null, IDictionary <string, object> htmlAttributesTextBox = null, CultureInfo culture = null)
        {
            if (this.dateRendered)
            {
                return(MvcHtmlString.Create(string.Empty));
            }
            if (this.dateInCalendar)
            {
                throw new ArgumentException(ControlsResources.DateTimeInput_Combo);
            }
            dateRendered = true;
            string newPrefix = BasicHtmlHelper.AddField(prefix, "$");

            if (culture == null)
            {
                culture = CultureInfo.CurrentUICulture;
            }
            if (htmlAttributesTextBox == null)
            {
                htmlAttributesTextBox = htmlAttributes;
            }
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }
            if (htmlAttributesTextBox == null)
            {
                htmlAttributesTextBox = new Dictionary <string, object>();
            }
            htmlAttributesTextBox["data-elementispart"] = "true";
            htmlAttributes["data-elementispart"]        = "true";
            DateTime?     min = currMin;
            DateTime?     max = currMax;
            StringBuilder sb  = new StringBuilder();


            BasicHtmlHelper.SetDefaultStyle(htmlAttributes, "text-align", "right");
            string sYear = string.Empty;

            if (useTextBoxForYear || min == null || !min.HasValue || max == null || !max.HasValue)
            {
                htmlAttributesTextBox["maxlength"] = "4";
                htmlAttributesTextBox["size"]      = "5";
                //AddFunctions(ref htmlAttributesTextBox, false);
                BasicHtmlHelper.SetDefaultStyle(htmlAttributesTextBox, "text-align", "right");
                BasicHtmlHelper.SetDefaultStyle(htmlAttributesTextBox, "width", "4em");
                sYear = htmlHelper.TextBox(
                    BasicHtmlHelper.AddField(newPrefix, "Year"), Year, htmlAttributesTextBox).ToString();
            }
            else
            {
                yearCombo = true;
                List <SelectListItem> allYears = new List <SelectListItem>(1);
                for (int year = Year; year <= Year; year++)
                {
                    allYears.Add(new SelectListItem()
                    {
                        Value    = year.ToString(),
                        Text     = AlignFourDigits(year),
                        Selected = Year == year
                    });
                }
                //AddFunctions(ref htmlAttributes, false);
                sYear = htmlHelper.DropDownList(
                    BasicHtmlHelper.AddField(newPrefix, "Year"),
                    allYears,
                    htmlAttributes).ToString();
            }
            sb.Append(RenderBasicScripts(culture));
            int minMonth = 1;
            int maxMonth = 12;

            if (min != null && min.HasValue && min.Value.Year == curr.Value.Year)
            {
                if (min.Value.Month > minMonth)
                {
                    minMonth = min.Value.Month;
                }
            }
            if (max != null && max.HasValue && curr.Value.Year == max.Value.Year)
            {
                if (max.Value.Month < maxMonth)
                {
                    maxMonth = max.Value.Month;
                }
            }
            List <SelectListItem> allMonths = new List <SelectListItem>(1);

            for (int month = Month; month <= Month; month++)
            {
                allMonths.Add(new SelectListItem()
                {
                    Value    = month.ToString(),
                    Text     = culture.DateTimeFormat.MonthNames[month - 1],
                    Selected = Month == month
                });
            }
            //AddFunctions(ref htmlAttributes, false);
            string sMonth = htmlHelper.DropDownList(
                BasicHtmlHelper.AddField(newPrefix, "Month"),
                allMonths,
                htmlAttributes).ToString();
            int minDay = 1;
            int maxDay = DateTime.DaysInMonth(Year, Month);

            if (min != null && min.HasValue &&
                min.Value.Year == curr.Value.Year && min.Value.Month == curr.Value.Month)
            {
                if (min.Value.Day > minDay)
                {
                    minDay = min.Value.Day;
                }
            }
            if (max != null && max.HasValue &&
                curr.Value.Year == max.Value.Year && curr.Value.Month == max.Value.Month)
            {
                if (max.Value.Day < maxDay)
                {
                    maxDay = max.Value.Day;
                }
            }
            List <SelectListItem> allDays = new List <SelectListItem>(1);

            for (int day = Day; day <= Day; day++)
            {
                allDays.Add(new SelectListItem()
                {
                    Value    = day.ToString(),
                    Text     = AlignTwoDigits(day),
                    Selected = Day == day
                });
            }
            //AddFunctions(ref htmlAttributes, true);
            string sDay = htmlHelper.DropDownList(
                BasicHtmlHelper.AddField(newPrefix, "Day"),
                allDays,
                htmlAttributes).ToString();

            char[] OrderInfo = dateOrder(culture);

            if (OrderInfo[0] == 'y')
            {
                sb.Append(sYear);
            }
            if (OrderInfo[0] == 'M')
            {
                sb.Append(sMonth);
            }
            if (OrderInfo[0] == 'd')
            {
                sb.Append(sDay);
            }

            if (OrderInfo[1] == 'y')
            {
                sb.Append(sYear);
            }
            if (OrderInfo[1] == 'M')
            {
                sb.Append(sMonth);
            }
            if (OrderInfo[1] == 'd')
            {
                sb.Append(sDay);
            }

            if (OrderInfo[2] == 'y')
            {
                sb.Append(sYear);
            }
            if (OrderInfo[2] == 'M')
            {
                sb.Append(sMonth);
            }
            if (OrderInfo[2] == 'd')
            {
                sb.Append(sDay);
            }

            return(MvcHtmlString.Create(sb.ToString()));
        }
Ejemplo n.º 6
0
        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;
            }
        }
Ejemplo n.º 7
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);
            }
        }