/// <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);
    }
示例#2
0
    /// <summary>
    /// External data binding handler.
    /// </summary>
    protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        int currentNodeId;

        sourceName = sourceName.ToLowerCSafe();
        switch (sourceName)
        {
        case "view":
        {
            // Dialog view item
            DataRowView         data = ((DataRowView)((GridViewRow)parameter).DataItem);
            CMSGridActionButton btn  = ((CMSGridActionButton)sender);
            // Current row is the Root document
            isRootDocument    = (ValidationHelper.GetInteger(data["NodeParentID"], 0) == 0);
            currentNodeId     = ValidationHelper.GetInteger(data["NodeID"], 0);
            isCurrentDocument = (currentNodeId == WOpenerNodeID);

            string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty);
            // Existing document culture
            if (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe())
            {
                string className = ValidationHelper.GetString(data["ClassName"], string.Empty);
                if (DataClassInfoProvider.GetDataClassInfo(className).ClassHasURL)
                {
                    var    relativeUrl = isRootDocument ? "~/" : DocumentUIHelper.GetPageHandlerPreviewPath(currentNodeId, culture, CurrentUser.UserName);
                    string url         = ResolveUrl(relativeUrl);

                    btn.OnClientClick = "ViewItem(" + ScriptHelper.GetString(url) + "); return false;";
                }
                else
                {
                    btn.Enabled = false;
                    btn.Style.Add(HtmlTextWriterStyle.Cursor, "default");
                }
            }
            // New culture version
            else
            {
                btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;";
            }
        }
        break;

        case "edit":
        {
            CMSGridActionButton btn = ((CMSGridActionButton)sender);
            if (IsEditVisible)
            {
                DataRowView data    = ((DataRowView)((GridViewRow)parameter).DataItem);
                string      culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty);
                currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0);
                int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0);

                if (!RequiresDialog || (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe()))
                {
                    // Go to the selected document or create a new culture version when not used in a dialog
                    btn.OnClientClick = "EditItem(" + currentNodeId + ", " + nodeParentId + "); return false;";
                }
                else
                {
                    // New culture version in a dialog
                    btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;";
                }
            }
            else
            {
                btn.Visible = false;
            }
        }
        break;

        case "delete":
        {
            // Delete button
            CMSGridActionButton btn = ((CMSGridActionButton)sender);

            // Hide the delete button for the root document
            btn.Visible = !isRootDocument;
        }
        break;

        case "contextmenu":
        {
            // Dialog context menu item
            CMSGridActionButton btn = ((CMSGridActionButton)sender);

            // Hide the context menu for the root document
            btn.Visible = !isRootDocument && !ShowAllLevels;
        }
        break;

        case "versionnumber":
        {
            // Version number
            if (parameter == DBNull.Value)
            {
                parameter = "-";
            }
            parameter = HTMLHelper.HTMLEncode(parameter.ToString());

            return(parameter);
        }

        case "documentname":
        {
            // Document name
            DataRowView data             = (DataRowView)parameter;
            string      className        = ValidationHelper.GetString(data["ClassName"], string.Empty);
            string      classDisplayName = ValidationHelper.GetString(data["classdisplayname"], null);
            string      name             = ValidationHelper.GetString(data["DocumentName"], string.Empty);
            string      culture          = ValidationHelper.GetString(data["DocumentCulture"], string.Empty);
            string      cultureString    = null;

            currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0);
            int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0);

            if (isRootDocument)
            {
                // User site name for the root document
                name = SiteContext.CurrentSiteName;
            }

            // Default culture
            if (culture.ToLowerCSafe() != CultureCode.ToLowerCSafe())
            {
                cultureString = " (" + culture + ")";
            }

            StringBuilder sb = new StringBuilder();

            if (ShowDocumentTypeIcon)
            {
                // Prepare tooltip for document type icon
                string iconTooltip = "";
                if (ShowDocumentTypeIconTooltip && (classDisplayName != null))
                {
                    string safeClassName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(classDisplayName));
                    iconTooltip = string.Format("onmouseout=\"UnTip()\" onmouseover=\"Tip('{0}')\"", HTMLHelper.EncodeForHtmlAttribute(safeClassName));
                }

                var dataClass = DataClassInfoProvider.GetDataClassInfo(className);
                if (dataClass != null)
                {
                    var iconClass = (string)dataClass.GetValue("ClassIconClass");
                    sb.Append(UIHelper.GetDocumentTypeIcon(Page, className, iconClass, additionalAttributes: iconTooltip));
                }
            }

            string safeName = HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50));
            if (DocumentNameAsLink && !isRootDocument)
            {
                string tooltip = UniGridFunctions.DocumentNameTooltip(data);

                string selectFunction = SelectItemJSFunction + "(" + currentNodeId + ", " + nodeParentId + ");";
                sb.Append("<a href=\"javascript: ", selectFunction, "\"");
                sb.Append(" onmouseout=\"UnTip()\" onmouseover=\"Tip('", HTMLHelper.EncodeForHtmlAttribute(tooltip), "')\">", safeName, cultureString, "</a>");
            }
            else
            {
                sb.Append(safeName, cultureString);
            }

            // Show document marks only if method is not called from grid export and document marks are allowed
            if ((sender != null) && ShowDocumentMarks)
            {
                // Prepare parameters
                int workflowStepId            = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(data, "DocumentWorkflowStepID"), 0);
                WorkflowStepTypeEnum stepType = WorkflowStepTypeEnum.Undefined;

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

                // Create data container
                IDataContainer container = new DataRowContainer(data);

                // Add icons and use current culture of processed node because of 'Not translated document' icon
                sb.Append(" ", DocumentUIHelper.GetDocumentMarks(Page, currentSiteName, ValidationHelper.GetString(container.GetValue("DocumentCulture"), string.Empty), stepType, container));
            }

            return(sb.ToString());
        }

        case "documentculture":
        {
            DocumentFlagsControl ucDocFlags = null;

            if (OnDocumentFlagsCreating != null)
            {
                // Raise event for obtaining custom DocumentFlagControl
                object result = OnDocumentFlagsCreating(this, sourceName, parameter);
                ucDocFlags = result as DocumentFlagsControl;

                // Check if something other than DocumentFlagControl was returned
                if ((ucDocFlags == null) && (result != null))
                {
                    return(result);
                }
            }

            // Dynamically load document flags control when not created
            if (ucDocFlags == null)
            {
                ucDocFlags = LoadUserControl("~/CMSAdminControls/UI/DocumentFlags.ascx") as DocumentFlagsControl;
            }

            // Set document flags properties
            if (ucDocFlags != null)
            {
                DataRowView data = (DataRowView)parameter;

                // Get node ID
                currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0);

                if (!string.IsNullOrEmpty(SelectLanguageJSFunction))
                {
                    ucDocFlags.SelectJSFunction = SelectLanguageJSFunction;
                }

                ucDocFlags.ID             = "docFlags" + currentNodeId;
                ucDocFlags.SiteCultures   = SiteCultures;
                ucDocFlags.NodeID         = currentNodeId;
                ucDocFlags.StopProcessing = true;

                // Keep the control for later usage
                FlagsControls.Add(ucDocFlags);
                return(ucDocFlags);
            }
        }
        break;

        case "modifiedwhen":
        case "modifiedwhentooltip":
            // Modified when
            if (string.IsNullOrEmpty(parameter.ToString()))
            {
                return(string.Empty);
            }

            DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME);
            currentUserInfo = currentUserInfo ?? MembershipContext.AuthenticatedUser;
            currentSiteInfo = currentSiteInfo ?? SiteContext.CurrentSite;

            return(sourceName.EqualsCSafe("modifiedwhen", StringComparison.InvariantCultureIgnoreCase)
                    ? TimeZoneHelper.ConvertToUserTimeZone(modifiedWhen, true, currentUserInfo, currentSiteInfo)
                    : TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo));

        default:
            if (OnExternalAdditionalDataBound != null)
            {
                return(OnExternalAdditionalDataBound(sender, sourceName, parameter));
            }

            break;
        }

        return(parameter);
    }