예제 #1
0
        private static ListItem[] GetListItems(IEnumerable <ContentType> contentTypes, Node contextNode)
        {
            var dict = new SortedDictionary <string, string>();

            if (contentTypes == null)
            {
                return(new ListItem[0]);
            }

            foreach (var contentType in contentTypes)
            {
                if (!SavingAction.CheckManageListPermission(contentType.NodeType, contextNode))
                {
                    continue;
                }

                var title = string.IsNullOrEmpty(contentType.DisplayName) ? contentType.Name : contentType.DisplayName;
                if (!dict.ContainsKey(title))
                {
                    dict.Add(title, contentType.Name);
                }
            }

            return(dict.Keys.Count == 0 ? new ListItem[0] : dict.Keys.Select(key => new ListItem(key, dict[key])).ToArray());
        }
        private static ListItem[] GetOtherListItems(IEnumerable <Node> nodes, Node contextNode)
        {
            if (nodes == null)
            {
                return(new ListItem[0]);
            }

            var dict = new SortedDictionary <string, string>();

            foreach (var node in nodes)
            {
                var displayName = string.Empty;
                var name        = string.Empty;
                var c           = node as GenericContent;
                var ctd         = node as ContentType;
                if (ctd != null)    // content type
                {
                    if (!SavingAction.CheckManageListPermission(ctd.NodeType, contextNode))
                    {
                        continue;
                    }

                    var content = Content.Create(ctd);
                    displayName = content.DisplayName;
                    name        = content.Name;
                }
                else if (c != null)   // content template
                {
                    if (!SavingAction.CheckManageListPermission(c.NodeType, contextNode))
                    {
                        continue;
                    }

                    var content = Content.Create(c);
                    displayName = content.DisplayName;
                    name        = content.Path;
                }
                var validTitle = string.IsNullOrEmpty(displayName) ? name : displayName;
                if (!dict.ContainsKey(validTitle))
                {
                    dict.Add(validTitle, name);
                }
            }

            return(dict.Keys.Count == 0 ? new ListItem[0] : dict.Keys.Select(key => new ListItem(key, dict[key])).ToArray());
        }
예제 #3
0
        protected override IEnumerable <ActionBase> CollectActions(Content context, string backUrl)
        {
            var actList = new List <ActionBase>();

            if (context == null || !context.Security.HasPermission(PermissionType.AddNew))
            {
                return(actList);
            }

            var app = ApplicationStorage.Instance.GetApplication("Add", context, PortalContext.Current.DeviceName);
            var gc  = context.ContentHandler as GenericContent;

            if (gc != null && app != null)
            {
                foreach (var node in GetNewItemNodes(gc))
                {
                    var ctype = node as ContentType;
                    if (ctype != null)
                    {
                        if (!DisplaySystemFolders && ctype.IsInstaceOfOrDerivedFrom("SystemFolder"))
                        {
                            continue;
                        }

                        //skip Add action if the user tries to add a list without having a manage container permission
                        if (!SavingAction.CheckManageListPermission(ctype.NodeType, context.ContentHandler))
                        {
                            continue;
                        }

                        var act = app.CreateAction(context, backUrl, new { ContentTypeName = ctype.Name });
                        if (act == null)
                        {
                            continue;
                        }
                        act.Text = ctype.DisplayName;
                        act.Icon = ctype.Icon;
                        actList.Add(act);
                    }
                    else
                    {
                        var ctd = node as GenericContent;
                        if (ctd == null)
                        {
                            continue;
                        }

                        if (!DisplaySystemFolders && ctd.NodeType.IsInstaceOfOrDerivedFrom("SystemFolder"))
                        {
                            continue;
                        }

                        //skip Add action if the user tries to add a list without having a manage container permission
                        if (!SavingAction.CheckManageListPermission(ctd.NodeType, context.ContentHandler))
                        {
                            continue;
                        }

                        var act = app.CreateAction(context, backUrl, new { ContentTypeName = ctd.Path });
                        act.Text = ctd.DisplayName;
                        act.Icon = ctd.Icon;
                        actList.Add(act);
                    }
                }
            }

            return(actList);
        }