Esempio n. 1
0
        public override void BuildForm(DotvvmControl hostControl, DynamicDataContext dynamicDataContext)
        {
            var entityPropertyListProvider = dynamicDataContext.RequestContext.Services.GetRequiredService <IEntityPropertyListProvider>();

            // create the rows
            var properties = GetPropertiesToDisplay(dynamicDataContext, entityPropertyListProvider);

            foreach (var property in properties)
            {
                // find the editorProvider for cell
                var editorProvider = FindEditorProvider(property, dynamicDataContext);
                if (editorProvider == null)
                {
                    continue;
                }

                // create the row
                HtmlGenericControl labelElement, controlElement;
                var formGroup = InitializeFormGroup(hostControl, property, dynamicDataContext, out labelElement, out controlElement);

                // create the label
                InitializeControlLabel(formGroup, labelElement, editorProvider, property, dynamicDataContext);

                // create the editorProvider
                InitializeControlEditor(formGroup, controlElement, editorProvider, property, dynamicDataContext);

                // create the validator
                InitializeValidation(formGroup, labelElement, controlElement, editorProvider, property, dynamicDataContext);
            }
        }
Esempio n. 2
0
        public override void BuildForm(DotvvmControl hostControl, DynamicDataContext dynamicDataContext)
        {
            var entityPropertyListProvider = dynamicDataContext.RequestContext.Configuration.ServiceProvider.GetService <IEntityPropertyListProvider>();

            // create the table
            var table = InitializeTable(hostControl, dynamicDataContext);

            // create the rows
            var properties = GetPropertiesToDisplay(dynamicDataContext, entityPropertyListProvider);

            foreach (var property in properties)
            {
                // find the editorProvider for cell
                var editorProvider = FindEditorProvider(property, dynamicDataContext);
                if (editorProvider == null)
                {
                    continue;
                }

                // create the row
                HtmlGenericControl labelCell, editorCell;
                var row = InitializeTableRow(table, property, dynamicDataContext, out labelCell, out editorCell);

                // create the label
                InitializeControlLabel(row, labelCell, editorProvider, property, dynamicDataContext);

                // create the editorProvider
                InitializeControlEditor(row, editorCell, editorProvider, property, dynamicDataContext);

                // create the validator
                InitializeValidation(row, labelCell, editorCell, editorProvider, property, dynamicDataContext);
            }
        }
Esempio n. 3
0
        public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context)
        {
            var matchedConvention = comboBoxConventions.Conventions.FirstOrDefault(c => c.Match.IsMatch(propertyInfo));

            if (matchedConvention == null)
            {
                return(false);
            }

            // store the convention in the context
            context.StateBag[new StateBagKey(this, propertyInfo)] = matchedConvention;
            return(true);
        }
Esempio n. 4
0
        protected virtual HtmlGenericControl InitializeFormGroup(DotvvmControl hostControl, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext, out HtmlGenericControl labelElement, out HtmlGenericControl controlElement)
        {
            var formGroup = new HtmlGenericControl("div");

            formGroup.Attributes["class"] = ControlHelpers.ConcatCssClasses(FormGroupCssClass, property.Styles?.FormRowCssClass);
            hostControl.Children.Add(formGroup);

            labelElement = new HtmlGenericControl("label");
            formGroup.Children.Add(labelElement);

            controlElement = new HtmlGenericControl("div");
            controlElement.Attributes["class"] = ControlHelpers.ConcatCssClasses(property.Styles?.FormControlContainerCssClass);
            formGroup.Children.Add(controlElement);

            return(formGroup);
        }
 public ValueBindingExpression GetValidationValueBinding(PropertyDisplayMetadata property, DynamicDataContext context)
 {
     return(context.CreateValueBinding(property.PropertyInfo.Name));
 }
Esempio n. 6
0
        /// <summary>
        /// Creates the table element for the form.
        /// </summary>
        protected virtual HtmlGenericControl InitializeTable(DotvvmControl hostControl, DynamicDataContext dynamicDataContext)
        {
            var table = new HtmlGenericControl("table");

            table.Attributes["class"] = "dotvvm-dynamicdata-form-table";

            hostControl.Children.Add(table);
            return(table);
        }
Esempio n. 7
0
 /// <summary>
 /// Creates the contents of the label cell for the specified property.
 /// </summary>
 protected virtual void InitializeControlLabel(HtmlGenericControl row, HtmlGenericControl labelCell, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext)
 {
     if (editorProvider.RenderDefaultLabel)
     {
         labelCell.Children.Add(new Literal(property.DisplayName));
     }
 }
        public GridViewColumn CreateColumn(GridView gridView, PropertyDisplayMetadata property, DynamicDataContext context)
        {
            var column = CreateColumnCore(gridView, property, context);

            column.CssClass       = ControlHelpers.ConcatCssClasses(column.CssClass, property.Styles?.GridCellCssClass);
            column.HeaderCssClass = ControlHelpers.ConcatCssClasses(column.HeaderCssClass, property.Styles?.GridHeaderCellCssClass);

            return(column);
        }
 /// <summary>
 /// Gets the DisplayMember for the ComboBox control from the ComboBoxSettingsAttribute.
 /// </summary>
 protected virtual string GetDisplayMember(PropertyDisplayMetadata property, DynamicDataContext context)
 {
     return(GetSettings(property.PropertyInfo)?.DisplayMember);
 }
Esempio n. 10
0
 protected override string GetValueMember(PropertyDisplayMetadata property, DynamicDataContext context)
 {
     return(base.GetValueMember(property, context) ?? GetConvention(property, context).Settings.ValueMember);
 }
Esempio n. 11
0
 public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context)
 {
     return(TextBoxHelper.CanHandleProperty(propertyInfo, context));
 }
Esempio n. 12
0
        protected override GridViewColumn CreateColumnCore(GridView gridView, PropertyDisplayMetadata property, DynamicDataContext context)
        {
            var column = new GridViewTextColumn();

            column.ValueType    = TextBoxHelper.GetValueTypeOrDefault(property.PropertyInfo);
            column.FormatString = property.FormatString;
            column.SetBinding(GridViewTextColumn.ValueBindingProperty, context.CreateValueBinding(property.PropertyInfo.Name));
            column.IsEditable = property.IsEditAllowed;
            return(column);
        }
        public override void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context)
        {
            var textBox = new BusinessPack.Controls.TextBox();

            container.Children.Add(textBox);

            var cssClass = ControlHelpers.ConcatCssClasses(ControlCssClass, property.Styles?.FormControlCssClass);

            if (!string.IsNullOrEmpty(cssClass))
            {
                textBox.Attributes["class"] = cssClass;
            }

            textBox.ValueType    = TextBoxHelper.GetValueType(property.PropertyInfo);
            textBox.FormatString = property.FormatString;
            textBox.SetBinding(TextBox.TextProperty, context.CreateValueBinding(property.PropertyInfo.Name));

            if (property.DataType == DataType.Password)
            {
                textBox.Type = TextBoxType.Password;
            }
            else if (property.DataType == DataType.MultilineText)
            {
                textBox.Type = TextBoxType.MultiLine;
            }

            if (textBox.IsPropertySet(DynamicEntity.EnabledProperty))
            {
                ControlHelpers.CopyProperty(textBox, DynamicEntity.EnabledProperty, textBox, TextBox.EnabledProperty);
            }
        }
Esempio n. 14
0
        protected virtual void InitializeValidation(HtmlGenericControl formGroup, HtmlGenericControl labelElement, HtmlGenericControl controlElement, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext)
        {
            if (dynamicDataContext.ValidationMetadataProvider.GetAttributesForProperty(property.PropertyInfo).OfType <RequiredAttribute>().Any())
            {
                if (labelElement.Attributes.ContainsKey("class"))
                {
                    labelElement.Attributes["class"] = ControlHelpers.ConcatCssClasses(labelElement.Attributes["class"] as string, "dynamicdata-required");
                }
                else
                {
                    labelElement.Attributes["class"] = "dynamicdata-required";
                }
            }

            if (editorProvider.CanValidate)
            {
                controlElement.SetValue(DotVVM.Framework.Controls.Validator.ValueProperty, editorProvider.GetValidationValueBinding(property, dynamicDataContext));
            }
        }
Esempio n. 15
0
 protected virtual void InitializeControlEditor(HtmlGenericControl formGroup, HtmlGenericControl controlElement, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext)
 {
     editorProvider.CreateControl(controlElement, property, dynamicDataContext);
 }
 /// <summary>
 /// Gets the DataSource binding expression for the ComboBox control from the ComboBoxSettingsAttribute.
 /// </summary>
 protected virtual string GetDataSourceBindingExpression(PropertyDisplayMetadata property, DynamicDataContext context)
 {
     return(GetSettings(property.PropertyInfo)?.DataSourceBinding);
 }
 /// <summary>
 /// Gets the EmptyItemText for the ComboBox control from the ComboBoxSettingsAttribute.
 /// </summary>
 protected virtual string GetEmptyItemText(PropertyDisplayMetadata property, DynamicDataContext context)
 {
     return(GetSettings(property.PropertyInfo)?.EmptyItemText);
 }
Esempio n. 18
0
 protected override string GetEmptyItemText(PropertyDisplayMetadata property, DynamicDataContext context)
 {
     return(base.GetEmptyItemText(property, context) ?? GetConvention(property, context).Settings.EmptyItemText);
 }
 protected abstract GridViewColumn CreateColumnCore(GridView gridView, PropertyDisplayMetadata property, DynamicDataContext context);
Esempio n. 20
0
 protected override string GetDataSourceBindingExpression(PropertyDisplayMetadata property, DynamicDataContext context)
 {
     return(base.GetDataSourceBindingExpression(property, context) ?? GetConvention(property, context).Settings.DataSourceBinding);
 }
 public abstract bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context);
Esempio n. 22
0
 private ComboBoxConvention GetConvention(PropertyDisplayMetadata property, DynamicDataContext context)
 {
     return((ComboBoxConvention)context.StateBag[new StateBagKey(this, property.PropertyInfo)]);
 }
Esempio n. 23
0
 /// <summary>
 /// Creates the contents of the editor cell for the specified property.
 /// </summary>
 protected virtual void InitializeControlEditor(HtmlGenericControl row, HtmlGenericControl editorCell, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext)
 {
     editorProvider.CreateControl(editorCell, property, dynamicDataContext);
 }
Esempio n. 24
0
        public static bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context)
        {
            var type = DynamicDataPropertyHandlerBase.UnwrapNullableType(propertyInfo.PropertyType);

            return(stringTypes.Contains(type) || numericTypes.Contains(type) || dateTypes.Contains(type));
        }
Esempio n. 25
0
        /// <summary>
        /// Initializes the validation on the row.
        /// </summary>
        protected virtual void InitializeValidation(HtmlGenericControl row, HtmlGenericControl labelCell, HtmlGenericControl editorCell, IFormEditorProvider editorProvider, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext)
        {
            if (dynamicDataContext.ValidationMetadataProvider.GetAttributesForProperty(property.PropertyInfo).OfType <RequiredAttribute>().Any())
            {
                labelCell.Attributes["class"] += " dynamicdata-required";
            }

            if (editorProvider.CanValidate)
            {
                row.SetValue(Validator.ValueProperty, editorProvider.GetValidationValueBinding(property, dynamicDataContext));
            }
        }
 public override bool CanHandleProperty(PropertyInfo propertyInfo, DynamicDataContext context)
 {
     return(GetSettings(propertyInfo) != null);
 }
Esempio n. 27
0
        /// <summary>
        /// Creates the table row for the specified property.
        /// </summary>
        protected virtual HtmlGenericControl InitializeTableRow(HtmlGenericControl table, PropertyDisplayMetadata property, DynamicDataContext dynamicDataContext, out HtmlGenericControl labelCell, out HtmlGenericControl editorCell)
        {
            var row = new HtmlGenericControl("tr");

            row.Attributes["class"] = property.Styles?.FormRowCssClass;
            table.Children.Add(row);

            labelCell = new HtmlGenericControl("td");
            labelCell.Attributes["class"] = ControlHelpers.ConcatCssClasses("dynamicdata-label", LabelCellCssClass);
            row.Children.Add(labelCell);

            editorCell = new HtmlGenericControl("td");
            editorCell.Attributes["class"] = ControlHelpers.ConcatCssClasses("dynamicdata-editor", EditorCellCssClass, property.Styles?.FormControlContainerCssClass);
            row.Children.Add(editorCell);

            return(row);
        }
        public override void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context)
        {
            var comboBox = new ComboBox()
            {
                EmptyItemText = GetEmptyItemText(property, context)
            };

            container.Children.Add(comboBox);

            comboBox.SetBinding(SelectorBase.ItemTextBindingProperty, context.CreateValueBinding(GetDisplayMember(property, context)));
            comboBox.SetBinding(SelectorBase.ItemValueBindingProperty, context.CreateValueBinding(GetValueMember(property, context)));

            comboBox.SetBinding(SelectorBase.ItemTextBindingProperty, context.CreateValueBinding(GetDisplayMember(property, context)));
            comboBox.SetBinding(SelectorBase.ItemValueBindingProperty, context.CreateValueBinding(GetValueMember(property, context)));
            comboBox.SetBinding(Selector.SelectedValueProperty, context.CreateValueBinding(property.PropertyInfo.Name));
            comboBox.SetBinding(ItemsControl.DataSourceProperty, GetDataSourceBinding(property, context, comboBox));

            var cssClass = ControlHelpers.ConcatCssClasses(ControlCssClass, property.Styles?.FormControlCssClass);

            if (!string.IsNullOrEmpty(cssClass))
            {
                comboBox.Attributes["class"] = cssClass;
            }

            if (container.IsPropertySet(DynamicEntity.EnabledProperty))
            {
                ControlHelpers.CopyProperty(container, DynamicEntity.EnabledProperty, comboBox, SelectorBase.EnabledProperty);
            }
        }
 public abstract void CreateControl(DotvvmControl container, PropertyDisplayMetadata property, DynamicDataContext context);
        /// <summary>
        /// Compiles the DataSource binding expression to a value binding.
        /// </summary>
        protected virtual ValueBindingExpression GetDataSourceBinding(PropertyDisplayMetadata property, DynamicDataContext context, ComboBox comboBox)
        {
            var dataSourceBindingExpression = GetDataSourceBindingExpression(property, context);

            if (string.IsNullOrEmpty(dataSourceBindingExpression))
            {
                throw new Exception($"The DataSource binding expression for property {property.PropertyInfo} must be specified!");
            }

            return(context.CreateValueBinding(dataSourceBindingExpression));
        }