Ejemplo n.º 1
0
    /// <summary>
    /// Create tree node from supplied data
    /// </summary>
    /// <param name="source">Tree node data</param>
    /// <returns>TreeNode</returns>
    public TreeNode CreateNode(ObjectTypeTreeNode source)
    {
        // Create new node
        TreeNode newNode = new TreeNode();

        // Get the image
        string type = source.ObjectType ?? source.Group;

        if (!UsePostback)
        {
            newNode.NavigateUrl = "#";
        }

        string template = NodeTextTemplate;

        // Site
        int siteId = 0;

        if (source.Site)
        {
            siteId = SiteID;
        }

        // Title
        var name = GetNodeName(type);

        if ((type == String.Empty) || (type == ObjectHelper.GROUP_OBJECTS))
        {
            template = SelectedNodeTextTemplate;
            siteId   = -1;
            name     = GetString("ObjectTasks.Root");
        }

        if (source.Main)
        {
            name = "<strong>" + name + "</strong>";
        }

        newNode.Text = template.Replace("##NODENAME##", name).Replace("##SITEID##", siteId.ToString()).Replace("##OBJECTTYPE##", HttpUtility.UrlEncode(type));

        if (ValueTextTemplate != null)
        {
            newNode.Value = ValueTextTemplate.Replace("##SITEID##", siteId.ToString()).Replace("##OBJECTTYPE##", type);
        }

        // Disable if not active node
        if (UsePostback && !source.Active)
        {
            newNode.SelectAction = TreeNodeSelectAction.None;
        }

        if (source.Group != null && !source.Active)
        {
            newNode.SelectAction = TreeNodeSelectAction.Expand;
        }

        // Add child nodes
        if (source.ChildNodes.Count > 0)
        {
            IEnumerable <ObjectTypeTreeNode> children = source.ChildNodes;
            if (source.SortChildren)
            {
                children = children.OrderBy(n => GetNodeName(n.ObjectType ?? n.Group));
            }

            foreach (var child in children)
            {
                if ((SiteID > 0) || !child.Site)
                {
                    if ((OnBeforeCreateNode == null) || OnBeforeCreateNode(child))
                    {
                        // Create child node
                        TreeNode childNode = CreateNode(child);
                        if ((child.ObjectType != null) || (childNode.ChildNodes.Count > 0))
                        {
                            newNode.ChildNodes.Add(childNode);
                            // Preselect node
                            if ((child.ObjectType == PreselectObjectType) && (child.Site == IsPreselectedObjectTypeSiteObject))
                            {
                                childNode.Selected = true;
                            }
                        }
                    }
                }
            }
        }

        newNode.Expanded = source.Expand;

        return(newNode);
    }
Ejemplo n.º 2
0
    public TreeNode CreateNode(ObjectTypeTreeNode source)
    {
        // Create new node
        TreeNode newNode = new TreeNode();

        newNode.Expanded = source.Expand;

        // Get the image
        string objectType = source.ObjectType ?? source.Group;

        if (!UsePostback)
        {
            newNode.NavigateUrl = "#";
        }

        string template = NodeTextTemplate;

        // Site
        int siteId = 0;

        if (source.Site)
        {
            siteId = SiteID;
        }

        // Title
        string name = GetString("ObjectTasks." + objectType.Replace(".", "_").Replace("#", "_"));

        // Image
        string imageUrl = GetObjectIconUrl(objectType, "list.png");
        string imageTag = "<img src=\"" + imageUrl + "\" alt=\"\" style=\"border:0px;vertical-align:middle;\" onclick=\"return false;\"/>";

        if ((objectType == String.Empty) || (objectType == CMSObjectHelper.GROUP_OBJECTS))
        {
            imageUrl = GetImageUrl("General/DefaultRoot.png");
            imageTag = "<img src=\"" + imageUrl + "\" alt=\"\" style=\"border:none;height:10px;width:1px;\" onclick=\"return false;\"/>";
            template = imageTag + SelectedNodeTextTemplate;
            siteId   = -1;
            name     = GetString("ObjectTasks.Root");
        }

        if (source.Main)
        {
            name = "<strong>" + name + "</strong>";
        }

        newNode.Text = template.Replace("##ICON##", imageTag).Replace("##NODENAME##", name).Replace("##SITEID##", siteId.ToString()).Replace("##OBJECTTYPE##", HttpUtility.UrlEncode(objectType));

        if (ValueTextTemplate != null)
        {
            newNode.Value = ValueTextTemplate.Replace("##SITEID##", siteId.ToString()).Replace("##OBJECTTYPE##", objectType);
        }

        // Add image to the node
        if (UseImages && (imageUrl != ""))
        {
            newNode.ImageUrl = imageUrl;
        }

        // Disable if not active node
        if (UsePostback && !source.Active)
        {
            newNode.SelectAction = TreeNodeSelectAction.None;
        }

        if (source.Group != null && !source.Active)
        {
            newNode.SelectAction = TreeNodeSelectAction.Expand;
        }

        // Add child nodes
        if (source.ChildNodes.Count > 0)
        {
            foreach (ObjectTypeTreeNode child in source.ChildNodes)
            {
                if ((SiteID > 0) || !child.Site)
                {
                    if ((OnBeforeCreateNode == null) || OnBeforeCreateNode(child))
                    {
                        // Create child node
                        TreeNode childNode = CreateNode(child);
                        if ((child.ObjectType != null) || (childNode.ChildNodes.Count > 0))
                        {
                            newNode.ChildNodes.Add(childNode);
                            // Preselect node
                            if ((child.ObjectType == PreselectObjectType) && (child.Site == IsPreselectedObjectTypeSiteObject))
                            {
                                childNode.Selected = true;
                            }
                        }
                    }
                }
            }
        }

        return(newNode);
    }