Exemplo n.º 1
0
        protected internal virtual ToolBarButton CreateToolBarButton(IEntityOperationContext ctx, EntityOperationGroup group)
        {
            var result = new ToolBarButton(ctx.Context.Prefix, ctx.OperationInfo.OperationSymbol.Key.Replace(".", "_"))
            {
                Style = ctx.OperationSettings?.Style ?? EntityOperationSettingsBase.AutoStyleFunction(ctx.OperationInfo),

                Tooltip = ctx.CanExecute,
                Enabled = ctx.CanExecute == null,
                Order   = ctx.OperationSettings != null ? ctx.OperationSettings.Order : 0,

                Text      = ctx.OperationSettings?.Text ?? (group == null || group.SimplifyName == null ? ctx.OperationInfo.OperationSymbol.NiceToString() : group.SimplifyName(ctx.OperationInfo.OperationSymbol.NiceToString())),
                OnClick   = ((ctx.OperationSettings != null && ctx.OperationSettings.HasClick) ? ctx.OperationSettings.OnClick(ctx) ?? DefaultClick(ctx) : DefaultClick(ctx)),
                HtmlProps = { { "data-operation", ctx.OperationInfo.OperationSymbol.Key } },

                Tag = ctx,
            };

            if (CustomizeToolBarButton != null)
            {
                return(CustomizeToolBarButton(result));
            }

            return(result);
        }
Exemplo n.º 2
0
        public virtual ToolBarButton[] ButtonBar_GetButtonBarElement(EntityButtonContext ctx, ModifiableEntity entity)
        {
            Entity ident = entity as Entity;

            if (ident == null)
            {
                return(null);
            }

            Type type = ident.GetType();

            var operations = (from oi in OperationInfos(type)
                              where oi.IsEntityOperation && (oi.AllowsNew.Value || !ident.IsNew)
                              let os = GetSettings <EntityOperationSettingsBase>(type, oi.OperationSymbol)
                                       let eoc = newEntityOperationContext.GetInvoker(os?.OverridenType ?? type)(ident, oi, ctx, os)
                                                 where (os != null && os.HasIsVisible) ? os.OnIsVisible(eoc) : ctx.ShowOperations
                                                 select eoc).ToList();

            if (operations.Any(eoc => eoc.OperationInfo.HasCanExecute == true))
            {
                Dictionary <OperationSymbol, string> canExecutes = OperationLogic.ServiceCanExecute(ident);
                foreach (var eoc in operations)
                {
                    var ce = canExecutes.TryGetC(eoc.OperationInfo.OperationSymbol);
                    if (ce != null && ce.HasText())
                    {
                        eoc.CanExecute = ce;
                    }
                }
            }

            List <ToolBarButton> buttons = new List <ToolBarButton>();
            Dictionary <EntityOperationGroup, ToolBarDropDown> groups = new Dictionary <EntityOperationGroup, ToolBarDropDown>();

            foreach (var eoc in operations.Where(c => c.OperationSettings == null || !c.OperationSettings.HideOnCanExecute || c.CanExecute == null))
            {
                EntityOperationGroup group = GetDefaultGroup(eoc);

                if (group != null)
                {
                    var cm = groups.GetOrCreate(group, () =>
                    {
                        var id = group == EntityOperationGroup.Create ? "tmConstructors" : "";

                        var tbm = new ToolBarDropDown(ctx.Prefix, id)
                        {
                            Title    = group.Description(),
                            Text     = group.Description(),
                            CssClass = group.CssClass,
                            Items    = new List <IMenuItem>(),
                            Order    = group.Order,
                        };

                        buttons.Add(tbm);

                        return(tbm);
                    });

                    cm.Items.Add(CreateToolBarButton(eoc, group).ToMenuItem());
                }
                else
                {
                    buttons.Add(CreateToolBarButton(eoc, null));
                }
            }

            foreach (var item in buttons.OfType <ToolBarDropDown>())
            {
                item.Items = item.Items.OrderBy(a => ((MenuItem)a).Order).ToList();
            }

            return(buttons.OrderBy(a => a.Order).ToArray());
        }