예제 #1
0
        public static MvcHtmlString RenderContent(HtmlHelper helper, TypeContext typeContext, RenderContentMode mode, EntityBase line)
        {
            TypeContext tc = TypeContextUtilities.CleanTypeContext((TypeContext)typeContext);

            ViewDataDictionary vdd = GetViewData(helper, line, tc);

            string partialViewName = line.PartialViewName ?? OnPartialViewName(tc);

            switch (mode)
            {
            case RenderContentMode.Content:
                return(helper.Partial(partialViewName, vdd));

            case RenderContentMode.ContentInVisibleDiv:
                return(helper.Div(typeContext.Compose(EntityBaseKeys.Entity),
                                  helper.Partial(partialViewName, vdd), "",
                                  null));

            case RenderContentMode.ContentInInvisibleDiv:
                return(helper.Div(typeContext.Compose(EntityBaseKeys.Entity),
                                  helper.Partial(partialViewName, vdd), "",
                                  new Dictionary <string, object> {
                    { "style", "display:none" }
                }));

            default:
                throw new InvalidOperationException();
            }
        }
예제 #2
0
        protected internal virtual PartialViewResult PartialView(ControllerBase controller, TypeContext tc, string partialViewName)
        {
            TypeContext cleanTC   = TypeContextUtilities.CleanTypeContext(tc);
            Type        cleanType = cleanTC.UntypedValue.GetType();

            if (!Navigator.IsViewable(cleanType, partialViewName))
            {
                throw new Exception(NormalControlMessage.ViewForType0IsNotAllowed.NiceToString().FormatWith(cleanType.Name));
            }

            controller.ViewData.Model = cleanTC;

            if (Navigator.IsReadOnly(cleanType))
            {
                cleanTC.ReadOnly = true;
            }

            cleanTC.ViewOverrides = Navigator.EntitySettings(cleanType).GetViewOverrides();

            return(new PartialViewResult
            {
                ViewName = partialViewName ?? Navigator.OnPartialViewName((ModifiableEntity)cleanTC.UntypedValue),
                ViewData = controller.ViewData,
                TempData = controller.TempData
            });
        }
예제 #3
0
        public static MvcHtmlString RenderPopup(HtmlHelper helper, TypeContext typeContext, RenderPopupMode mode, EntityBase line, bool isTemplate = false)
        {
            TypeContext tc = TypeContextUtilities.CleanTypeContext((TypeContext)typeContext);

            ViewDataDictionary vdd = GetViewData(helper, line, tc);

            string partialViewName = line.PartialViewName ?? OnPartialViewName(tc);

            vdd[ViewDataKeys.PartialViewName]       = partialViewName;
            vdd[ViewDataKeys.ViewMode]              = !line.ReadOnly;
            vdd[ViewDataKeys.ViewMode]              = ViewMode.View;
            vdd[ViewDataKeys.ShowOperations]        = true;
            vdd[ViewDataKeys.RequiresSaveOperation] = EntityKindCache.RequiresSaveOperation(tc.UntypedValue.GetType());
            vdd[ViewDataKeys.WriteEntityState]      =
                !isTemplate &&
                !(tc.UntypedValue is EmbeddedEntity) &&
                ((ModifiableEntity)tc.UntypedValue).Modified == ModifiedState.SelfModified;

            switch (mode)
            {
            case RenderPopupMode.Popup:
                return(helper.Partial(Navigator.Manager.PopupControlView, vdd));

            case RenderPopupMode.PopupInDiv:
                return(helper.Div(typeContext.Compose(EntityBaseKeys.Entity),
                                  helper.Partial(Navigator.Manager.PopupControlView, vdd),
                                  "",
                                  new Dictionary <string, object> {
                    { "style", "display:none" }
                }));

            default:
                throw new InvalidOperationException();
            }
        }
        public static MvcHtmlString EmbeddedControl <T, S>(this HtmlHelper helper, TypeContext <T> tc, Expression <Func <T, S> > property, Action <EmbeddedControl> settingsModifier)
        {
            TypeContext context = TypeContextUtilities.CleanTypeContext(Common.WalkExpression(tc, property));

            var vo = tc.ViewOverrides;

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

            var ec = new EmbeddedControl();

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

            string viewName = ec.ViewName;

            if (viewName == null)
            {
                var es = Navigator.EntitySettings(context.Type.CleanType());

                viewName = es.OnPartialViewName((ModifiableEntity)context.UntypedValue);

                context.ViewOverrides = es.GetViewOverrides();
            }

            ViewDataDictionary vdd = new ViewDataDictionary(context);

            if (ec.ViewData != null)
            {
                vdd.AddRange(ec.ViewData);
            }

            var result = helper.Partial(viewName, vdd);

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

            return(vo.OnSurroundLine(context.PropertyRoute, helper, tc, result));
        }