コード例 #1
0
        protected virtual NormalWindow SetNormalWindowEntity(NormalWindow win, ModifiableEntity entity, ViewOptionsBase options, EntitySettings es, Control ctrl)
        {
            Type entityType = entity.GetType();

            win.MainControl    = ctrl;
            win.ShowOperations = options.ShowOperations;
            win.ViewMode       = options.ViewButtons;

            entity = options.Clone ? (ModifiableEntity)((ICloneable)entity).Clone() : entity;
            win.OnPreEntityLoaded(entity);
            win.DataContext = entity;

            if (options.ReadOnly ?? OnIsReadOnly(entityType, entity))
            {
                Common.SetIsReadOnly(win, true);
            }

            if (options is ViewOptions)
            {
                win.SaveProtected = ((ViewOptions)options).RequiresSaveOperation ??
                                    (typeof(Entity).IsAssignableFrom(entityType) && EntityKindCache.RequiresSaveOperation(entityType)); //Matters even on Ok
            }
            TaskNormalWindow?.Invoke(win, entity);

            return(win);
        }
コード例 #2
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();
            }
        }
コード例 #3
0
ファイル: OperationLogic.cs プロジェクト: CangPham/framework
 static void EntityEventsGlobal_Saving(Entity ident)
 {
     if (ident.IsGraphModified &&
         EntityKindCache.RequiresSaveOperation(ident.GetType()) && !AllowSaveGlobally && !IsSaveAllowedInContext(ident.GetType()))
     {
         throw new InvalidOperationException("Saving '{0}' is controlled by the operations. Use OperationLogic.AllowSave<{0}>() or execute {1}".FormatWith(
                                                 ident.GetType().Name,
                                                 operations.GetValue(ident.GetType()).Values
                                                 .Where(IsExecuteNoLite)
                                                 .CommaOr(o => o.OperationSymbol.Key)));
     }
 }
コード例 #4
0
        public virtual object View(object entityOrLite, ViewOptions options)
        {
            if (entityOrLite == null)
            {
                throw new ArgumentNullException("entity");
            }

            ModifiableEntity entity   = entityOrLite as ModifiableEntity;
            Type             liteType = null;

            if (entity == null)
            {
                liteType = Lite.Extract(entityOrLite.GetType());
                entity   = Server.Retrieve((Lite <Entity>)entityOrLite);
            }

            EntitySettings es = AssertViewableEntitySettings(entity);

            if (!es.OnIsViewable())
            {
                throw new Exception("{0} is not viewable".FormatWith(entity));
            }

            Control ctrl = options.View ?? es.CreateView(entity, options.PropertyRoute);

            ctrl = es.OnOverrideView(entity, ctrl);

            NormalWindow win = CreateNormalWindow();

            SetNormalWindowEntity(win, (ModifiableEntity)entity, options, es, ctrl);

            if (options.AllowErrors != AllowErrors.Ask)
            {
                win.AllowErrors = options.AllowErrors;
            }

            bool?ok = win.ShowDialog();

            if (ok != true)
            {
                return(null);
            }

            object result = win.DataContext;

            if (liteType != null)
            {
                Entity ident = (Entity)result;

                bool saveProtected = ((ViewOptions)options).RequiresSaveOperation ?? EntityKindCache.RequiresSaveOperation(ident.GetType());

                if (GraphExplorer.HasChanges(ident))
                {
                    if (saveProtected)
                    {
                        throw new InvalidOperationException("The lite '{0}' of type '{1}' is SaveProtected but has changes. Consider setting SaveProtected = false in ViewOptions".FormatWith(entityOrLite, liteType.TypeName()));
                    }

                    return(ident.ToLiteFat());
                }

                return(ident.ToLite());
            }
            return(result);
        }
コード例 #5
0
        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
            });
        }