+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Pre-existing select node site map WebEditor?

Pre-existing select node site map WebEditor?

13 posts, 0 answered
  1. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    10 Oct 2007
    Link to this post
    Is there a pre-existing [WebEditor()] control that displays the TreeView SiteMap and allows a node to be selected?  The selected node would then return the Guid associated with the CmsPage?

    If so, what is it and how do I reference it?  Thanks.

    Gabe
    ==================
  2. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    11 Oct 2007
    Link to this post
    Whoops!  Pepi already made a great post on this subject.  It can be found here:

    http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-babbdt.aspx

    UrlEditorWrapper is close, but not quite what I'm looking for.  I don't want files to be selectable; only pages.  It looks like I may need to create my own.

    Gabe
    ===============
  3. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    11 Oct 2007
    Link to this post
    Hello Gabe,
     
    We have a class that represents control for selecting pages from the site map and returns the URL of the page. You can use it as follows:

        [WebEditor("Telerik.Cms.Web.UI.CmsUrlWebEditor, Telerik.Cms")] 
        public string SinglePage 
        { 
            get 
            { 
                return this.singlePage; 
            } 
            set 
            { 
                this.singlePage = value
            } 
        } 
     
        private string singlePage; 

    Hope this helps.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    11 Oct 2007
    Link to this post
    Thanks for the reply Pepi.

    It looks like "CmsUrlWebEditor" returns the URL and not the Guid associated with the page.  Is there a way to make this return the Guid?

    Thanks,

    Gabe
    ===================
  5. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    12 Oct 2007
    Link to this post
    The "Dynamic Hyper Link" control has a similar property (PageId) and it uses Telerik.Cms.Web.UI.DhlIdEditor for its WebEditor.  I tried using this for my own property and kept getting "object reference not set" errors.

    As it turns out, "Dynamic Hyper Links" have 2 properties ("PageId" and "NavigateUrl").  If either of them is changed the other gets updated as well.  So, as near as I can tell, DhlIdEditor is updating 2 properties at once.

    In my scenario, I only needed the Page ID, not the Page URL.  Long story short, I don't believe Sitefinity comes with a WebEditor that does what I need it to do.

    So I built one.  It is posted below:

    using System;  
    using System.Data;  
    using System.Text;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using Telerik.Cms.Web.UI;  
    using System.ComponentModel;  
     
    using Telerik;  
    using Telerik.Cms;  
    using Telerik.Cms.Web;  
    using Telerik.Cms.Web.UI;  
    using Telerik.Cms.Engine;  
    using Telerik.WebControls;  
     
    namespace WebEditors  
    {  
     
        /// <summary> 
        /// Type editor control that let's  auser select a page and return the Guid value to   
        /// the control.  
        /// </summary> 
        public class CmsIdWebEditor : WebUITypeEditor<Guid> 
        {  
            private Guid selectedGuid;  
            private RadTreeView ourTree;  
     
            /// <summary> 
            /// Overriden property of WebUITypeEditor. When user clicks "I'm done" this value is being sent  
            /// back to the property that opened this editor.  
            /// </summary> 
            public override Guid Value  
            {  
                get  
                {  
                    return new Guid(ourTree.SelectedNode.Value);  
                }  
                set  
                {  
                    this.selectedGuid = value;  
                }  
            }  
     
            /// <summary> 
            /// Called by ASP.NET. Creates child controls for this control.  
            /// </summary> 
            protected override void CreateChildControls()  
            {  
                this.Controls.Clear();  
     
                CmsSiteMapProvider ourMapProvider = (CmsSiteMapProvider)SiteMap.Provider;  
     
                DataTable SiteMapTable = new DataTable();  
                SiteMapTable.Columns.Add("ID");  
                SiteMapTable.Columns.Add("Parent");  
                SiteMapTable.Columns.Add("Text");  
     
                foreach (CmsSiteMapNode node in ourMapProvider.RootNode.GetAllNodes())  
                {  
                    DataRow row = SiteMapTable.NewRow();  
     
                    row["ID"] = node.CmsPage.ID.ToString();  
                    row["Parent"] = node.CmsPage.ParentID.ToString();  
                    row["Text"] = node.CmsPage.Title;  
     
                    if (row["Parent"].ToString() == "00000000-0000-0000-0000-000000000000")  
                    {  
                        row["Parent"] = null;  
                    }  
     
                    SiteMapTable.Rows.Add(row);  
                }  
     
                ourTree = new RadTreeView();  
                ourTree.ID = "RadTreeView1";  
                ourTree.DataSource = SiteMapTable;  
                ourTree.DataFieldID = "ID";  
                ourTree.DataFieldParentID = "Parent";  
                ourTree.DataTextField = "Text";  
                ourTree.DataValueField = "ID";  
                ourTree.DataBind();  
     
                this.Controls.Add(ourTree);  
            }  
        }  
    }  
     

    To use it you need to preface your property with something like this:

    [WebEditorAttribute("WebEditors.CmsIdWebEditor, App_Code")]


    If anyone see anything that could be improved, let me know.

    Gabe
    ===============
  6. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    12 Oct 2007
    Link to this post
    Hi Gabe,

    If you want to use DhlIdEditor class, you should have both PageId and NavigateUrl properties in your control i. e. you should have a property with WebEditor DhlIdEditor and another property with WebEditor DhlUrlEditor. These two properties are closely connected and when you change one of them, the value of the other is managed automatically. They are set as dependent properties to achieve the synchronization. Here is an example for using Telerik.Cms.Web.UI.DhlIdEditor:

        [TypeConverter("Telerik.Cms.Web.UI.GuidTypeConverter, Telerik.Cms"), WebEditor("Telerik.Cms.Web.UI.DhlIdEditor, Telerik.Cms"), Category("Navigation"), DefaultValue(typeof(Guid), "00000000-0000-0000-0000-000000000000")] 
        public Guid PageId 
        { 
            get 
            { 
                return this.pageId; 
            } 
            set 
            { 
                this.pageId = value; 
            } 
        } 
     
        [UrlProperty, WebEditor("Telerik.Cms.Web.UI.DhlUrlEditor, Telerik.Cms"), Bindable(true), Category("Navigation"), DefaultValue("")] 
        public string NavigateUrl 
        { 
            get 
            { 
                if (this.PageId != Guid.Empty) 
                { 
                    CmsManager manager = new CmsManager(); 
                    ICmsPage page = (ICmsPage)manager.GetPage(this.PageId); 
                    if (page != null
                    { 
                        if (page.PageType == CmsPageType.External) 
                            return page.ExternalUrl; 
                        else 
                        { 
                            return UrlHelper.ResolveLanguageUrl(page.DefaultUrl.Url); 
                        } 
                    } 
                } 
                return this.navigateUrl; 
            } 
            set 
            { 
                this.navigateUrl = value; 
            } 
        } 
     
        private Guid pageId; 
        private string navigateUrl; 

    In the attachment you can find the source code of DhlIdEditor class. If you remove the implementation of dependent properties, you will achieve the desired functionality.

    Hope this helps.

    Regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    12 Oct 2007
    Link to this post
    Hi Pepi.  Thanks so much for posting this.  In order to get this code to compile I had to remove some dependency references that were lurking in this code.  I have posted the new version below:

    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    using Telerik.Cms.Web.UI;  
    using Telerik.WebControls;  
    using System.Web.UI;  
    using System.IO;  
    using System.Web.UI.WebControls;  
    using Telerik.Cms;  
    using Telerik.Cms.Web;  
    using Telerik.Cms.Resources;  
     
    namespace WebEditors  
    {  
        public class PageIdWebEditor : WebUITypeEditor<Guid> 
        {  
            #region Public Properties  
     
            public override void RenderBeginTag(HtmlTextWriter writer)  
            {  
            }  
     
            public override void RenderEndTag(HtmlTextWriter writer)  
            {  
            }  
     
            protected override HtmlTextWriterTag TagKey  
            {  
                get  
                {  
                    return HtmlTextWriterTag.Div;  
                }  
            }  
     
            public override Guid Value  
            {  
                get  
                {  
                    Guid pageId = Guid.Empty;  
     
                    if (this.container.Tree.SelectedNode != null)  
                        pageId = new Guid(this.container.Tree.SelectedNode.Value);  
     
                    if (pageId != Guid.Empty)  
                        return ((ICmsPage)manager.GetPage(pageId)).ID;  
     
                    return Guid.Empty;  
                }  
                set  
                {  
                }  
            }  
     
            public ITemplate ItemTemplate  
            {  
                get  
                {  
                    return this.itemTemplate;  
                }  
                set  
                {  
                    this.itemTemplate = value;  
                }  
            }  
     
            public string ItemTemplatePath  
            {  
                get  
                {  
                    string value = (string)this.ViewState["ItemTemplatePath"];  
                    return String.IsNullOrEmpty(value) ? "~/Sitefinity/Admin/ControlTemplates/Pages/SiteMapSelector.ascx" : value;  
                }  
                set  
                {  
                    this.ViewState["ItemTemplatePath"] = value;  
                }  
            }  
     
            public SiteMapContainer Container  
            {  
                get  
                {  
                    return this.container;  
                }  
            }  
     
            public RadTreeView TreeView  
            {  
                get  
                {  
                    return this.tree;  
                }  
            }  
     
            #endregion  
     
            #region Methods  
     
            protected override void OnInit(EventArgs e)  
            {  
                base.OnInit(e);  
                this.manager = new CmsManager();  
            }  
     
            protected override void CreateChildControls()  
            {  
                this.Controls.Clear();  
     
                this.container = new SiteMapContainer(this);  
     
                if (this.itemTemplate == null)  
                {  
                    if (this.Page != null)  
                    {  
                        string path = this.ItemTemplatePath;  
                        if (File.Exists(this.Page.MapPath(path)))  
                            thisthis.itemTemplate = this.Page.LoadTemplate(path);  
                        else  
                            this.itemTemplate = new DefaultTemplate();  
                    }  
                }  
                this.itemTemplate.InstantiateIn(this.container);  
     
                thisthis.tree = this.container.Tree;  
                if (tree != null)  
                {  
                    tree.NodeExpand += new RadTreeView.RadTreeViewEventHandler(tree_NodeExpand);  
     
                    RadTreeNode root = new RadTreeNode();  
                    root.CssClass = "cmsRoot";  
                    root.CssClassOver = "cmsRootOver";  
                    root.CssClassSelect = "cmsRootSelect";  
                    root.Value = Guid.Empty.ToString();  
                    root.Text = "All Pages";  
                    root.Expanded = true;  
                    root.ToolTip = "";  
                    tree.Nodes.Add(root);  
                    this.LoadNodes(root);  
                }  
                this.Controls.Add(this.container);  
     
            }  
     
            private void LoadNodes(RadTreeNode root)  
            {  
                foreach (ICmsPage page in manager.GetPages(new Guid(root.Value)))  
                {  
                    RadTreeNode node = new RadTreeNode();  
                    node.Value = page.ID.ToString();  
                    node.Text = page.MenuName;  
                    node.ToolTip = page.MenuName;  
     
                    if (page.Pages.Count > 0)  
                    {  
                        node.ExpandMode = ExpandMode.ServerSide;  
                    }  
     
                    if (page.ID == UrlHelper.HomePageID)  
                    {  
                        node.CssClass = "cmsHomePageNode";  
                        node.CssClassOver = "cmsHomePageNodeOver";  
                        node.CssClassSelect = "cmsHomePageNodeSelect";  
                    }  
                    else if (page.PageType == CmsPageType.External)  
                    {  
                        node.CssClass = "cmsExternalPageNode";  
                        node.CssClassOver = "cmsExternalPageNodeOver";  
                        node.CssClassSelect = "cmsExternalPageNodeSelect";  
                    }  
                    else if (page.PageType == CmsPageType.Group)  
                    {  
                        node.CssClass = "cmsPageGroup";  
                        node.CssClassOver = "cmsPageGroupOver";  
                        node.CssClassSelect = "cmsPageGroupSelect";  
                    }  
                    root.Nodes.Add(node);  
                }  
            }  
     
            #endregion  
     
            #region Event Handlers  
     
            void tree_NodeExpand(object sender, RadTreeNodeEventArgs e)  
            {  
                this.LoadNodes(e.NodeClicked);  
            }  
     
            #endregion  
     
            #region Private Members  
     
            private SiteMapContainer container;  
            private ITemplate itemTemplate;  
            private CmsManager manager;  
            private RadTreeView tree;  
     
            #endregion  
     
            #region Default Templates  
     
            private class DefaultTemplate : ITemplate  
            {  
                public void InstantiateIn(Control container)  
                {  
     
                }  
            }  
     
            #endregion  
     
            #region Container  
     
            public class SiteMapContainer : GenericContainer<PageIdWebEditor> 
            {  
                public SiteMapContainer(PageIdWebEditor owner)  
                    : base(owner)  
                {  
                }  
     
                public RadTreeView Tree  
                {  
                    get  
                    {  
                        if (this.tree == null)  
                            this.tree = base.FindRequiredControl<RadTreeView>();  
                        return this.tree;  
                    }  
                }  
     
     
                private RadTreeView tree;  
            }  
     
            #endregion  
        }  
    }  
     

    Gabe
    =================
  8. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    15 Oct 2007
    Link to this post
    Hello Gabe,

    I tested your last implementation of PageIdWebEditor selector and it works according to expectations. Congratulations and thanks a lot for posting this in the forum!

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. Sean
    Sean avatar
    271 posts
    Registered:
    31 May 2006
    25 Nov 2008
    Link to this post
    Hi Gabe & Pepi,

    I am not sure if you noticed this but in the latest sitefinity release the HomePage property of the UrlHelper class is no longer public and that is the only bit of Gabes PageIdWebEditor class that I couldn't get to work with 3.5.  Not that it is crucial of course as it only is for applying the css classes to the treeview.

    Cheers
    Sean
  10. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    25 Nov 2008
    Link to this post
    Hello Sean,

    Yes, there are changes in Sitefinity API and HomePageID property does not exist anymore. Please refer to the following thread that provides an example how to get home page id in v3.5 and later: http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bgtgkg.aspx

    Do let us know if you need any further assistance.


    Best wishes,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    09 Feb 2009
    Link to this post
  12. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    21 Oct 2010
    Link to this post
    Hello,

    I am using some User Controls that were working in the previous version of Sitefinity. But now I am trying the same controls in Sitefinity 4Beta2 and for URL properties the button to choose a URL is not there. I am using the same WebEditor. Why does a control that worked in Sitefinity 3.7 does not work in Sitefinity 4.0?

    Many thanks,
    Andrei
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Oct 2010
    Link to this post
    Hi Andrei,

    The implementation of the WebEditors is different than this one used in 3.x. For more information, please take a look at support for custom WebUIType editor

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
13 posts, 0 answered