Пример #1
0
        public static MvcHtmlString ValueLine <T, S>(this HtmlHelper helper, TypeContext <T> tc, Expression <Func <T, S> > property, Action <ValueLine> settingsModifier)
        {
            TypeContext <S> context = Common.WalkExpression(tc, property);

            var vo = tc.ViewOverrides;

            if (vo != null && !vo.IsVisible(context.PropertyRoute))
            {
                return(vo.OnSurroundLine(context.PropertyRoute, helper, tc, null));
            }

            ValueLine vl = new ValueLine(typeof(S), context.Value, context, null, context.PropertyRoute);

            Common.FireCommonTasks(vl);

            if (settingsModifier != null)
            {
                settingsModifier(vl);
            }

            var result = helper.InternalValueLine(vl);

            if (vo == null)
            {
                return(result);
            }

            return(vo.OnSurroundLine(vl.PropertyRoute, helper, tc, result));
        }
Пример #2
0
        public static MvcHtmlString EnumComboBox(this HtmlHelper helper, ValueLine valueLine)
        {
            var  uType = valueLine.Type.UnNullify();
            Enum value = valueLine.UntypedValue as Enum;

            return(InternalComboBox(helper, valueLine, uType, value));
        }
Пример #3
0
        public static MvcHtmlString TimeSpanPicker(this HtmlHelper helper, ValueLine valueLine)
        {
            TimeSpan?value = (TimeSpan?)valueLine.UntypedValue;

            if (valueLine.ReadOnly)
            {
                MvcHtmlString result = MvcHtmlString.Empty;
                if (valueLine.WriteHiddenOnReadonly)
                {
                    result = result.Concat(HiddenWithoutId(valueLine.Prefix, value?.ToString(valueLine.Format)));
                }

                return(result.Concat(helper.FormControlStatic(valueLine, valueLine.Prefix, value?.ToString(valueLine.Format), valueLine.ValueHtmlProps)));
            }

            var dateFormatAttr = valueLine.PropertyRoute.PropertyInfo.GetCustomAttribute <TimeSpanDateFormatAttribute>();

            if (dateFormatAttr != null)
            {
                return(helper.TimePicker(valueLine.Prefix, true, value, dateFormatAttr.Format, CultureInfo.CurrentCulture, valueLine.ValueHtmlProps));
            }
            else
            {
                valueLine.ValueHtmlProps.AddCssClass("form-control");
                return(helper.TextBox(valueLine.Prefix, value == null ? "" : value.Value.ToString(valueLine.Format, CultureInfo.CurrentCulture), valueLine.ValueHtmlProps));
            }
        }
Пример #4
0
        private static MvcHtmlString InternalComboBox(HtmlHelper helper, ValueLine valueLine, Type uType, Enum value)
        {
            if (valueLine.ReadOnly)
            {
                MvcHtmlString result = MvcHtmlString.Empty;
                if (valueLine.WriteHiddenOnReadonly)
                {
                    result = result.Concat(HiddenWithoutId(valueLine.Prefix, valueLine.UntypedValue.ToString()));
                }

                string str = value == null ? null :
                             LocalizedAssembly.GetDescriptionOptions(uType).IsSet(DescriptionOptions.Members) ? value.NiceToString() : value.ToString();

                return(result.Concat(helper.FormControlStatic(valueLine, valueLine.Prefix, str, valueLine.ValueHtmlProps)));
            }

            StringBuilder         sb    = new StringBuilder();
            List <SelectListItem> items = valueLine.EnumComboItems ?? valueLine.CreateComboItems();

            if (value != null)
            {
                items.Where(e => e.Value == value.ToString())
                .SingleOrDefaultEx()?.Do(s => s.Selected = true);
            }

            valueLine.ValueHtmlProps.AddCssClass("form-control");
            return(helper.SafeDropDownList(valueLine.Prefix, items, valueLine.ValueHtmlProps));
        }
Пример #5
0
        public static MvcHtmlString CheckBox(this HtmlHelper helper, ValueLine valueLine)
        {
            bool?value = (bool?)valueLine.UntypedValue;

            if (!valueLine.InlineCheckbox)
            {
                valueLine.ValueHtmlProps.AddCssClass("form-control");
            }
            return(helper.CheckBox(valueLine.Prefix, value ?? false, !valueLine.ReadOnly, valueLine.ValueHtmlProps));
        }
Пример #6
0
        static void TaskSetFormatText(LineBase bl)
        {
            ValueLine vl = bl as ValueLine;

            if (vl != null && bl.PropertyRoute.PropertyRouteType == PropertyRouteType.FieldOrProperty)
            {
                string format = Reflector.FormatString(bl.PropertyRoute);
                if (format != null)
                {
                    vl.Format = format;
                }
            }
        }
Пример #7
0
        public static MvcHtmlString NumericTextbox(this HtmlHelper helper, ValueLine valueLine)
        {
            if (!valueLine.ReadOnly)
            {
                valueLine.ValueHtmlProps.Add("onkeydown", Reflector.IsDecimalNumber(valueLine.Type) ?
                                             "return SF.InputValidator.isDecimal(event);" :
                                             "return SF.InputValidator.isNumber(event);");
            }

            valueLine.ValueHtmlProps.AddCssClass("numeric");

            return(helper.TextboxInLine(valueLine));
        }
Пример #8
0
        static void TaskSetUnitText(LineBase bl)
        {
            ValueLine vl = bl as ValueLine;

            if (vl != null && vl.PropertyRoute.PropertyRouteType == PropertyRouteType.FieldOrProperty)
            {
                UnitAttribute ua = bl.PropertyRoute.PropertyInfo.GetCustomAttribute <UnitAttribute>();
                if (ua != null)
                {
                    vl.UnitText = ua.UnitName;
                }
            }
        }
Пример #9
0
        public static MvcHtmlString BooleanEnumComboBox(this HtmlHelper helper, ValueLine valueLine)
        {
            var uType = valueLine.Type.UnNullify();

            if (uType != typeof(bool))
            {
                throw new InvalidOperationException("valueLine Type is not a boolean");
            }

            BooleanEnum?value = ToBooleanEnum((bool?)valueLine.UntypedValue);

            return(InternalComboBox(helper, valueLine, typeof(BooleanEnum), value));
        }
Пример #10
0
        private static MvcHtmlString InternalValue(HtmlHelper helper, ValueLine valueLine)
        {
            HtmlStringBuilder sb     = new HtmlStringBuilder();
            ValueLineType     vltype = valueLine.ValueLineType ?? Configurator.GetDefaultValueLineType(valueLine.Type);

            using (valueLine.UnitText == null ? null : sb.SurroundLine(new HtmlTag("div").Class("input-group")))
            {
                sb.AddLine(Configurator.Helper[vltype](helper, valueLine));

                if (valueLine.UnitText.HasText())
                {
                    sb.AddLine(helper.Span(null, valueLine.UnitText, "input-group-addon"));
                }
            }

            return(sb.ToHtml());
        }
Пример #11
0
        public static MvcHtmlString TextboxInLine(this HtmlHelper helper, ValueLine valueLine)
        {
            string value = (valueLine.UntypedValue as IFormattable)?.ToString(valueLine.Format, CultureInfo.CurrentCulture) ??
                           valueLine.UntypedValue?.ToString() ?? "";

            if (valueLine.ReadOnly)
            {
                MvcHtmlString result = MvcHtmlString.Empty;
                if (valueLine.WriteHiddenOnReadonly)
                {
                    result = result.Concat(HiddenWithoutId(valueLine.Prefix, value));
                }

                if (valueLine.UnitText.HasText())
                {
                    return(result.Concat(new HtmlTag("p").Id(valueLine.Prefix).SetInnerText(value).Class("form-control").Attrs(valueLine.ValueHtmlProps).ToHtml()));
                }
                else
                {
                    return(result.Concat(helper.FormControlStatic(valueLine, valueLine.Prefix, value, valueLine.ValueHtmlProps)));
                }
            }

            if (!valueLine.ValueHtmlProps.ContainsKey("autocomplete"))
            {
                valueLine.ValueHtmlProps.Add("autocomplete", "off");
            }
            else
            {
                valueLine.ValueHtmlProps.Remove("autocomplete");
            }



            valueLine.ValueHtmlProps["onblur"] = "this.setAttribute('value', this.value); " + (valueLine.ValueHtmlProps.ContainsKey("onblur") ? valueLine.ValueHtmlProps["onblur"] : null);

            if (!valueLine.ValueHtmlProps.ContainsKey("type"))
            {
                valueLine.ValueHtmlProps["type"] = "text";
            }

            valueLine.ValueHtmlProps.AddCssClass("form-control");
            return(helper.TextBox(valueLine.Prefix, value, valueLine.ValueHtmlProps));
        }
Пример #12
0
        private static MvcHtmlString InternalValueLine(this HtmlHelper helper, ValueLine valueLine)
        {
            if (!valueLine.Visible || (valueLine.HideIfNull && valueLine.UntypedValue == null))
            {
                return(MvcHtmlString.Empty);
            }

            if (valueLine.PlaceholderLabels && !valueLine.ValueHtmlProps.ContainsKey("placeholder"))
            {
                valueLine.ValueHtmlProps["placeholder"] = valueLine.LabelText;
            }

            var value = InternalValue(helper, valueLine);

            if (valueLine.InlineCheckbox)
            {
                return(new HtmlTag("label").InnerHtml("{0} {1}".FormatHtml(value, valueLine.LabelText)).ToHtml());
            }

            return(helper.FormGroup(valueLine, valueLine.Prefix, valueLine.LabelHtml ?? valueLine.LabelText.FormatHtml(), value));
        }
Пример #13
0
        public static MvcHtmlString ColorTextbox(this HtmlHelper helper, ValueLine valueLine)
        {
            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div").Class("input-group")))
            {
                valueLine.ValueHtmlProps.AddCssClass("form-control");

                ColorEmbedded color = (ColorEmbedded)valueLine.UntypedValue;

                sb.AddLine(helper.TextBox(valueLine.Prefix, color == null ? "" : color.RGBHex(), valueLine.ValueHtmlProps));

                sb.AddLine(new HtmlTag("span").Class("input-group-addon").InnerHtml(new HtmlTag("i")));
            }

            sb.AddLine(new HtmlTag("script").InnerHtml(MvcHtmlString.Create(
                                                           @" $(function(){
        $('#" + valueLine.Prefix + @"').parent().colorpicker()" + (valueLine.ReadOnly ? ".colorpicker('disable')" : null) + @";
   });")));

            return(sb.ToHtml());
        }
Пример #14
0
        public static MvcHtmlString DateTimePicker(this HtmlHelper helper, ValueLine valueLine)
        {
            DateTime?value = (DateTime?)valueLine.UntypedValue;

            if (value.HasValue)
            {
                value = value.Value.ToUserInterface();
            }

            if (valueLine.ReadOnly)
            {
                MvcHtmlString result = MvcHtmlString.Empty;
                if (valueLine.WriteHiddenOnReadonly)
                {
                    result = result.Concat(HiddenWithoutId(valueLine.Prefix, value?.ToString(valueLine.Format)));
                }

                return(result.Concat(helper.FormControlStatic(valueLine, valueLine.Prefix, value?.ToString(valueLine.Format), valueLine.ValueHtmlProps)));
            }

            valueLine.ValueHtmlProps.AddCssClass("form-control");
            return(helper.DateTimePicker(valueLine.Prefix, true, value, valueLine.Format, CultureInfo.CurrentCulture, valueLine.ValueHtmlProps));
        }
Пример #15
0
        public static MvcHtmlString TextAreaInLine(this HtmlHelper helper, ValueLine valueLine)
        {
            if (valueLine.ReadOnly)
            {
                MvcHtmlString result = MvcHtmlString.Empty;
                if (valueLine.WriteHiddenOnReadonly)
                {
                    result = result.Concat(HiddenWithoutId(valueLine.Prefix, (string)valueLine.UntypedValue));
                }

                if (valueLine.FormControlStaticAsFormControlReadonly)
                {
                    valueLine.ValueHtmlProps.AddCssClass("readonly-textarea");
                }

                return(result.Concat(helper.FormControlStatic(valueLine, valueLine.Prefix, (string)valueLine.UntypedValue, valueLine.ValueHtmlProps)));
            }

            valueLine.ValueHtmlProps.Add("autocomplete", "off");
            valueLine.ValueHtmlProps["onblur"] = "this.innerHTML = this.value; " + (valueLine.ValueHtmlProps.ContainsKey("onblur") ? valueLine.ValueHtmlProps["onblur"] : null);
            valueLine.ValueHtmlProps.AddCssClass("form-control");
            return(helper.TextArea(valueLine.Prefix, (string)valueLine.UntypedValue, valueLine.ValueHtmlProps));
        }
Пример #16
0
        public static void TaskSetHtmlProperties(LineBase bl)
        {
            ValueLine vl = bl as ValueLine;

            if (vl != null && bl.PropertyRoute.PropertyRouteType == PropertyRouteType.FieldOrProperty)
            {
                var slv = Validator.TryGetPropertyValidator(bl.PropertyRoute)?.Validators.OfType <StringLengthValidatorAttribute>().FirstOrDefault();
                if (slv != null)
                {
                    int max = slv.Max; //-1 if not set
                    if (max != -1)
                    {
                        vl.ValueHtmlProps.Add("maxlength", max);
                        int?maxSize = ValueLineHelper.Configurator.MaxValueLineSize;
                        vl.ValueHtmlProps.Add("size", maxSize.HasValue ? Math.Min(max, maxSize.Value) : max);
                    }

                    if (slv.MultiLine)
                    {
                        vl.ValueLineType = ValueLineType.TextArea;
                    }
                }
            }
        }
Пример #17
0
        private static MvcHtmlString PrintValueField(HtmlHelper helper, Context parent, FilterOption filterOption)
        {
            var implementations = filterOption.Token.GetImplementations();

            if (filterOption.Token.Type.IsLite())
            {
                Lite<IEntity> lite = (Lite<IEntity>)Common.Convert(filterOption.Value, filterOption.Token.Type);
                if (lite != null && string.IsNullOrEmpty(lite.ToString()))
                    Database.FillToString(lite);

                Type cleanType = Lite.Extract(filterOption.Token.Type);
                if (EntityKindCache.IsLowPopulation(cleanType) && !cleanType.IsInterface && !implementations.Value.IsByAll)
                {
                    EntityCombo ec = new EntityCombo(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                    {
                        Implementations = implementations.Value,
                    };
                    EntityBaseHelper.ConfigureEntityButtons(ec, filterOption.Token.Type.CleanType());
                    ec.FormGroupStyle = FormGroupStyle.None;
                    ec.Create = false;
                    ec.ReadOnly = filterOption.Frozen;
                    return EntityComboHelper.InternalEntityCombo(helper, ec);
                }
                else
                {
                    EntityLine el = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                    {
                        Implementations = implementations.Value,
                    };

                    if (el.Implementations.Value.IsByAll)
                        el.Autocomplete = false;

                    EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType());
                    el.FormGroupStyle = FormGroupStyle.None;
                    el.Create = false;
                    el.ReadOnly = filterOption.Frozen;

                    return EntityLineHelper.InternalEntityLine(helper, el);
                }
            }
            else if (filterOption.Token.Type.IsEmbeddedEntity())
            {
                EmbeddedEntity lite = (EmbeddedEntity)Common.Convert(filterOption.Value, filterOption.Token.Type);
                EntityLine el = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                {
                    Implementations = null,
                    Autocomplete = false,
                };
                EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType());
                el.FormGroupStyle = FormGroupStyle.None;
                el.Create = false;
                el.ReadOnly = filterOption.Frozen;

                return EntityLineHelper.InternalEntityLine(helper, el);
            }
            else
            {
                var vl = new ValueLine(filterOption.Token.Type, filterOption.Value, parent, "", filterOption.Token.GetPropertyRoute())
                {
                    FormGroupStyle = FormGroupStyle.None,
                    ReadOnly = filterOption.Frozen,
                    Format = filterOption.Token.Format,
                    UnitText = filterOption.Token.Unit,
                }; 

                if (filterOption.Token.Type.UnNullify().IsEnum)
                {
                    vl.EnumComboItems = ValueLine.CreateComboItems(EnumEntity.GetValues(vl.Type.UnNullify()), vl.UntypedValue == null || vl.Type.IsNullable());
                }

                return ValueLineHelper.ValueLine(helper, vl);
            }
            
            throw new InvalidOperationException("Invalid filter for type {0}".FormatWith(filterOption.Token.Type.Name));
        }
Пример #18
0
        private static MvcHtmlString PrintValueField(HtmlHelper helper, Context parent, FilterOption filterOption)
        {
            var implementations = filterOption.Token.GetImplementations();

            if (filterOption.Token.Type.IsLite())
            {
                Lite <IEntity> lite = (Lite <IEntity>)Common.Convert(filterOption.Value, filterOption.Token.Type);
                if (lite != null && string.IsNullOrEmpty(lite.ToString()))
                {
                    Database.FillToString(lite);
                }

                Type cleanType = Lite.Extract(filterOption.Token.Type);
                if (EntityKindCache.IsLowPopulation(cleanType) && !cleanType.IsInterface && !implementations.Value.IsByAll)
                {
                    EntityCombo ec = new EntityCombo(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                    {
                        Implementations = implementations.Value,
                    };
                    EntityBaseHelper.ConfigureEntityButtons(ec, filterOption.Token.Type.CleanType());
                    ec.FormGroupStyle = FormGroupStyle.None;
                    ec.Create         = false;
                    ec.ReadOnly       = filterOption.Frozen;
                    return(EntityComboHelper.InternalEntityCombo(helper, ec));
                }
                else
                {
                    EntityLine el = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                    {
                        Implementations = implementations.Value,
                    };

                    if (el.Implementations.Value.IsByAll)
                    {
                        el.Autocomplete = false;
                    }

                    EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType());
                    el.FormGroupStyle = FormGroupStyle.None;
                    el.Create         = false;
                    el.ReadOnly       = filterOption.Frozen;

                    return(EntityLineHelper.InternalEntityLine(helper, el));
                }
            }
            else if (filterOption.Token.Type.IsEmbeddedEntity())
            {
                EmbeddedEntity lite = (EmbeddedEntity)Common.Convert(filterOption.Value, filterOption.Token.Type);
                EntityLine     el   = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute())
                {
                    Implementations = null,
                    Autocomplete    = false,
                };
                EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType());
                el.FormGroupStyle = FormGroupStyle.None;
                el.Create         = false;
                el.ReadOnly       = filterOption.Frozen;

                return(EntityLineHelper.InternalEntityLine(helper, el));
            }
            else
            {
                var vl = new ValueLine(filterOption.Token.Type, filterOption.Value, parent, "", filterOption.Token.GetPropertyRoute())
                {
                    FormGroupStyle = FormGroupStyle.None,
                    ReadOnly       = filterOption.Frozen,
                    Format         = filterOption.Token.Format,
                    UnitText       = filterOption.Token.Unit,
                };

                if (filterOption.Token.Type.UnNullify().IsEnum)
                {
                    vl.EnumComboItems = ValueLine.CreateComboItems(EnumEntity.GetValues(vl.Type.UnNullify()), vl.UntypedValue == null || vl.Type.IsNullable());
                }

                return(ValueLineHelper.ValueLine(helper, vl));
            }

            throw new InvalidOperationException("Invalid filter for type {0}".FormatWith(filterOption.Token.Type.Name));
        }
Пример #19
0
 public static MvcHtmlString ValueLine(this HtmlHelper helper, ValueLine valueLine)
 {
     return(helper.InternalValueLine(valueLine));
 }