Exemple #1
0
        private static string BuildPath(string name, NgModelPathOptions ngModelPathOptions)
        {
            var jsOpt = ngModelPathOptions ?? new NgModelPathOptions();

            var parts = name.Split('.').Select(s => s.ToCamelCase()).Skip(jsOpt.SkipParts).ToList();

            if (!string.IsNullOrEmpty(jsOpt.Prefix))
            {
                parts.Insert(0, jsOpt.Prefix);
            }

            var path = string.Join(".", parts);

            return(path);
        }
Exemple #2
0
        public static MvcHtmlString ButtonDirective(this HtmlHelper htmlHelper, string text, object htmlAttributes = null,
                                                    NgModelPathOptions ngModelPathOptions = null, ButtonTypesEnum type = ButtonTypesEnum.Submit)
        {
            var attributes = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            if (!attributes.ContainsKey("ng-click"))
            {
                throw new Exception("There is no ng_click attribute passed to ButtonDirective.");
            }

            AttributeManager.AddButtonClassAttribute(attributes, type);

            attributes.Add("value", text);
            attributes.Add("type", "button");
            var builder = new TagBuilder("input");

            builder.MergeAttributes(attributes);
            return(MvcHtmlString.Create(builder.ToString()));
        }
Exemple #3
0
        public static MvcHtmlString TextBoxDirectiveFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper,
                                                                            Expression <Func <TModel, TProperty> > expression, object htmlAttributes = null,
                                                                            NgModelPathOptions ngModelPathOptions = null, ControlSizesEnum type = ControlSizesEnum.Medium,
                                                                            bool isTextArea = false)
        {
            var attributes = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            AttributeManager.AddTitleAttribute(attributes);

            string name = ExpressionHelper.GetExpressionText(expression);

            AttributeManager.AddNgModelAttribute(attributes, name, ngModelPathOptions);

            if (isTextArea)
            {
                return(htmlHelper.TextAreaFor(expression, attributes));
            }

            return(htmlHelper.TextBoxFor(expression, attributes));
        }
Exemple #4
0
        public static MvcHtmlString DirectiveFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper,
                                                                     Expression <Func <TModel, TProperty> > expression, string directiveName, object htmlAttributes = null,
                                                                     NgModelPathOptions ngModelPathOptions = null, string tagName = "div")
        {
            var    attributes    = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
            string name          = ExpressionHelper.GetExpressionText(expression);
            string containerName = String.Format("{0}.{1}", directiveName, name);

            AttributeManager.AddNgModelAttribute(attributes, name, ngModelPathOptions);

            var tagBuilder = new TagBuilder(tagName);

            tagBuilder.MergeAttribute(directiveName, "");
            tagBuilder.MergeAttribute("name", containerName);
            tagBuilder.MergeAttributes(attributes);

            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);

            tagBuilder.MergeAttributes(htmlHelper.GetUnobtrusiveValidationAttributes(containerName, metadata));

            return(MvcHtmlString.Create(tagBuilder.ToString()));
        }
Exemple #5
0
 public static void AddNgModelAttribute(IDictionary <string, object> attributes, string name, NgModelPathOptions ngModelPathOptions)
 {
     if (!attributes.ContainsKey("ng-model"))
     {
         var model = BuildPath(name, ngModelPathOptions);
         attributes.Add("ng-model", model);
     }
 }
Exemple #6
0
        /// <summary>
        /// Перегруженный метод DropDownListDirective. Работает с IEnumerable закрытый типом SelectListItem
        /// </summary>
        public static MvcHtmlString DropDownListDirective(this HtmlHelper htmlHelper, string name, IEnumerable <SelectListItem> listOfOptions, object htmlAttributes = null, NgModelPathOptions ngModelPathOptions = null)
        {
            var attributes = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            return(htmlHelper.DropDownList(name, listOfOptions, attributes));
        }
Exemple #7
0
        /// <summary>
        /// Перегруженный метод DropDownListDirective. Принимает имя, которые должно показываться пользователю при инициализации списка.
        /// Но, вместо этого, показывает только enum и пустое место. Нужно гармонизировать обе версии метода. Один сделать для отображения только enum.
        /// Второй, для отображения enum и дополнительного сообщения.
        /// </summary>
        public static MvcHtmlString DropDownListDirective(this HtmlHelper htmlHelper, string name, Enum enumType, string dispalyName, object htmlAttributes = null, NgModelPathOptions ngModelPathOptions = null)
        {
            var attributes    = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
            var listOfOptions = new SelectList(Enum.GetNames(enumType.GetType()));

            return(htmlHelper.DropDownList(name, listOfOptions, dispalyName, attributes));
        }
Exemple #8
0
 public static MvcHtmlString TagsInputDirectiveFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, TProperty> > expression, object htmlAttributes = null, NgModelPathOptions ngModelPathOptions = null)
 {
     return(DirectiveFor(htmlHelper, expression, "mt-tags-input", htmlAttributes, ngModelPathOptions));
 }