/// <summary>
    /// Creates the tree node.
    /// </summary>
    /// <param name="sourceNode">Source node</param>
    /// <param name="index">Node index</param>
    /// <param name="childNode">True if the node is child node</param>
    protected System.Web.UI.WebControls.TreeNode CreateNode(TreeSiteMapNode sourceNode, int index, bool childNode)
    {
        System.Web.UI.WebControls.TreeNode newNode = new System.Web.UI.WebControls.TreeNode();
        ISimpleDataContainer container             = sourceNode;

        int nodeId    = (int)container.GetValue("NodeID");
        int nodeLevel = (int)container.GetValue("NodeLevel");

        if (nodeId < 0)
        {
            newNode.SelectAction = TreeNodeSelectAction.None;
            newNode.Text         = GetString("ContentTree.ReadDocumentDenied");
            newNode.NavigateUrl  = (DeniedNodePostback ? mBasePath + "#" : string.Empty);
            return(newNode);
        }

        // Show complete node if index is lower than MaxTreeNodes or level is lower than RootNodeLevel
        if ((MaxTreeNodes <= 0) || (index < MaxTreeNodes) || (nodeLevel <= MapProvider.RootNodeLevel + 1))
        {
            allNodes[nodeId] = newNode;

            // Set the base data
            newNode.Value       = nodeId.ToString();
            newNode.NavigateUrl = "javascript:void(0);";

            int           classId = ValidationHelper.GetInteger(container.GetValue("NodeClassID"), 0);
            DataClassInfo ci      = DataClassInfoProvider.GetDataClassInfo(classId);
            if (ci == null)
            {
                throw new Exception("[ContentTree.CreateNode]: Node class not found.");
            }

            string className = ci.ClassName;

            // Use file type icons for file
            var sb = new StringBuilder();
            if (UseCMSFileIcons && string.Equals(className, SystemDocumentTypes.File, StringComparison.InvariantCultureIgnoreCase))
            {
                string extension = ValidationHelper.GetString(container.GetValue("DocumentType"), string.Empty);
                string image     = UIHelper.GetFileIcon(Page, extension, FontIconSizeEnum.Standard, CMSFileIconSet);
                sb.Append(image);
            }
            // Use class icons
            else
            {
                var iconClass = ValidationHelper.GetString(ci.GetValue("ClassIconClass"), String.Empty);
                var icon      = UIHelper.GetDocumentTypeIcon(Page, className, iconClass);
                sb.Append(icon);
            }
            string imageTag = sb.ToString();

            string nodeName     = HttpUtility.HtmlEncode(ValidationHelper.GetString(container.GetValue("DocumentName"), string.Empty));
            string nodeNameJava = ScriptHelper.GetString(nodeName);
            string marks        = "";

            // Render special marks only if allowed
            if (AllowMarks)
            {
                int workflowStepId            = ValidationHelper.GetInteger(container.GetValue("DocumentWorkflowStepID"), 0);
                WorkflowStepTypeEnum stepType = WorkflowStepTypeEnum.Undefined;

                if (workflowStepId > 0)
                {
                    WorkflowStepInfo stepInfo = WorkflowStepInfoProvider.GetWorkflowStepInfo(workflowStepId);
                    if (stepInfo != null)
                    {
                        stepType = stepInfo.StepType;
                    }
                }

                // Add icons
                marks = DocumentUIHelper.GetDocumentMarks(Page, SiteName, Culture, stepType, sourceNode, true);
                if (!string.IsNullOrEmpty(marks))
                {
                    marks = string.Format("<span class=\"tn-group\">{0}</span>", marks);
                }
            }

            string template;

            if ((SelectedNode != null) && (nodeId == SelectedNode.NodeID))
            {
                template         = SelectedNodeTextTemplate;
                selectedRendered = true;
            }
            else
            {
                template = NodeTextTemplate;
            }

            // Prepare the node text
            newNode.Text = ResolveNode(template, nodeName, imageTag, nodeNameJava, nodeId, marks);

            // Drag and drop envelope
            if (AllowDragAndDrop)
            {
                sb.Length = 0;

                if (childNode)
                {
                    sb.Append("<span id=\"target_", nodeId, "\"><span class=\"DDItem\" id=\"node_", nodeId, "\"><span class=\"DDHandle\" id=\"handle_", nodeId, "\" onmousedown=\"return false;\" onclick=\"return false;\">", newNode.Text, "</span></span></span>");
                }
                else
                {
                    sb.Append("<span id=\"target_", nodeId, "\" class=\"RootNode\"><span class=\"DDItem\" id=\"node_", nodeId, "\">", newNode.Text, "</span></span>");
                }

                newNode.Text = sb.ToString();
            }

            bool nodeHasChildren = ValidationHelper.GetBoolean(container.GetValue("NodeHasChildren"), false);
            // Check if can expand
            if (!nodeHasChildren)
            {
                newNode.PopulateOnDemand = false;
                newNode.Expanded         = true;
            }
            else
            {
                if ((sourceNode.ChildNodes.Count > 0) || !sourceNode.ChildNodesLoaded)
                {
                    newNode.PopulateOnDemand = true;
                }
            }

            // Set expanded status
            string aliasPath = ValidationHelper.GetString(container.GetValue("NodeAliasPath"), string.Empty);
            newNode.Expanded = aliasPath.Equals(MapProvider.Path, StringComparison.InvariantCultureIgnoreCase) || expandNodes.Contains(nodeId);
        }
        else
        {
            string parentNodeId = ValidationHelper.GetString(container.GetValue("NodeParentID"), string.Empty);
            newNode.Value       = nodeId.ToString();
            newNode.Text        = MaxTreeNodeText.Replace("##PARENTNODEID##", parentNodeId);
            newNode.NavigateUrl = "#";
        }

        return(newNode);
    }
Exemple #2
0
    /// <summary>
    /// Creation of new tree folder node.
    /// </summary>
    /// <param name="dirInfo">Folder information</param>
    /// <param name="index">Index in tree to check if max number of item isn't exceeded</param>
    /// <returns></returns>
    protected TreeNode CreateNode(DirectoryInfo dirInfo, int index)
    {
        if ((dirInfo != null) && (this.IsAllowed(dirInfo.FullName.ToLower())) && (!this.IsExcluded(dirInfo.FullName.ToLower())))
        {
            System.Web.UI.WebControls.TreeNode newNode = new System.Web.UI.WebControls.TreeNode();

            // Check if node is part of preselected path
            string preselectedPath = this.DefaultPath;
            if (!this.DefaultPath.ToLower().StartsWith(this.FullStartingPath.ToLower().TrimEnd('\\')))
            {
                preselectedPath = DirectoryHelper.CombinePath(this.FullStartingPath, this.DefaultPath);
            }

            if (index == MaxTreeNodes)
            {
                newNode.Value       = "";
                newNode.Text        = MaxTreeNodeText.Replace("##PARENTNODEID##", dirInfo.Parent == null ? "" : dirInfo.Parent.FullName.Replace("\\", "\\\\").Replace("'", "\\'"));
                newNode.NavigateUrl = mBasePath + "#";
            }
            else if ((index < MaxTreeNodes) || (preselectedPath.ToLower().StartsWith(dirInfo.FullName.ToLower())))
            {
                newNode.Value       = dirInfo.FullName;
                newNode.NavigateUrl = mBasePath + "#";

                string imageUrl = "";
                string tooltip  = "";

                imageUrl = treeFileSystem.LineImagesFolder + "/folder.gif";
                string imageTag     = "<img src=\"" + imageUrl + "\" alt=\"\" style=\"border:0px;vertical-align:middle;\" onclick=\"return false;\"" + tooltip + "/>";
                string nodeName     = HttpUtility.HtmlEncode(dirInfo.Name);
                string nodeNameJava = ScriptHelper.GetString(nodeName);

                string preSel = this.FullStartingPath.TrimEnd('\\').ToLower();
                if (this.DefaultPath.ToLower().StartsWith(this.FullStartingPath.ToLower().TrimEnd('\\')))
                {
                    preSel = this.DefaultPath.ToLower();
                }
                else if (!String.IsNullOrEmpty(this.DefaultPath))
                {
                    preSel = DirectoryHelper.CombinePath(preSel, this.DefaultPath.ToLower());
                }


                if ((preSel != "") && (newNode.Value.ToLower() == preSel))
                {
                    newNode.Text = SelectedNodeTextTemplate.Replace("##NODENAMEJAVA##", nodeNameJava).Replace("##NODENAME##", nodeName).Replace("##ICON##", imageTag).Replace("##NODEID##", newNode.Value.Replace("\\", "\\\\").Replace("'", "\\'"));
                }
                else
                {
                    newNode.Text = NodeTextTemplate.Replace("##NODENAMEJAVA##", nodeNameJava).Replace("##NODENAME##", nodeName).Replace("##ICON##", imageTag).Replace("##NODEID##", newNode.Value.Replace("\\", "\\\\").Replace("'", "\\'"));
                }

                int childNodesCount = 0;
                try
                {
                    childNodesCount = ValidationHelper.GetInteger(GetAllowedChildNumber(dirInfo), 0);
                    if (childNodesCount == 0)
                    {
                        newNode.PopulateOnDemand = false;
                        newNode.Expanded         = true;
                    }
                    else
                    {
                        newNode.PopulateOnDemand = true;
                        newNode.Expanded         = false;
                    }
                }
                catch
                {
                    // Access error
                    newNode.PopulateOnDemand = false;
                    newNode.Expanded         = true;
                }
                finally
                {
                    newNode.Text = newNode.Text.Replace("##NODECHILDNODESCOUNT##", childNodesCount.ToString());
                }
            }

            else
            {
                return(null);
            }

            return(newNode);
        }
        return(null);
    }
Exemple #3
0
    /// <summary>
    /// Creation of new tree folder node.
    /// </summary>
    /// <param name="dirInfo">Folder information</param>
    /// <param name="index">Index in tree to check if max number of item isn't exceeded</param>
    /// <returns>Created node</returns>
    protected TreeNode CreateNode(DirectoryInfo dirInfo, int index)
    {
        if (dirInfo == null)
        {
            return(null);
        }

        string fullName      = dirInfo.FullName;
        string lowerFullName = fullName.ToLowerCSafe();

        TreeNode newNode = null;

        if (IsAllowed(lowerFullName) && !IsExcluded(lowerFullName))
        {
            newNode = new TreeNode();

            string        name   = dirInfo.Name;
            DirectoryInfo parent = dirInfo.Parent;

            // Check if node is part of preselected path
            string preselectedPath = DefaultPath;
            if (!DefaultPath.ToLowerCSafe().StartsWithCSafe(FullStartingPath.ToLowerCSafe().TrimEnd('\\')))
            {
                preselectedPath = DirectoryHelper.CombinePath(FullStartingPath, DefaultPath);
            }

            if (index == MaxTreeNodes)
            {
                newNode.Value       = "";
                newNode.Text        = MaxTreeNodeText.Replace("##PARENTNODEID##", ((parent == null) ? "" : parent.FullName.Replace("\\", "\\\\").Replace("'", "\\'")));
                newNode.NavigateUrl = mBasePath + "#";
            }
            else if ((index < MaxTreeNodes) || preselectedPath.ToLowerCSafe().StartsWithCSafe(lowerFullName))
            {
                newNode.Value       = fullName;
                newNode.NavigateUrl = mBasePath + "#";

                string nodeName     = HttpUtility.HtmlEncode(name);
                string nodeNameJava = ScriptHelper.GetString(nodeName);

                string preSel = FullStartingPath.TrimEnd('\\').ToLowerCSafe();
                if (DefaultPath.ToLowerCSafe().StartsWithCSafe(FullStartingPath.ToLowerCSafe().TrimEnd('\\')))
                {
                    preSel = DefaultPath.ToLowerCSafe();
                }
                else if (!String.IsNullOrEmpty(DefaultPath))
                {
                    preSel = DirectoryHelper.CombinePath(preSel, DefaultPath.ToLowerCSafe());
                }


                if ((preSel != "") && (newNode.Value.ToLowerCSafe() == preSel))
                {
                    newNode.Text = SelectedNodeTextTemplate.Replace("##NODENAMEJAVA##", nodeNameJava).Replace("##NODENAME##", nodeName).Replace("##ICON##", "").Replace("##NODEID##", newNode.Value.Replace("\\", "\\\\").Replace("'", "\\'"));
                }
                else
                {
                    newNode.Text = NodeTextTemplate.Replace("##NODENAMEJAVA##", nodeNameJava).Replace("##NODENAME##", nodeName).Replace("##ICON##", "").Replace("##NODEID##", newNode.Value.Replace("\\", "\\\\").Replace("'", "\\'"));
                }

                int childNodesCount = 0;
                try
                {
                    childNodesCount = ValidationHelper.GetInteger(GetAllowedChildNumber(dirInfo), 0);
                    if (childNodesCount == 0)
                    {
                        newNode.PopulateOnDemand = false;
                        newNode.Expanded         = true;
                    }
                    else
                    {
                        newNode.PopulateOnDemand = true;
                        newNode.Expanded         = false;
                    }
                }
                catch
                {
                    // Access error
                    newNode.PopulateOnDemand = false;
                    newNode.Expanded         = true;
                }
                finally
                {
                    newNode.Text = newNode.Text.Replace("##NODECHILDNODESCOUNT##", childNodesCount.ToString());
                }
            }
        }

        return(newNode);
    }
    /// <summary>
    /// Creates tree node.
    /// </summary>
    /// <param name="sourceNode">Node with source data</param>
    /// <param name="index">Node index</param>
    protected TreeNode CreateNode(ForumPostTreeNode sourceNode, int index)
    {
        if (sourceNode == null)
        {
            return(null);
        }

        // Create tree node
        TreeNode newNode = new TreeNode();

        DataRow dr = (DataRow)sourceNode.ItemData;

        // Check whether item data are defined, if not it is root node
        if (dr != null)
        {
            int sourceNodeId = (int)dr["PostID"];
            int nodeLevel    = (int)dr["PostLevel"];

            // Check on maximum post in tree
            if (!UseMaxPostNodes || (index < MaxPostNodes) || (MaxPostNodes <= 0))
            {
                #region "Set node values and appearance"

                newNode.Value        = sourceNodeId.ToString();
                newNode.SelectAction = TreeNodeSelectAction.None;

                bool   isApproved  = ValidationHelper.GetBoolean(dr["PostApproved"], false);
                string postSubject = (string)dr["PostSubject"];

                string cssClass = ItemCssClass;

                // Add CSS class for unapproved posts
                if (HighlightUnApprove && !isApproved)
                {
                    cssClass += " PostUnApproved";
                }

                string statusIcons = "";
                if (OnGetStatusIcons != null)
                {
                    statusIcons = OnGetStatusIcons(sourceNode);
                }


                // Set by display mode
                switch (ShowMode)
                {
                // Dynamic detail mode
                case ShowModeEnum.DynamicDetailMode:
                    newNode.Text = CreateDynamicDetailModeNode(dr, cssClass, statusIcons, postSubject);
                    break;

                // Detail mode
                case ShowModeEnum.DetailMode:
                    newNode.Text = CreateDetailModeNode(dr);
                    break;

                // Tree mode
                default:

                    if (Selected == sourceNodeId)
                    {
                        cssClass = SelectedItemCssClass;

                        string spanId = String.Empty;
                        if (AdministrationMode)
                        {
                            spanId = "id=\"treeSelectedNode\"";
                        }

                        newNode.Text = String.Format("<span {0} class=\"{1}\" onclick=\"ShowPost({2}); SelectForumNode(this);\"><span class=\"Name\">{4}{3}</span></span>",
                                                     spanId, cssClass, newNode.Value, statusIcons, HTMLHelper.HTMLEncode(postSubject));
                    }
                    else
                    {
                        newNode.Text = String.Format("<span class=\"{0}\" onclick=\"ShowPost({1}); SelectForumNode(this);\"><span class=\"Name\">{3}{2}</span></span>",
                                                     cssClass, newNode.Value, statusIcons, HTMLHelper.HTMLEncode(postSubject));
                    }
                    break;
                }

                #endregion


                if (!ExpandTree)
                {
                    #region "Populate deeper levels on demand"

                    // Check if can expand
                    string childCountColumn = "PostThreadPosts";

                    // Check if unapproved posts can be included
                    if (AdministrationMode || UserIsModerator)
                    {
                        childCountColumn = "PostThreadPostsAbsolute";
                    }

                    int childNodesCount = ValidationHelper.GetInteger(dr[childCountColumn], 0);

                    // If the post is thread(level = 0) then childnodes count 1 means no real child-post
                    if ((childNodesCount == 0) || ((childNodesCount == 1) && (nodeLevel == 0)))
                    {
                        newNode.PopulateOnDemand = false;

                        // No children -> expand
                        newNode.Expanded = true;
                    }
                    else
                    {
                        if (!sourceNode.ChildNodesLoaded)
                        {
                            newNode.PopulateOnDemand = true;
                            newNode.Expanded         = false;
                        }
                    }

                    #endregion


                    #region "Expand nodes on the current path"

                    // If preselect is set = first load
                    if (RegularLoad)
                    {
                        string currentNodePath     = (string)dr["PostIDPath"];
                        string currentSelectedPath = String.Empty;

                        if (SelectedPost != null)
                        {
                            currentSelectedPath = SelectedPost.PostIDPath;
                        }

                        // Expand if node is on the path
                        if (currentSelectedPath.StartsWithCSafe(currentNodePath))
                        {
                            // Raise OnTreeNodePopulate
                            newNode.PopulateOnDemand = true;
                            newNode.Expanded         = true;
                        }
                        else
                        {
                            newNode.Expanded = false;
                        }
                    }

                    #endregion
                }
                else
                {
                    // Populate will be called on each node
                    newNode.PopulateOnDemand = true;
                    newNode.Expanded         = true;
                }
            }
            else
            {
                string parentNodeId = ValidationHelper.GetString(dr["PostParentID"], "");
                newNode.Value        = sourceNodeId.ToString();
                newNode.Text         = MaxTreeNodeText.Replace("##PARENTNODEID##", parentNodeId);
                newNode.SelectAction = TreeNodeSelectAction.None;
            }
        }
        // Root node populate by default
        else
        {
            // Root node as forum display name
            ForumInfo fi = ForumInfoProvider.GetForumInfo(ForumID);

            if (fi != null)
            {
                newNode.Text         = "<span class=\"" + ItemCssClass + "\" onclick=\"ShowPost('-1'); SelectForumNode(this); \"><span class=\"Name\">" + HTMLHelper.HTMLEncode(fi.ForumDisplayName) + "</span></span>";
                newNode.Value        = "0";
                newNode.SelectAction = TreeNodeSelectAction.None;
            }

            newNode.PopulateOnDemand = true;
            newNode.Expanded         = true;
        }

        return(newNode);
    }
    /// <summary>
    /// Creates the tree node.
    /// </summary>
    /// <param name="sourceNode">Source node</param>
    /// <param name="index">Node index</param>
    /// <param name="childNode">True if the node is child node</param>
    protected System.Web.UI.WebControls.TreeNode CreateNode(TreeSiteMapNode sourceNode, int index, bool childNode)
    {
        System.Web.UI.WebControls.TreeNode newNode = new System.Web.UI.WebControls.TreeNode();
        ISimpleDataContainer container             = sourceNode;

        int nodeId    = (int)container.GetValue("NodeID");
        int nodeLevel = (int)container.GetValue("NodeLevel");

        if (nodeId < 0)
        {
            newNode.SelectAction = TreeNodeSelectAction.None;
            newNode.Text         = GetString("ContentTree.ReadDocumentDenied");
            newNode.NavigateUrl  = (DeniedNodePostback ? mBasePath + "#" : string.Empty);
            return(newNode);
        }

        if ((index < MaxTreeNodes) || (nodeLevel <= MapProvider.RootNodeLevel + 1))
        {
            allNodes[nodeId] = newNode;

            // Set the base data
            newNode.Value       = nodeId.ToString();
            newNode.NavigateUrl = "javascript:void(0);";

            int           classId = ValidationHelper.GetInteger(container.GetValue("NodeClassID"), 0);
            DataClassInfo ci      = DataClassInfoProvider.GetDataClass(classId);
            if (ci == null)
            {
                throw new Exception("[ContentTree.CreateNode]: Node class not found.");
            }

            string className = ci.ClassName.ToLowerCSafe();
            string imageUrl  = string.Empty;
            string tooltip   = string.Empty;

            // Use file type icons for cms.file
            if (UseCMSFileIcons && (className == "cms.file"))
            {
                string extension = ValidationHelper.GetString(container.GetValue("DocumentType"), string.Empty);
                imageUrl = GetFileIconUrl(extension, CMSFileIconSet);
                tooltip  = " title=\"" + extension.ToLowerCSafe().TrimStart('.') + "\" ";
            }
            // Use class icons
            else
            {
                imageUrl = GetDocumentTypeIconUrl(className);
            }

            StringBuilder sb = new StringBuilder();
            sb.Append("<img src=\"", imageUrl, "\" alt=\"\" style=\"border:0px;vertical-align:middle;\" onclick=\"return false;\"", tooltip, " class=\"", (className == "cms.root" ? "Image20" : "Image16"), "\" />");
            string imageTag = sb.ToString();

            string nodeName     = HttpUtility.HtmlEncode(ValidationHelper.GetString(container.GetValue("DocumentName"), string.Empty));
            string nodeNameJava = ScriptHelper.GetString(nodeName);

            // Render special marks only if allowed
            if (AllowMarks)
            {
                int workflowStepId            = ValidationHelper.GetInteger(container.GetValue("DocumentWorkflowStepID"), 0);
                WorkflowStepTypeEnum stepType = WorkflowStepTypeEnum.Undefined;

                if (workflowStepId > 0)
                {
                    WorkflowStepInfo stepInfo = WorkflowStepInfoProvider.GetWorkflowStepInfo(workflowStepId);
                    if (stepInfo != null)
                    {
                        stepType = stepInfo.StepType;
                    }
                }

                // Add icons
                nodeName += DocumentHelper.GetDocumentMarks(Page, SiteName, Culture, stepType, sourceNode);
            }

            string template = null;

            if ((SelectedNode != null) && (nodeId == SelectedNode.NodeID))
            {
                template         = SelectedNodeTextTemplate;
                selectedRendered = true;
            }
            else
            {
                template = NodeTextTemplate;
            }

            // Prepare the node text
            newNode.Text = ResolveNode(template, nodeName, imageTag, nodeNameJava, nodeId);

            int childNodesCount = ValidationHelper.GetInteger(container.GetValue("NodeChildNodesCount"), 0);
            newNode.Text = newNode.Text.Replace("##NODECHILDNODESCOUNT##", childNodesCount.ToString());

            // Drag and drop envelope
            if (AllowDragAndDrop)
            {
                sb.Length = 0;

                if (childNode)
                {
                    sb.Append("<span id=\"target_", nodeId, "\"><span class=\"DDItem\" id=\"node_", nodeId, "\"><span class=\"DDHandle\" id=\"handle_", nodeId, "\" onmousedown=\"return false;\" onclick=\"return false;\">", newNode.Text, "</span></span></span>");
                }
                else
                {
                    sb.Append("<span id=\"target_", nodeId, "\" class=\"RootNode\"><span class=\"DDItem\" id=\"node_", nodeId, "\">", newNode.Text, "</span></span>");
                }

                newNode.Text = sb.ToString();
            }

            // Check if can expand
            if (childNodesCount == 0)
            {
                newNode.PopulateOnDemand = false;
                newNode.Expanded         = true;
            }
            else
            {
                if ((sourceNode.ChildNodes.Count > 0) || !sourceNode.ChildNodesLoaded)
                {
                    newNode.PopulateOnDemand = true;
                }
            }

            // Set expanded status
            string aliasPath = ValidationHelper.GetString(container.GetValue("NodeAliasPath"), string.Empty);
            newNode.Expanded = (aliasPath.ToLowerCSafe() == MapProvider.UsedPath.ToLowerCSafe()) || (expandNodes.Contains(nodeId));
        }
        else
        {
            string parentNodeId = ValidationHelper.GetString(container.GetValue("NodeParentID"), string.Empty);
            newNode.Value       = nodeId.ToString();
            newNode.Text        = MaxTreeNodeText.Replace("##PARENTNODEID##", parentNodeId);
            newNode.NavigateUrl = "#";
        }

        return(newNode);
    }