Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register the dialog script
        ScriptHelper.RegisterScriptFile(this, @"~/CMSModules/Content/CMSDesk/tree.js");
        ScriptHelper.RegisterDialogScript(this);
        ScriptHelper.RegisterJQuery(Page);

        AddScript(string.Format("treeUrl = '{0}'; var contentDir = '{1}';\n",
                                ResolveUrl("~/CMSModules/Content/CMSDesk/Tree.aspx"),
                                ResolveUrl("~/CMSModules/Content/CMSDesk/")));

        treeContent.NodeTextTemplate         = string.Format("{0}<span class=\"ContentTreeItem\" onclick=\"SelectNode(##NODEID##, this); return false;\">##ICON##<span class=\"Name\">##NODENAME##</span></span>{1}", ContextMenuContainer.GetStartTag("nodeMenu", "##NODEID##", false, false), ContextMenuContainer.GetEndTag(false));
        treeContent.SelectedNodeTextTemplate = string.Format("{0}<span id=\"treeSelectedNode\" class=\"ContentTreeSelectedItem\" onclick=\"SelectNode(##NODEID##, this); return false;\">##ICON##<span class=\"Name\">##NODENAME##</span></span>{1}", ContextMenuContainer.GetStartTag("nodeMenu", "##NODEID##", false, false), ContextMenuContainer.GetEndTag(false));
        treeContent.MaxTreeNodeText          = string.Format("<span class=\"ContentTreeItem\" onclick=\"Listing(##PARENTNODEID##, this); return false;\"><span class=\"Name\" style=\"font-style: italic;\">{0}</span></span>", GetString("ContentTree.SeeListing"));
        treeContent.SelectPublishedData      = false;

        if (!string.IsNullOrEmpty(CMSContext.CurrentUser.UserStartingAliasPath))
        {
            treeContent.Path = CMSContext.CurrentUser.UserStartingAliasPath;
        }

        if (!Page.IsCallback)
        {
            // If nodeId set, init the list of the nodes to expand
            int expandNodeId = QueryHelper.GetInteger("expandnodeid", 0);
            int nodeId       = QueryHelper.GetInteger("nodeid", 0);

            if (RequestHelper.IsPostBack())
            {
                nodeId = ValidationHelper.GetInteger(Param1, 0);
                if (Action.ToLower() == "refresh")
                {
                    expandNodeId = ValidationHelper.GetInteger(Param2, 0);
                }
            }

            // Current Node ID
            treeContent.NodeID       = nodeId;
            treeContent.ExpandNodeID = expandNodeId;

            string script = null;

            // Setup the current node script
            if ((nodeId > 0) && !RequestHelper.IsPostBack())
            {
                script += string.Format("currentNodeId = {0};\n", nodeId);
            }

            script +=
                @"function ProcessRequest(action, param1, param2){
    var elm = jQuery('#" + pnlTreeArea.ClientID + @"');
    jQuery('#hdnScroll').val(elm.scrollTop());
    jQuery('#hdnAction').val(action); 
    jQuery('#hdnParam1').val(param1); 
    jQuery('#hdnParam2').val(param2);" +
                ClientScript.GetPostBackEventReference(this, null) + "}\n";

            AddScript(script);

            imgRefresh.ImageUrl      = GetImageUrl("CMSModules/CMS_Content/ContextMenu/Refresh.png");
            imgRefresh.AlternateText = GetString("general.refresh");
            imgRefresh.Attributes.Add("onclick", "RefreshTree(" + nodeId + ",null)");
            AddScript(string.Format("var refreshIconID = \"{0}\";", imgRefresh.ClientID));
        }
    }
    protected override void OnInit(EventArgs e)
    {
        if (!RequestHelper.IsCallback() && RequestHelper.IsPostBack())
        {
            NodeID = ValidationHelper.GetInteger(Param1, 0);
            if (Action.ToLowerCSafe() == "refresh")
            {
                ExpandNodeID = ValidationHelper.GetInteger(Param2, 0);
            }
        }

        // Set up the tree
        if ((NodeID > 0) && !RequestHelper.IsPostBack())
        {
            treeElem.SelectedNodeID = NodeID;
            // Setup the current node script
            AddScript(string.Format("currentNodeId = {0};", NodeID));
        }

        treeElem.ExpandNodeID = ExpandNodeID;
        treeElem.Culture = Culture;
        treeElem.NodeTextTemplate = string.Format("{0}<span class=\"ContentTreeItem\" onclick=\"{2} SelectNode(##NODEID##, this); return false;\">##ICON##<span class=\"Name\">##NODENAME##</span></span>{1}##STATUSICONS##", ContextMenuContainer.GetStartTag("nodeMenu", "##NODEID##", false, false), ContextMenuContainer.GetEndTag(false), BeforeSelectNodeScript);
        treeElem.SelectedNodeTextTemplate = string.Format("{0}<span id=\"treeSelectedNode\" class=\"ContentTreeSelectedItem\" onclick=\"{2} SelectNode(##NODEID##, this); return false;\">##ICON##<span class=\"Name\">##NODENAME##</span></span>{1}##STATUSICONS##", ContextMenuContainer.GetStartTag("nodeMenu", "##NODEID##", false, false), ContextMenuContainer.GetEndTag(false), BeforeSelectNodeScript);
        treeElem.MaxTreeNodeText = string.Format("<span class=\"ContentTreeItem\" onclick=\"Listing(##PARENTNODEID##, this); return false;\"><span class=\"Name\" >{0}</span></span>", GetString("general.SeeListing"));
        treeElem.SelectPublishedData = false;
        treeElem.IsProductTree = IsProductTree;

        if (IsProductTree)
        {
            menuCont.MenuControlPath = "~/CMSModules/Ecommerce/Controls/UI/ProductSectionsContextMenu.ascx";
            treeElem.RootNodeCreated += treeElem_RootNodeCreated;

            // Filter only product section nodes
            string where = "NodeClassID IN (SELECT ClassID FROM CMS_Class WHERE ClassIsProductSection = 1)";

            // Check if products are to be displayed in tree
            if (DisplayProductsInSectionsTree)
            {
                // Include product documents
                where = SqlHelper.AddWhereCondition(where, "(NodeSKUID IS NOT NULL)", "OR");
            }

            treeElem.MapProvider.WhereCondition = SqlHelper.AddWhereCondition(treeElem.MapProvider.WhereCondition, where);
        }
        else
        {
            menuCont.MenuControlPath = "~/CMSModules/Content/Controls/TreeContextMenu.ascx";
        }

        if (!string.IsNullOrEmpty(StartingAliasPath))
        {
            treeElem.Path = StartingAliasPath;
        }
        base.OnInit(e);
    }
    protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        sourceName = sourceName.ToLowerCSafe();
        DataRowView drv = null;
        bool        modifyPermission = true;
        string      documentCulture  = null;

        switch (sourceName)
        {
        case "documentname":
            drv = parameter as DataRowView;
            string documentName        = null;
            string encodedDocumentName = null;
            string documentType        = null;
            documentCulture = ValidationHelper.GetString(drv.Row["DocumentCulture"], string.Empty);
            string alias           = ValidationHelper.GetString(drv.Row["NodeAlias"], string.Empty);
            int    nodeId          = ValidationHelper.GetInteger(drv.Row["NodeID"], 0);
            int    documentId      = ValidationHelper.GetInteger(drv.Row["DocumentID"], 0);
            bool   isLinked        = (ValidationHelper.GetInteger(drv["NodeLinkedNodeID"], 0) != 0);
            Guid   nodeGuid        = ValidationHelper.GetGuid(drv.Row["NodeGUID"], Guid.Empty);
            string fileDescription = ValidationHelper.GetString(drv.Row["FileDescription"], string.Empty);
            Guid   fileAttachment  = ValidationHelper.GetGuid(drv.Row["FileAttachment"], Guid.Empty);

            // Get permissions flags
            modifyPermission = TreeSecurityProvider.CheckPermission(drv.Row, NodePermissionsEnum.Modify, documentCulture);
            bool modifyCulturePermission     = TreeSecurityProvider.CheckPermission(drv.Row, NodePermissionsEnum.Modify, PreferredCultureCode);
            bool deletePermission            = TreeSecurityProvider.CheckPermission(drv.Row, NodePermissionsEnum.Delete, documentCulture);
            bool modifyPermissionsPermission = TreeSecurityProvider.CheckPermission(drv.Row, NodePermissionsEnum.ModifyPermissions, documentCulture);
            bool readPermission = !CheckPermissions || TreeSecurityProvider.CheckPermission(drv.Row, NodePermissionsEnum.Read, documentCulture);

            if (modifyPermission)
            {
                documentName = ValidationHelper.GetString(drv.Row["DocumentName"], string.Empty);
                documentType = ValidationHelper.GetString(drv.Row["DocumentType"], string.Empty);
            }
            else
            {
                documentName = ValidationHelper.GetString(drv.Row["PublishedDocumentName"], string.Empty);
                documentType = ValidationHelper.GetString(drv.Row["PublishedDocumentType"], string.Empty);
            }

            encodedDocumentName = HTMLHelper.HTMLEncode(documentName);

            string fileTypeIcon = UIHelper.GetFileIcon(Page, documentType, tooltip: HTMLHelper.HTMLEncode(documentType));
            string flagIcon     = null;
            if (documentCulture.ToLowerCSafe() != PreferredCultureCode.ToLowerCSafe())
            {
                flagIcon = "<img class=\"Icon\" src=\"" + GetFlagIconUrl(documentCulture, "16x16") + "\" alt=\"" + HTMLHelper.HTMLEncode(documentCulture) + "\" />";
            }

            string menuParameter = ScriptHelper.GetString(nodeId + "|" + documentCulture);

            string attachmentName = encodedDocumentName;

            string toolTip = UIHelper.GetTooltipAttributes(null, 0, 0, null, null, null, fileDescription, null, 300);

            // Generate link to open document
            if (fileAttachment != Guid.Empty)
            {
                // Get document URL
                string attachmentUrl = AuthenticationHelper.ResolveUIUrl(AttachmentURLProvider.GetPermanentAttachmentUrl(nodeGuid, alias));
                if (modifyPermission)
                {
                    attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "latestfordocid", ValidationHelper.GetString(documentId, string.Empty));
                    attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "hash", ValidationHelper.GetHashString("d" + documentId));
                }
                attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString());

                if (!string.IsNullOrEmpty(attachmentUrl))
                {
                    attachmentName = "<a href=\"" + HTMLHelper.EncodeForHtmlAttribute(attachmentUrl) + "\" " + toolTip + ">" + encodedDocumentName + "</a> ";
                }
            }
            else
            {
                attachmentName = "<span" + toolTip + ">" + encodedDocumentName + "</span>";
            }

            // Add linked flag
            if (isLinked)
            {
                attachmentName += DocumentHelper.GetDocumentMarkImage(Page, DocumentMarkEnum.Link);
            }

            bool showContextMenu = readPermission && (modifyPermission || modifyPermissionsPermission || deletePermission || (IsAuthorizedToCreate && modifyCulturePermission));
            // Generate row with icons, hover action and context menu
            StringBuilder contextMenuString = new StringBuilder();
            contextMenuString.Append("<table>");
            contextMenuString.Append("<tr>");

            if (showContextMenu)
            {
                contextMenuString.Append(ContextMenuContainer.GetStartTag("libraryMenu_" + arrowContextMenu.ClientID, menuParameter, false, HtmlTextWriterTag.Td, "ArrowIcon", null));
                contextMenuString.Append("<a class=\"btn-unigrid-action\"><i class=\"icon-ellipsis\"></i></a>");
                contextMenuString.Append(ContextMenuContainer.GetEndTag(HtmlTextWriterTag.Td));
            }
            else
            {
                contextMenuString.Append("<td class=\"NoIcon\">&nbsp;</td>");
            }

            if (showContextMenu)
            {
                contextMenuString.Append(ContextMenuContainer.GetStartTag("libraryMenu_" + rowContextMenu.ClientID, menuParameter, true, HtmlTextWriterTag.Td, "FileTypeIcon", null));
            }
            else
            {
                contextMenuString.Append("<td class=\"FileTypeIcon\">");
            }
            contextMenuString.Append(fileTypeIcon);
            contextMenuString.Append(ContextMenuContainer.GetEndTag(HtmlTextWriterTag.Td));

            if (showContextMenu)
            {
                contextMenuString.Append(ContextMenuContainer.GetStartTag("libraryMenu_" + rowContextMenu.ClientID, menuParameter, true, HtmlTextWriterTag.Td, "RowContent", "width: 100%;"));
            }
            else
            {
                contextMenuString.Append("<td class=\"RowContent\" style=\"width: 100%;\">");
            }
            contextMenuString.Append(attachmentName);
            contextMenuString.Append(ContextMenuContainer.GetEndTag(HtmlTextWriterTag.Td));

            if (!string.IsNullOrEmpty(flagIcon))
            {
                contextMenuString.Append(ContextMenuContainer.GetStartTag("libraryMenu_" + rowContextMenu.ClientID, menuParameter, true, HtmlTextWriterTag.Td, "FlagIcon", null));
                contextMenuString.Append(flagIcon);
                contextMenuString.Append(ContextMenuContainer.GetEndTag(HtmlTextWriterTag.Td));
            }
            contextMenuString.Append("  </tr>");
            contextMenuString.Append("</table>");
            return(contextMenuString.ToString());

        case "modifiedwhen":
        case "modifiedwhentooltip":
            if (string.IsNullOrEmpty(parameter.ToString()))
            {
                return(string.Empty);
            }
            else
            {
                // Handle time zones
                DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME);

                if (sourceName == "modifiedwhen")
                {
                    if (IsLiveSite)
                    {
                        return(TimeZoneMethods.ConvertDateTime(modifiedWhen, this));
                    }
                    else
                    {
                        return(TimeZoneHelper.GetCurrentTimeZoneDateTimeString(modifiedWhen, CurrentUser, CurrentSite, out usedTimeZone));
                    }
                }
                else
                {
                    if (!IsLiveSite)
                    {
                        if (TimeZoneHelper.TimeZonesEnabled && (usedTimeZone == null))
                        {
                            TimeZoneHelper.GetCurrentTimeZoneDateTimeString(modifiedWhen, CurrentUser, CurrentSite, out usedTimeZone);
                        }
                        return(TimeZoneHelper.GetUTCLongStringOffset(usedTimeZone));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

        case "status":
            string stepName = string.Empty;
            string toReturn = string.Empty;

            // Extract datarow
            drv      = parameter as DataRowView;
            stepName = GetString("general.dash");
            TreeNode node = DocumentHelper.GetDocument(ValidationHelper.GetInteger(drv["DocumentID"], 0), TreeProvider);
            if (node != null)
            {
                var step = node.WorkflowStep;
                if (step != null)
                {
                    stepName = step.StepDisplayName;
                }
            }
            // Gain desired values from datarow view
            int checkedOutByUserId = ValidationHelper.GetInteger(drv["DocumentCheckedOutByUserID"], 0);
            documentCulture  = ValidationHelper.GetString(drv.Row["DocumentCulture"], string.Empty);
            modifyPermission = TreeSecurityProvider.CheckPermission(drv.Row, NodePermissionsEnum.Modify, documentCulture);

            // Add 'checked out' icon
            if ((checkedOutByUserId > 0) && modifyPermission)
            {
                toReturn = " " + DocumentHelper.GetDocumentMarkImage(Page, DocumentMarkEnum.CheckedOut);
            }

            toReturn = stepName + toReturn;
            return(toReturn);
        }
        return(parameter);
    }