private static int? GetMaxlength(FeatureContext context) {
            if (context is PropertyContext) {
                return (context as PropertyContext).Property.MaxLength;
            }
            if (context is ParameterContext) {
                return (context as ParameterContext).Parameter.MaxLength;
            }
            // todo is this correct exception
            throw new BadRequestNOSException(String.Format("Unexpected context type {0}", context.GetType()));

            //throw new UnexpectedCallException(string.Format("Unexpected context type {0}", context.GetType()));
        }
        private static RangeData GetRange(FeatureContext context) {
            if (context is PropertyContext) {
                return new RangeData((context as PropertyContext).Property.Range);
            }
            if (context is ParameterContext) {
                return new RangeData((context as ParameterContext).Parameter.Range);
            }
            // todo is this correct exception
            throw new BadRequestNOSException(String.Format("Unexpected context type {0}", context.GetType()));

            //throw new UnexpectedCallException(string.Format("Unexpected context type {0}", context.GetType()));
        }
        private static void AddRemoteValidation(this HtmlHelper html, FeatureContext context, RouteValueDictionary htmlAttributes) {
            htmlAttributes["data-val"] = "true";
            htmlAttributes["data-val-remote"] = MvcUi.InvalidEntry;

            string action;
            RouteValueDictionary routeValueDictionary;

            if (context is PropertyContext) {
                var propertyContext = context as PropertyContext;
                action = "ValidateProperty";
                routeValueDictionary = new RouteValueDictionary(new {
                    id = Encode(html.Facade().OidTranslator.GetOidTranslation(propertyContext.Target)),
                    propertyName = propertyContext.Property.Id
                });
            } else {
                // (context is ParameterContext)
                var parameterContext = context as ParameterContext;
                action = "ValidateParameter";
                routeValueDictionary = new RouteValueDictionary(new {
                    id = Encode(html.Facade().OidTranslator.GetOidTranslation(parameterContext.Target)),
                    actionName = parameterContext.Action.Id,
                    parameterName = parameterContext.Parameter.Id
                });
            }

            htmlAttributes["data-val-remote-url"] = html.GenerateUrl(action, "Ajax", routeValueDictionary);
        }
        private static void AddClientValidationAttributes(this HtmlHelper html, FeatureContext context, RouteValueDictionary htmlAttributes) {
            if (html.IsMandatory(context)) {
                htmlAttributes["data-val"] = "true";
                htmlAttributes["data-val-required"] = MvcUi.Mandatory;
            }

            // remote validation and autocomplete on reference fields do not play nicely together as the actual value is in the hidden field
            if (IsAjax(context) && !IsAutoComplete(context)) {
                html.AddRemoteValidation(context, htmlAttributes);
            }

            var range = GetRange(context);
            var regex = GetRegex(context);
            var maxLength = GetMaxlength(context).GetValueOrDefault(0);

            RangeValidation(range, htmlAttributes);

            RegExValidation(regex, htmlAttributes);

            MaxlengthValidation(maxLength, htmlAttributes);
        }
        private static bool IsAutoComplete(FeatureContext context) {
            if (context is PropertyContext) {
                return (context as PropertyContext).Property.IsAutoCompleteEnabled;
            }
            if (context is ParameterContext) {
                return (context as ParameterContext).Parameter.IsAutoCompleteEnabled;
            }
            // todo is this correct exception
            throw new BadRequestNOSException(String.Format("Unexpected context type {0}", context.GetType()));

            // throw new UnexpectedCallException(string.Format("Unexpected context type {0}", context.GetType()));
        }
 private static string GetMandatoryIndicator(this HtmlHelper html, FeatureContext context) {
     return html.IsMandatory(context) ? html.MandatoryIndicator() : String.Empty;
 }
 private static IEnumerable<SelectListItem> GetItems(this HtmlHelper html, string id, FeatureContext context) {
     if (context is PropertyContext) {
         return html.GetItems(id, context as PropertyContext);
     }
     if (context is ParameterContext) {
         return html.GetItems(id, context as ParameterContext);
     }
     // todo is this correct exception
     throw new BadRequestNOSException(String.Format("Unexpected context type {0}", context.GetType()));
     //throw new UnexpectedCallException(string.Format("Unexpected context type {0}", context.GetType()));
 }
Esempio n. 8
0
 private static bool IsMandatory(FeatureContext context) {
     if (context is PropertyContext) {
         return IsMandatory(context as PropertyContext);
     }
     if (context is ParameterContext) {
         return IsMandatory(context as ParameterContext);
     }
     throw new UnexpectedCallException(string.Format("Unexpected context type {0}", context.GetType()));
 }
Esempio n. 9
0
        private static void AddTextControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, FeatureContext context, string id, string value) {
            var typicalLengthFacet = context.Feature.GetFacet<ITypicalLengthFacet>();
            var multiLineFacet = context.Feature.GetFacet<IMultiLineFacet>();
            var maxLengthFacet = context.Feature.GetFacet<IMaxLengthFacet>();

            int numberOfLines = multiLineFacet.NumberOfLines;
            int width = multiLineFacet.Width == 0 ? (typicalLengthFacet.Value == 0 ? 20 : typicalLengthFacet.Value)/multiLineFacet.NumberOfLines : multiLineFacet.Width;
            int maxLength = maxLengthFacet == null ? 0 : maxLengthFacet.Value;

            string textBox = html.GetTextControl(id, numberOfLines, width, maxLength, value, htmlAttributes);
            tag.InnerHtml += textBox + GetMandatoryIndicator(context) + html.ValidationMessage(id);
        }
Esempio n. 10
0
 private static void AddPasswordControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, FeatureContext context, string id, string value) {
     var typicalLengthFacet = context.Feature.GetFacet<ITypicalLengthFacet>();
     htmlAttributes["size"] = typicalLengthFacet.Value == 0 ? 20 : typicalLengthFacet.Value;
     tag.InnerHtml += html.Password(id, value, htmlAttributes) + GetMandatoryIndicator(context) + html.ValidationMessage(id);
 }
Esempio n. 11
0
        private static void AddClientValidationAttributes(this HtmlHelper html, FeatureContext context, RouteValueDictionary htmlAttributes) {
            if (IsMandatory(context)) {
                htmlAttributes["data-val"] = "true";
                htmlAttributes["data-val-required"] = MvcUi.Mandatory;
            }

            // remote validation and autocomplete on reference fields do not play nicely together as the actual value is in the hidden field
            if (IsAjax(context) && !IsAutoComplete(context)) {
                html.AddRemoteValidation(context, htmlAttributes);
            }

            var supportedFacetTypes = new List<Type> {typeof (IRangeFacet), typeof (IRegExFacet), typeof (IMaxLengthFacet)};
            IEnumerable<IFacet> facets = supportedFacetTypes.Select(ft => context.Feature.GetFacet(ft));

            facets.ForEach(f => ClientValidationHandlers.ForEach(a => a(f, htmlAttributes)));
        }
Esempio n. 12
0
 private static string GetMandatoryIndicator(FeatureContext context) {
     return IsMandatory(context) ? MandatoryIndicator() : string.Empty;
 }
Esempio n. 13
0
 private static bool IsAutoComplete(FeatureContext context) {
     if (context is PropertyContext) {
         var assoc = ((context as PropertyContext).Property) as IOneToOneAssociation;
         return assoc != null && assoc.IsAutoCompleteEnabled;
     }
     if (context is ParameterContext) {
         return (context as ParameterContext).Parameter.IsAutoCompleteEnabled;
     }
     throw new UnexpectedCallException(string.Format("Unexpected context type {0}", context.GetType()));
 }
 private static void AddDropDownControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, FeatureContext context, string id) {
     IEnumerable<SelectListItem> items = html.GetItems(id, context);
     tag.InnerHtml += html.DropDownList(id, items, htmlAttributes) + html.GetMandatoryIndicator(context) + html.ValidationMessage(id);
 }
        private static bool IsMandatory(this HtmlHelper html, FeatureContext context) {
            if (context is PropertyContext) {
                return html.IsMandatory(context as PropertyContext);
            }
            if (context is ParameterContext) {
                return html.IsMandatory(context as ParameterContext);
            }
            // todo is this correct exception
            throw new BadRequestNOSException(String.Format("Unexpected context type {0}", context.GetType()));

            //throw new UnexpectedCallException(string.Format("Unexpected context type {0}", context.GetType()));
        }
 private static void AddListBoxControl(this HtmlHelper html, TagBuilder tag, RouteValueDictionary htmlAttributes, FeatureContext context, string id) {
     IEnumerable<SelectListItem> items = html.GetItems(id, context).ToList();
     int lines = items.Count() < 10 ? items.Count() : 10;
     htmlAttributes.Add("size", lines);
     tag.InnerHtml += html.ListBox(id, items, htmlAttributes) + html.GetMandatoryIndicator(context) + html.ValidationMessage(id);
 }
Esempio n. 17
0
 private static bool IsAjax(FeatureContext context) {
     return !context.Feature.ContainsFacet<IAjaxFacet>();
 }