protected void DocumentManager_OnAfterAction(object sender, DocumentManagerEventArgs e)
    {
        TreeNode node = e.Node;

        int newNodeId = node.NodeID;

        if (newdocument || newculture)
        {
            // Store error text
            if (!string.IsNullOrEmpty(formElem.MessagesPlaceHolder.ErrorText))
            {
                SessionHelper.SetValue("FormErrorText|" + newNodeId, formElem.MessagesPlaceHolder.ErrorText);
            }
        }
        else
        {
            // Reload the form
            formElem.LoadForm(true);
        }

        // If not menu item type nor EditLive view mode, switch to form mode to keep editing the form
        if (!TreePathUtils.IsMenuItemType(node.NodeClassName) && (CMSContext.ViewMode != ViewModeEnum.EditLive))
        {
            CMSContext.ViewMode = ViewModeEnum.EditForm;
        }
    }
    /// <summary>
    /// Translates object to new culture.
    /// </summary>
    protected void btnTranslate_Click(object sender, EventArgs e)
    {
        if (TranslationServiceHelper.IsAuthorizedToTranslateDocument(Node, MembershipContext.AuthenticatedUser))
        {
            try
            {
                // Submits the document to translation service
                string err = translationElem.SubmitToTranslation();
                if (string.IsNullOrEmpty(err))
                {
                    // Refresh page
                    string script;
                    if (RequiresDialog)
                    {
                        string url = UrlResolver.ResolveUrl(DocumentURLProvider.GetUrl(Node) + "?" + URLHelper.LanguageParameterName + "=" + RequiredCulture);
                        script = "window.top.location = " + ScriptHelper.GetString(url) + ";";
                    }
                    else
                    {
                        ViewModeEnum mode = ViewModeEnum.Edit;
                        if (!TreePathUtils.IsMenuItemType(Node.NodeClassName) && (PortalContext.ViewMode != ViewModeEnum.EditLive))
                        {
                            mode = ViewModeEnum.EditForm;
                        }
                        script = "if (FramesRefresh) { FramesRefresh(" + Node.NodeID + ", '" + mode + "'); }";
                    }

                    ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript(script));
                }
                else
                {
                    ShowError(err);
                }
            }
            catch (Exception ex)
            {
                ShowError(GetString("ContentRequest.TranslationFailed"), ex.Message);
                TranslationServiceHelper.LogEvent(ex);
            }
        }
        else
        {
            RedirectToAccessDenied("CMS.Content", "SubmitForTranslation");
        }
    }
Beispiel #3
0
    /// <summary>
    /// Save new or existing document.
    /// </summary>
    /// <param name="forceRefreshTree">Indicates if content tree should be refreshed</param>
    private void SaveDocument(bool forceRefreshTree)
    {
        if (nodeId > 0)
        {
            // Validate the form first
            if (formElem.BasicForm.ValidateData())
            {
                bool createAnother = newdocument && ValidationHelper.GetBoolean(Request.Params["hidAnother"], false);

                if (!newdocument && !newculture)
                {
                    // Get the document
                    node = DocumentHelper.GetDocument(nodeId, CMSContext.PreferredCultureCode, TreeProvider);

                    // Check modify permissions
                    if (CMSContext.CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
                    {
                        formElem.Enabled     = false;
                        lblWorkflowInfo.Text = String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), node.NodeAliasPath);
                        PassiveRefresh(nodeId, node.NodeParentID, node.DocumentName);
                        return;
                    }
                }

                try
                {
                    // Backup original document's values - before saving
                    string   originalDocumentName = node.DocumentName;
                    DateTime originalPublishFrom  = node.DocumentPublishFrom;
                    DateTime originalPublishTo    = node.DocumentPublishTo;
                    bool     wasArchived          = node.IsArchived;
                    bool     wasInPublishedStep   = node.IsInPublishStep;

                    // If not using check-in/check-out, check out automatically (not for new document and new culture version)
                    if (!newdocument && !newculture && AutoCheck)
                    {
                        if (node != null)
                        {
                            // Check out
                            VersionManager.CheckOut(node, node.IsPublished, true);
                        }
                    }

                    // Tree node is returned from CMSForm.Save method
                    if ((node != null) && !newdocument && !newculture)
                    {
                        formElem.Save(node);
                    }
                    else
                    {
                        // Document was not saved yet
                        node = null;

                        // Product should be created -> save document only when product data are valid
                        if ((chkCreateProduct.Checked) && (ucNewProduct != null))
                        {
                            if (ucNewProduct.ValidateData())
                            {
                                node = formElem.Save();
                            }
                        }
                        // Product should not be created -> save document
                        else
                        {
                            node = formElem.Save();
                        }
                    }

                    if (node != null)
                    {
                        // Create product only if the doc. type can be product
                        if ((newdocument) && (chkCreateProduct.Checked) && (ucNewProduct != null) && (ucNewProduct.ClassObj.ClassIsProduct))
                        {
                            // Create product
                            ucNewProduct.Node = node;

                            GeneralizedInfo skuObj = ucNewProduct.SaveData();
                            if (skuObj != null)
                            {
                                // Asssign new product to the document
                                node.NodeSKUID = skuObj.ObjectID;
                                DocumentHelper.UpdateDocument(node, TreeProvider, true);
                            }
                        }

                        // If not using check-in/check-out
                        if (AutoCheck)
                        {
                            // Check in the document (not for new document and new culture version)
                            if (!newdocument && !newculture)
                            {
                                VersionManager.CheckIn(node, null, null);
                            }
                            else
                            {
                                // Automatically publish
                                // Check if allowed 'Automatically publish changes'
                                WorkflowInfo wi = WorkflowManager.GetNodeWorkflow(node);
                                if (wi.WorkflowAutoPublishChanges)
                                {
                                    WorkflowManager.AutomaticallyPublish(node, wi, null);
                                }
                            }
                        }

                        int newNodeId = node.NodeID;
                        if (newdocument || newculture)
                        {
                            // Store error text
                            if (!string.IsNullOrEmpty(formElem.lblError.Text))
                            {
                                SessionHelper.SetValue("FormErrorText|" + newNodeId, formElem.lblError.Text);
                            }

                            if (createAnother)
                            {
                                PassiveRefresh(node.NodeParentID, node.NodeParentID, "");
                                AddScript("CreateAnother();");
                            }
                            else
                            {
                                // Refresh frame in split mode
                                if (newculture && displaySplitMode && (CultureHelper.GetOriginalPreferredCulture() != node.DocumentCulture))
                                {
                                    AddScript("SplitModeRefreshFrame();");
                                }
                                else
                                {
                                    // Document tree is refreshed and new document is displayed
                                    AddScript("RefreshTree(" + newNodeId + "," + newNodeId + "); SelectNode(" + newNodeId + ");");
                                }
                            }
                        }
                        else
                        {
                            // Refresh content tree and frames if 'forceRefreshTree' is True or document was changed
                            if (forceRefreshTree || ((originalDocumentName != node.DocumentName) || (wasInPublishedStep != node.IsInPublishStep) || (wasArchived != node.IsArchived) ||
                                                     (((originalPublishFrom != node.DocumentPublishFrom) || (originalPublishTo != node.DocumentPublishTo)) &&
                                                      (AutoCheck || (WorkflowManager.GetNodeWorkflow(node) == null)))))
                            {
                                // Refresh content tree and frames
                                PassiveRefresh(nodeId, node.NodeParentID, node.DocumentName);
                            }
                            else
                            {
                                // Refresh frames
                                FramesRefresh(false, nodeId);
                            }

                            // Reload the form
                            ReloadForm();
                            string oldInfo = formElem.lblInfo.Text;
                            formElem.LoadForm(false);
                            formElem.lblInfo.Text  = oldInfo;
                            formElem.lblInfo.Text += "<br />";
                        }

                        // If not menuitem type, switch to form mode to keep editing the form
                        if (!TreePathUtils.IsMenuItemType(node.NodeClassName))
                        {
                            CMSContext.ViewMode = ViewModeEnum.EditForm;
                        }
                    }
                }
                catch (Exception ex)
                {
                    AddAlert(GetString("ContentRequest.SaveFailed") + " : " + ex.Message);
                }
            }
        }
    }
    /// <summary>
    /// Creates new culture version of object.
    /// </summary>
    protected void btnCreateDocument_Click(object sender, EventArgs e)
    {
        if (radCopy.Checked)
        {
            string   sourceCulture    = copyCulturesElem.Value.ToString();
            TreeNode actualSourceNode = DocumentHelper.GetDocument(NodeID, sourceCulture, Tree);
            TreeNode sourceNode       = actualSourceNode.IsLink ? DocumentHelper.GetDocument(Tree.GetOriginalNode(actualSourceNode), Tree) : actualSourceNode;

            if (sourceNode != null)
            {
                if (chkSaveBeforeEditing.Checked && (Node != null))
                {
                    // Create the version first
                    TreeNode newCulture = TreeNode.New(Node.ClassName);

                    // The 'DocumentABTestConfiguration' is excluded from copying node to another culture as A/B test is linked to the culture specific node
                    var excludedColumns = new[] { "DocumentABTestConfiguration" };

                    DocumentHelper.CopyNodeData(sourceNode, newCulture, new CopyNodeDataSettings(true, excludedColumns)
                    {
                        ResetChanges = true
                    });

                    if (string.Equals(Node.ClassName, "cms.blogpost", StringComparison.InvariantCultureIgnoreCase))
                    {
                        // Ensure blog post hierarchy if node is blog post
                        newCulture.DocumentCulture = RequiredCulture;
                        DocumentHelper.EnsureBlogPostHierarchy(newCulture, DocumentHelper.GetDocument(newCulture.NodeParentID, TreeProvider.ALL_CULTURES, Tree), Tree);
                    }

                    var settings = new NewCultureDocumentSettings(newCulture, RequiredCulture, Tree)
                    {
                        CopyAttachments       = true,
                        CopyCategories        = true,
                        ClearAttachmentFields = false
                    };

                    try
                    {
                        DocumentHelper.InsertNewCultureVersion(settings);
                    }
                    catch (Exception ex)
                    {
                        // Catch possible exceptions
                        LogAndShowError("Content", "NEWCULTUREVERSION", ex);
                        return;
                    }

                    // Make sure document is published when versioning without workflow is applied
                    var workflow = newCulture.GetWorkflow();
                    if ((workflow != null) && workflow.WorkflowAutoPublishChanges && !workflow.UseCheckInCheckOut(newCulture.NodeSiteName))
                    {
                        newCulture.MoveToPublishedStep();
                    }

                    // Refresh page
                    if (RequiresDialog)
                    {
                        string url = UrlResolver.ResolveUrl(DocumentURLProvider.GetUrl(newCulture) + "?" + URLHelper.LanguageParameterName + "=" + RequiredCulture);
                        ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript(" wopener.location = " + ScriptHelper.GetString(url) + "; CloseDialog();"));
                    }
                    else
                    {
                        ViewModeEnum mode = ViewModeEnum.Edit;
                        if (!TreePathUtils.IsMenuItemType(Node.NodeClassName) && (PortalContext.ViewMode != ViewModeEnum.EditLive))
                        {
                            mode = ViewModeEnum.EditForm;
                        }
                        ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript("if (FramesRefresh) { FramesRefresh(" + Node.NodeID + ", '" + mode + "'); }"));
                    }
                }
                else
                {
                    var url = GetEditUrl(Node);
                    url = URLHelper.AddParameterToUrl(url, "sourcedocumentid", sourceNode.DocumentID.ToString());

                    if (RequiresDialog)
                    {
                        // Reload new page after save
                        url = URLHelper.AddParameterToUrl(url, "reloadnewpage", "true");
                    }

                    // Provide information about actual node
                    if (actualSourceNode.IsLink)
                    {
                        url = URLHelper.AddParameterToUrl(url, "sourcenodeid", actualSourceNode.NodeID.ToString());
                    }
                    URLHelper.ResponseRedirect(url);
                }
            }
            else
            {
                ShowError(GetString("transman.notallowedcreate"));
            }
        }
        else
        {
            var url = GetEditUrl(Node);

            if (RequiresDialog)
            {
                // Reload new page after save
                url = URLHelper.AddParameterToUrl(url, "reloadnewpage", "true");
            }

            URLHelper.ResponseRedirect(url);
        }
    }
    protected void btnCreateDocument_Click(object sender, EventArgs e)
    {
        if (radCopy.Checked)
        {
            string   sourceCulture    = copyCulturesElem.Value.ToString();
            TreeNode actualSourceNode = DocumentHelper.GetDocument(NodeID, sourceCulture, Tree);
            TreeNode sourceNode       = actualSourceNode.IsLink ? DocumentHelper.GetDocument(Tree.GetOriginalNode(actualSourceNode), Tree) : actualSourceNode;

            if (sourceNode != null)
            {
                if (chkSaveBeforeEditing.Checked && (node != null))
                {
                    // Create the version first
                    TreeNode newCulture = TreeNode.New(node.ClassName);
                    DocumentHelper.CopyNodeData(sourceNode, newCulture, new CopyNodeDataSettings(true, null));
                    NewCultureDocumentSettings settings = new NewCultureDocumentSettings
                    {
                        Node            = newCulture,
                        CultureCode     = RequiredCulture,
                        CopyAttachments = true,
                        CopyCategories  = true
                    };
                    DocumentHelper.InsertNewCultureVersion(settings);

                    // Refresh page
                    if (RequiresDialog)
                    {
                        string url = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(newCulture.NodeAliasPath) + "?" + URLHelper.LanguageParameterName + "=" + RequiredCulture);
                        ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript(" wopener.location = " + ScriptHelper.GetString(url) + "; CloseDialog();"));
                    }
                    else
                    {
                        ViewModeEnum mode = ViewModeEnum.Edit;
                        if (!TreePathUtils.IsMenuItemType(node.NodeClassName) && (CMSContext.ViewMode != ViewModeEnum.EditLive))
                        {
                            mode = ViewModeEnum.EditForm;
                        }
                        ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript("if (FramesRefresh) { FramesRefresh(" + node.NodeID + ", '" + mode + "'); }"));
                    }
                }
                else
                {
                    var url = GetEditUrl(node);
                    url = URLHelper.AddParameterToUrl(url, "sourcedocumentid", sourceNode.DocumentID.ToString());
                    // Provide information about actual node
                    if ((actualSourceNode != null) && actualSourceNode.IsLink)
                    {
                        url = URLHelper.AddParameterToUrl(url, "sourcenodeid", actualSourceNode.NodeID.ToString());
                    }
                    Response.Redirect(url);
                }
            }
            else
            {
                ShowError(GetString("transman.notallowedcreate"));
            }
        }
        else
        {
            var url = GetEditUrl(node);
            Response.Redirect(url);
        }
    }