상속: EntityBase
예제 #1
0
        private static MvcHtmlString LinkOrSpan(HtmlHelper helper, EntityLine entityLine)
        {
            MvcHtmlString result;

            if (entityLine.Navigate || entityLine.View)
            {
                var lite = (entityLine.UntypedValue as Lite <IEntity>) ??
                           (entityLine.UntypedValue as IEntity)?.Let(i => i.ToLite(i.IsNew));

                var dic = new Dictionary <string, object>
                {
                    { "onclick", entityLine.SFControlThen("view_click(event)") }
                };

                result = helper.Href(entityLine.Compose(EntityBaseKeys.Link),
                                     entityLine.UntypedValue?.ToString(),
                                     "#",
                                     JavascriptMessage.navigate.NiceToString(), entityLine.ReadOnly ? null : "form-control  btn-default sf-entity-line-entity",
                                     dic);
            }
            else
            {
                result = helper.Span(entityLine.Compose(EntityBaseKeys.Link),
                                     entityLine.UntypedValue?.ToString() ?? " ",
                                     entityLine.ReadOnly ? null : "form-control btn-default sf-entity-line-entity");
            }

            if (entityLine.ReadOnly)
            {
                return(new HtmlTag("p").Class("form-control-static").InnerHtml(result));
            }

            return(result);
        }
예제 #2
0
        public static void TaskSetImplementations(LineBase bl)
        {
            EntityBase eb = bl as EntityBase;

            if (eb != null)
            {
                PropertyRoute route = bl.PropertyRoute;

                if (bl.Type.IsMList())
                {
                    route = route.Add("Item");
                }

                if (route.Type.CleanType().IsIEntity())
                {
                    IImplementationsFinder finder = typeof(ModelEntity).IsAssignableFrom(route.RootType) ?
                                                    (IImplementationsFinder)Navigator.EntitySettings(route.RootType) : Schema.Current;

                    eb.Implementations = finder.FindImplementations(route);

                    if (eb.Implementations.Value.IsByAll)
                    {
                        EntityLine el = eb as EntityLine;
                        if (el != null)
                        {
                            el.Autocomplete = false;
                        }
                    }
                }
            }
        }
예제 #3
0
        private static MvcHtmlString AutocompleteTextBox(HtmlHelper helper, EntityLine entityLine)
        {
            if (!entityLine.Autocomplete)
            {
                return(helper.FormControlStatic(entityLine, entityLine.Compose(EntityBaseKeys.ToStr), null, null));
            }

            var htmlAttr = new Dictionary <string, object>
            {
                { "class", "form-control sf-entity-autocomplete" },
                { "autocomplete", "off" },
            };

            if (entityLine.PlaceholderLabels)
            {
                htmlAttr.Add("placeholder", entityLine.LabelText);
            }

            return(helper.TextBox(
                       entityLine.Compose(EntityBaseKeys.ToStr),
                       null,
                       htmlAttr));
        }
예제 #4
0
        public static MvcHtmlString EntityLine <T, S>(this HtmlHelper helper, TypeContext <T> tc, Expression <Func <T, S> > property, Action <EntityLine> 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));
            }

            EntityLine el = new EntityLine(typeof(S), context.Value, context, null, context.PropertyRoute);

            EntityBaseHelper.ConfigureEntityBase(el, el.CleanRuntimeType ?? el.Type.CleanType());

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

            Common.FireCommonTasks(el);

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

            var result = helper.InternalEntityLine(el);

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

            return(vo.OnSurroundLine(el.PropertyRoute, helper, tc, result));
        }
예제 #5
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));
        }
예제 #6
0
        internal static MvcHtmlString InternalEntityLine(this HtmlHelper helper, EntityLine entityLine)
        {
            if (!entityLine.Visible || (entityLine.HideIfNull && entityLine.UntypedValue == null))
            {
                return(MvcHtmlString.Empty);
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("div", entityLine.Prefix).Class("SF-entity-line SF-control-container")))
            {
                sb.AddLine(helper.HiddenRuntimeInfo(entityLine));

                using (sb.SurroundLine(new HtmlTag("div", entityLine.Compose("hidden")).Class("hide")))
                {
                    if (entityLine.UntypedValue != null)
                    {
                        sb.AddLine(AutocompleteTextBox(helper, entityLine));
                        sb.AddLine(EntityButtonHelper.Create(helper, entityLine, btn: true));
                        sb.AddLine(EntityButtonHelper.Find(helper, entityLine, btn: true));
                    }
                    else
                    {
                        sb.AddLine(LinkOrSpan(helper, entityLine));
                        sb.AddLine(EntityButtonHelper.View(helper, entityLine, btn: true));
                        sb.AddLine(EntityButtonHelper.Remove(helper, entityLine, btn: true));
                    }
                }

                using (sb.SurroundLine(new HtmlTag("div", entityLine.Compose("inputGroup")).Class("input-group")))
                {
                    if (entityLine.UntypedValue == null)
                    {
                        sb.AddLine(AutocompleteTextBox(helper, entityLine));
                    }
                    else
                    {
                        sb.AddLine(LinkOrSpan(helper, entityLine));
                    }

                    using (sb.SurroundLine(new HtmlTag("span", entityLine.Compose("shownButton")).Class("input-group-btn")))
                    {
                        if (entityLine.UntypedValue == null)
                        {
                            sb.AddLine(EntityButtonHelper.Create(helper, entityLine, btn: true));
                            sb.AddLine(EntityButtonHelper.Find(helper, entityLine, btn: true));
                        }
                        else
                        {
                            sb.AddLine(EntityButtonHelper.View(helper, entityLine, btn: true));
                            sb.AddLine(EntityButtonHelper.Remove(helper, entityLine, btn: true));
                        }
                    }
                }

                if (entityLine.Type.IsEmbeddedEntity() && entityLine.Create)
                {
                    EmbeddedEntity embedded   = (EmbeddedEntity) new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(entityLine.Type.CleanType());
                    TypeContext    templateTC = ((TypeContext)entityLine.Parent).Clone(embedded);
                    sb.AddLine(EntityBaseHelper.EmbeddedTemplate(entityLine, EntityBaseHelper.RenderPopup(helper, templateTC, RenderPopupMode.Popup, entityLine, isTemplate: true), null));
                }

                if (EntityBaseHelper.EmbeddedOrNew((Modifiable)entityLine.UntypedValue))
                {
                    sb.AddLine(EntityBaseHelper.RenderPopup(helper, (TypeContext)entityLine.Parent, RenderPopupMode.PopupInDiv, entityLine));
                }


                sb.AddLine(entityLine.ConstructorScript(JsModule.Lines, "EntityLine"));
            }

            return(helper.FormGroup(entityLine, entityLine.Prefix, entityLine.LabelHtml ?? entityLine.LabelText.FormatHtml(), sb.ToHtml()));
        }
예제 #7
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));
        }