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 }); }
public static MvcHtmlString LightEntityLine(this HtmlHelper helper, Lite <IEntity> lite, bool isSearch, bool targetBlank = true, string innerText = null) { if (lite == null) { return(MvcHtmlString.Empty); } if (lite.ToString() == null) { Database.FillToString(lite); } if (!Navigator.IsNavigable(lite.EntityType, null, isSearch)) { return((innerText ?? lite.ToString()).EncodeHtml()); } Dictionary <string, object> htmlAtributes = new Dictionary <string, object>(); if (targetBlank) { htmlAtributes.Add("target", "_blank"); } if (!Navigator.EntitySettings(lite.EntityType).AvoidPopup) { htmlAtributes.Add("data-entity-link", lite.Key()); } return(helper.Href("", innerText ?? lite.ToString(), Navigator.NavigateRoute(lite), HttpUtility.HtmlEncode(lite.ToString()), "sf-light-entity-line", htmlAtributes)); }
protected internal virtual PartialViewResult PopupControl(ControllerBase controller, TypeContext typeContext, PopupOptionsBase popupOptions) { Type cleanType = typeContext.UntypedValue.GetType(); ModifiableEntity entity = (ModifiableEntity)typeContext.UntypedValue; AssertViewableEntitySettings(entity); controller.ViewData.Model = typeContext; controller.ViewData[ViewDataKeys.PartialViewName] = popupOptions.PartialViewName ?? Navigator.OnPartialViewName(entity); typeContext.ViewOverrides = Navigator.EntitySettings(entity.GetType()).GetViewOverrides(); bool isReadOnly = popupOptions.ReadOnly ?? Navigator.IsReadOnly(entity); if (isReadOnly) { typeContext.ReadOnly = true; } ViewMode mode = popupOptions.ViewMode; controller.ViewData[ViewDataKeys.ViewMode] = mode; controller.ViewData[ViewDataKeys.ShowOperations] = popupOptions.ShowOperations; if (mode == ViewMode.View) { controller.ViewData[ViewDataKeys.RequiresSaveOperation] = ((PopupViewOptions)popupOptions).RequiresSaveOperation ?? EntityKindCache.RequiresSaveOperation(entity.GetType()); } return(new PartialViewResult { ViewName = PopupControlView, ViewData = controller.ViewData, TempData = controller.TempData }); }
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; } } } } }
private static string OnPartialViewName(TypeContext tc) { EntitySettings es = Navigator.EntitySettings(tc.UntypedValue.GetType()); var result = es.OnPartialViewName((ModifiableEntity)tc.UntypedValue); tc.ViewOverrides = es.GetViewOverrides(); return(result); }
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)); }
public void FillViewDataForViewing(ControllerBase controller, IRootEntity rootEntity, NavigateOptions options) { TypeContext tc = TypeContextUtilities.UntypedNew(rootEntity, ""); controller.ViewData.Model = tc; var entity = (ModifiableEntity)rootEntity; controller.ViewData[ViewDataKeys.PartialViewName] = options.PartialViewName ?? Navigator.OnPartialViewName(entity); tc.ViewOverrides = Navigator.EntitySettings(entity.GetType()).GetViewOverrides(); if (controller.ViewData[ViewDataKeys.TabId] == null) { controller.ViewData[ViewDataKeys.TabId] = GetOrCreateTabID(controller); } controller.ViewData[ViewDataKeys.ShowOperations] = options.ShowOperations; controller.ViewData[ViewDataKeys.WriteEntityState] = options.WriteEntityState || (bool?)controller.ViewData[ViewDataKeys.WriteEntityState] == true; AssertViewableEntitySettings(entity); tc.ReadOnly = options.ReadOnly ?? Navigator.IsReadOnly(entity); }
public R GetRuntimeValue <R>(MappingContext <T> ctx, PropertyRoute route) where R : class, T { if (AllowedMappings != null && !AllowedMappings.ContainsKey(typeof(R))) { return((R)(object)ctx.None(ValidationMessage.Type0NotAllowed.NiceToString().FormatWith(typeof(R)))); } Mapping <R> mapping = (Mapping <R>)(AllowedMappings?.TryGetC(typeof(R)) ?? Navigator.EntitySettings(typeof(R)).UntypedMappingLine); SubContext <R> sc = new SubContext <R>(ctx.Prefix, null, route, ctx) { Value = ctx.Value as R }; // If the type is different, the AutoEntityMapping has the current value but EntityMapping just null sc.Value = mapping(sc); ctx.SupressChange = sc.SupressChange; ctx.AddChild(sc); return(sc.Value); }
public static MappingContext <T> ApplyChanges <T>(this T entity, ControllerBase controller, string prefix = null, PropertyRoute route = null, SortedList <string, string> inputs = null) where T : ModifiableEntity { Mapping <T> mapping = (Mapping <T>)Navigator.EntitySettings(typeof(T)).UntypedMappingMain; return(ApplyChanges <T>(entity, controller, mapping, prefix, route, inputs)); }