예제 #1
0
파일: GridModel.cs 프로젝트: Godoy/CMS
        protected virtual IEnumerable<GridAction> GetActions(ModelMetadata modelMetadata, ViewContext viewContext)
        {
            List<GridAction> actions = new List<GridAction>();
            if (modelMetadata is KoobooModelMetadata)
            {
                foreach (var item in ((KoobooModelMetadata)modelMetadata).Attributes.OfType<GridActionAttribute>().OrderBy(it => it.Order))
                {
                    if (item.ColumnVisibleArbiter != null)
                    {
                        var columnArbiter = (IColumnVisibleArbiter)Activator.CreateInstance(item.ColumnVisibleArbiter);
                        if (!columnArbiter.IsVisible(viewContext))
                        {
                            continue;
                        }
                    }

                    var gridAction = new GridAction()
                    {
                        ActionName = item.ActionName,
                        ControllerName = item.ControllerName,
                        DisplayName = item.DisplayName ?? item.ActionName,
                        ConfirmMessage = item.ConfirmMessage,
                        VisibleProperty = item.CellVisibleProperty,
                        Icon = item.Icon,
                        Title = item.Title,
                        Class = item.Class,
                        InheritRouteValues = item.InheritRouteValues
                    };

                    if (!string.IsNullOrEmpty(item.RouteValueProperties))
                    {
                        List<GridActionRouteValuesSetting> settingList = new List<GridActionRouteValuesSetting>();
                        foreach (var property in item.RouteValueProperties.Split(','))
                        {
                            var setting = ParseRouteValueSetting(property);
                            if (setting != null)
                            {
                                settingList.Add(setting);
                            }
                        }
                        gridAction.RouteValuesSetting = settingList;
                    }
                    if (item.CellVisibleArbiter != null)
                    {
                        gridAction.VisibleArbiter = (IVisibleArbiter)Activator.CreateInstance(item.CellVisibleArbiter);
                    }
                    if (item.RouteValuesGetter != null)
                    {
                        gridAction.RouteValuesGetter = (IGridActionRouteValuesGetter)Activator.CreateInstance(item.RouteValuesGetter);
                    }
                    if (item.Renderer != null)
                    {
                        gridAction.Renderer = (IGridItemActionRender)Activator.CreateInstance(item.Renderer);
                    }

                    actions.Add(gridAction);
                }
            }
            else
            {
                //other ModelMetadata type....
            }
            return actions;
        }
예제 #2
0
        protected virtual IEnumerable <GridAction> GetActions(ModelMetadata modelMetadata, ViewContext viewContext)
        {
            List <GridAction> actions = new List <GridAction>();

            if (modelMetadata is KoobooModelMetadata)
            {
                foreach (var item in ((KoobooModelMetadata)modelMetadata).Attributes.OfType <GridActionAttribute>().OrderBy(it => it.Order))
                {
                    if (item.ColumnVisibleArbiter != null)
                    {
                        var columnArbiter = (IColumnVisibleArbiter)Activator.CreateInstance(item.ColumnVisibleArbiter);
                        if (!columnArbiter.IsVisible(viewContext))
                        {
                            continue;
                        }
                    }

                    var gridAction = new GridAction()
                    {
                        ActionName         = item.ActionName,
                        ControllerName     = item.ControllerName,
                        DisplayName        = item.DisplayName ?? item.ActionName,
                        ConfirmMessage     = item.ConfirmMessage,
                        VisibleProperty    = item.CellVisibleProperty,
                        Icon               = item.Icon,
                        Title              = item.Title,
                        Class              = item.Class,
                        InheritRouteValues = item.InheritRouteValues
                    };

                    if (!string.IsNullOrEmpty(item.RouteValueProperties))
                    {
                        List <GridActionRouteValuesSetting> settingList = new List <GridActionRouteValuesSetting>();
                        foreach (var property in item.RouteValueProperties.Split(','))
                        {
                            var setting = ParseRouteValueSetting(property);
                            if (setting != null)
                            {
                                settingList.Add(setting);
                            }
                        }
                        gridAction.RouteValuesSetting = settingList;
                    }
                    if (item.CellVisibleArbiter != null)
                    {
                        gridAction.VisibleArbiter = (IVisibleArbiter)Activator.CreateInstance(item.CellVisibleArbiter);
                    }
                    if (item.RouteValuesGetter != null)
                    {
                        gridAction.RouteValuesGetter = (IGridActionRouteValuesGetter)Activator.CreateInstance(item.RouteValuesGetter);
                    }
                    if (item.Renderer != null)
                    {
                        gridAction.Renderer = (IGridItemActionRender)Activator.CreateInstance(item.Renderer);
                    }

                    actions.Add(gridAction);
                }
            }
            else
            {
                //other ModelMetadata type....
            }
            return(actions);
        }