public static TreeListColumnBuilder <TRow> AddFor <TRow, TProperty>(this CollectionFactory <TreeListColumnBuilder <TRow> > factory, Expression <Func <TRow, TProperty> > expression)
 {
     return(factory.Add(delegate(IHtmlHelperAdapter html, TreeListColumnBuilder <TRow> item)
     {
         string expressionText = GetExpressionText(html, expression);
         item.DataField(expressionText);
         ModelExplorer modelExplorer = GetModelExplorer(html, expression);
         ModelMetadata modelMetadata = modelExplorer?.Metadata;
         if (modelMetadata != null)
         {
             string displayName = GetDisplayName(modelMetadata);
             if (!string.IsNullOrEmpty(displayName))
             {
                 item.Caption(displayName);
             }
             GridColumnDataType?gridColumnDataType = GetGridColumnDataType(modelMetadata);
             if (gridColumnDataType.HasValue)
             {
                 item.DataType(gridColumnDataType.Value);
             }
             IEnumerable <IDictionary <string, object> > validationRules = DataAnnotationsHelper.GetValidationRules(expressionText, modelExplorer, html.ViewContext);
             if (validationRules.Any())
             {
                 item.Options["validationRules"] = validationRules;
             }
         }
     }));
 }
Esempio n. 2
0
        public static void PrepareEditorFor <TModel, TProperty>(this WidgetBuilder builder, IHtmlHelperAdapter html, Expression <Func <TModel, TProperty> > expression)
        {
            ViewContext viewContext = html.ViewContext;

            Portability.IModelExpressionProviderAdapter modelExpressionProvider = Portability.GetModelExpressionProvider(viewContext);
            ModelExplorer modelExplorer  = modelExpressionProvider.GetModelExplorer(expression, new ViewDataDictionary <TModel>(viewContext.ViewData));
            string        expressionText = modelExpressionProvider.GetExpressionText(expression);

            builder.Options["name"]  = expressionText;
            builder.Options["value"] = modelExplorer?.Model;
            builder.ValidationRules  = DataAnnotationsHelper.GetValidationRules(expressionText, modelExplorer, viewContext);
        }
 public static FormSimpleItemBuilder AddSimpleFor <TFormData, TProperty>(this FormItemsFactory <TFormData> factory, Expression <Func <TFormData, TProperty> > expression)
 {
     return(factory.AddSimple(delegate(IHtmlHelperAdapter html, FormSimpleItemBuilder item)
     {
         string expressionText = GetExpressionText(html, expression);
         item.DataField(expressionText);
         ModelExplorer modelExplorer = GetModelExplorer(html, expression);
         ModelMetadata modelMetadata = modelExplorer?.Metadata;
         if (modelMetadata != null)
         {
             Func <FormItemEditorFactory, WidgetBuilder> formItemEditor = GetFormItemEditor(modelMetadata);
             if (formItemEditor != null && !factory.HasParentOwner("dxDataGrid", "dxTreeList"))
             {
                 item.Editor(formItemEditor);
             }
             string displayName = GetDisplayName(modelMetadata);
             if (!string.IsNullOrEmpty(displayName))
             {
                 item.Label(delegate(FormItemLabelBuilder label)
                 {
                     label.Text(displayName);
                 });
             }
             string displayPrompt = GetDisplayPrompt(modelMetadata);
             if (!string.IsNullOrEmpty(displayPrompt))
             {
                 OptionsOwnerBuilder.GetNestedOptions(item.Options, "editorOptions")["placeholder"] = displayPrompt;
             }
             string displayDescription = GetDisplayDescription(modelMetadata);
             if (!string.IsNullOrEmpty(displayDescription))
             {
                 item.HelpText(displayDescription);
             }
             IEnumerable <IDictionary <string, object> > validationRules = DataAnnotationsHelper.GetValidationRules(expressionText, modelExplorer, html.ViewContext);
             if (validationRules.Any())
             {
                 item.Options["validationRules"] = validationRules;
             }
         }
     }));
 }