Example #1
0
        private static CustomAction Normalize(CustomAction customAction, int[] selectedActionsIds)
        {
            if (customAction.IsNew)
            {
                customAction.Action.ControllerActionUrl = ControllerActionUrl;
                customAction.Action.Code = !string.IsNullOrEmpty(customAction.ForceActionCode) ? customAction.ForceActionCode : $"custom_{DateTime.Now.Ticks}";
            }

            var entityType = EntityTypeRepository.GetById(customAction.Action.EntityTypeId);

            if (entityType.ContextMenu == null)
            {
                entityType.ContextMenu = ContextMenuRepository.GetByCode(entityType.Code);
            }

            customAction.Action.EntityType = entityType;
            customAction.Action.Name       = customAction.Name;
            customAction.Action.TabId      = entityType.TabId;
            customAction.CalculateOrder(entityType.Id);

            if (!customAction.ShowInToolbar)
            {
                customAction.ParentActions         = null;
                customAction.Action.ToolbarButtons = Enumerable.Empty <ToolbarButton>();
            }
            else if (selectedActionsIds != null)
            {
                var result = new List <ToolbarButton>();
                foreach (var id in selectedActionsIds)
                {
                    var button = customAction.Action.ToolbarButtons?.FirstOrDefault(n => n.ParentActionId == id) ?? new ToolbarButton();
                    button.ActionId       = customAction.Action.Id;
                    button.ParentActionId = id;
                    button.Name           = customAction.Name;
                    button.Icon           = !string.IsNullOrWhiteSpace(customAction.IconUrl) ? customAction.IconUrl : ToolbarButtonDefaultIconUrl;
                    button.Order          = customAction.Order + 1000;
                    result.Add(button);
                }

                customAction.Action.ToolbarButtons = result;
            }

            BackendActionTypeRepository.GetById(customAction.Action.TypeId);
            if (customAction.ShowInMenu)
            {
                if (entityType.ContextMenu == null)
                {
                    throw new ApplicationException(string.Format(CustomActionStrings.ThereIsNoContextMenuForEntityType, entityType.Name));
                }

                ContextMenuItem contentMenuItem;
                if (customAction.Action.ContextMenuItems != null && customAction.Action.ContextMenuItems.Any())
                {
                    contentMenuItem = customAction.Action.ContextMenuItems.First();
                }
                else
                {
                    contentMenuItem = new ContextMenuItem();
                }

                contentMenuItem.ContextMenuId        = entityType.ContextMenu.Id;
                contentMenuItem.ActionId             = customAction.Action.Id;
                contentMenuItem.Name                 = customAction.Name;
                contentMenuItem.Icon                 = !string.IsNullOrWhiteSpace(customAction.IconUrl) ? customAction.IconUrl : ToolbarButtonDefaultIconUrl;
                contentMenuItem.Order                = customAction.Order + 1000;
                customAction.Action.ContextMenuItems = new[] { contentMenuItem };
            }
            else
            {
                customAction.Action.ContextMenuItems = Enumerable.Empty <ContextMenuItem>();
            }

            if (!customAction.Action.IsInterface)
            {
                customAction.Action.IsWindow = false;
            }
            else
            {
                customAction.Action.ConfirmPhrase = null;
                customAction.Action.HasPreAction  = false;
            }

            if (!customAction.Action.IsWindow)
            {
                customAction.Action.WindowHeight = null;
                customAction.Action.WindowWidth  = null;
            }

            if (!IsEntityTypeSiteDescendants(entityType.Id))
            {
                customAction.SiteIds      = new int[] {};
                customAction.SiteExcluded = false;
            }

            if (!IsEntityTypeContentDescendants(entityType.Id))
            {
                customAction.ContentIds      = new int[] {};
                customAction.ContentExcluded = false;
            }

            return(customAction);
        }
Example #2
0
 /// <summary>
 /// Возвращает тип сущности по ее идентификатору
 /// </summary>
 /// <param name="entityTypeId">идентификатор типа сущности</param>
 /// <returns>информация о типе сущности</returns>
 public static EntityType GetById(int entityTypeId) => EntityTypeRepository.GetById(entityTypeId);