示例#1
0
 public virtual void Render(TextWriter writer)
 {
     foreach (var child in PartsAdapter.GetItemsInZone(CurrentItem, ZoneName))
     {
         RenderTemplate(writer, child);
     }
 }
示例#2
0
        protected virtual void AddChildItem(Control container, ContentItem item)
        {
            if (AddingChild != null)
            {
                AddingChild.Invoke(this, new ItemEventArgs(item));
            }

            Control addedControl;

            if (GettingItemTemplate != null)
            {
                TemplateUrlEventArgs args = new TemplateUrlEventArgs(item);
                GettingItemTemplate(this, args);
                if (string.IsNullOrEmpty(args.TemplateUrl))
                {
                    addedControl = PartsAdapter.AddChildPart(item, container);
                }
                else
                {
                    addedControl = PartsAdapter.AddUserControl(args.TemplateUrl, container, args.Item);
                }
            }
            else
            {
                addedControl = PartsAdapter.AddChildPart(item, container);
            }

            if (AddedItemTemplate != null)
            {
                AddedItemTemplate.Invoke(this, new ControlEventArgs(addedControl));
            }
        }
示例#3
0
        public void CanResolve_PossibleChildren()
        {
            PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem);

            IEnumerable <ItemDefinition> items = controller.GetAllowedDefinitions(pageItem, "Zone1", null);

            Assert.That(items.Count(), Is.GreaterThan(0));
        }
示例#4
0
        public void CanFilter_ItemsInZone()
        {
            PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem);

            IEnumerable <ContentItem> items = controller.GetParts(pageItem, "ZoneNone", Interfaces.Viewing);

            Assert.That(items.Count(), Is.EqualTo(0));
        }
示例#5
0
        public void CanAddTo_ItemsInZone()
        {
            PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem);

            IEnumerable <ContentItem> items = controller.GetItemsInZone(pageItem, "ZoneAll");

            Assert.That(items.Count(), Is.EqualTo(2));
        }
示例#6
0
        public void Retrieves_ItemsInZone()
        {
            PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(customItem);

            IEnumerable <ContentItem> items = controller.GetParts(customItem, "Zone1", Interfaces.Viewing, ControlPanelState.Unknown);

            Assert.That(items.Count(), Is.EqualTo(1));
        }
示例#7
0
        public void Retrieves_ItemsInZone()
        {
            PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(customItem);

            IEnumerable <ContentItem> items = controller.GetItemsInZone(customItem, "Zone1");

            Assert.That(items.Count(), Is.EqualTo(1));
        }
示例#8
0
        public void CanResolve_PossibleChildrenWithAuthorization()
        {
            PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem);

            IEnumerable <ItemDefinition> items = controller.GetAllowedDefinitions(pageItem, CreatePrincipal("admin"));

            Assert.That(items.Count(), Is.EqualTo(7));

            items = controller.GetAllowedDefinitions(pageItem, CreatePrincipal("admin", "MyTestRole"));

            Assert.That(items.Count(), Is.EqualTo(8));
        }
示例#9
0
        public virtual void Render(TextWriter writer)
        {
            if (N2.Web.Mvc.Html.RegistrationExtensions.GetRegistrationExpression(Html) != null)
            {
                return;
            }

            foreach (var child in PartsAdapter.GetParts(CurrentItem, ZoneName, GetInterface()))
            {
                RenderTemplate(writer, child);
            }
        }
示例#10
0
        private ItemList GetItems()
        {
            ItemListEventArgs args = new ItemListEventArgs(null);

            OnSelecting(args);

            if (CurrentItem != null && args.Items == null)
            {
                args.Items = new ItemList(PartsAdapter.GetParts(CurrentItem, ZoneName, GetInterface()));
            }

            OnSelected(args);
            OnFiltering(args);
            return(args.Items);
        }
示例#11
0
        /// <summary>Gets part definitions that can be added to the given page.</summary>
        /// <param name="adapter"></param>
        /// <param name="item"></param>
        /// <param name="pageZones"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static IEnumerable <ItemDefinition> GetPartDefinitions(PartsAdapter adapter, ContentItem item, IEnumerable <Zone> pageZones, IPrincipal user)
        {
            IEnumerable <ItemDefinition> availableDefinitions;

            if (pageZones == null)
            {
                availableDefinitions = adapter.GetAllowedDefinitions(item, user);
            }
            else
            {
                availableDefinitions = GetPossibleDefinitions(adapter, pageZones, user);
            }

            return(availableDefinitions
                   .OrderBy(d => d.SortOrder)
                   .ThenBy(d => d.Title));
        }
示例#12
0
        /// <summary>Gets part definitions that can be added to the given page.</summary>
        /// <param name="adapter"></param>
        /// <param name="item"></param>
        /// <param name="pageZones"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static IEnumerable <ItemDefinition> GetPartDefinitions(PartsAdapter adapter, ContentItem item, IEnumerable <Zone> pageZones, IPrincipal user)
        {
            IEnumerable <ItemDefinition> availableDefinitions;

            if (pageZones == null)
            {
                availableDefinitions = adapter.GetAllowedDefinitions(item, user);
            }
            else
            {
                availableDefinitions = GetPossibleDefinitions(adapter, pageZones, user);
            }

            return(from x in availableDefinitions
                   orderby x ascending, x.Title ascending
                   select x);
        }
示例#13
0
        /// <summary>Gets part definitions that can be added to the given page.</summary>
        /// <param name="adapter"></param>
        /// <param name="item"></param>
        /// <param name="pageZones"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static IEnumerable <ItemDefinition> GetPartDefinitions(PartsAdapter adapter, ContentItem item, IEnumerable <Zone> pageZones, IPrincipal user)
        {
            IEnumerable <ItemDefinition> availableDefinitions;

            if (pageZones == null)
            {
                availableDefinitions = adapter.GetAllowedDefinitions(item, user);
            }
            else
            {
                availableDefinitions = GetPossibleDefinitions(adapter, pageZones, user);
            }

            var sortedDefinitions = new List <ItemDefinition>();

            sortedDefinitions.AddRange(availableDefinitions);
            sortedDefinitions.Sort();
            return(sortedDefinitions);
        }
示例#14
0
        protected void RenderReplacingPreviewed(TextWriter writer, string preview)
        {
            int itemID;

            if (int.TryParse(preview, out itemID))
            {
                ContentItem previewedItem = Html.ResolveService <IPersister>().Get(itemID);
                if (previewedItem != null && previewedItem.VersionOf.HasValue)
                {
                    foreach (var child in PartsAdapter.GetParts(CurrentItem, ZoneName, GetInterface()))
                    {
                        if (previewedItem.VersionOf.Value == child)
                        {
                            RenderTemplate(writer, previewedItem);
                        }
                        else
                        {
                            RenderTemplate(writer, child);
                        }
                    }
                }
            }
        }
示例#15
0
        private static List <ItemDefinition> GetPossibleDefinitions(PartsAdapter adapter, IEnumerable <Zone> pageZones, IPrincipal user)
        {
            var availableDefinitions = new List <ItemDefinition>();

            foreach (Zone z in pageZones)
            {
                ContentItem item     = z.CurrentItem;
                string      zoneName = z.ZoneName;
                if (item == null || string.IsNullOrEmpty(zoneName))
                {
                    continue;
                }

                foreach (ItemDefinition definition in adapter.GetAllowedDefinitions(item, zoneName, user))
                {
                    if (!availableDefinitions.Contains(definition))
                    {
                        availableDefinitions.Add(definition);
                    }
                }
            }
            return(availableDefinitions);
        }
示例#16
0
        protected override void CreateItems(Control container)
        {
            if (State.IsFlagSet(ControlPanelState.DragDrop) && (AllowExternalManipulation || CurrentItem == CurrentPage || Find.ClosestPage(CurrentItem) == CurrentPage))
            {
                if (ZoneName.IndexOfAny(new[] { '.', ',', ' ', '\'', '"', '\t', '\r', '\n' }) >= 0)
                {
                    throw new N2Exception("Zone '" + ZoneName + "' contains illegal characters.");
                }

                Panel zoneContainer = AddPanel(this, ZoneName + " dropZone");
                if (CurrentItem.ID != 0 && !CurrentItem.VersionOf.HasValue)
                {
                    zoneContainer.Attributes[PartUtilities.PathAttribute] = CurrentItem.Path;
                }
                else
                {
                    zoneContainer.Attributes[PartUtilities.PathAttribute] = Find.ClosestPage(CurrentItem).Path;
                    zoneContainer.Attributes["data-versionKey"]           = CurrentItem.GetVersionKey();
                    zoneContainer.Attributes["data-versionIndex"]         = CurrentItem.VersionIndex.ToString();
                }
                zoneContainer.Attributes[PartUtilities.ZoneAttribute]    = ZoneName;
                zoneContainer.Attributes[PartUtilities.AllowedAttribute] = PartUtilities.GetAllowedNames(ZoneName, PartsAdapter.GetAllowedDefinitions(CurrentItem, ZoneName, Page.User));

                zoneContainer.ToolTip = GetToolTip(GetDefinition(CurrentItem), ZoneName);
                base.CreateItems(zoneContainer);
            }
            else
            {
                base.CreateItems(this);
            }
        }
        public override void Render(TextWriter writer)
        {
            if (state == ControlPanelState.DragDrop)
            {
                if (ZoneName.IndexOfAny(new[] { '.', ',', ' ', '\'', '"', '\t', '\r', '\n' }) >= 0)
                {
                    throw new N2Exception("Zone '" + ZoneName + "' contains illegal characters.");
                }

                writer.Write("<div class='" + ZoneName + " dropZone'");
                writer.WriteAttribute(PartUtilities.PathAttribute, CurrentItem.Path)
                .WriteAttribute(PartUtilities.ZoneAttribute, ZoneName)
                .WriteAttribute(PartUtilities.AllowedAttribute, PartUtilities.GetAllowedNames(ZoneName, PartsAdapter.GetAllowedDefinitions(CurrentItem, ZoneName, Html.ViewContext.HttpContext.User)))
                .WriteAttribute("title", ZoneTitle ?? DroppableZone.GetToolTip(Html.ResolveService <IDefinitionManager>().GetDefinition(CurrentItem), ZoneName))
                .Write(">");

                RenderPreview(writer);

                writer.Write("</div>");
            }
            else if (state == ControlPanelState.Previewing)
            {
                RenderPreview(writer);
            }
            else
            {
                base.Render(writer);
            }
        }
示例#18
0
        public void CanResolve_ZoneAdapter()
        {
            PartsAdapter controller = dispatcher.ResolveAdapter <PartsAdapter>(pageItem);

            Assert.That(controller, Is.TypeOf(typeof(PageZoneAdapter)));
        }
示例#19
0
        public override void Render(TextWriter writer)
        {
            if (writer == null)
            {
                throw new NullReferenceException("writer cannot be null");
            }

            if (state.IsFlagSet(ControlPanelState.DragDrop))
            {
                if (String.IsNullOrWhiteSpace(ZoneName))
                {
                    throw new N2Exception("Zone name cannot be null, empty, or consist only of whitespace.");
                }
                if (ZoneName.IndexOfAny(new[] { '.', ',', ' ', '\'', '"', '\t', '\r', '\n' }) >= 0)
                {
                    throw new N2Exception("Zone '" + ZoneName + "' contains illegal characters.");
                }
                if (CurrentItem == null)
                {
                    throw new N2Exception("CurrentItem cannot be null");
                }
                var dm = Html.ResolveService <IDefinitionManager>();
                if (dm == null)
                {
                    throw new N2Exception("Failed to resolve the definition manager.");
                }



                writer.Write("<div class=\"" + ZoneName + " dropZone\"");
                if (CurrentItem.ID != 0 && !CurrentItem.VersionOf.HasValue)
                {
                    writer.WriteAttribute(PartUtilities.PathAttribute, CurrentItem.Path);
                }
                else
                {
                    writer.WriteAttribute(PartUtilities.PathAttribute, (Find.ClosestPage(CurrentItem) ?? CurrentItem).Path);
                    writer.WriteAttribute("data-versionKey", CurrentItem.GetVersionKey());
                    writer.WriteAttribute("data-versionIndex", CurrentItem.VersionIndex.ToString());
                }
                writer.WriteAttribute(PartUtilities.ZoneAttribute, ZoneName)
                .WriteAttribute(PartUtilities.AllowedAttribute, PartUtilities.GetAllowedNames(ZoneName, PartsAdapter.GetAllowedDefinitions(CurrentItem, ZoneName, Html.ViewContext.HttpContext.User)))
                .WriteAttribute("title", ZoneTitle ?? DroppableZone.GetToolTip(dm.GetDefinition(CurrentItem), ZoneName));
                writer.Write(">");

                RenderPreview(writer);

                writer.Write("</div>");
            }
            else if (state.IsFlagSet(ControlPanelState.Previewing))
            {
                RenderPreview(writer);
            }
            else
            {
                base.Render(writer);
            }
        }
示例#20
0
        protected override void CreateItems(Control container)
        {
            state = ControlPanel.GetState(Page);
            if (state == ControlPanelState.DragDrop && (AllowExternalManipulation || CurrentItem == CurrentPage))
            {
                if (ZoneName.IndexOfAny(new[] { '.', ',', ' ', '\'', '"', '\t', '\r', '\n' }) >= 0)
                {
                    throw new N2Exception("Zone '" + ZoneName + "' contains illegal characters.");
                }

                Panel zoneContainer = AddPanel(this, ZoneName + " dropZone");
                zoneContainer.Attributes[PartUtilities.PathAttribute]    = CurrentItem.Path;
                zoneContainer.Attributes[PartUtilities.ZoneAttribute]    = ZoneName;
                zoneContainer.Attributes[PartUtilities.AllowedAttribute] = PartUtilities.GetAllowedNames(ZoneName, PartsAdapter.GetAllowedDefinitions(CurrentItem, ZoneName, Page.User));
                zoneContainer.ToolTip = GetToolTip(GetDefinition(CurrentItem), ZoneName);
                base.CreateItems(zoneContainer);
            }
            else
            {
                base.CreateItems(this);
            }
        }