Esempio n. 1
0
        private static ModelClientValidationRule RequiredAttributeRule(PropertyVm propertyVm, object attribute)
        {
            var a = attribute as RequiredAttribute;

            return((a == null)
                       ? null
                       : new ModelClientValidationRequiredRule(a.FormatErrorMessage(propertyVm.DisplayName)));
        }
Esempio n. 2
0
        private static ModelClientValidationRule RegexAttributeRule(PropertyVm propertyVm, object attribute)
        {
            var a = attribute as RegularExpressionAttribute;

            return((a == null)
                       ? null
                       : new ModelClientValidationRegexRule(a.FormatErrorMessage(propertyVm.DisplayName), a.Pattern));
        }
Esempio n. 3
0
        public static IEnumerable <PropertyVm> GetPropertyVmsUsingReflection(object model, Type fallbackModelType)
        {
            var type = model != null?model.GetType() : fallbackModelType;

            var typeVm = new PropertyVm(typeof(string), "__type")
            {
                DisplayName = "",
                IsHidden    = true,
                Value       = StringEncoder
            };

            yield return(typeVm);

            var properties = type.GetTypeInfo().DeclaredProperties;

            foreach (var property in properties)
            {
                if (properties.Any(p => p.Name + "_choices" == property.Name))
                {
                    continue; //skip this is it is choice
                }

                if (properties.Any(p => p.Name + "_choices" == property.Name))
                {
                    continue; //skip this is it is choice
                }

                if (properties.Any(p => p.Name + "_show" == property.Name))
                {
                    continue; //skip this is it is show
                }


                if (!(type.GetTypeInfo().GetDeclaredMethod(property.Name + "_show")?.Invoke(model, null) as bool? ?? true))
                {
                    continue;
                }
                if (!(type.GetTypeInfo().GetDeclaredProperty(property.Name + "_show")?.GetValue(model) as bool? ?? true))
                {
                    continue;
                }


                var          inputVm = new PropertyVm(model, property);
                PropertyInfo choices = properties.SingleOrDefault(p => p.Name == property.Name + "_choices");
                if (choices != null)
                {
                    inputVm.Choices = (IEnumerable)choices.GetMethod.Invoke(model, null);
                }
                PropertyInfo suggestions = properties.SingleOrDefault(p => p.Name == property.Name + "_suggestions");
                if (suggestions != null)
                {
                    inputVm.Suggestions = (IEnumerable)suggestions.GetMethod.Invoke(model, null);
                }

                yield return(inputVm);
            }
        }
Esempio n. 4
0
        private static ModelClientValidationRule RangeAttribteRule(PropertyVm propertyVm, object attribute)
        {
            var a = attribute as RangeAttribute;

            return((a == null)
                       ? null
                       : new ModelClientValidationRangeRule(a.FormatErrorMessage(propertyVm.DisplayName), a.Minimum,
                                                            a.Maximum));
        }
Esempio n. 5
0
        private static ModelClientValidationRule StringLengthAttributeRule(PropertyVm propertyVm, object attribute)
        {
            var a = attribute as StringLengthAttribute;

            return((a == null)
                       ? null
                       : new ModelClientValidationStringLengthRule(a.FormatErrorMessage(propertyVm.DisplayName),
                                                                   a.MinimumLength, a.MaximumLength));
        }
Esempio n. 6
0
        //public static string Raw(this bool value, string output)
        //{
        //    return (value ? output : "");
        //}
        //public static string Raw(this string value)
        //{
        //    return (value);
        //}

        //public static string InputAtts(this PropertyVm vm)
        //{
        //    return string.Join("", string.Join(" ", new string[] { vm.Disabled(), vm.Readonly(), vm.DataAtts() }));
        //}
        //public static string Disabled(this PropertyVm vm)
        //{
        //    return Attr(vm.Disabled, "disabled", null);
        //}
        //public static string Readonly(this PropertyVm vm)
        //{
        //    return Attr(vm.Readonly, "readonly", null);
        //}
        public static string DataAtts(this PropertyVm vm)
        {
            var sb = new StringBuilder();

            foreach (var att in vm.DataAttributes)
            {
                sb.Append("data-" + att.Key + "='" + att.Value + "' ");
            }
            return(sb.ToString());
        }
Esempio n. 7
0
        public static ObjectChoices[] Choices(this MyFfHtmlHelper html, PropertyVm model)
        {
            var choices = (from obj in model.Choices.Cast <object>().ToArray()
                           let choiceType = obj == null ? model.Type : obj.GetType()
                                            let properties = FF.PropertiesFor(obj, choiceType)
                                                             .Each(p => p.Name = model.Name + "." + p.Name)
                                                             .Each(p => p.Readonly |= model.Readonly)
                                                             .Each(p => p.Id = Guid.NewGuid().ToString())
                                                             select new ObjectChoices
            {
                obj = obj, choiceType = choiceType, properties = properties,
                name = (obj != null ? obj.DisplayName() : choiceType.DisplayName())
            }).ToArray();

            return(choices);
        }
Esempio n. 8
0
        public static IEnumerable <PropertyVm> GetPropertyVmsUsingReflection(IStringEncoder helper, object model, Type fallbackModelType)
        {
            var type = model != null?model.GetType() : fallbackModelType;

            var typeVm = new PropertyVm(typeof(string), "__type")
            {
                DisplayName = "",
                IsHidden    = true,
                Value       = helper.WriteTypeToString(type)
            };

            yield return(typeVm);

            var properties = type.GetProperties();

            foreach (var property in properties)
            {
                if (properties.Any(p => p.Name + "_choices" == property.Name))
                {
                    continue; //skip this is it is choice
                }

                var          inputVm = new PropertyVm(model, property);
                PropertyInfo choices = properties.SingleOrDefault(p => p.Name == property.Name + "_choices");
                if (choices != null)
                {
                    inputVm.Choices = (IEnumerable)choices.GetGetMethod().Invoke(model, null);
                }
                PropertyInfo suggestions = properties.SingleOrDefault(p => p.Name == property.Name + "_suggestions");
                if (suggestions != null)
                {
                    inputVm.Suggestions = (IEnumerable)suggestions.GetGetMethod().Invoke(model, null);
                }

                yield return(inputVm);
            }
        }
Esempio n. 9
0
        public static string UnobtrusiveValidation(FfHtmlHelper helper, PropertyVm property)
        {
            var sb = new StringBuilder();

            var rules = UnobtrusiveValidationRules.SelectMany(r => r(property));

            if (rules.Any() == false)
            {
                return("");
            }

            sb.Append("data-val=\"true\" ");
            foreach (var rule in rules)
            {
                var prefix = string.Format(" data-val-{0}", rule.ValidationType);
                sb.AppendFormat(prefix + "=\"{0}\" ", rule.ErrorMessage);
                foreach (var parameter in rule.ValidationParameters)
                {
                    sb.AppendFormat(prefix + "-{0}=\"{1}\" ", parameter.Key, parameter.Value);
                }
            }

            return(sb.ToString());
        }
Esempio n. 10
0
        public static MvcHtmlString UnobtrusiveValidation(this MyFfHtmlHelper helper, PropertyVm property)
        {
            var unobtrusiveValidation = ValidationHelper.UnobtrusiveValidation(helper, property);

            return(new MvcHtmlString(unobtrusiveValidation));
        }
Esempio n. 11
0
 public static ObjectChoices[] Choices(this IHtmlHelper html, PropertyVm model)
 {
     return(new FormFactoryHtmlHelper(html).Choices(model));
 }
Esempio n. 12
0
        public static string BestPropertyName <THelper>(THelper html, PropertyVm vm) where THelper : FfHtmlHelper
        {
            var viewname = BestViewName(html.ViewFinder, vm.Type, "FormFactory/Property.");

            return(viewname);
        }
Esempio n. 13
0
 public static IHtmlString Render(this PropertyVm propertyVm, HtmlHelper html)
 {
     return(html.Partial("FormFactory/Form.Property", propertyVm));
 }
Esempio n. 14
0
        public static IHtmlContent UnobtrusiveValidation(this IHtmlHelper helper, PropertyVm property)
        {
            var unobtrusiveValidation = ValidationHelper.UnobtrusiveValidation(new FormFactoryHtmlHelper(helper), property);

            return(new HtmlString(unobtrusiveValidation));
        }
Esempio n. 15
0
 private static IEnumerable <ModelClientValidationRule> GetRulesFromAttributes(PropertyVm property)
 {
     return(property.GetCustomAttributes()
            .SelectMany(attribute => UnobtrusiveValidationAttributeRules,
                        (attribute, rule) => rule(property, attribute))
            .Where(r => r != null));
 }
Esempio n. 16
0
 public static bool HasAttribute <TAtt>(this PropertyVm propertyVm)
 {
     return(propertyVm.GetCustomAttributes().OfType <TAtt>().Any());
 }
Esempio n. 17
0
        public static MvcHtmlString BestProperty(this MyFfHtmlHelper html, PropertyVm vm)
        {
            string viewName = ViewFinderExtensions.BestPropertyName(html, vm);

            return(html.Partial(viewName, vm));
        }
Esempio n. 18
0
 public static IHtmlString InputAtts(this PropertyVm vm)
 {
     return(new HtmlString(string.Join("", string.Join(" ", new string[] { vm.Disabled().ToString(), vm.Readonly().ToString(), vm.DataAtts().ToString() }))));
 }
Esempio n. 19
0
 public static IHtmlString Disabled(this PropertyVm vm)
 {
     return(Attr(vm.Disabled, "disabled", null));
 }
Esempio n. 20
0
 public static IHtmlString Readonly(this PropertyVm vm)
 {
     return(Attr(vm.Readonly, "readonly", null));
 }
Esempio n. 21
0
        public static IHtmlString Placeholder(PropertyVm pi)
        {
            var placeHolderText = pi.GetCustomAttributes().OfType <DisplayAttribute>().Select(a => a.Prompt).FirstOrDefault();

            return(Attr((!string.IsNullOrWhiteSpace(placeHolderText)), "placeholder", placeHolderText));
        }
        public static IHtmlContent BestProperty(this IHtmlHelper html, PropertyVm vm)
        {
            string viewName = ViewFinderExtensions.BestPropertyName(new FormFactoryHtmlHelper(html), vm);

            return(html.Partial(viewName, vm));
        }