protected void DocumentManager_OnSaveData(object sender, DocumentManagerEventArgs e)
    {
        e.UpdateDocument = false;

        string errorMessage = null;
        string newPageName  = txtPageName.Text.Trim();

        if (!String.IsNullOrEmpty(newPageName))
        {
            // Limit length
            newPageName = TreePathUtils.EnsureMaxNodeNameLength(newPageName, pageClassName);
        }

        TreeNode node = e.Node;

        node.DocumentName = newPageName;

        bool updateGuidAfterInsert = false;

        // Same template for all language versions by default
        PageTemplateInfo pti = selTemplate.EnsureTemplate(node.DocumentName, node.NodeGUID, ref errorMessage);

        if (pti != null)
        {
            node.SetDefaultPageTemplateID(pti.PageTemplateId);

            // Template should by updated after document insert
            if (!pti.IsReusable)
            {
                updateGuidAfterInsert = true;
            }
        }

        // Insert node if no error
        if (String.IsNullOrEmpty(errorMessage))
        {
            // Insert the document
            // Ensures documents consistency (blog post hierarchy etc.)
            DocumentManager.EnsureDocumentsConsistency();
            DocumentHelper.InsertDocument(node, DocumentManager.ParentNode, DocumentManager.Tree);

            if (updateGuidAfterInsert)
            {
                PageTemplateInfo pageTemplateInfo = PageTemplateInfoProvider.GetPageTemplateInfo(node.NodeTemplateID);
                if (pageTemplateInfo != null)
                {
                    // Update template's node GUID
                    pageTemplateInfo.PageTemplateNodeGUID = node.NodeGUID;
                    PageTemplateInfoProvider.SetPageTemplateInfo(pageTemplateInfo);
                }
            }
        }
        else
        {
            e.IsValid      = false;
            e.ErrorMessage = errorMessage;
        }
    }
Beispiel #2
0
    protected void DocumentManager_OnSaveData(object sender, DocumentManagerEventArgs e)
    {
        e.UpdateDocument = false;

        string errorMessage = null;
        string newPageName  = txtPageName.Text.Trim();

        if (!String.IsNullOrEmpty(newPageName))
        {
            // Limit length
            newPageName = TreePathUtils.EnsureMaxNodeNameLength(newPageName, pageClassName);
        }

        TreeNode node = e.Node;

        node.DocumentName = newPageName;

        bool updateGuidAfterInsert = false;

        // Same template for all language versions by default
        PageTemplateInfo pti = selTemplate.EnsureTemplate(node.DocumentName, node.NodeGUID, ref errorMessage);

        if (pti != null)
        {
            node.SetDefaultPageTemplateID(pti.PageTemplateId);

            // Template should by updated after document insert
            if (!pti.IsReusable)
            {
                updateGuidAfterInsert = true;
            }
        }

        // Insert node if no error
        if (String.IsNullOrEmpty(errorMessage))
        {
            // Insert the document
            // Ensures documents consistency (blog post hierarchy etc.)
            DocumentManager.EnsureDocumentsConsistency();
            DocumentHelper.InsertDocument(node, DocumentManager.ParentNode, DocumentManager.Tree);

            if (updateGuidAfterInsert)
            {
                PageTemplateInfo pageTemplateInfo = PageTemplateInfoProvider.GetPageTemplateInfo(node.NodeTemplateID);
                if (pageTemplateInfo != null)
                {
                    // Update template's node GUID
                    pageTemplateInfo.PageTemplateNodeGUID = node.NodeGUID;
                    PageTemplateInfoProvider.SetPageTemplateInfo(pageTemplateInfo);
                }
            }

            // Create default SKU if configured
            if (ModuleManager.CheckModuleLicense(ModuleName.ECOMMERCE, RequestContext.CurrentDomain, FeatureEnum.Ecommerce, ObjectActionEnum.Insert))
            {
                bool?skuCreated = node.CreateDefaultSKU();
                if (skuCreated.HasValue && !skuCreated.Value)
                {
                    AddError(GetString("com.CreateDefaultSKU.Error"));
                }
            }

            if (node.NodeSKUID > 0)
            {
                DocumentManager.UpdateDocument(true);
            }
        }
        else
        {
            e.IsValid      = false;
            e.ErrorMessage = errorMessage;
        }
    }
Beispiel #3
0
    protected void DocumentManager_OnSaveData(object sender, DocumentManagerEventArgs e)
    {
        e.UpdateDocument = false;

        string errorMessage = null;
        string newPageName  = txtPageName.Text.Trim();

        if (!String.IsNullOrEmpty(newPageName))
        {
            // Limit length
            newPageName = TreePathUtils.EnsureMaxNodeNameLength(newPageName, pageClassName);
        }

        TreeNode node = e.Node;

        node.DocumentName = newPageName;

        bool wireframe = node.IsWireframe() && PortalHelper.IsWireframingEnabled(CMSContext.CurrentSiteName);

        if (wireframe)
        {
            // Ensure the node GUID
            node.EnsureGUID();
            node.DocumentSearchExcluded = true;

            // Wireframe
            PageTemplateInfo pti = selTemplate.EnsureTemplate(node.DocumentName, node.NodeGUID, ref errorMessage);
            if (pti != null)
            {
                node.NodeWireframeTemplateID = pti.PageTemplateId;
            }
        }
        else
        {
            // Same template for all language versions by default
            PageTemplateInfo pti = selTemplate.EnsureTemplate(node.DocumentName, node.NodeGUID, ref errorMessage);
            if (pti != null)
            {
                node.SetDefaultPageTemplateID(pti.PageTemplateId);
            }
        }

        // Insert node if no error
        if (String.IsNullOrEmpty(errorMessage))
        {
            // Switch to design mode (the template is empty at this moment)
            if (!DocumentManager.CreateAnother && (CMSContext.ViewMode != ViewModeEnum.EditLive))
            {
                if (wireframe)
                {
                    // Wireframe mode for wireframes
                    CMSContext.ViewMode = ViewModeEnum.Wireframe;
                }
                else if (selTemplate.NewTemplateIsEmpty)
                {
                    // Design mode for empty template
                    CMSContext.ViewMode = ViewModeEnum.Design;
                }
            }

            // Insert the document
            if (DocumentManager.Mode == FormModeEnum.Convert)
            {
                DocumentManager.UpdateDocument(true);
            }
            else
            {
                // Ensures documents consistency (blog post hierarchy etc.)
                DocumentManager.EnsureDocumentsConsistency();
                DocumentHelper.InsertDocument(node, DocumentManager.ParentNodeID, DocumentManager.Tree);
            }

            // Create default SKU if configured
            if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
            {
                bool?skuCreated = node.CreateDefaultSKU();
                if (skuCreated.HasValue && !skuCreated.Value)
                {
                    AddError(GetString("com.CreateDefaultSKU.Error"), null);
                }
            }

            if (node.NodeSKUID > 0)
            {
                DocumentManager.UpdateDocument(true);
            }
        }
        else
        {
            e.IsValid      = false;
            e.ErrorMessage = errorMessage;
        }
    }