Пример #1
0
    private object GetAttachmentHtml(ISimpleDataContainer container)
    {
        // Attachment name
        string name      = ValidationHelper.GetString(container["AttachmentName"], "");
        Guid   guid      = ValidationHelper.GetGuid(container["AttachmentGUID"], Guid.Empty);
        int    siteId    = ValidationHelper.GetInteger(container["AttachmentSiteID"], 0);
        string extension = ValidationHelper.GetString(container["AttachmentExtension"], "");

        // File name
        name = Path.GetFileNameWithoutExtension(name);

        string url = ResolveUrl("~/CMSPages/GetFile.aspx?guid=") + guid;

        if (siteId != currentSiteId)
        {
            // Add the site name to the URL if not current site
            SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId);
            if (si != null)
            {
                url += "&sitename=" + si.SiteName;
            }
        }

        string tooltipSpan = name;
        bool   isImage     = ImageHelper.IsImage(extension);

        string variant = ValidationHelper.GetString(container["AttachmentVariantDefinitionIdentifier"], "");

        if (isImage)
        {
            int imageWidth  = ValidationHelper.GetInteger(container["AttachmentImageWidth"], 0);
            int imageHeight = ValidationHelper.GetInteger(container["AttachmentImageHeight"], 0);

            string id = guid.ToString();
            if (!String.IsNullOrEmpty(variant))
            {
                url += "&variant=" + variant;
                id  += "_" + variant;
            }

            string tooltip = UIHelper.GetTooltipAttributes(url, imageWidth, imageHeight, null, name, extension, null, null, 300);
            tooltipSpan = "<span id=\"" + id + "\" " + tooltip + ">" + name + "</span>";
        }

        var html = UIHelper.GetFileIcon(Page, extension, tooltip: name) + "&nbsp;<a href=\"" + url + "\" target=\"_blank\">" + tooltipSpan + "</a>";

        if (!String.IsNullOrEmpty(variant))
        {
            var displayedVariantName = ResHelper.GetAPIString("AttachmentVariant." + variant, variant);
            html += String.Format(" ({0})", displayedVariantName);
        }

        return(html);
    }
    /// <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);
    }
    /// <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);
    }