public override HtmlTag Build(ElementRequest request)
        {
            var attr = request.Accessor.GetAttribute<ValueOfAttribute>();

            var value = ValueObjectRegistry.GetValueObjectHolder(attr.Name);

            if (value == null) return new TextboxTag(request.ElementId, request.Value<string>());

            var defaultValue = "";
            if (request.RawValue != null)
            {
                defaultValue = request.RawValue.ToString();
            }
            if (defaultValue.IsEmpty())
            {
                ValueObject @default = value.Values.FirstOrDefault(x => x.IsDefault);
                if (@default != null) defaultValue = @default.Key;
            }

            return new SelectTag(tag =>
                                     {
                                         tag.TopOption(string.Format("-- Select {0} --", value.GetKey()), null);
                                         value.Values.Each(vo => tag.Option(vo.Value, vo.Key));
                                         tag.SelectByValue(defaultValue);
                                     });
        }
 private static void SetSelectedValue(ElementRequest request, SelectTag select)
 {
     if (!request.ValueIsEmpty())
     {
         select.SelectByValue(request.Value <int>().ToString());
     }
 }
		protected override HtmlTag BuildTag(ElementRequest req)
		{
			var attrib = GetCheckBoxListAttribute(req);
			var optionPairs = GetOptionPairs(req, attrib);
			var checkedOptions = req.Value<IList<int>>().Cast<object>();
			var groupName = req.ElementId;

			var div = attrib.Horizontal ? Tags.Span : Tags.Div;
			foreach (var item in optionPairs)
			{
				var isChecked = checkedOptions.Contains(item.Value);
				var label = Tags.Label.For(groupName).Text(item.Text);
				var checkBox = Tags.Checkbox(isChecked).Name(groupName).Value(item.Value);

				div.Nest(
					Tags.Div.Nest(
						Tags.Span
							.AddClass("option")
							.AddClass(attrib.Horizontal ? "horizontalOption" : "")
							.Nest(
								label,
								checkBox
							)));
			}
			return div.AddClass("checkboxes");
		}
        public override HtmlTag Build(ElementRequest request)
        {
            var name = request.Accessor.Name;
            var pair = request.Value<AutoCompleteInput>();

            var textBoxId = name + "Text";
            var textBox = Tags.Input
                .Attr(HtmlAttributeConstants.Type, "Text")
                .Id(textBoxId)
                .Value(pair.Text)
                .Attr(HtmlAttributeConstants.Name, textBoxId);

            var valueBoxId = name + "Value";
            var valueBox = Tags.Hidden
                .Id(valueBoxId)
                .Value(pair.Value)
                .Attr(HtmlAttributeConstants.Name, valueBoxId);

            var createScript = GetCreateScript(textBoxId, pair.Url);

            var resultScript = GetResultScript(textBoxId, valueBoxId);

            return Tags.Span.Nest(
                textBox,
                valueBox,
                createScript,
                resultScript
                );
        }
        public static void ModifyWithDropDown <TType>(
            this ElementRequest request,
            IEnumerable <TType> items,
            Func <TType, string> getId,
            Func <TType, string> getDisplay)
        {
            request.CurrentTag.RemoveAttr("type");
            request.CurrentTag.TagName("select");

            var value = request.Value <TType>();

            foreach (var item in items)
            {
                var optionTag = new HtmlTag("option")
                                .Value(getId(item))
                                .Text(getDisplay(item));

                if (value != null && value.Equals(item))
                {
                    optionTag.Attr("selected");
                }

                request.CurrentTag.Append(optionTag);
            }
        }
Beispiel #6
0
        public override HtmlTag Build(ElementRequest request)
        {
            var aca    = request.Get <IActionContextAccessor>();
            var teamId = int.Parse((string)aca.ActionContext.RouteData.Values["teamId"]);
            var db     = request.Get <SupportManagerContext>();

            var results = db.TeamMembers.Where(m => m.TeamId == teamId).SelectMany(m => m.User.PhoneNumbers)
                          .Select(upn => new { upn.User.DisplayName, upn.Id, upn.Value }).OrderBy(upn => upn.DisplayName).ToList();

            var selectTag = new SelectTag(t =>
            {
                t.Option(string.Empty, string.Empty); // blank default option
                foreach (var result in results)
                {
                    t.Option($"{result.DisplayName} - {result.Value}", result.Id);
                }
            });

            var entity = request.Value <UserPhoneNumber>();

            if (entity != null)
            {
                selectTag.SelectByValue(entity.Id);
            }

            return(selectTag);
        }
        public HtmlTag Build(ElementRequest request)
        {
            var attribute = request.Accessor.GetAttribute <ValueOfAttribute>();
            var list      = request.Get <IFindListOf>().Find(attribute.ItemType).ToList();

            var defaultValue = request.Value <string>();

            if (string.IsNullOrEmpty(defaultValue))
            {
                defaultValue = list.Select(x => x.Key).FirstOrDefault();
            }

            return(new SelectTag(tag =>
            {
                foreach (var selectListItem in list)
                {
                    tag.Option(selectListItem.Text, selectListItem.Key);
                }

                if (defaultValue != null)
                {
                    tag.SelectByValue(defaultValue);
                }

                if (!string.IsNullOrEmpty(attribute.FilteredBy))
                {
                    tag.Data("filtered-by", attribute.FilteredBy);
                }
            }));
        }
        protected override HtmlTag BuildTag(ElementRequest request)
        {
            var attribute = GetCheckBoxListAttribute(request);
            var tag = attribute.Horizontal ? Tags.Span : Tags.Div;

            var optionPairs = GetOptionPairs(request, attribute);
            var checkedOptions = request.Value<IList<int>>().Cast<object>();
            var groupName = request.ElementId;
            foreach (var option in optionPairs)
            {
                var isChecked = checkedOptions.Contains(option.Value);
                var label = Tags.Label.For(groupName).Text(option.Text);
                var checkBox = Tags.Checkbox(isChecked).Name(groupName).Value(option.Value);

                tag.Nest(
                    Tags.Div.Nest(
                        Tags.Span
                            .AddClass(OptionSpanClass)
                            .AddClass(attribute.Horizontal ? OptionHorizontalSpanClass : string.Empty)
                            .Nest(
                                label,
                                checkBox
                            )));
            }

            return tag
                .AddClass(CheckBoxesClass);
        }
 private static void SetSelectedValue(ElementRequest request, SelectTag select)
 {
     if (!request.ValueIsEmpty())
     {
         select.SelectByValue(request.Value<int>().ToString());
     }
 }
Beispiel #10
0
        public override HtmlTag Build(ElementRequest request)
        {
            var name = request.Accessor.Name;
            var pair = request.Value <AutoCompleteInput>();

            var textBoxId = name + "Text";
            var textBox   = Tags.Input
                            .Attr(HtmlAttributeConstants.Type, "Text")
                            .Id(textBoxId)
                            .Value(pair.Text)
                            .Attr(HtmlAttributeConstants.Name, textBoxId);

            var valueBoxId = name + "Value";
            var valueBox   = Tags.Hidden
                             .Id(valueBoxId)
                             .Value(pair.Value)
                             .Attr(HtmlAttributeConstants.Name, valueBoxId);

            var createScript = GetCreateScript(textBoxId, pair.Url);

            var resultScript = GetResultScript(textBoxId, valueBoxId);

            return(Tags.Span.Nest(
                       textBox,
                       valueBox,
                       createScript,
                       resultScript
                       ));
        }
Beispiel #11
0
        protected override HtmlTag BuildTag(ElementRequest request)
        {
            var attribute = GetCheckBoxListAttribute(request);
            var tag       = attribute.Horizontal ? Tags.Span : Tags.Div;

            var optionPairs    = GetOptionPairs(request, attribute);
            var checkedOptions = request.Value <IList <int> >().Cast <object>();
            var groupName      = request.ElementId;

            foreach (var option in optionPairs)
            {
                var isChecked = checkedOptions.Contains(option.Value);
                var label     = Tags.Label.For(groupName).Text(option.Text);
                var checkBox  = Tags.Checkbox(isChecked).Name(groupName).Value(option.Value);

                tag.Nest(
                    Tags.Div.Nest(
                        Tags.Span
                        .AddClass(OptionSpanClass)
                        .AddClass(attribute.Horizontal ? OptionHorizontalSpanClass : string.Empty)
                        .Nest(
                            label,
                            checkBox
                            )));
            }

            return(tag
                   .AddClass(CheckBoxesClass));
        }
        protected override HtmlTag BuildTag(ElementRequest request)
        {
            var isChecked = request.Value<bool>();

            return Tags.Checkbox(isChecked)
                .Value(CheckBoxValueWhenChecked)
                .Id(request.ElementId);
        }
        protected override HtmlTag BuildTag(ElementRequest request)
        {
            var isChecked = request.Value <bool>();

            return(Tags.Checkbox(isChecked)
                   .Value(CheckBoxValueWhenChecked)
                   .Id(request.ElementId));
        }
 public static HtmlTag CheckBoxBuilder(ElementRequest request)
 {
     var isChecked = request.Value<bool>();
     var tag = new CheckboxTag(isChecked);
     tag.Attr("name", request.Accessor.Name);
     tag.AddClass("checkbox");
     return tag;
 }
Beispiel #15
0
        public AccessRight RightsFor(ElementRequest request)
        {
            if (request.Value <string>().StartsWith("J"))
            {
                return(AccessRight.All);
            }

            return(AccessRight.ReadOnly);
        }
 private MonthOfYear GetValue(ElementRequest request)
 {
     var value = MonthOfYear.Current;
     if (!request.ValueIsEmpty())
     {
         value = request.Value<MonthOfYear>();
     }
     return value;
 }
        private IEnumerable <string> GetNamesOfFlagsThatAreSet(ElementRequest request)
        {
            var value         = request.Value <int>();
            var flagsEnumType = RemoveNullableIfNecessary(request.Accessor.PropertyType);

            return(EnumHelper
                   .GetOptions(flagsEnumType)
                   .Where(o => ValueHasOptionSet(value, o))
                   .Select(o => o.Name));
        }
            private MonthOfYear GetValue(ElementRequest request)
            {
                var value = MonthOfYear.Current;

                if (!request.ValueIsEmpty())
                {
                    value = request.Value <MonthOfYear>();
                }
                return(value);
            }
        private IEnumerable<string> GetNamesOfFlagsThatAreSet(ElementRequest request)
        {
            var value = request.Value<int>();
            var flagsEnumType = RemoveNullableIfNecessary(request.Accessor.PropertyType);

            return EnumHelper
                .GetOptions(flagsEnumType)
                .Where(o => ValueHasOptionSet(value, o))
                .Select(o => o.Name);
        }
        private static void buildOptions(ElementRequest request, SelectTag tag)
        {
            var listElements = GetListElementTitlesOrderedByRank(request);

            listElements.ElementTitles.Each(title => tag.Option(title, title));

            var requestValue = request.Value <string>();

            var defaultValue = requestValue.IsNotEmpty() ? requestValue : listElements.DefaultElementTitle;

            tag.SelectByValue(defaultValue);
        }
        protected override HtmlTag BuildTag(ElementRequest request)
        {
            var tag = new CalendarTextBox(request.ElementId);

            if (request.ValueIsEmpty())
            {
                return tag;
            }

            var value = request.Value<DateTime>();
            return tag.SetDate(value);
        }
		protected override HtmlTag BuildTag(ElementRequest request)
		{
			var tag = Tags.Span;
			if (request.ValueIsEmpty())
			{
				return tag;
			}

			var value = request.Value<DateTime>();
			tag.Text(value.ToShortDateString());
			return tag;
		}
        private static void buildOptions(ElementRequest request, SelectTag tag)
        {
            var listElements = GetListElementTitlesOrderedByRank(request);

            listElements.ElementTitles.Each(title => tag.Option(title, title));

            var requestValue = request.Value<string>();

            var defaultValue = requestValue.IsNotEmpty() ? requestValue : listElements.DefaultElementTitle;

            tag.SelectByValue(defaultValue);
        }
 public static HtmlTag BuildDisplay(ElementRequest request)
 {
     var time = request.Value<Time>();
     var baseName = request.Accessor.Name;
     var tag = new HtmlTag("span", c =>
                                       {
                                           c.Append(BuildTimeElementDisplayTag(baseName + Minutes, time.Minutes, "##"));
                                           c.Append(new LiteralTag(":"));
                                           c.Append(BuildTimeElementDisplayTag(baseName + Seconds, time.Seconds, "0#.#"));
                                       });
     return tag;
 }
Beispiel #25
0
        protected override HtmlTag BuildTag(ElementRequest request)
        {
            var tag = new DateAndTimeTextBoxTag(request.ElementId);

            if (request.ValueIsEmpty())
            {
                return(tag);
            }

            var value = request.Value <DateTime>();

            return(tag.SetDateAndTime(value));
        }
        protected override HtmlTag BuildTag(ElementRequest request)
        {
            var tag = Tags.Span;

            if (request.ValueIsEmpty())
            {
                return(tag);
            }

            var value = request.Value <DateTime>()
                        .ToShortDateString();

            return(tag.Text(value));
        }
		protected override HtmlTag BuildTag(ElementRequest request)
		{
			var tag = Tags.Span;
			if (request.ValueIsEmpty())
			{
				return tag;
			}

			var value = request.Value<int>();
			var type = RemoveNullableIfNecessary(request.Accessor.PropertyType);
			var options = EnumHelper.GetOptions(type);
			var values = options.Where(o => (value & (int) o.GetValue(null)) > 0).Select(o => o.Name).ToArray();
			tag.Text(String.Join(", ", values));
			return tag;
		}
        private static HtmlTag BuildCheckBox(ElementRequest request)
        {
            var namingConvention = new DotNotationElementNamingConvention();
            var name             = namingConvention.GetName(request.HolderType(), request.Accessor);

            var checkboxTag = new CheckboxTag(request.Value <bool>())
                              .Attr("value", "true")
                              .Attr("name", name)
                              .Attr("id", name);

            var mvcConventionHiddenInput = new HiddenTag()
                                           .Attr("value", "false")
                                           .Attr("name", name);

            checkboxTag.After(mvcConventionHiddenInput);
            return(checkboxTag);
        }
		private Action<SelectTag> BuildOptions(ElementRequest req)
		{
			var hasBlankOption = req.Accessor.HasAttribute<WithBlankOption>();
			return tag =>
			       	{
			       		var options = GetOptions(req);
			       		if (hasBlankOption)
			       		{
			       			tag.Option("", "");
			       		}
			       		foreach (var f in options)
			       		{
			       			tag.Option(GetText(f, req), f.GetRawConstantValue().ToString());
			       		}
			       		if (!req.ValueIsEmpty())
			       		{
			       			tag.SelectByValue(req.Value<int>().ToString());
			       		}
			       	};
		}
        public override HtmlTag Build(ElementRequest request)
        {
            var results = Source(request);

            var selectTag = new SelectTag(t =>
            {
                t.Option(string.Empty, string.Empty); // blank default option
                foreach (var result in results)
                {
                    BuildOptionTag(t, result, request);
                }
            });

            var entity = request.Value <T>();

            if (entity != null)
            {
                selectTag.SelectByValue(GetValue(entity));
            }

            return(selectTag);
        }
 public override HtmlTag Build(ElementRequest request)
 {
     var url = request.Value<string>();
     var newTag = new HtmlTag("a").Attr("href", url).Text(url);
     return newTag;
 }
		protected override HtmlTag BuildTag(ElementRequest request)
		{
			return Tags.Checkbox(request.Value<bool>()).Value("true").Id(request.ElementId);
		}
        protected override HtmlTag BuildTag(ElementRequest request)
        {
            var text = request.Value <bool>() ? "Yes" : "No";

            return(Tags.Span.Text(text));
        }
Beispiel #34
0
 public static void ToTextArea(ElementRequest request)
 {
     request.CurrentTag.RemoveAttr("type");
     request.CurrentTag.TagName("TextArea");
     request.CurrentTag.AppendHtml(request.Value <string>());
 }
 protected override HtmlTag BuildTag(ElementRequest request)
 {
     var text = request.Value<bool>() ? "Yes" : "No";
     return Tags.Span.Text(text);
 }
		protected override HtmlTag BuildTag(ElementRequest request)
		{
			var date = request.ValueIsEmpty() ? (DateTime?) null : request.Value<DateTime>();
			return new CalendarTextBox(request.ElementId, date);
		}