Example #1
0
        public Action <IRendererTreeBuilder> BuildRendererTree <TItem>(IActualItemContext <TItem> actualItemContext, FormField field) where TItem : class
        {
            var localColumnName = actualItemContext.ActualColumnName;
            var value           = actualItemContext.GetActualItemColumnValue(localColumnName);

            var valueExpression = Expression.Lambda <Func <string> >(
                Expression.Property(
                    Expression.Constant(actualItemContext.ActualItem),
                    field.Info));

            return(builder =>
            {
                builder
                .OpenElement(HtmlTagNames.Div, "form-field-wrapper")
                .OpenComponent(typeof(InputText))
                .AddAttribute("id", $"create-form-{localColumnName}")
                .AddAttribute("class", "edit-text-field")
                .AddAttribute("Value", value)
                .AddAttribute("ValueExpression", valueExpression)
                .AddAttribute("ValueChanged", eventCallbackFactory.Create <string>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                .CloseComponent()
                .AddValidationMessage <string>(valueExpression)
                .CloseElement();
            });
        }
Example #2
0
        public Action <IRendererTreeBuilder> BuildRendererTree <TItem>(IActualItemContext <TItem> actualItemContext, PropertyInfo field) where TItem : class
        {
            var localColumnName = actualItemContext.ActualColumnName;
            var localValue      = actualItemContext.GetActualItemColumnValue(localColumnName);

            var valueExpression = Expression.Lambda(Expression.Property(Expression.Constant(actualItemContext.ActualItem), field));
            var optionsFragment = CreateOptionsFragment(localValue);
            var valueChanged    = CreateValueChangedCallback(field);

            InitializeSelectInputContext(actualItemContext, field, localColumnName);

            return(builder =>
            {
                builder
                .OpenElement(HtmlTagNames.Div, "form-field-wrapper")
                .OpenComponent(typeof(InputSelect <>).MakeGenericType(field.GetMemberType()))
                .AddAttribute("Id", $"create-form-{localColumnName}")
                .AddAttribute("Class", "edit-text-field")
                .AddAttribute("Value", localValue)
                .AddAttribute("ValueExpression", valueExpression)
                .AddAttribute(RenderTreeBuilder.ChildContent, optionsFragment)
                .AddAttribute("ValueChanged", valueChanged)
                .CloseComponent()
                .OpenComponent(typeof(ValidationMessage <>).MakeGenericType(field.GetMemberType()))
                .AddAttribute("For", valueExpression)
                .CloseComponent()
                .CloseElement();
            });
        }
        public override void BuildInputRendererTree(IRendererTreeBuilder rendererTreeBuilder, IActualItemContext <object> actualItemContext, Action <string, object> onChangeAction, string columnName)
        {
            var value = actualItemContext.GetActualItemColumnValue(columnName);

            if (IsSupportedDateType(value))
            {
                var dateTimeValue         = ConvertToDateTime(value);
                var dateValueContainsTime = Math.Abs(dateTimeValue.TimeOfDay.TotalSeconds) > 0.00000000001;
                var dateFormat            = dateValueContainsTime ? "yyyy-MM-dd'T'HH:mm:ss" : "yyyy-MM-dd";

                rendererTreeBuilder
                .OpenElement(HtmlTagNames.Div, "edit-field-wrapper")
                .OpenElement(HtmlTagNames.Input, "edit-text-field")
                .AddAttribute(HtmlAttributes.Type, dateValueContainsTime ? "datetime-local" : "date")
                .AddAttribute(HtmlAttributes.Value, BindConverter.FormatValue(dateTimeValue, dateFormat))
                .AddAttribute(HtmlJsEvents.OnChange, EventCallback.Factory.Create(this,
                                                                                  (ChangeEventArgs e) =>
                {
                    onChangeAction?.Invoke(columnName, BindConverterExtensions.ConvertTo(e.Value, DateTime.MinValue));
                }))
                .CloseElement()
                .CloseElement();
            }
            else
            {
                Successor.BuildInputRendererTree(rendererTreeBuilder, actualItemContext, onChangeAction, columnName);
            }
        }
        public override void BuildInputRendererTree(IRendererTreeBuilder rendererTreeBuilder, IActualItemContext <object> actualItemContext, Action <string, object> onChangeAction)
        {
            var localColumnName = actualItemContext.ActualColumnName;
            var value           = actualItemContext.GetActualItemColumnValue(localColumnName);

            if (IsSupportedDateType(value))
            {
                var dateTimeValue          = ConvertToDateTime(value);
                var dateValueContatinsTime = dateTimeValue.TimeOfDay.TotalSeconds != 0;
                var dateFormat             = dateValueContatinsTime ? "yyyy-MM-dd'T'HH:mm:ss" : "yyyy-MM-dd";

                rendererTreeBuilder
                .OpenElement(HtmlTagNames.Div, "edit-field-wrapper")
                .OpenElement(HtmlTagNames.Input, "edit-text-field")
                .AddAttribute(HtmlAttributes.Type, dateValueContatinsTime ? "datetime-local" : "date")
                .AddAttribute(HtmlAttributes.Value, BindMethods.GetValue(dateTimeValue, dateFormat))
                .AddAttribute(HtmlJSEvents.OnChange, BindMethods.SetValueHandler(delegate(DateTime __value)
                {
                    onChangeAction?.Invoke(localColumnName, __value);
                }, dateTimeValue, dateFormat))
                .CloseElement()
                .CloseElement();
            }
            else
            {
                successor.BuildInputRendererTree(rendererTreeBuilder, actualItemContext, onChangeAction);
            }
        }
Example #5
0
        public Action <IRendererTreeBuilder> BuildRendererTree <TItem>(IActualItemContext <TItem> actualItemContext, PropertyInfo field) where TItem : class
        {
            var localColumnName = actualItemContext.ActualColumnName;
            var value           = actualItemContext.GetActualItemColumnValue(localColumnName);

            var valueExpression = Expression.Lambda <Func <bool> >(
                Expression.Property(
                    Expression.Constant(actualItemContext.ActualItem),
                    field));

            return(builder =>
            {
                builder
                .OpenElement(HtmlTagNames.Div, "checkbox")
                .OpenElement(HtmlTagNames.Label)
                .OpenComponent(typeof(InputCheckbox))
                .AddAttribute("Id", $"create-form-{localColumnName}")
                .AddAttribute("Class", string.Empty)
                .AddAttribute("Value", value)
                .AddAttribute("ValueExpression", valueExpression)
                .AddAttribute("ValueChanged", eventCallbackFactory.Create <bool>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                .CloseComponent()
                .OpenElement(HtmlTagNames.Span, "cr")
                .OpenElement(HtmlTagNames.I, "cr-icon fa fa-check")
                .CloseElement()
                .CloseElement()
                .CloseElement()
                .CloseElement()
                .AddValidationMessage <bool>(valueExpression);
            });
        }
Example #6
0
        public Action <IRendererTreeBuilder> BuildRendererTree <TItem>(IActualItemContext <TItem> actualItemContext, FormField field) where TItem : class
        {
            var localColumnName = actualItemContext.ActualColumnName;
            var value           = actualItemContext.GetActualItemColumnValue(localColumnName);

            var valueExpression = GetValueExpression(actualItemContext.ActualItem, field);
            var convertedValue  = ConvertToDateTime(value);

            actualItemContext.SetActualItemColumnValue(localColumnName, convertedValue);

            return(builder =>
            {
                builder
                .OpenElement(HtmlTagNames.Div, "form-field-wrapper")
                .OpenComponent(typeof(InputDate <>).MakeGenericType(field.Type))
                .AddAttribute("id", $"create-form-{localColumnName}")
                .AddAttribute("class", "edit-text-field")
                .AddAttribute("Value", convertedValue)
                .AddAttribute("ValueExpression", valueExpression);

                if (field.UnderlyneType == typeof(DateTime))
                {
                    if (field.IsNullable)
                    {
                        builder
                        .AddAttribute("ValueChanged", eventCallbackFactory.Create <DateTime?>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <DateTime?>(valueExpression);
                    }
                    else
                    {
                        builder
                        .AddAttribute("ValueChanged", eventCallbackFactory.Create <DateTime>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <DateTime>(valueExpression);
                    }
                }
                else
                {
                    if (field.IsNullable)
                    {
                        builder
                        .AddAttribute("ValueChanged", eventCallbackFactory.Create <DateTimeOffset?>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <DateTimeOffset?>(valueExpression);
                    }
                    else
                    {
                        builder
                        .AddAttribute("ValueChanged", eventCallbackFactory.Create <DateTimeOffset>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <DateTimeOffset>(valueExpression);
                    }
                }

                builder.CloseElement();
            });
        }
Example #7
0
        public Action <IRendererTreeBuilder> BuildRendererTree <TItem>(IActualItemContext <TItem> actualItemContext, PropertyInfo field) where TItem : class
        {
            var localColumnName = actualItemContext.ActualColumnName;
            var value           = actualItemContext.GetActualItemColumnValue(localColumnName);

            var valueExpression = GetValueExpression(value, actualItemContext.ActualItem, field);

            return(builder =>
            {
                builder
                .OpenElement(HtmlTagNames.Div, "form-field-wrapper")
                .OpenComponent(typeof(InputNumber <>).MakeGenericType(field.GetMemberType()))
                .AddAttribute("Id", $"create-form-{localColumnName}")
                .AddAttribute("Class", "edit-text-field")
                .AddAttribute("Value", value)
                .AddAttribute("ValueExpression", valueExpression);

                if (value is int)
                {
                    builder
                    .AddAttribute("ValueChanged", eventCallbackFactory.Create <int>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                    .CloseComponent()
                    .AddValidationMessage <int>(valueExpression);
                }
                else if (value is long)
                {
                    builder
                    .AddAttribute("ValueChanged", eventCallbackFactory.Create <long>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                    .CloseComponent()
                    .AddValidationMessage <long>(valueExpression);
                }
                else if (value is decimal)
                {
                    builder
                    .AddAttribute("ValueChanged", eventCallbackFactory.Create <decimal>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                    .CloseComponent()
                    .AddValidationMessage <decimal>(valueExpression);
                }
                else if (value is double)
                {
                    builder
                    .AddAttribute("ValueChanged", eventCallbackFactory.Create <double>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                    .CloseComponent()
                    .AddValidationMessage <double>(valueExpression);
                }
                else if (value is float)
                {
                    builder
                    .AddAttribute("ValueChanged", eventCallbackFactory.Create <float>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                    .CloseComponent()
                    .AddValidationMessage <float>(valueExpression);
                }

                builder.CloseElement();
            });
        }
        public override void BuildInputRendererTree(IRendererTreeBuilder rendererTreeBuilder, IActualItemContext <object> actualItemContext, Action <string, object> onChangeAction, string columnName)
        {
            var value = actualItemContext.GetActualItemColumnValue(columnName);

            rendererTreeBuilder
            .OpenElement(HtmlTagNames.Div, "edit-field-wrapper")
            .OpenElement(HtmlTagNames.Input, "edit-text-field")
            .AddAttribute(HtmlAttributes.Type, GetInputType(value?.ToString() ?? InputTypeText))
            .AddAttribute(HtmlAttributes.Value, BindConverter.FormatValue(value))
            .AddAttribute(HtmlJsEvents.OnChange, EventCallback.Factory.Create(this,
                                                                              (ChangeEventArgs e) => onChangeAction?.Invoke(columnName, BindConverterExtensions.ConvertTo(e.Value, string.Empty)))
                          )
            .CloseElement()
            .CloseElement();
        }
Example #9
0
        public Action <IRendererTreeBuilder> BuildRendererTree <TItem>(IActualItemContext <TItem> actualItemContext, FormField field) where TItem : class
        {
            var localColumnName = actualItemContext.ActualColumnName;
            var value           = actualItemContext.GetActualItemColumnValue(localColumnName);

            var valueExpression = GetValueExpression(actualItemContext.ActualItem, field);

            return(builder =>
            {
                builder
                .OpenElement(HtmlTagNames.Div, "checkbox")
                .OpenElement(HtmlTagNames.Label)
                .OpenComponent(typeof(InputCheckbox))
                .AddAttribute("Id", $"create-form-{localColumnName}")
                .AddAttribute("Class", string.Empty)
                .AddAttribute("Value", value)
                .AddAttribute("ValueExpression", valueExpression);

                if (field.IsNullable)
                {
                    builder.AddAttribute("ValueChanged", eventCallbackFactory.Create <bool?>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)));
                }
                else
                {
                    builder.AddAttribute("ValueChanged", eventCallbackFactory.Create <bool>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)));
                }

                builder
                .CloseComponent()
                .OpenElement(HtmlTagNames.Span, "cr")
                .OpenElement(HtmlTagNames.I, "cr-icon fa fa-check")
                .CloseElement()
                .CloseElement()
                .CloseElement()
                .CloseElement();

                if (field.IsNullable)
                {
                    builder.AddValidationMessage <bool?>(valueExpression);
                }
                else
                {
                    builder.AddValidationMessage <bool>(valueExpression);
                }
            });
        }
        public override void BuildInputRendererTree(IRendererTreeBuilder rendererTreeBuilder, IActualItemContext <object> actualItemContext, Action <string, object> onChangeAction)
        {
            var localColumnName = actualItemContext.ActualColumnName;
            var value           = actualItemContext.GetActualItemColumnValue(localColumnName);

            if (value is Enum enumTypeValue)
            {
                var actualStringValue = enumTypeValue.ToString();

                rendererTreeBuilder
                .OpenElement(HtmlTagNames.Div, "edit-field-wrapper")
                .OpenElement(HtmlTagNames.Select, "edit-text-field")
                .AddAttribute(HtmlJSEvents.OnChange, EventCallback.Factory.Create(this,
                                                                                  (ChangeEventArgs e) =>
                {
                    var parsedValue = Enum.Parse(value.GetType(), e.Value.ToString());
                    onChangeAction?.Invoke(localColumnName, parsedValue);
                }
                                                                                  ));

                foreach (var enumValue in Enum.GetValues(enumTypeValue.GetType()))
                {
                    var enumStringValue = enumValue.ToString();

                    rendererTreeBuilder.OpenElement(HtmlTagNames.Option);
                    if (enumStringValue == actualStringValue)
                    {
                        rendererTreeBuilder.AddAttribute(HtmlAttributes.Selected, true);
                    }

                    rendererTreeBuilder
                    .AddAttribute(HtmlAttributes.Value, enumStringValue)
                    .AddContent(enumStringValue)
                    .CloseElement();
                }

                rendererTreeBuilder
                .CloseElement()
                .CloseElement();
            }
            else
            {
                successor.BuildInputRendererTree(rendererTreeBuilder, actualItemContext, onChangeAction);
            }
        }
        public override void BuildInputRendererTree(IRendererTreeBuilder rendererTreeBuilder, IActualItemContext <object> actualItemContext, Action <string, object> onChangeAction)
        {
            var localColumnName = actualItemContext.ActualColumnName;
            var value           = actualItemContext.GetActualItemColumnValue(localColumnName);

            rendererTreeBuilder
            .OpenElement(HtmlTagNames.Div, "edit-field-wrapper")
            .OpenElement(HtmlTagNames.Input, "edit-text-field")
            .AddAttribute(HtmlAttributes.Type, GetInputType(value?.ToString() ?? InputTypeText))
            .AddAttribute(HtmlAttributes.Value, BindMethods.GetValue(value))
            .AddAttribute(HtmlJSEvents.OnChange,
                          BindMethods.SetValueHandler(delegate(string __value)
            {
                onChangeAction?.Invoke(localColumnName, __value);
            }, value?.ToString() ?? string.Empty)
                          )
            .CloseElement()
            .CloseElement();
        }
Example #12
0
        public override void BuildInputRendererTree(IRendererTreeBuilder rendererTreeBuilder, IActualItemContext <object> actualItemContext, Action <string, object> onChangeAction, string columnName)
        {
            var value = actualItemContext.GetActualItemColumnValue(columnName);

            if (IsSupportedNumberType(value))
            {
                rendererTreeBuilder
                .OpenElement(HtmlTagNames.Div, "edit-field-wrapper")
                .OpenElement(HtmlTagNames.Input, "edit-text-field")
                .AddAttribute(HtmlAttributes.Type, "number");

                TryAddOnChangeHandler(rendererTreeBuilder, onChangeAction, columnName, value);

                rendererTreeBuilder
                .CloseElement()
                .CloseElement();
            }
            else
            {
                Successor.BuildInputRendererTree(rendererTreeBuilder, actualItemContext, onChangeAction, columnName);
            }
        }
Example #13
0
        public Action <IRendererTreeBuilder> BuildRendererTree <TItem>(IActualItemContext <TItem> actualItemContext, FormField field, string localColumnName) where TItem : class
        {
            var value = actualItemContext.GetActualItemColumnValue(localColumnName);

            var valueExpression = GetValueExpression(actualItemContext.ActualItem, field);

            return(builder =>
            {
                builder
                .OpenElement(HtmlTagNames.Div, "form-field-wrapper")
                .OpenComponent(typeof(InputNumber <>).MakeGenericType(field.Type))
                .AddAttribute("id", $"create-form-{localColumnName}")
                .AddAttribute("class", "edit-text-field")
                .AddAttribute("Value", value)
                .AddAttribute("ValueExpression", valueExpression);

                if (field.UnderlyingType == typeof(int))
                {
                    if (field.IsNullable)
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <int?>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <int?>(valueExpression);
                    }
                    else
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <int>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <int>(valueExpression);
                    }
                }
                else if (field.UnderlyingType == typeof(long))
                {
                    if (field.IsNullable)
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <long?>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <long?>(valueExpression);
                    }
                    else
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <long>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <long>(valueExpression);
                    }
                }
                else if (field.UnderlyingType == typeof(decimal))
                {
                    if (field.IsNullable)
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <decimal?>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <decimal?>(valueExpression);
                    }
                    else
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <decimal>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <decimal>(valueExpression);
                    }
                }
                else if (field.UnderlyingType == typeof(double))
                {
                    if (field.IsNullable)
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <double?>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <double?>(valueExpression);
                    }
                    else
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <double>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <double>(valueExpression);
                    }
                }
                else if (field.UnderlyingType == typeof(float))
                {
                    if (field.IsNullable)
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <float?>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <float?>(valueExpression);
                    }
                    else
                    {
                        builder
                        .AddAttribute("ValueChanged", _eventCallbackFactory.Create <float>(this, v => actualItemContext.SetActualItemColumnValue(localColumnName, v)))
                        .CloseComponent()
                        .AddValidationMessage <float>(valueExpression);
                    }
                }

                builder.CloseElement();
            });
        }