Example #1
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (pt != null)
        {
            // Limit text length
            txtTemplateCodeName.Text    = TextHelper.LimitLength(txtTemplateCodeName.Text.Trim(), 100, "");
            txtTemplateDisplayName.Text = TextHelper.LimitLength(txtTemplateDisplayName.Text.Trim(), 200, "");

            // finds whether required fields are not empty
            string result = new Validator().NotEmpty(txtTemplateDisplayName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateDisplayName")).NotEmpty(txtTemplateCodeName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateCodeName"))
                            .IsCodeName(txtTemplateCodeName.Text, GetString("general.invalidcodename"))
                            .Result;

            if (String.IsNullOrEmpty(result))
            {
                // Check if template with given name already exists
                if (PageTemplateInfoProvider.PageTemplateNameExists(txtTemplateCodeName.Text))
                {
                    lblError.Text = GetString("general.codenameexists");
                    return;
                }

                if (pt.IsReusable == true)
                {
                    // Clone template with clear
                    pt = pt.Clone(true);
                }
                pt.CodeName    = txtTemplateCodeName.Text;
                pt.DisplayName = txtTemplateDisplayName.Text;
                pt.Description = txtTemplateDescription.Text;

                pt.CategoryID = Convert.ToInt32(categorySelector.Value);

                pt.IsReusable         = true;
                pt.PageTemplateSiteID = 0;
                try
                {
                    PageTemplateInfoProvider.SetPageTemplateInfo(pt);
                    int siteId = QueryHelper.GetInteger("siteid", 0);
                    if (siteId > 0)
                    {
                        PageTemplateInfoProvider.AddPageTemplateToSite(pt.PageTemplateId, siteId);
                    }
                    ltlScript.Text = ScriptHelper.GetScript("SelectActualData(" + pt.PageTemplateId.ToString() + ", " + pt.IsPortal.ToString().ToLower() + ", " + pt.IsReusable.ToString().ToLower() + ");");
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = result;
            }
        }
    }
    private void EnsureAdHocTemplate(DocumentManagerEventArgs e)
    {
        var pti = PageTemplateInfoProvider.GetPageTemplateInfo(formElem.DefaultPageTemplateID);

        // Ensure ad-hoc template as default
        if ((pti != null) && pti.IsReusable && pti.PageTemplateCloneAsAdHoc)
        {
            // Create ad-hoc template (display name is created automatically)
            var adHocTemplate = PageTemplateInfoProvider.CloneTemplateAsAdHoc(pti, null, SiteContext.CurrentSiteID, e.Node.NodeGUID);
            PageTemplateInfoProvider.SetPageTemplateInfo(adHocTemplate);
            formElem.DefaultPageTemplateID = adHocTemplate.PageTemplateId;

            if (SiteContext.CurrentSite != null)
            {
                PageTemplateInfoProvider.AddPageTemplateToSite(adHocTemplate.PageTemplateId, SiteContext.CurrentSiteID);
            }
        }
    }
Example #3
0
    protected void SaveSites()
    {
        // Remove old items
        string newValues = ValidationHelper.GetString(usSites.Value, null);
        string items     = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int siteId = ValidationHelper.GetInteger(item, 0);

                    PageTemplateInfoProvider.RemovePageTemplateFromSite(pageTemplateId, siteId);
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    int siteId = ValidationHelper.GetInteger(item, 0);

                    PageTemplateInfoProvider.AddPageTemplateToSite(pageTemplateId, siteId);
                }
            }
        }

        lblInfo.Visible = true;
        lblInfo.Text    = GetString("General.ChangesSaved");
    }
Example #4
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (pt != null)
        {
            // Limit text length
            txtTemplateDisplayName.Text = TextHelper.LimitLength(txtTemplateDisplayName.Text.Trim(), 200, "");

            // finds whether required fields are not empty
            string result = new Validator()
                            .NotEmpty(txtTemplateDisplayName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateDisplayName"))
                            .NotEmpty(txtTemplateCodeName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateCodeName"))
                            .IsCodeName(txtTemplateCodeName.Text, GetString("general.invalidcodename"))
                            .Result;

            if (String.IsNullOrEmpty(result))
            {
                // Check if template with given name already exists
                if (PageTemplateInfoProvider.PageTemplateNameExists(txtTemplateCodeName.Text))
                {
                    ShowError(GetString("general.codenameexists"));
                }

                if (pt.IsReusable || !chkKeep.Checked)
                {
                    // Clone template with clear
                    pt = pt.Clone(true);
                }
                pt.CodeName    = txtTemplateCodeName.Text;
                pt.DisplayName = txtTemplateDisplayName.Text;
                pt.Description = txtTemplateDescription.Text;

                pt.CategoryID = Convert.ToInt32(categorySelector.Value);

                // Reset the Ad-hoc status
                pt.IsReusable           = true;
                pt.PageTemplateNodeGUID = Guid.Empty;

                pt.PageTemplateSiteID = 0;

                try
                {
                    PageTemplateInfoProvider.SetPageTemplateInfo(pt);
                    int siteId = QueryHelper.GetInteger("siteid", 0);
                    if (siteId > 0)
                    {
                        PageTemplateInfoProvider.AddPageTemplateToSite(pt.PageTemplateId, siteId);
                    }

                    if (!chkKeep.Checked)
                    {
                        ShowInformation(GetString("PortalEngine.SaveNewPageTemplate.Saved"));

                        txtTemplateCodeName.Text = pt.CodeName;

                        pnlContent.Enabled = false;
                        btnOk.Visible      = false;
                    }
                    else
                    {
                        string script;

                        bool refresh = QueryHelper.GetBoolean("refresh", false);
                        if (refresh)
                        {
                            script = "wopener.location.replace(wopener.location); CloseDialog();";
                        }
                        else
                        {
                            String selId = QueryHelper.GetString("selectorID", String.Empty);
                            script = "SelectTemplate(" + pt.PageTemplateId + "," + ScriptHelper.GetString(selId) + ");";
                        }

                        ltlScript.Text = ScriptHelper.GetScript(script);
                    }
                }
                catch (Exception ex)
                {
                    ShowError(ex.Message);
                }
            }
            else
            {
                ShowError(result);
            }
        }
    }
Example #5
0
    /// <summary>
    /// Ensures the template from the selection and returns the template ID.
    /// </summary>
    /// <param name="documentName">Document name for the ad-hoc template</param>
    /// <param name="nodeGuid">Owner node GUID in case of ad-hoc template</param>
    /// <param name="errorMessage">Returns the error message</param>
    public PageTemplateInfo EnsureTemplate(string documentName, Guid nodeGuid, ref string errorMessage)
    {
        bool cloneAsAdHoc = false;
        bool masterOnly   = false;

        PageTemplateInfo templateInfo = null;

        // Template selection
        if (radUseTemplate.Checked)
        {
            // Template page
            int templateId = ValidationHelper.GetInteger(templateSelector.SelectedItem, 0);
            if (templateId > 0)
            {
                // Get the template and check if it should be cloned
                templateInfo = PageTemplateInfoProvider.GetPageTemplateInfo(templateId);
                if (templateInfo != null)
                {
                    cloneAsAdHoc = templateInfo.PageTemplateCloneAsAdHoc;
                }
            }
            else
            {
                errorMessage = GetString("NewPage.TemplateError");

                // Reload template selector to show correct subtree
                templateSelector.ResetToDefault();
            }
        }
        else if (radInherit.Checked)
        {
            // Inherited page
        }
        else if (radCreateBlank.Checked || radCreateEmpty.Checked)
        {
            // Create custom template info for the page
            templateInfo = new PageTemplateInfo();

            if (radCreateBlank.Checked)
            {
                // Blank page with layout
                int layoutId = ValidationHelper.GetInteger(layoutSelector.SelectedItem, 0);
                if (layoutId > 0)
                {
                    templateInfo.LayoutID = layoutId;

                    // Copy layout to selected template
                    if (chkLayoutPageTemplate.Checked)
                    {
                        templateInfo.LayoutID = 0;
                        LayoutInfo li = LayoutInfoProvider.GetLayoutInfo(layoutId);
                        if (li != null)
                        {
                            templateInfo.PageTemplateLayout     = li.LayoutCode;
                            templateInfo.PageTemplateLayoutType = li.LayoutType;
                        }
                        else
                        {
                            errorMessage = GetString("NewPage.LayoutError");
                        }
                    }
                }
                else
                {
                    errorMessage = GetString("NewPage.LayoutError");
                }
            }
            else if (radCreateEmpty.Checked)
            {
                // Empty template
                templateInfo.LayoutID           = 0;
                templateInfo.PageTemplateLayout = "<cms:CMSWebPartZone ZoneID=\"zoneA\" runat=\"server\" />";

                templateInfo.PageTemplateLayoutType = LayoutTypeEnum.Ascx;
            }

            if (String.IsNullOrEmpty(errorMessage))
            {
                cloneAsAdHoc = true;
                masterOnly   = true;
            }
        }

        if (cloneAsAdHoc)
        {
            // Prepare ad-hoc template name
            string displayName = "Ad-hoc: " + documentName;

            // Create ad-hoc template
            templateInfo = PageTemplateInfoProvider.CloneTemplateAsAdHoc(templateInfo, displayName, SiteContext.CurrentSiteID, nodeGuid);

            // Set inherit only master
            if (masterOnly)
            {
                templateInfo.InheritPageLevels = "\\";
            }

            PageTemplateInfoProvider.SetPageTemplateInfo(templateInfo);

            if (SiteContext.CurrentSite != null)
            {
                PageTemplateInfoProvider.AddPageTemplateToSite(templateInfo.PageTemplateId, SiteContext.CurrentSiteID);
            }

            CheckOutTemplate(templateInfo);
        }

        // Assign owner node GUID
        if ((templateInfo != null) && !templateInfo.IsReusable)
        {
            templateInfo.PageTemplateNodeGUID = nodeGuid;
        }

        // Reload the template selector in case of error
        if (!String.IsNullOrEmpty(errorMessage))
        {
            if (radUseTemplate.Checked)
            {
                templateSelector.ReloadData();
            }
        }

        return(templateInfo);
    }
Example #6
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (pt != null)
        {
            // Limit text length
            txtTemplateDisplayName.Text = TextHelper.LimitLength(txtTemplateDisplayName.Text.Trim(), 200, "");

            // finds whether required fields are not empty
            string result = new Validator()
                            .NotEmpty(txtTemplateDisplayName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateDisplayName"))
                            .NotEmpty(txtTemplateCodeName.Text, GetString("Administration-PageTemplate_General.ErrorEmptyTemplateCodeName"))
                            .IsCodeName(txtTemplateCodeName.Text, GetString("general.invalidcodename"))
                            .Result;

            if (String.IsNullOrEmpty(result))
            {
                // Check if template with given name already exists
                if (PageTemplateInfoProvider.PageTemplateNameExists(txtTemplateCodeName.Text))
                {
                    ShowError(GetString("general.codenameexists"));
                }

                bool templateCloned      = false;
                var  reusableOrInherited = pt.IsReusable || QueryHelper.GetBoolean("inherits", false);

                // Clone template when page template is reusable or inherited from the parent page or template shouldn't be assigned to the current page
                // Do not clone template when page template is ad-hoc and new template should be assigned to the current page
                if (reusableOrInherited || !chkKeep.Checked)
                {
                    // Clone template with clear
                    pt             = pt.Clone(true);
                    templateCloned = true;
                }

                // Moving an ad-hoc template to a reusable template
                if (!pt.IsReusable)
                {
                    // Transfer template layout from file system to the database object to ensure that the new layout file (created afterwards) will contain the correct content
                    pt.PageTemplateLayout = pt.PageTemplateLayout;
                }

                pt.CodeName    = txtTemplateCodeName.Text;
                pt.DisplayName = txtTemplateDisplayName.Text;
                pt.Description = txtTemplateDescription.Text;

                pt.CategoryID = Convert.ToInt32(categorySelector.Value);

                // Reset the Ad-hoc status
                pt.IsReusable           = true;
                pt.PageTemplateNodeGUID = Guid.Empty;

                pt.PageTemplateSiteID = 0;

                if (templateCloned)
                {
                    // After all properties were set, reset object original values in order to behave as a new object. This ensures that a new layout file is created and the original one is not deleted.
                    pt.ResetChanges();
                }

                try
                {
                    PageTemplateInfoProvider.SetPageTemplateInfo(pt);
                    int siteId = QueryHelper.GetInteger("siteid", 0);
                    if (siteId > 0)
                    {
                        PageTemplateInfoProvider.AddPageTemplateToSite(pt.PageTemplateId, siteId);
                    }

                    if (!chkKeep.Checked)
                    {
                        ShowInformation(GetString("PortalEngine.SaveNewPageTemplate.Saved"));

                        txtTemplateCodeName.Text = pt.CodeName;

                        pnlContent.Enabled = false;
                        btnOk.Visible      = false;
                    }
                    else
                    {
                        var documentId = QueryHelper.GetInteger("documentId", 0);
                        if (reusableOrInherited && (documentId > 0))
                        {
                            // Assign the new page template to the current document
                            AssignNewTemplateToDocument(documentId, pt.PageTemplateId);
                        }

                        RegisterPageTemplateSavedScript();
                    }
                }
                catch (Exception ex)
                {
                    ShowError(ex.Message);
                }
            }
            else
            {
                ShowError(result);
            }
        }
    }
Example #7
0
    /// <summary>
    /// Ensures the template from the selection and returns the template ID.
    /// </summary>
    /// <param name="documentName">Document name for the ad-hoc template</param>
    /// <param name="errorMessage">Returns the error message</param>
    public int EnsureTemplate(string documentName, ref string errorMessage)
    {
        int result = 0;

        // Template selection
        if (radUseTemplate.Checked)
        {
            // Template page
            int templateId = ValidationHelper.GetInteger(templateSelector.SelectedItem, 0);
            if (templateId > 0)
            {
                result = templateId;
            }
            else
            {
                errorMessage = GetString("NewPage.TemplateError");
            }
        }
        else if (radInherit.Checked)
        {
            // Inherited page
        }
        else if (radCreateBlank.Checked || radCreateEmpty.Checked)
        {
            // Create custom template info for the page
            PageTemplateInfo templateInfo = new PageTemplateInfo(true);

            // Prepare ad-hoc template name
            string displayName = "Ad-hoc: " + documentName;

            if (radCreateBlank.Checked)
            {
                // Blank page with layout
                int layoutId = ValidationHelper.GetInteger(layoutSelector.SelectedItem, 0);
                if (layoutId > 0)
                {
                    templateInfo.LayoutID = layoutId;

                    // Copy layout to selected template
                    if (chkLayoutPageTemplate.Checked)
                    {
                        templateInfo.LayoutID = 0;
                        LayoutInfo li = LayoutInfoProvider.GetLayoutInfo(layoutId);
                        if (li != null)
                        {
                            templateInfo.PageTemplateLayout     = li.LayoutCode;
                            templateInfo.PageTemplateLayoutType = li.LayoutType;
                        }
                        else
                        {
                            errorMessage = GetString("NewPage.LayoutError");
                        }
                    }
                }
                else
                {
                    errorMessage = GetString("NewPage.LayoutError");
                }
            }
            else if (radCreateEmpty.Checked)
            {
                // Empty template
                templateInfo.LayoutID               = 0;
                templateInfo.PageTemplateLayout     = "<cc1:CMSWebPartZone ID=\"zoneLeft\" runat=\"server\" />";
                templateInfo.PageTemplateLayoutType = LayoutTypeEnum.Ascx;
            }

            if (String.IsNullOrEmpty(errorMessage))
            {
                // Create ad-hoc template
                templateInfo = PageTemplateInfoProvider.CloneTemplateAsAdHoc(templateInfo, displayName, CMSContext.CurrentSiteID);

                // Set inherit only master
                templateInfo.InheritPageLevels = "\\";
                PageTemplateInfoProvider.SetPageTemplateInfo(templateInfo);

                if (CMSContext.CurrentSite != null)
                {
                    PageTemplateInfoProvider.AddPageTemplateToSite(templateInfo.PageTemplateId, CMSContext.CurrentSiteID);
                }

                // Assign the template to document
                result = templateInfo.PageTemplateId;
            }
        }

        // Reload the template selector in case of error
        if (!String.IsNullOrEmpty(errorMessage))
        {
            if (radUseTemplate.Checked)
            {
                templateSelector.ReloadData();
            }
        }

        return(result);
    }