コード例 #1
0
        protected virtual void OnItemCreating(ItemEventArgs e)
        {
            EventHandler <ItemEventArgs> handler = base.Events[EventItemCreating] as EventHandler <ItemEventArgs>;

            if (handler != null)
            {
                handler.Invoke(this, e);
            }

            if (e.AffectedItem != null)
            {
                IDefinitionManager definitions      = Engine.Definitions;
                ISecurityManager   security         = Engine.SecurityManager;
                ContentActivator   activator        = Engine.Resolve <ContentActivator>();
                ItemDefinition     parentDefinition = definitions.GetDefinition(parentItem);

                if (parentDefinition.IsChildAllowed(definitions, parentItem, parentDefinition))
                {
                    e.AffectedItem = Engine.Resolve <ContentActivator>().CreateInstance(parentItem.GetContentType(), parentItem);
                    return;
                }
                foreach (ItemDefinition definition in definitions.GetAllowedChildren(parentItem, null).WhereAuthorized(security, HttpContext.Current.User, parentItem))
                {
                    e.AffectedItem = activator.CreateInstance(definition.ItemType, parentItem);
                    return;
                }
                throw new N2.Definitions.NoItemAllowedException(parentItem);
            }
        }
コード例 #2
0
        private void LoadAllowedTypes()
        {
            int allowedChildrenCount = ParentItemDefinition.GetAllowedChildren(Definitions, Selection.SelectedItem).Count();
            IList <ItemDefinition> allowedChildren = Definitions.GetAllowedChildren(Selection.SelectedItem, ZoneName)
                                                     .WhereAuthorized(Engine.SecurityManager, User, Selection.SelectedItem)
                                                     .ToList();

            if (!IsAuthorized(Permission.Write))
            {
                cvPermission.IsValid = false;
                return;
            }

            if (allowedChildrenCount == 0)
            {
                Title = string.Format(GetLocalResourceString("NewPage.Title.NoneAllowed", "No item is allowed below an item of type \"{0}\""), ParentItemDefinition.Title);
            }
            else if (allowedChildrenCount == 1 && allowedChildren.Count == 1)
            {
                Response.Redirect(GetEditUrl(allowedChildren[0]));
            }
            else
            {
                Title = string.Format(GetLocalResourceString("NewPage.Title.Select", "Select type of item below \"{0}\""), ActualItem.Title);

                var top  = allowedChildren.OrderByDescending(d => d.NumberOfItems).ThenBy(d => d.SortOrder).Take(1).ToList();
                var rest = allowedChildren.Except(top).ToList();

                AvailableDefinitions = top.Union(rest).ToList();
            }
        }
コード例 #3
0
        public override ActionResult Index()
        {
            if ("Tests" != (string)RouteData.DataTokens["area"])
            {
                throw new Exception("Incorrect area: " + RouteData.Values["area"]);
            }

            return(PartialView(definitions.GetAllowedChildren(CurrentPage, null).WhereAuthorized(security, User, CurrentPage)));
        }
コード例 #4
0
        public override ActionResult Index()
        {
            if ("Tests" != (string)RouteData.DataTokens["area"])
            {
                throw new Exception("Incorrect area: " + RouteData.Values["area"]);
            }

            if (CurrentItem.IsPage)
            {
                return(View());
            }
            else
            {
                return(PartialView("Partial", definitions.GetAllowedChildren(CurrentPage, null).WhereAuthorized(Engine.SecurityManager, User, CurrentPage)));
            }
        }
コード例 #5
0
        public override ActionResult Index()
        {
            if ("Tests" != (string)RouteData.DataTokens["area"])
            {
                throw new Exception("Incorrect area: " + RouteData.Values["area"]);
            }

            ViewData["RemainingItems"] = remainingItems;

            if (CurrentItem.ShowEveryone || security.IsEditor(User))
            {
                return(PartialView(definitions.GetAllowedChildren(CurrentPage, null).WhereAuthorized(security, User, CurrentPage)));
            }
            else
            {
                return(Content(""));
            }
        }
コード例 #6
0
 private void LoadAdd()
 {
     lblLocationTitle.DataBind();
     txtTitle.Text       = Selection.SelectedItem.Title;
     ddlTypes.DataSource = Definitions.GetAllowedChildren(Selection.SelectedItem, "", User)
                           .SelectMany(d =>
     {
         return(new [] { new
                         {
                             Value = d.Discriminator,
                             Title = d.Title
                         } }.Union(Templates.GetTemplates(d.ItemType).Select(t =>
                                                                             new
         {
             Value = d.Discriminator + ":" + t.Name,
             Title = "*  " + t.Title
         })));
     });
     ddlTypes.DataBind();
 }
コード例 #7
0
ファイル: Default.aspx.cs プロジェクト: nikita239/Aspect
 private void LoadAdd()
 {
     lblLocationTitle.DataBind();
     txtTitle.Text       = Selection.SelectedItem.Title;
     ddlTypes.DataSource = Definitions.GetAllowedChildren(Selection.SelectedItem, null)
                           .WhereAuthorized(Engine.SecurityManager, User, Selection.SelectedItem)
                           .SelectMany(d =>
     {
         return(new [] { new
                         {
                             Value = d.Discriminator,
                             Title = d.Title
                         } }.Union(Engine.Resolve <ITemplateAggregator>().GetTemplates(d.ItemType).Select(t =>
                                                                                                          new
         {
             Value = d.Discriminator + ":" + t.Name,
             Title = "*  " + t.Title
         })));
     });
     ddlTypes.DataBind();
 }