Example #1
0
        private string BuildHierarchy(ContentItem selected, CreationPosition position)
        {
            var filter   = Engine.EditManager.GetEditorFilter(User);
            var siblings = Find.EnumerateSiblings(selected, 1, 1);
            HierarchyNode <string> root = new HierarchyNode <string>(null);

            foreach (var sibling in filter.Pipe(siblings))
            {
                if (sibling == selected)
                {
                    var node = new HierarchyNode <string>(GetNodeText(sibling, true));
                    if (position == CreationPosition.Before)
                    {
                        root.Children.Add(new HierarchyNode <string>("<a href='#'><img src='../Resources/icons/add.png' alt='add'/></a> New item"));
                    }

                    ContentItem first = First(sibling.Children, filter);
                    if (first != null)
                    {
                        node.Children.Add(new HierarchyNode <string>(GetNodeText(first, false)));
                        ContentItem last = Last(sibling.Children, filter);
                        if (last != null)
                        {
                            node.Children.Add(new HierarchyNode <string>("..."));
                            node.Children.Add(new HierarchyNode <string>(GetNodeText(last, false)));
                        }
                    }
                    if (position == CreationPosition.Below)
                    {
                        node.Children.Add(new HierarchyNode <string>("<a href='#'><img src='../Resources/icons/add.png' alt='add'/></a> New item"));
                    }

                    root.Children.Add(node);
                    if (position == CreationPosition.After)
                    {
                        root.Children.Add(new HierarchyNode <string>("<a href='#'><img src='../Resources/icons/add.png' alt='add'/></a> New item"));
                    }
                }
                else
                {
                    root.Children.Add(new HierarchyNode <string>(GetNodeText(sibling, false)));
                }
            }
            return(root.ToString((c) => c == null ? "" : "<span>" + c, (p) => "<span class='indent'>", (p) => "</span>", (c) => c == null ? "" : "</span>"));
        }
Example #2
0
        /// <summary>Gets the url to edit page creating new items.</summary>
        /// <param name="selected">The selected item.</param>
        /// <param name="definition">The type of item to edit.</param>
        /// <param name="zoneName">The zone to add the item to.</param>
        /// <param name="position">The position relative to the selected item to add the item.</param>
        /// <returns>The url to the edit page.</returns>
        public virtual string GetEditNewPageUrl(ContentItem selected, ItemDefinition definition, string zoneName,
                                                CreationPosition position)
        {
            if (selected == null)
            {
                throw new ArgumentNullException("selected");
            }
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            ContentItem parent = (position != CreationPosition.Below)
                                                ? selected.Parent
                                                : selected;

            if (selected == null)
            {
                throw new N2Exception("Cannot insert item before or after the root page.");
            }

            Url url = Url.ResolveTokens(EditItemUrl);

            url = url.AppendQuery(SelectionUtility.SelectedQueryKey, parent.Path);
            url = url.AppendQuery("discriminator", definition.Discriminator);
            if (!string.IsNullOrEmpty(zoneName))
            {
                url = url.AppendQuery("zoneName", zoneName);
            }
            if (!string.IsNullOrEmpty(definition.TemplateKey))
            {
                url = url.AppendQuery("template", definition.TemplateKey);
            }

            if (position == CreationPosition.Before)
            {
                url = url.AppendQuery("before", selected.Path);
            }
            else if (position == CreationPosition.After)
            {
                url = url.AppendQuery("after", selected.Path);
            }
            return(url);
        }
Example #3
0
		/// <summary>Gets the url to edit page creating new items.</summary>
		/// <param name="selected">The selected item.</param>
		/// <param name="definition">The type of item to edit.</param>
		/// <param name="zoneName">The zone to add the item to.</param>
		/// <param name="position">The position relative to the selected item to add the item.</param>
		/// <returns>The url to the edit page.</returns>
		public virtual string GetEditNewPageUrl(ContentItem selected, ItemDefinition definition, string zoneName,
												CreationPosition position)
		{
			if (selected == null) throw new ArgumentNullException("selected");
			if (definition == null) throw new ArgumentNullException("definition");

			ContentItem parent = (position != CreationPosition.Below)
									? selected.Parent
									: selected;

			if (selected == null)
				throw new N2Exception("Cannot insert item before or after the root page.");

			Url url = Url.ResolveTokens(EditItemUrl);
			url = url.AppendQuery(SelectionUtility.SelectedQueryKey, parent.Path);
			url = url.AppendQuery("discriminator", definition.Discriminator);
			if (!string.IsNullOrEmpty(zoneName))
				url = url.AppendQuery("zoneName", zoneName);
			if (!string.IsNullOrEmpty(definition.TemplateKey))
				url = url.AppendQuery("template", definition.TemplateKey);

			if (position == CreationPosition.Before)
				url = url.AppendQuery("before", selected.Path);
			else if (position == CreationPosition.After)
				url = url.AppendQuery("after", selected.Path);

			if (selected.VersionOf.HasValue)
			{
				url = url.AppendQuery(PathData.VersionIndexQueryKey, selected.VersionIndex)
					.AppendQuery("VersionKey", selected.GetVersionKey());
			}

			return url;
		}
Example #4
0
        /// <summary>Gets the url to edit page creating new items.</summary>
        /// <param name="selected">The selected item.</param>
        /// <param name="definition">The type of item to edit.</param>
        /// <param name="zoneName">The zone to add the item to.</param>
        /// <param name="position">The position relative to the selected item to add the item.</param>
        /// <returns>The url to the edit page.</returns>
        public virtual string GetEditNewPageUrl(ContentItem selected, ItemDefinition definition, string zoneName,
            CreationPosition position)
        {
            if (selected == null) throw new ArgumentNullException("selected");
            if (definition == null) throw new ArgumentNullException("definition");

            ContentItem parent = (position != CreationPosition.Below)
                                 	? selected.Parent
                                 	: selected;

            if (selected == null)
                throw new N2Exception("Cannot insert item before or after the root page.");

            Url url = Url.ResolveTokens(EditItemUrl);
            url = url.AppendQuery("selected", parent.Path);
            url = url.AppendQuery("discriminator", definition.Discriminator);
            url = url.AppendQuery("zoneName", zoneName);

            if (position == CreationPosition.Before)
                url = url.AppendQuery("before", selected.Path);
            else if (position == CreationPosition.After)
                url = url.AppendQuery("after", selected.Path);
            return url;
        }
Example #5
0
        private string BuildHierarchy(ContentItem selected, CreationPosition position)
        {
            var filter = Engine.EditManager.GetEditorFilter(User);
            var siblings = Find.EnumerateSiblings(selected, 1, 1);
            HierarchyNode<string> root = new HierarchyNode<string>(null);
            foreach (var sibling in filter.Pipe(siblings))
            {
                if (sibling == selected)
                {
                    var node = new HierarchyNode<string>(GetNodeText(sibling, true));
                    if (position == CreationPosition.Before)
                        root.Children.Add(new HierarchyNode<string>("<a href='#'><img src='../Resources/icons/add.png' alt='add'/></a> New item"));

                    ContentItem first = First(sibling.Children, filter);
                    if (first != null)
                    {
                        node.Children.Add(new HierarchyNode<string>(GetNodeText(first, false)));
                        ContentItem last = Last(sibling.Children, filter);
                        if (last != null)
                        {
                            node.Children.Add(new HierarchyNode<string>("..."));
                            node.Children.Add(new HierarchyNode<string>(GetNodeText(last, false)));
                        }
                    }
                    if (position == CreationPosition.Below)
                        node.Children.Add(new HierarchyNode<string>("<a href='#'><img src='../Resources/icons/add.png' alt='add'/></a> New item"));

                    root.Children.Add(node);
                    if (position == CreationPosition.After)
                        root.Children.Add(new HierarchyNode<string>("<a href='#'><img src='../Resources/icons/add.png' alt='add'/></a> New item"));
                }
                else
                    root.Children.Add(new HierarchyNode<string>(GetNodeText(sibling, false)));
            }
            return root.ToString((c) => c == null ? "" : "<span>" + c, (p) => "<span class='indent'>", (p) => "</span>", (c) => c == null ? "" : "</span>");
        }
Example #6
0
 public string GetEditNewPageUrl(ContentItem selected, ItemDefinition definition, string zoneName, CreationPosition position)
 {
     return(urls.GetEditNewPageUrl(selected, definition, zoneName, position));
 }
Example #7
0
        /// <summary>Gets the url to edit page creating new items.</summary>
        /// <param name="selected">The selected item.</param>
        /// <param name="definition">The type of item to edit.</param>
        /// <param name="zoneName">The zone to add the item to.</param>
        /// <param name="position">The position relative to the selected item to add the item.</param>
        /// <returns>The url to the edit page.</returns>
        public string GetEditNewPageUrl(ContentItem selected, ContentType definition, string zoneName, CreationPosition position)
        {
            if (selected == null) throw new ArgumentNullException("selected");
            if (definition == null) throw new ArgumentNullException("definition");

            ContentItem parent = (position != CreationPosition.Below) ? selected.Parent : selected;

            if (selected == null)
                throw new ZeusException("Cannot insert item before or after the root page.");

            Url url = new Url(EditItemUrl);
            url = url.AppendQuery("selected", parent.Path);
            url = url.AppendQuery("discriminator", definition.Discriminator);
            url = url.AppendQuery("zoneName", zoneName);

            switch (position)
            {
                case CreationPosition.Before:
                    url = url.AppendQuery("before", selected.Path);
                    break;
                case CreationPosition.After:
                    url = url.AppendQuery("after", selected.Path);
                    break;
            }

            return url.ToString();
        }