コード例 #1
0
    /// <summary>
    /// Saves the layout.
    /// </summary>
    /// <returns>Returns true if successful</returns>
    private bool SaveLayout()
    {
        string codeName = tbCodeName.Text.Trim();

        // Find out whether required fields are not empty
        string result = new Validator()
                        .NotEmpty(codeName, GetString("Administration-PageLayout_New.ErrorEmptyLayoutCodeName"))
                        .NotEmpty(tbLayoutDisplayName.Text, GetString("Administration-PageLayout_New.ErrorEmptyLayoutDisplayName"))
                        .NotEmpty(tbLayoutCode.Text.Trim(), GetString("Administration-PageLayout_New.ErrorEmptyLayoutCode"))
                        .IsCodeName(codeName, GetString("general.invalidcodename"))
                        .Result;

        if (result == "")
        {
            if (li == null)
            {
                li = new LayoutInfo();
            }

            li.LayoutCodeName    = codeName;
            li.LayoutDisplayName = tbLayoutDisplayName.Text.Trim();
            li.LayoutDescription = tbLayoutDescription.Text;
            li.LayoutType        = LayoutInfoProvider.GetLayoutTypeEnum(this.drpType.SelectedValue);

            if (li.LayoutCheckedOutByUserID <= 0)
            {
                li.LayoutCode = tbLayoutCode.Text;
                li.LayoutCSS  = txtLayoutCSS.Text;
            }

            try
            {
                LayoutInfoProvider.SetLayoutInfo(li);
                lblInfo.Visible   = true;
                lblInfo.Text      = GetString("General.ChangesSaved");
                breadcrumbs[1, 0] = li.LayoutDisplayName;
            }
            catch (Exception ex)
            {
                lblInfo.Visible  = false;
                lblError.Visible = true;
                lblError.Text    = ex.Message.Replace("%%name%%", li.LayoutCodeName);
                return(false);
            }

            layoutId = li.LayoutId;

            UploadFile.ObjectID = layoutId;
            UploadFile.UploadFile();

            return(!UploadFile.SavingFailed);
        }
        else
        {
            lblError.Text    = result;
            lblError.Visible = true;
            return(false);
        }
    }
コード例 #2
0
    /// <summary>
    /// Save layout.
    /// </summary>
    public bool SaveLayout()
    {
        PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(templateId);

        if (pti != null)
        {
            if (radShared.Checked)
            {
                // Shared layout
                pnlCheckOutInfo.Visible = false;
                pti.LayoutID            = ValidationHelper.GetInteger(selectShared.Value, 0);
                pti.PageTemplateLayout  = "";
                pti.PageTemplateCSS     = "";
            }
            else
            {
                LayoutTypeEnum layoutType = LayoutInfoProvider.GetLayoutTypeEnum(this.drpType.SelectedValue);

                if ((layoutType != LayoutTypeEnum.Ascx) || user.IsAuthorizedPerResource("CMS.Design", "EditCode"))
                {
                    // Custom layout
                    pnlCheckOutInfo.Visible    = true;
                    pti.LayoutID               = 0;
                    pti.PageTemplateLayoutType = layoutType;
                    pti.PageTemplateLayout     = txtCustom.Text;
                    pti.PageTemplateCSS        = txtCustomCSS.Text;
                }
            }

            PageTemplateInfoProvider.SetPageTemplateInfo(pti);

            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");

            return(true);
        }

        return(false);
    }
コード例 #3
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if ((nodeId > 0) && (node != null))
        {
            LayoutTypeEnum layoutType = LayoutInfoProvider.GetLayoutTypeEnum(drpType.SelectedValue);

            // Check the permissions
            if ((layoutType != LayoutTypeEnum.Ascx) || user.IsAuthorizedPerResource("CMS.Design", "EditCode"))
            {
                // Update the layout
                if (node.DocumentPageTemplateID > 0)
                {
                    PageTemplateInfo pti = PageTemplateInfoProvider.GetPageTemplateInfo(node.DocumentPageTemplateID);
                    if (pti != null)
                    {
                        // Get shared layout
                        LayoutInfo li = LayoutInfoProvider.GetLayoutInfo(pti.LayoutID);
                        if (li != null)
                        {
                            // Update shared layout
                            li.LayoutCode = txtLayout.Text;
                            li.LayoutType = layoutType;

                            LayoutInfoProvider.SetLayoutInfo(li);
                        }
                        else if (pti.PageTemplateLayoutCheckedOutByUserID <= 0)
                        {
                            // Update custom layout
                            pti.PageTemplateLayout     = txtLayout.Text;
                            pti.PageTemplateLayoutType = layoutType;

                            PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                        }
                    }
                }
            }

            // Update fields
            node.NodeBodyElementAttributes = txtBodyCss.Text;
            node.NodeDocType  = txtDocType.Text;
            node.NodeHeadTags = txtHeadTags.Value.ToString();

            // Update the node
            node.Update();

            // Update search index
            if ((node.PublishedVersionExists) && (SearchIndexInfoProvider.SearchEnabled))
            {
                SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Update, PredefinedObjectType.DOCUMENT, SearchHelper.ID_FIELD, node.GetSearchID());
            }

            // Log synchronization
            DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree);

            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");

            // Clear cache
            PageInfoProvider.RemoveAllPageInfosFromCache();
        }
    }
コード例 #4
0
ファイル: EditLayout.ascx.cs プロジェクト: kudutest2/Kentico
    /// <summary>
    /// Saves the layout code.
    /// </summary>
    /// <returns>Returns true if save successful</returns>
    private bool SaveLayout()
    {
        LayoutInfo       li  = this.PagePlaceholder.LayoutInfo;
        PageTemplateInfo pti = this.PagePlaceholder.PageTemplateInfo;

        if ((li != null) || (pti != null))
        {
            string mPath = "";
            if ((HttpContext.Current != null) && (HttpContext.Current.Server != null))
            {
                mPath = HttpContext.Current.Server.UrlPathEncode(URLHelper.ApplicationPath);
            }

            LayoutTypeEnum layoutType = LayoutInfoProvider.GetLayoutTypeEnum(this.drpType.SelectedValue);

            // Check the permissions
            if ((layoutType != LayoutTypeEnum.Ascx) || user.IsAuthorizedPerResource("CMS.Design", "EditCode"))
            {
                if (li != null)
                {
                    // Shared layout
                    li.LayoutType = layoutType;
                    li.LayoutCode = HTMLHelper.UnResolveUrls(this.txtLayout.Text, mPath);

                    LayoutInfoProvider.SetLayoutInfo(li);
                }
                else
                {
                    // Custom layout
                    pti.PageTemplateLayoutType = layoutType;
                    pti.PageTemplateLayout     = HTMLHelper.UnResolveUrls(this.txtLayout.Text, mPath);

                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
            }
            this.lblLayoutInfo.Text = ResHelper.GetString("General.ChangesSaved", culture);

            // Resave page template XML
            if (layoutType == LayoutTypeEnum.Ascx)
            {
                PageTemplateInfo ti = this.PagePlaceholder.PageInfo.PageTemplateInfo;
                if ((ti != null) && (ti.PageTemplateId > 0))
                {
                    try
                    {
                        // Load the layout
                        CMSAbstractLayout layout = (CMSAbstractLayout)this.Page.LoadControl(LayoutInfoProvider.GetLayoutUrl(li.LayoutCodeName, li.LayoutVersionGUID));
                        layout.ID = "abstractLayout";

                        // Remove zones without web parts
                        ArrayList removeZones = new ArrayList();
                        foreach (WebPartZoneInstance zone in ti.WebPartZones)
                        {
                            if (zone.WebParts.Count <= 0)
                            {
                                removeZones.Add(zone);
                            }
                        }
                        foreach (WebPartZoneInstance zone in removeZones)
                        {
                            ti.WebPartZones.Remove(zone);
                        }

                        // Ensure all zones
                        foreach (DictionaryEntry zone in layout.WebPartZones)
                        {
                            ti.EnsureZone(((CMSWebPartZone)zone.Value).ID);
                        }

                        this.Controls.Remove(layout);

                        // Save the page template
                        PageTemplateInfoProvider.SetPageTemplateInfo(ti);
                    }
                    catch
                    {
                    }
                }
            }

            return(true);
        }
        else
        {
            return(false);
        }
    }