예제 #1
0
    /// <summary>
    /// Gets and bulk updates web part layouts. Called when the "Get and bulk update layouts" button is pressed.
    /// Expects the CreateWebPartLayout method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWebPartLayouts()
    {
        // Prepare the parameters
        string where = "WebPartLayoutCodeName LIKE N'MyNewLayout%'";

        // Get the data
        DataSet layouts = WebPartLayoutInfoProvider.GetWebPartLayouts(where, null);

        if (!DataHelper.DataSourceIsEmpty(layouts))
        {
            // Loop through the individual items
            foreach (DataRow layoutDr in layouts.Tables[0].Rows)
            {
                // Create object from DataRow
                WebPartLayoutInfo modifyLayout = new WebPartLayoutInfo(layoutDr);

                // Update the properties
                modifyLayout.WebPartLayoutDisplayName = modifyLayout.WebPartLayoutDisplayName.ToUpper();

                // Save the changes
                WebPartLayoutInfoProvider.SetWebPartLayoutInfo(modifyLayout);
            }

            return(true);
        }

        return(false);
    }
예제 #2
0
    protected override void CreateChildControls()
    {
        ucHierarchy.DialogMode    = RequiresDialog;
        ucHierarchy.DisplayFooter = RequiresDialog;

        int layoutId           = QueryHelper.GetInteger("layoutid", 0);
        WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);

        if (wpli != null)
        {
            ucHierarchy.PreviewObjectName = wpli.WebPartLayoutCodeName;
            ucHierarchy.PreviewURLSuffix  = "&previewobjectidentifier=" + wpli.WebPartLayoutCodeName;
        }
        else
        {
            ShowError(GetString("editedobject.notexists"));
        }

        if (layoutId != 0)
        {
            EditedObject = wpli;
        }

        base.CreateChildControls();
    }
예제 #3
0
    /// <summary>
    /// Check out.
    /// </summary>
    protected void btnCheckOut_Click(object sender, EventArgs e)
    {
        // Ensure version before check-out
        using (CMSActionContext context = new CMSActionContext())
        {
            context.AllowAsyncActions = false;

            SetCurrentLayout(false, true);
        }

        try
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (wpi != null)
            {
                WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                if (wpli != null)
                {
                    SiteManagerFunctions.CheckOutWebPartLayout(wpli.WebPartLayoutID);
                }
            }
        }
        catch (Exception ex)
        {
            this.lblError.Text    = GetString("WebPartLayout.ErrorCheckout") + ": " + ex.Message;
            this.lblError.Visible = true;
            return;
        }

        SetCheckPanel(null);
    }
예제 #4
0
    /// <summary>
    /// Check in.
    /// </summary>
    protected void btnCheckIn_Click(object sender, EventArgs e)
    {
        try
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (wpi != null)
            {
                WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                if (wpli != null)
                {
                    SiteManagerFunctions.CheckInWebPartLayout(wpli.WebPartLayoutID);
                    etaCode.ReadOnly = false;
                    etaCode.Enabled  = true;
                    etaCSS.ReadOnly  = false;
                    etaCSS.Enabled   = true;
                }
            }
        }
        catch (Exception ex)
        {
            this.lblError.Text    = GetString("WebPartLayout.ErrorCheckin") + ": " + ex.Message;
            this.lblError.Visible = true;
            return;
        }


        SetCheckPanel(null);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = "Web part layout properties";

        // Get the layout
        layoutId = QueryHelper.GetInteger("layoutId", 0);
        wpli     = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);
        if (wpli != null)
        {
            wpi = WebPartInfoProvider.GetWebPartInfo(wpli.WebPartLayoutWebPartID);
        }

        // Init GUI
        mCheckOut     = GetString("WebPartLayout.CheckOut");
        mCheckIn      = GetString("WebPartLayout.CheckIn");
        mUndoCheckOut = GetString("WebPartLayout.DiscardCheckOut");
        mSave         = GetString("General.Save");

        lblDisplayName.Text = GetString("WebPartEditLayoutEdit.lblDisplayName");
        lblCodeName.Text    = GetString("WebPartEditLayoutEdit.lblCodeName");
        lblCode.Text        = GetString("WebPartEditLayoutEdit.lblCode");
        lblDescription.Text = GetString("WebPartEditLayoutEdit.lblDescription");

        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        rfvCodeName.ErrorMessage    = GetString("webparteditlayoutedit.rfvcodenamerequired");

        LoadData();

        this.plcCssLink.Visible = String.IsNullOrEmpty(tbCSS.Text.Trim());
    }
예제 #6
0
    /// <summary>
    /// Saves the form data.
    /// </summary>
    private void Save()
    {
        // Remove "." due to virtual path provider replacement
        txtCodeName.Text = txtCodeName.Text.Replace(".", "");

        txtDisplayName.Text = txtDisplayName.Text.Trim();
        txtCodeName.Text    = txtCodeName.Text.Trim();

        string errorMessage = new Validator()
                              .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage)
                              .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage)
                              .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename"))
                              .Result;

        if (errorMessage != String.Empty)
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
            return;
        }

        // Check web part id
        int         webPartId = QueryHelper.GetInteger("webpartId", 0);
        WebPartInfo wpi       = WebPartInfoProvider.GetWebPartInfo(webPartId);

        if (wpi == null)
        {
            lblError.Text    = GetString("WebPartEditLayoutNew.InvalidWebPartID");
            lblError.Visible = true;
            return;
        }

        // Check web part layout code name
        WebPartLayoutInfo tempwpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, txtCodeName.Text);

        if (tempwpli != null)
        {
            lblError.Text    = GetString("WebPartEditLayoutNew.CodeNameAlreadyExist");
            lblError.Visible = true;
            return;
        }


        // Create and fill info structure
        WebPartLayoutInfo wpli = new WebPartLayoutInfo();

        wpli.WebPartLayoutID          = 0;
        wpli.WebPartLayoutCodeName    = txtCodeName.Text;
        wpli.WebPartLayoutDisplayName = txtDisplayName.Text;
        wpli.WebPartLayoutCode        = tbCode.Text;
        wpli.WebPartLayoutCSS         = tbCSS.Text;
        wpli.WebPartLayoutDescription = txtDescription.Text;
        wpli.WebPartLayoutWebPartID   = webPartId;

        WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);

        URLHelper.Redirect("WebPart_Edit_Layout_Frameset.aspx?layoutID=" + wpli.WebPartLayoutID + "&webpartID=" + webPartId);
    }
    protected override void OnPreInit(EventArgs e)
    {
        WebPartInstance webPart = null;

        // Check permissions for web part properties UI
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerUIElement("CMS.Design", "WebPartProperties.Layout"))
        {
            RedirectToUIElementAccessDenied("CMS.Design", "WebPartProperties.Layout");
        }

        if (webpartId != "")
        {
            // Get pageinfo
            PageInfo pi = GetPageInfo(aliasPath, templateId, cultureCode);
            if (pi == null)
            {
                return;
            }

            // Get page template
            PageTemplateInfo pti = pi.UsedPageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.TemplateInstance.GetWebPart(webpartId);
            }

        }

        if (webPart != null)
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            layoutCodeName = QueryHelper.GetString("layoutcodename", String.Empty);

            if (String.IsNullOrEmpty(layoutCodeName))
            {
                // Get the current layout name
                layoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }

            if (wpi != null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, layoutCodeName);
                if (wpli != null)
                {
                    if ((layoutCodeName != "|default|") && (layoutCodeName != "|new|") && !QueryHelper.GetBoolean("tabmode", false))
                    {
                        string url = UIContextHelper.GetElementUrl("CMS.Design", "Design.WebPartProperties.LayoutEdit", false, wpli.WebPartLayoutID);
                        url = URLHelper.AppendQuery(url, RequestContext.CurrentQueryString);
                        url = URLHelper.AddParameterToUrl(url, "tabmode", "1");
                        URLHelper.Redirect(url);
                    }
                }
            }
        }
        base.OnPreInit(e);
    }
예제 #8
0
    /// <summary>
    /// Deletes web part layout. Called when the "Delete layout" button is pressed.
    /// Expects the CreateWebPartLayout method to be run first.
    /// </summary>
    private bool DeleteWebPartLayout()
    {
        // Get the web part layout
        WebPartLayoutInfo deleteLayout = WebPartLayoutInfoProvider.GetWebPartLayoutInfo("MyNewWebpart", "MyNewLayout");

        // Delete the web part layout
        WebPartLayoutInfoProvider.DeleteWebPartLayoutInfo(deleteLayout);

        return(deleteLayout != null);
    }
    protected override void OnPreInit(EventArgs e)
    {
        WebPartInstance webPart = null;

        // Check permissions for web part properties UI
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerUIElement("CMS.Design", "WebPartProperties.Layout"))
        {
            RedirectToUIElementAccessDenied("CMS.Design", "WebPartProperties.Layout");
        }

        if (webpartId != "")
        {
            // Get pageinfo
            PageInfo pi = GetPageInfo(aliasPath, templateId, cultureCode);
            if (pi == null)
            {
                return;
            }

            // Get page template
            PageTemplateInfo pti = pi.UsedPageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.TemplateInstance.GetWebPart(webpartId);
            }
        }

        if (webPart != null)
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            layoutCodeName = QueryHelper.GetString("layoutcodename", String.Empty);

            if (String.IsNullOrEmpty(layoutCodeName))
            {
                // Get the current layout name
                layoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }

            if (wpi != null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, layoutCodeName);
                if (wpli != null)
                {
                    if ((layoutCodeName != "|default|") && (layoutCodeName != "|new|") && !QueryHelper.GetBoolean("tabmode", false))
                    {
                        string url = UIContextHelper.GetElementUrl("CMS.Design", "Design.WebPartProperties.LayoutEdit", false, wpli.WebPartLayoutID);
                        url = URLHelper.AppendQuery(url, RequestContext.CurrentQueryString);
                        url = URLHelper.AddParameterToUrl(url, "tabmode", "1");
                        URLHelper.Redirect(url);
                    }
                }
            }
        }
        base.OnPreInit(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions for web part properties UI
        var currentUser = MembershipContext.AuthenticatedUser;

        if (!currentUser.IsAuthorizedPerUIElement("CMS.Design", "WebPartProperties.Layout"))
        {
            RedirectToUIElementAccessDenied("CMS.Design", "WebPartProperties.Layout");
        }

        WebPartInstance webPart = null;

        if (webpartId != "")
        {
            // Get pageinfo
            PageInfo pi = GetPageInfo(aliasPath, templateId, cultureCode);
            if (pi != null)
            {
                // Get page template
                PageTemplateInfo pti = pi.UsedPageTemplateInfo;

                // Get web part
                if ((pti != null) && ((pti.TemplateInstance != null)))
                {
                    webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.TemplateInstance.GetWebPart(webpartId);
                }
            }
        }

        // If the web part is not found, do not continue
        if (webPart != null)
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (wpi != null)
            {
                // Get the current layout name
                if (String.IsNullOrEmpty(LayoutCodeName))
                {
                    // Get the current layout name
                    LayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
                }

                // Load the web part information
                if (LayoutCodeName != "")
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                    SetEditedObject(wpli, null);
                }
            }
        }

        // Set page tabs
        InitTabs("webpartlayoutcontent");
        SetTab(0, GetString("general.general"), "webpartproperties_layout.aspx" + RequestContext.CurrentQueryString, null);
    }
    protected override void OnPreInit(EventArgs e)
    {
        WebPartInstance webPart = null;

        // Check permissions for web part properties UI
        if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", "WebPartProperties.Layout"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "WebPartProperties.Layout");
        }

        if (webpartId != "")
        {
            // Get pageinfo
            PageInfo pi = GetPageInfo(aliasPath, templateId, cultureCode);
            if (pi == null)
            {
                return;
            }

            // Get page template
            PageTemplateInfo pti = pi.UsedPageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.GetWebPart(webpartId);
            }

        }

        if (webPart != null)
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            layoutCodeName = QueryHelper.GetString("layoutcodename", String.Empty);

            if (String.IsNullOrEmpty(layoutCodeName))
            {
                // Get the current layout name
                layoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }

            if (wpi != null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, layoutCodeName);
                if (wpli != null)
                {
                    if ((layoutCodeName != "|default|") && (layoutCodeName != "|new|"))
                    {
                        SetEditedObject(wpli, "WebPartProperties_layout_frameset_frameset.aspx");
                    }
                }
            }
        }

        base.OnPreInit(e);
    }
    protected override void OnPreInit(EventArgs e)
    {
        WebPartInstance webPart = null;

        // Check permissions for web part properties UI
        if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", "WebPartProperties.Layout"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "WebPartProperties.Layout");
        }

        if (webpartId != "")
        {
            // Get pageinfo
            PageInfo pi = GetPageInfo(aliasPath, templateId, cultureCode);
            if (pi == null)
            {
                return;
            }

            // Get page template
            PageTemplateInfo pti = pi.UsedPageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.GetWebPart(webpartId);
            }
        }

        if (webPart != null)
        {
            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            layoutCodeName = QueryHelper.GetString("layoutcodename", String.Empty);

            if (String.IsNullOrEmpty(layoutCodeName))
            {
                // Get the current layout name
                layoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }

            if (wpi != null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, layoutCodeName);
                if (wpli != null)
                {
                    if ((layoutCodeName != "|default|") && (layoutCodeName != "|new|"))
                    {
                        SetEditedObject(wpli, "WebPartProperties_layout_frameset_frameset.aspx");
                    }
                }
            }
        }

        base.OnPreInit(e);
    }
예제 #13
0
    /// <summary>
    /// Handles the OnBeforeSave event of the EditForm control.
    /// </summary>
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Remove "." due to virtual path provider replacement
        txtCodeName.Text = txtCodeName.Text.Replace(".", "");

        WebPartLayoutInfo li = EditForm.EditedObject as WebPartLayoutInfo;

        if (li != null)
        {
            if (webPartInfo != null)
            {
                li.WebPartLayoutWebPartID = webPartInfo.WebPartID;
            }
        }
    }
예제 #14
0
    /// <summary>
    /// Gets and updates web part layout. Called when the "Get and update layout" button is pressed.
    /// Expects the CreateWebPartLayout method to be run first.
    /// </summary>
    private bool GetAndUpdateWebPartLayout()
    {
        // Get the web part layout
        WebPartLayoutInfo updateLayout = WebPartLayoutInfoProvider.GetWebPartLayoutInfo("MyNewWebpart", "MyNewLayout");

        if (updateLayout != null)
        {
            // Update the properties
            updateLayout.WebPartLayoutDisplayName = updateLayout.WebPartLayoutDisplayName.ToLower();

            // Save the changes
            WebPartLayoutInfoProvider.SetWebPartLayoutInfo(updateLayout);

            return(true);
        }

        return(false);
    }
예제 #15
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        WebPartLayoutInfo wpli = EditedObject as WebPartLayoutInfo;

        if (!isDialog)
        {
            InitBreadcrumbs(2);
            SetBreadcrumb(0, GetString("WebParts.Layout"), ResolveUrl("~/CMSModules/PortalEngine/UI/Webparts/Development/WebPart_Edit_Layout.aspx") + URLHelper.Url.Query, "_parent", null);
            SetBreadcrumb(1, wpli.WebPartLayoutDisplayName, null, null, null);
        }

        if (!StorageHelper.IsExternalStorage(wpli.GetThemePath()))
        {
            SetTab(0, GetString("general.general"), "WebPart_Edit_Layout_Edit.aspx" + URLHelper.Url.Query, "SetHelpTopic('helpTopic', 'newedit_webpart_layout');");
            SetTab(1, GetString("stylesheet.theme"), "WebPart_Edit_Layout_Theme.aspx" + URLHelper.Url.Query, "SetHelpTopic('helpTopic', 'webpart_layout_theme');");
        }
    }
예제 #16
0
    /// <summary>
    /// Retrieves the stylesheets of the web part layout from the database.
    /// </summary>
    /// <param name="layoutFullName">Layout full name</param>
    /// <returns>The stylesheet data (plain version only)</returns>
    private static CMSOutputResource GetWebPartLayout(string layoutFullName)
    {
        WebPartLayoutInfo layoutInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutFullName);

        if (layoutInfo == null)
        {
            return(null);
        }

        // Build the result
        CMSOutputResource resource = new CMSOutputResource()
        {
            Data         = HTMLHelper.ResolveCSSUrls(layoutInfo.WebPartLayoutCSS, URLHelper.ApplicationPath),
            LastModified = layoutInfo.WebPartLayoutLastModified,
            Etag         = layoutInfo.WebPartLayoutFullName
        };

        return(resource);
    }
예제 #17
0
    /// <summary>
    /// Handles the OnBeforeSave event of the EditForm control.
    /// </summary>
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Remove "." due to virtual path provider replacement
        txtCodeName.Text = txtCodeName.Text.Replace(".", "");

        WebPartLayoutInfo li = EditForm.EditedObject as WebPartLayoutInfo;

        if (li != null)
        {
            if (!currentUser.IsAuthorizedPerResource("CMS.Design", "EditCode"))
            {
                li.WebPartLayoutCode = GetDefaultCode();
            }

            if (webPartInfo != null)
            {
                li.WebPartLayoutWebPartID = webPartInfo.WebPartID;
            }
        }
    }
예제 #18
0
    /// <summary>
    /// Creates web part layout. Called when the "Create layout" button is pressed.
    /// </summary>
    private bool CreateWebPartLayout()
    {
        // Get the web part
        WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo("MyNewWebpart");

        if (webpart != null)
        {
            // Create new web part layout object
            WebPartLayoutInfo newLayout = new WebPartLayoutInfo();

            // Set the properties
            newLayout.WebPartLayoutDisplayName = "My new layout";
            newLayout.WebPartLayoutCodeName    = "MyNewLayout";
            newLayout.WebPartLayoutWebPartID   = webpart.WebPartID;
            newLayout.WebPartLayoutCode        = "This is the new layout of MyNewWebpart webpart.";

            // Save the web part layout
            WebPartLayoutInfoProvider.SetWebPartLayoutInfo(newLayout);

            return(true);
        }
        return(false);
    }
예제 #19
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Setup the file system browser
        int layoutId  = QueryHelper.GetInteger("layoutid", 0);
        int webPartId = QueryHelper.GetInteger("webpartid", 0);

        if ((webPartId > 0) && (layoutId > 0))
        {
            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);
            EditedObject = wpli;

            if (wpli != null)
            {
                // Ensure the theme folder
                themeElem.Path = wpli.GetThemePath();
            }
        }
        else
        {
            EditedObject = null;
        }
    }
예제 #20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Setup the filesystem browser
        int layoutId  = QueryHelper.GetInteger("layoutid", 0);
        int webPartId = QueryHelper.GetInteger("webpartid", 0);

        if ((webPartId > 0) && (layoutId > 0))
        {
            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);
            EditedObject = wpli;

            WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPartId);

            if ((wpli != null) && (wpi != null))
            {
                // Ensure the theme folder
                themeElem.Path = "~/App_Themes/Components/WebParts/" + ValidationHelper.GetSafeFileName(wpi.WebPartName) + "/Layouts/" + ValidationHelper.GetSafeFileName(wpli.WebPartLayoutCodeName);
            }
        }
        else
        {
            EditedObject = null;
        }
    }
    /// <summary>
    /// Sets check out/in/undo panel
    /// </summary>
    protected void SetCheckPanel(WebPartLayoutInfo mwpli)
    {
        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
        WebPartLayoutInfo wpli = mwpli;
        if (wpi != null)
        {
            if (wpli == null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
            }
        }

        if (wpli != null)
        {
            this.pnlCheckOutInfo.Visible = true;

            if (wpli.WebPartLayoutCheckedOutByUserID > 0)
            {
                etaCode.ReadOnly = true;
                etaCSS.ReadOnly = true;

                string username = null;
                UserInfo ui = UserInfoProvider.GetUserInfo(wpli.WebPartLayoutCheckedOutByUserID);
                if (ui != null)
                {
                    username = HTMLHelper.HTMLEncode(ui.FullName);
                }

                plcCheckOut.Visible = false;

                // Checked out by current machine
                if (wpli.WebPartLayoutCheckedOutMachineName.ToLower() == HTTPHelper.MachineName.ToLower())
                {
                    this.plcCheckIn.Visible = true;

                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOut"), Server.MapPath(wpli.WebPartLayoutCheckedOutFilename));
                }
                else
                {
                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOutOnAnotherMachine"), wpli.WebPartLayoutCheckedOutMachineName, username);
                }

                if (CMSContext.CurrentUser.IsGlobalAdministrator)
                {
                    this.plcUndoCheckOut.Visible = true;
                }
            }
            else
            {
                wpi = WebPartInfoProvider.GetWebPartInfo(wpli.WebPartLayoutWebPartID);
                if (wpi != null)
                {
                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckOutInfo"), Server.MapPath(WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, wpli.WebPartLayoutCodeName, null)));

                    this.plcCheckOut.Visible = true;
                    this.plcCheckIn.Visible = false;
                    this.plcUndoCheckOut.Visible = false;
                }
            }
        }
    }
    /// <summary>
    /// Saves the form data.
    /// </summary>
    private void Save()
    {
        // Remove "." due to virtual path provider replacement
        txtCodeName.Text = txtCodeName.Text.Replace(".", "");

        txtDisplayName.Text = txtDisplayName.Text.Trim();
        txtCodeName.Text = txtCodeName.Text.Trim();

        string errorMessage = new Validator()
            .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage)
            .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage)
            .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename"))
            .Result;

        if (errorMessage != String.Empty)
        {
            lblError.Text = errorMessage;
            lblError.Visible = true;
            return;
        }

        // Check web part id
        int webPartId = QueryHelper.GetInteger("webpartId", 0);
        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPartId);
        if (wpi == null)
        {
            lblError.Text = GetString("WebPartEditLayoutNew.InvalidWebPartID");
            lblError.Visible = true;
            return;
        }

        // Check web part layout code name
        WebPartLayoutInfo tempwpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, txtCodeName.Text);
        if (tempwpli != null)
        {
            lblError.Text = GetString("WebPartEditLayoutNew.CodeNameAlreadyExist");
            lblError.Visible = true;
            return;
        }

        // Create and fill info structure
        WebPartLayoutInfo wpli = new WebPartLayoutInfo();

        wpli.WebPartLayoutID = 0;
        wpli.WebPartLayoutCodeName = txtCodeName.Text;
        wpli.WebPartLayoutDisplayName = txtDisplayName.Text;
        wpli.WebPartLayoutCode = tbCode.Text;
        wpli.WebPartLayoutCSS = tbCSS.Text;
        wpli.WebPartLayoutDescription = txtDescription.Text;
        wpli.WebPartLayoutWebPartID = webPartId;

        WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);

        URLHelper.Redirect("WebPart_Edit_Layout_Frameset.aspx?layoutID=" + wpli.WebPartLayoutID + "&webpartID=" + webPartId);
    }
예제 #23
0
    /// <summary>
    /// Selected index changed.
    /// </summary>
    private void InitLayoutForm()
    {
        if (webPartInfo != null)
        {
            if (!String.IsNullOrEmpty(LayoutCodeName))
            {
                if (LayoutCodeName == "|new|")
                {
                    // New layout
                    plcDescription.Visible  = true;
                    plcValues.Visible       = true;
                    etaCode.ReadOnly        = false;
                    etaCSS.ReadOnly         = false;
                    etaCode.Rows            = 19;
                    pnlMenu.Visible         = false;
                    pnlCheckOutInfo.Visible = false;

                    // Prefill with default layout
                    etaCode.Text = GetDefaultCode();
                }
                else
                {
                    etaCode.Rows           = 24;
                    plcDescription.Visible = false;
                    plcValues.Visible      = false;
                    etaCode.ReadOnly       = false;

                    if (LayoutCodeName == "|default|")
                    {
                        // Get default code and disable editing
                        etaCode.Text = GetDefaultCode();

                        etaCode.ReadOnly = true;
                        etaCSS.ReadOnly  = true;
                        etaCSS.Text      = webPartInfo.WebPartCSS;

                        pnlMenu.Visible         = false;
                        pnlCheckOutInfo.Visible = false;
                    }
                    else
                    {
                        // Other layouts
                        etaCode.Rows = 18;

                        pnlMenu.Visible         = true;
                        pnlCheckOutInfo.Visible = true;
                        etaCode.Text            = "Loading...";

                        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
                        if (wpi != null)
                        {
                            // Get the layout code from layout info
                            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                            if (wpli != null)
                            {
                                SetCheckPanel(null);

                                etaCode.Text    = wpli.WebPartLayoutCode;
                                etaCSS.ReadOnly = false;
                                etaCSS.Text     = wpli.WebPartLayoutCSS;
                            }
                        }
                    }
                }
            }
        }
        else
        {
        }
    }
    /// <summary>
    /// Handles the OnAfterAction event of the ObjectManager control.
    /// </summary>
    protected void ObjectManager_OnAfterAction(object sender, SimpleObjectManagerEventArgs e)
    {
        wpli = EditForm.EditedObject as WebPartLayoutInfo;

        if ((wpli == null) || (wpli.WebPartLayoutID <= 0) || (!e.IsValid))
        {
            // Do not continue if the object has not been created
            return;
        }

        LayoutCodeName = wpli.WebPartLayoutCodeName;

        if (e.ActionName == ComponentEvents.SAVE)
        {
            if (EditForm.ValidateData())
            {
                if (!isSiteManager)
                {
                    SetCurrentLayout(true);
                }

                if (ValidationHelper.GetBoolean(hdnClose.Value, false))
                {
                    // If window to close, register close script
                    CloseDialog();
                }
                else
                {
                    // Redirect parent for new
                    if (isNew)
                    {
                        if (isSiteManager)
                        {
                            URLHelper.Redirect(String.Format("{0}&parentobjectid={1}&objectid={2}&displaytitle={3}",
                                UIContextHelper.GetElementUrl("CMS.Design", "Edit.WebPartLayout"), webPartInfo.WebPartID, wpli.WebPartLayoutID, false));
                        }
                        else
                        {
                            var codeName = (wpli != null) ? wpli.WebPartLayoutCodeName : string.Empty;
                            var redirectUrl = ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/WebPartProperties_layout_frameset.aspx") + URLHelper.UpdateParameterInUrl(RequestContext.CurrentQueryString, "layoutcodename", codeName);
                            ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "RefreshHeader", ScriptHelper.GetScript("parent.location ='" + redirectUrl + "'"));

                            // Reload the parent page after save
                            EnsureParentPageRefresh();
                        }
                    }
                    else
                    {
                        if (!isSiteManager)
                        {
                            // Reload the parent page after save
                            EnsureParentPageRefresh();
                        }

                        // If all ok show changes saved
                        RegisterRefreshScript();
                    }
                }
            }

            // Clear warning text
            editMenuElem.MessagesPlaceHolder.WarningText = "";
        }

        if (DialogMode)
        {
            switch (e.ActionName)
            {
                case ComponentEvents.SAVE:
                case ComponentEvents.CHECKOUT:
                case ComponentEvents.UNDO_CHECKOUT:
                case ComponentEvents.CHECKIN:
                    ScriptHelper.RegisterStartupScript(Page, typeof(string), "wopenerRefresh", ScriptHelper.GetScript("if (wopener && wopener.refresh) { wopener.refresh(); }"));
                    break;
            }
        }

        if (isSiteManager && (e.ActionName != ComponentEvents.CHECKOUT) && EditForm.DisplayNameChanged)
        {
            ScriptHelper.RegisterClientScriptBlock(Page, typeof(String), "RefreshBreadcrumbs", ScriptHelper.GetScript("if (parent.refreshBreadcrumbs != null && parent.document.pageLoaded) {parent.refreshBreadcrumbs('" + ResHelper.LocalizeString(EditForm.EditedObject.Generalized.ObjectDisplayName) + "')}"));
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = "Web part layout properties";

        // Get the layout
        layoutId = QueryHelper.GetInteger("layoutId", 0);
        wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);
        if (wpli != null)
        {
            wpi = WebPartInfoProvider.GetWebPartInfo(wpli.WebPartLayoutWebPartID);
        }

        // Init GUI
        mCheckOut = GetString("WebPartLayout.CheckOut");
        mCheckIn = GetString("WebPartLayout.CheckIn");
        mUndoCheckOut = GetString("WebPartLayout.DiscardCheckOut");
        mSave = GetString("General.Save");

        lblDisplayName.Text = GetString("WebPartEditLayoutEdit.lblDisplayName");
        lblCodeName.Text = GetString("WebPartEditLayoutEdit.lblCodeName");
        lblCode.Text = GetString("WebPartEditLayoutEdit.lblCode");
        lblDescription.Text = GetString("WebPartEditLayoutEdit.lblDescription");

        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        rfvCodeName.ErrorMessage = GetString("webparteditlayoutedit.rfvcodenamerequired");

        LoadData();

        this.plcCssLink.Visible = String.IsNullOrEmpty(tbCSS.Text.Trim());
    }
    /// <summary>
    /// Save new layout.
    /// </summary>
    protected bool Save()
    {
        if (webPartInfo != null)
        {
            // Remove "." due to virtual path provider replacement
            txtLayoutName.Text = txtLayoutName.Text.Replace(".", "");

            string result = new Validator().NotEmpty(txtLayoutName.Text, GetString("WebPartPropertise.errCodeName")).NotEmpty(txtLayoutDisplayName.Text, GetString("WebPartPropertise.errDisplayName")).IsCodeName(txtLayoutName.Text, GetString("WebPartPropertise.errCodeNameFormat")).Result;

            if (result == "")
            {
                WebPartLayoutInfo tmpLayInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(webPartInfo.WebPartName, txtLayoutName.Text.Trim());
                if (tmpLayInfo == null)
                {
                    WebPartLayoutInfo wpli = new WebPartLayoutInfo();

                    wpli.WebPartLayoutCodeName = txtLayoutName.Text.Trim();

                    wpli.WebPartLayoutDescription = txtDescription.Text;
                    wpli.WebPartLayoutDisplayName = txtLayoutDisplayName.Text;

                    if (CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode"))
                    {
                        wpli.WebPartLayoutCode = etaCode.Text;
                    }
                    else
                    {
                        wpli.WebPartLayoutCode = GetDefaultCode();
                    }

                    wpli.WebPartLayoutCSS = etaCSS.Text;
                    wpli.WebPartLayoutWebPartID = webPartInfo.WebPartID;

                    WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);

                    LayoutCodeName = wpli.WebPartLayoutCodeName;

                    txtDescription.Text = "";
                    txtLayoutDisplayName.Text = "";
                    txtLayoutName.Text = "";

                    plcDescription.Visible = false;
                    plcValues.Visible = false;
                    etaCode.Rows = 17;

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

                    pnlMenu.Visible = true;
                    pnlCheckOutInfo.Visible = true;
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text = GetString("WebPartPropertise.CodeNameAllreadyExists");
                    etaCode.Rows = 17;
                    return false;
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text = result;
                etaCode.Rows = 17;
                return false;
            }
        }

        return true;
    }
예제 #27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        StringSafeDictionary <object> decodedProperties = new StringSafeDictionary <object>();

        foreach (DictionaryEntry param in Properties)
        {
            // Decode special CK editor char
            String str = String.Empty;
            if (param.Value != null)
            {
                str = param.Value.ToString().Replace("%25", "%");
            }

            decodedProperties[(string)param.Key] = HttpUtility.UrlDecode(str);
        }
        Properties = decodedProperties;

        string widgetName = ValidationHelper.GetString(Properties["name"], String.Empty);

        // Widget name must be specified
        if (String.IsNullOrEmpty(widgetName))
        {
            AddErrorWebPart("widgets.invalidname", null);
            return;
        }

        WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(widgetName);

        if (wi == null)
        {
            AddErrorWebPart("widget.failedtoload", null);
            return;
        }

        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(wi.WidgetWebPartID);

        if (wpi == null)
        {
            return;
        }

        //no widgets can be used as inline
        if (!wi.WidgetForInline)
        {
            AddErrorWebPart("widgets.cantbeusedasinline", null);
            return;
        }

        try
        {
            FormInfo fi = null;
            DataRow  dr = null;

            using (var cs = new CachedSection <FormInfo>(ref fi, 1440, (PortalContext.ViewMode == ViewModeEnum.LiveSite), null, "inlinewidgetcontrol", wi.WidgetID, wpi.WebPartID))
            {
                if (cs.LoadData)
                {
                    // Merge widget and it's parent webpart properties
                    string props = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);

                    // Prepare form
                    const WidgetZoneTypeEnum zoneType = WidgetZoneTypeEnum.Editor;
                    fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, zoneType, props, true, wi.WidgetDefaultValues);

                    // Apply changed values
                    dr = fi.GetDataRow();
                    fi.LoadDefaultValues(dr);

                    if (cs.Cached)
                    {
                        cs.CacheDependency = CacheHelper.GetCacheDependency("cms.webpart|byid|" + wpi.WebPartID + "\n" + "cms.widget|byid|" + wi.WidgetID);
                    }

                    cs.Data = fi;
                }
            }

            // Get datarow
            if (dr == null)
            {
                dr = fi.GetDataRow();
                fi.LoadDefaultValues(dr);
            }

            // Incorporate inline parameters to datarow
            string publicFields = ";containertitle;container;";
            if (wi.WidgetPublicFileds != null)
            {
                publicFields += ";" + wi.WidgetPublicFileds.ToLowerCSafe() + ";";
            }

            // Load the widget control
            string url = null;

            // Set widget layout
            WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wi.WidgetLayoutID);

            if (wpli != null)
            {
                // Load specific layout through virtual path
                url = wpli.Generalized.GetVirtualFileRelativePath(WebPartLayoutInfo.EXTERNAL_COLUMN_CODE, wpli.WebPartLayoutVersionGUID);
            }
            else
            {
                // Load regularly
                url = WebPartInfoProvider.GetWebPartUrl(wpi, false);
            }

            CMSAbstractWebPart control = (CMSAbstractWebPart)Page.LoadUserControl(url);
            control.PartInstance = new WebPartInstance();

            // Use current page placeholder
            control.PagePlaceholder = PortalHelper.FindParentPlaceholder(this);

            // Set all form values to webpart
            foreach (DataColumn column in dr.Table.Columns)
            {
                object value      = dr[column];
                string columnName = column.ColumnName.ToLowerCSafe();

                //Resolve set values by user
                if (Properties.Contains(columnName))
                {
                    FormFieldInfo ffi = fi.GetFormField(columnName);
                    if ((ffi != null) && ffi.Visible && ((ffi.DisplayIn == null) || !ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD)))
                    {
                        value = Properties[columnName];
                    }
                }

                // Resolve macros in defined in default values
                if (!String.IsNullOrEmpty(value as string))
                {
                    // Do not resolve macros for public fields
                    if (publicFields.IndexOfCSafe(";" + columnName + ";") < 0)
                    {
                        // Check whether current column
                        bool avoidInjection = control.SQLProperties.Contains(";" + columnName + ";");

                        // Resolve macros
                        MacroSettings settings = new MacroSettings()
                        {
                            AvoidInjection = avoidInjection,
                        };
                        value = control.ContextResolver.ResolveMacros(value.ToString(), settings);
                    }
                }

                control.PartInstance.SetValue(column.ColumnName, value);
            }

            control.PartInstance.IsWidget = true;

            // Load webpart content
            control.OnContentLoaded();

            // Add webpart to controls collection
            Controls.Add(control);

            // Handle DisableViewstate setting
            control.EnableViewState = !control.DisableViewState;
        }

        catch (Exception ex)
        {
            AddErrorWebPart("widget.failedtoload", ex);
        }
    }
예제 #28
0
    /// <summary>
    /// Handles form's after data load event.
    /// </summary>
    protected void EditForm_OnAfterDataLoad(object sender, EventArgs e)
    {
        etaCode.Language = LanguageEnum.HTML;

        cssLayoutEditor.Editor.Language      = LanguageEnum.CSS;
        cssLayoutEditor.Editor.ShowBookmarks = true;

        // Do not check changes
        DocumentManager.RegisterSaveChangesScript = false;

        EditForm.OnBeforeSave += EditForm_OnBeforeSave;

        etaCode.Language = LanguageEnum.HTML;

        wpli = UIContext.EditedObject as WebPartLayoutInfo;

        layoutID = QueryHelper.GetInteger("layoutid", 0);

        isSiteManager = ((MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin) && layoutID != 0) || QueryHelper.GetBoolean("sitemanager", false));
        isNew         = (LayoutCodeName == "|new|");
        isDefault     = (LayoutCodeName == "|default|") || (!isSiteManager && string.IsNullOrEmpty(LayoutCodeName));

        if ((wpli == null) || (wpli.WebPartLayoutID <= 0))
        {
            isNew |= isSiteManager;
            editMenuElem.ObjectManager.ObjectType = WebPartLayoutInfo.OBJECT_TYPE;
        }

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "PreviewHierarchyPerformAction", ScriptHelper.GetScript("function actionPerformed(action) { if (action == 'saveandclose') { document.getElementById('" + hdnClose.ClientID + "').value = '1'; } " + editMenuElem.ObjectManager.GetJSFunction(ComponentEvents.SAVE, null, null) + "; }"));

        currentUser = MembershipContext.AuthenticatedUser;

        // Get web part instance (if edited in administration)
        if ((webpartId != "") && !isSiteManager)
        {
            // Get page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture);
            if (pi == null)
            {
                ShowInformation(GetString("WebPartProperties.WebPartNotFound"), persistent: false);
            }
            else
            {
                // Get page template
                pti = pi.UsedPageTemplateInfo;
                if ((pti != null) && ((pti.TemplateInstance != null)))
                {
                    webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.TemplateInstance.GetWebPart(webpartId);
                }
            }
        }

        // If the web part is not found, try web part ID
        if (webPart == null)
        {
            wpi = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(webpartId, 0));
            if (wpi == null)
            {
                ShowError(GetString("WebPartProperties.WebPartNotFound"));
                return;
            }
        }
        else
        {
            // CMS desk
            wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (string.IsNullOrEmpty(LayoutCodeName))
            {
                // Get the current layout name
                LayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }
        }

        if (wpi != null)
        {
            // Load the web part information
            webPartInfo = wpi;
            bool loaded = false;

            if (!RequestHelper.IsPostBack())
            {
                if (wpli != null)
                {
                    editMenuElem.MenuPanel.Visible = true;

                    // Read-only code text area
                    etaCode.Editor.ReadOnly = false;
                    loaded = true;
                }

                if (!loaded)
                {
                    string fileName = WebPartInfoProvider.GetFullPhysicalPath(webPartInfo);

                    // Check if filename exist
                    if (!FileHelper.FileExists(fileName))
                    {
                        ShowError(GetString("WebPartProperties.FileNotExist"));
                        pnlContent.Visible = false;
                        editMenuElem.ObjectEditMenu.Visible = false;
                    }
                    else
                    {
                        // Load default web part layout code
                        etaCode.Text = File.ReadAllText(Server.MapPath(fileName));

                        // Load default web part CSS
                        cssLayoutEditor.Text = wpi.WebPartCSS;
                    }
                }
            }
        }

        if (((wpli == null) || (wpli.WebPartLayoutID <= 0)) && isSiteManager)
        {
            editMenuElem.Title.Breadcrumbs.AddBreadcrumb(new BreadcrumbItem
            {
                Text        = GetString("WebParts.Layout"),
                RedirectUrl = String.Format("{0}&parentobjectid={1}&displaytitle={2}", UIContextHelper.GetElementUrl("CMS.Design", "WebPart.Layout"), QueryHelper.GetInteger("webpartid", 0), false)
            });

            editMenuElem.Title.Breadcrumbs.AddBreadcrumb(new BreadcrumbItem
            {
                Text = GetString("webparts_layout_newlayout"),
            });
        }

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ApplyButton", ScriptHelper.GetScript(
                                                   "function SetRefresh(refreshpage) { document.getElementById('" + hidRefresh.ClientID + @"').value = refreshpage; }
             function OnApplyButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('save');refreshPreview(); }  
             function OnOKButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('saveandclose'); } "));

        InitLayoutForm();
    }
예제 #29
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions for web part properties UI
        CurrentUserInfo currentUser = CMSContext.CurrentUser;

        if (!currentUser.IsAuthorizedPerUIElement("CMS.Content", "WebPartProperties.Layout"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "WebPartProperties.Layout");
        }

        // Check saved
        bool saved = false;

        if (QueryHelper.GetBoolean("saved", false))
        {
            saved           = true;
            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");
        }

        // Init GUI
        mCheckOut     = GetString("WebPartLayout.CheckOut");
        mCheckIn      = GetString("WebPartLayout.CheckIn");
        mUndoCheckOut = GetString("WebPartLayout.DiscardCheckOut");
        mSave         = GetString("General.Save");

        this.imgSave.ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/Save.png");

        this.imgCheckIn.ImageUrl  = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkin.png");
        this.imgCheckOut.ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkout.png");

        this.imgUndoCheckOut.ImageUrl      = GetImageUrl("CMSModules/CMS_Content/EditMenu/undocheckout.png");
        this.btnUndoCheckOut.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("General.ConfirmUndoCheckOut")) + ");";

        if (webpartId != "")
        {
            // Get pageinfo
            pi = GetPageInfo(aliasPath, templateId);
            if (pi == null)
            {
                this.lblInfo.Text        = GetString("WebPartProperties.WebPartNotFound");
                this.pnlFormArea.Visible = false;
                return;
            }

            // Get page template
            pti = pi.PageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.GetWebPart(webpartId);
            }
        }

        // If the web part is not found, do not continue
        if (webPart == null)
        {
            this.lblInfo.Text        = GetString("WebPartProperties.WebPartNotFound");
            this.pnlFormArea.Visible = false;

            return;
        }
        else
        {
            if (String.IsNullOrEmpty(LayoutCodeName))
            {
                // Get the current layout name
                LayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }
        }

        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);

        if (wpi != null)
        {
            // Load the web part information
            webPartInfo = wpi;
            bool loaded = false;

            if (!RequestHelper.IsPostBack())
            {
                pnlMenu.Visible         = false;
                pnlCheckOutInfo.Visible = false;

                if (LayoutCodeName != "")
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                    if (wpli != null)
                    {
                        if ((LayoutCodeName != "|default|") && (LayoutCodeName != "|new|"))
                        {
                            SetEditedObject(wpli, "WebPartProperties_layout_frameset_frameset.aspx");
                        }

                        pnlMenu.Visible         = true;
                        pnlCheckOutInfo.Visible = true;

                        // Read-only code text area
                        etaCode.ReadOnly = false;
                        etaCSS.ReadOnly  = false;

                        // Set checkout panel
                        SetCheckPanel(wpli);

                        etaCode.Text = wpli.WebPartLayoutCode;
                        etaCSS.Text  = wpli.WebPartLayoutCSS;
                        loaded       = true;
                    }
                }

                if (!loaded)
                {
                    string fileName = webPartInfo.WebPartFileName;

                    if (webPartInfo.WebPartParentID > 0)
                    {
                        WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(webPartInfo.WebPartParentID);
                        if (pwpi != null)
                        {
                            fileName = pwpi.WebPartFileName;
                        }
                    }

                    if (!fileName.StartsWith("~"))
                    {
                        fileName = "~/CMSWebparts/" + fileName;
                    }

                    // Check if filename exist
                    if (!FileHelper.FileExists(fileName))
                    {
                        lblError.Text      = GetString("WebPartProperties.FileNotExist");
                        lblError.Visible   = true;
                        plcContent.Visible = false;
                    }
                    else
                    {
                        // Load default web part layout code
                        etaCode.Text = File.ReadAllText(Server.MapPath(fileName));

                        // Load default web part CSS
                        etaCSS.Text = wpi.WebPartCSS;
                    }
                }
            }
        }

        btnOnOK.Click += new EventHandler(btnOnOK_Click);

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ApplyButton", ScriptHelper.GetScript(
                                                   "function SetRefresh(refreshpage) { document.getElementById('" + this.hidRefresh.ClientID + "').value = refreshpage; } \n" +
                                                   "function OnApplyButton(refreshpage) { SetRefresh(refreshpage); " + Page.ClientScript.GetPostBackEventReference(lnkSave, "") + "} \n" +
                                                   "function OnOKButton(refreshpage) { SetRefresh(refreshpage); " + Page.ClientScript.GetPostBackEventReference(btnOnOK, "") + "} \n"
                                                   ));

        if (saved && (LayoutCodeName == "|new|"))
        {
            // Refresh menu
            string query = URLHelper.Url.Query;
            query = URLHelper.AddParameterToUrl(query, "layoutcodename", webPart.GetValue("WebPartLayout").ToString());
            query = URLHelper.AddParameterToUrl(query, "reload", "true");

            string scriptText = ScriptHelper.GetScript(@"parent.frames['webpartpropertiesmenu'].location = 'webpartproperties_layout_menu.aspx" + query + "';");
            ScriptHelper.RegisterStartupScript(this, typeof(string), "ReloadAfterNewLayout", scriptText);
        }

        if (!RequestHelper.IsPostBack())
        {
            InitLayoutForm();
        }

        this.plcCssLink.Visible = String.IsNullOrEmpty(etaCSS.Text.Trim());
        this.lnkStyles.Visible  = !String.IsNullOrEmpty(LayoutCodeName) && (LayoutCodeName != "|default|");
    }
예제 #30
0
    /// <summary>
    /// Handles the OnAfterAction event of the ObjectManager control.
    /// </summary>
    protected void ObjectManager_OnAfterAction(object sender, SimpleObjectManagerEventArgs e)
    {
        wpli = EditForm.EditedObject as WebPartLayoutInfo;

        if (wpli != null)
        {
            LayoutCodeName = wpli.WebPartLayoutCodeName;
        }

        if (e.ActionName == ComponentEvents.SAVE)
        {
            if (EditForm.ValidateData())
            {
                if (!isSiteManager)
                {
                    SetCurrentLayout(true);
                }

                if (ValidationHelper.GetBoolean(hdnClose.Value, false))
                {
                    // If window to close, register close script
                    CloseDialog();
                }
                else
                {
                    // Redirect parent for new
                    if (isNew)
                    {
                        if (isSiteManager)
                        {
                            URLHelper.Redirect("WebPart_Edit_Layout_Frameset.aspx?layoutID=" + wpli.WebPartLayoutID + "&webpartID=" + webPartInfo.WebPartID);
                        }
                        else
                        {
                            var codeName    = (wpli != null) ? wpli.WebPartLayoutCodeName : string.Empty;
                            var redirectUrl = ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/WebPartProperties_layout_frameset.aspx") + URLHelper.UpdateParameterInUrl(URLHelper.Url.Query, "layoutcodename", codeName);
                            ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "RefreshHeader", ScriptHelper.GetScript("parent.location ='" + redirectUrl + "'"));
                        }
                    }
                    else
                    {
                        if (!isSiteManager)
                        {
                            // Reload the parent page after save
                            EnsureParentPageRefresh();
                        }

                        // If all ok show changes saved
                        ShowChangesSaved();
                        RegisterRefreshScript();
                    }
                }
            }

            // Clear warning text
            editMenuElem.MessagesPlaceHolder.WarningText = "";
        }

        if (DialogMode)
        {
            switch (e.ActionName)
            {
            case ComponentEvents.SAVE:
            case ComponentEvents.CHECKOUT:
            case ComponentEvents.UNDO_CHECKOUT:
            case ComponentEvents.CHECKIN:
                ScriptHelper.RegisterStartupScript(Page, typeof(string), "wopenerRefresh", ScriptHelper.GetScript("if (wopener && wopener.refresh) { wopener.refresh(); }"));
                break;
            }
        }

        if (isSiteManager && (e.ActionName != ComponentEvents.CHECKOUT))
        {
            ScriptHelper.RefreshTabHeader(Page, null);
        }
    }
    protected override void OnInit(EventArgs e)
    {
        // Do not check changes
        DocumentManager.RegisterSaveChangesScript = false;

        EditForm.OnBeforeSave += EditForm_OnBeforeSave;

        etaCode.Editor.Language = LanguageEnum.HTML;
        etaCSS.Editor.Language = LanguageEnum.CSS;

        wpli = CMSContext.EditedObject as WebPartLayoutInfo;

        layoutID = QueryHelper.GetInteger("layoutid", 0);

        isSiteManager = ((CMSContext.CurrentUser.IsGlobalAdministrator && layoutID != 0) || QueryHelper.GetBoolean("sitemanager", false));
        isNew = (LayoutCodeName == "|new|");
        isDefault = (LayoutCodeName == "|default|") || (!isSiteManager && string.IsNullOrEmpty(LayoutCodeName));

        if ((wpli == null) && isSiteManager)
        {
            isNew = true;
        }

        if (wpli == null)
        {
            editMenuElem.ObjectManager.ObjectType = PredefinedObjectType.WEBPARTLAYOUT;
        }

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "PreviewHierarchyPerformAction", ScriptHelper.GetScript("function actionPerformed(action) { if (action == 'saveandclose') { document.getElementById('" + hdnClose.ClientID + "').value = '1'; } " + editMenuElem.ObjectManager.GetJSFunction(ComponentEvents.SAVE, null, null) + "; }"));

        RegisterResizeHeaders();

        currentUser = CMSContext.CurrentUser;

        // Get webpart instance (if edited in CMSDesk)
        if ((webpartId != "") && !isSiteManager)
        {
            // Get pageinfo
            pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture);
            if (pi == null)
            {
                ShowInformation(GetString("WebPartProperties.WebPartNotFound"), null, false);
            }

            // Get page template
            pti = pi.UsedPageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.GetWebPart(webpartId);
            }
        }

        // If the web part is not found, try webpart ID
        if (webPart == null)
        {
            // Site manager
            wpi = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(webpartId, 0));
            if (wpi == null)
            {
                ShowError(GetString("WebPartProperties.WebPartNotFound"), null, null);
                startWithFullScreen = false;
                return;
            }
        }
        else
        {
            // CMS desk
            wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (string.IsNullOrEmpty(LayoutCodeName))
            {
                // Get the current layout name
                LayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }
        }

        if (wpi != null)
        {
            if (CMSObjectHelper.UseCheckinCheckout && (!isNew || isSiteManager))
            {
                pnlFormArea.CssClass = "PreviewDefaultContentLarge";
            }
            else
            {
                pnlFormArea.CssClass = "PreviewDefaultContent";
            }

            // Load the web part information
            webPartInfo = wpi;
            bool loaded = false;

            if (!RequestHelper.IsPostBack())
            {
                if (wpli != null)
                {
                    editMenuElem.MenuPanel.Visible = true;

                    // Read-only code text area
                    etaCode.Editor.ReadOnly = false;
                    loaded = true;
                }

                if (!loaded)
                {
                    string fileName = webPartInfo.WebPartFileName;

                    if (webPartInfo.WebPartParentID > 0)
                    {
                        WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(webPartInfo.WebPartParentID);
                        if (pwpi != null)
                        {
                            fileName = pwpi.WebPartFileName;
                        }
                    }

                    if (!fileName.StartsWithCSafe("~"))
                    {
                        fileName = "~/CMSWebparts/" + fileName;
                    }

                    // Check if filename exist
                    if (!FileHelper.FileExists(fileName))
                    {
                        ShowError(GetString("WebPartProperties.FileNotExist"), null, null);
                        plcContent.Visible = false;
                    }
                    else
                    {
                        // Load default web part layout code
                        etaCode.Text = File.ReadAllText(Server.MapPath(fileName));

                        // Load default web part CSS
                        etaCSS.Text = wpi.WebPartCSS;
                        startWithFullScreen = false;
                    }
                }
            }
        }

        if ((wpli == null) && isSiteManager)
        {
            pnlFormArea.CssClass += " NewPreviewContent";

            var breadcrumbs = new string[2, 3];
            breadcrumbs[0, 0] = GetString("WebParts.Layout");
            breadcrumbs[0, 1] = ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Edit_Layout.aspx?webpartid=" + QueryHelper.GetInteger("webpartid", 0));
            breadcrumbs[1, 0] = GetString("webparts_layout_newlayout");
            editMenuElem.PageTitleBreadcrumbs = breadcrumbs;
        }

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ApplyButton", ScriptHelper.GetScript(
            "function SetRefresh(refreshpage) { document.getElementById('" + hidRefresh.ClientID + @"').value = refreshpage; }
             function OnApplyButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('save');refreshPreview(); }
             function OnOKButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('saveandclose'); } "));

        InitLayoutForm();

        plcCssLink.Visible = string.IsNullOrEmpty(etaCSS.Text.Trim());

        base.OnInit(e);
    }
    /// <summary>
    /// Save layout code.
    /// </summary>
    protected bool SaveData()
    {
        // Remove "." due to virtual path provider replacement
        txtCodeName.Text = txtCodeName.Text.Replace(".", "");

        txtDisplayName.Text = txtDisplayName.Text.Trim();
        txtCodeName.Text    = txtCodeName.Text.Trim();

        string errorMessage = new Validator()
                              .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage)
                              .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage)
                              .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")).Result;

        int         webPartId   = ValidationHelper.GetInteger(Request.QueryString["webpartId"], 0);
        WebPartInfo webPartInfo = WebPartInfoProvider.GetWebPartInfo(webPartId);

        if (webPartInfo == null)
        {
            errorMessage = GetString("WebPartEditLayoutEdit.InvalidWebPartID");
        }

        if (errorMessage != String.Empty)
        {
            lblError.Text    = errorMessage;
            lblError.Visible = true;
            return(false);
        }

        // Get layout info
        WebPartLayoutInfo webPartLayoutInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);

        if (webPartLayoutInfo != null)
        {
            // Get layout info using its code name - layout code name must be unique
            DataSet ds = WebPartLayoutInfoProvider.GetWebPartLayouts("WebPartLayoutCodeName = '" + WebPartLayoutInfoProvider.GetWebPartLayoutFullCodeName(webPartInfo.WebPartName, txtCodeName.Text) + "'", null);

            // Find anything?
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                WebPartLayoutInfo temp = new WebPartLayoutInfo(ds.Tables[0].Rows[0]);
                // Is it the same layout?
                if ((ds.Tables[0].Rows.Count > 1) || (temp.WebPartLayoutID != webPartLayoutInfo.WebPartLayoutID))
                {
                    lblError.Text    = String.Format(GetString("WebPartEditLayoutEdit.CodeNameAlreadyExist"), txtCodeName.Text);
                    lblError.Visible = true;
                    return(false);
                }
            }

            webPartLayoutInfo.WebPartLayoutCodeName    = txtCodeName.Text;
            webPartLayoutInfo.WebPartLayoutDisplayName = txtDisplayName.Text;
            webPartLayoutInfo.WebPartLayoutDescription = txtDescription.Text;

            if (!webPartLayoutInfo.Generalized.IsCheckedOut)
            {
                webPartLayoutInfo.WebPartLayoutCode = etaCode.Text;
                webPartLayoutInfo.WebPartLayoutCSS  = tbCSS.Text;
            }

            WebPartLayoutInfoProvider.SetWebPartLayoutInfo(webPartLayoutInfo);

            // Reload header if changes were saved
            if (TabMode)
            {
                ScriptHelper.RefreshTabHeader(Page, null);
            }
        }
        return(true);
    }
    /// <summary>
    /// Creates web part layout. Called when the "Create layout" button is pressed.
    /// </summary>
    private bool CreateWebPartLayout()
    {
        // Get the web part
        WebPartInfo webpart = WebPartInfoProvider.GetWebPartInfo("MyNewWebpart");
        if (webpart != null)
        {
            // Create new web part layout object
            WebPartLayoutInfo newLayout = new WebPartLayoutInfo();

            // Set the properties
            newLayout.WebPartLayoutDisplayName = "My new layout";
            newLayout.WebPartLayoutCodeName = "MyNewLayout";
            newLayout.WebPartLayoutWebPartID = webpart.WebPartID;
            newLayout.WebPartLayoutCode = "This is the new layout of MyNewWebpart webpart.";

            // Save the web part layout
            WebPartLayoutInfoProvider.SetWebPartLayoutInfo(newLayout);

            return true;
        }
        return false;
    }
예제 #34
0
    /// <summary>
    /// Handles the OnAfterAction event of the ObjectManager control.
    /// </summary>
    protected void ObjectManager_OnAfterAction(object sender, SimpleObjectManagerEventArgs e)
    {
        wpli = EditForm.EditedObject as WebPartLayoutInfo;

        if ((wpli == null) || (wpli.WebPartLayoutID <= 0) || (!e.IsValid))
        {
            // Do not continue if the object has not been created
            return;
        }

        LayoutCodeName = wpli.WebPartLayoutCodeName;

        if (e.ActionName == ComponentEvents.SAVE)
        {
            if (EditForm.ValidateData())
            {
                if (!isSiteManager)
                {
                    SetCurrentLayout(true);
                }

                if (ValidationHelper.GetBoolean(hdnClose.Value, false))
                {
                    // If window to close, register close script
                    CloseDialog();
                }
                else
                {
                    // Redirect parent for new
                    if (isNew)
                    {
                        if (isSiteManager)
                        {
                            URLHelper.Redirect(String.Format("{0}&parentobjectid={1}&objectid={2}&displaytitle={3}",
                                                             UIContextHelper.GetElementUrl("CMS.Design", "Edit.WebPartLayout"), webPartInfo.WebPartID, wpli.WebPartLayoutID, false));
                        }
                        else
                        {
                            var codeName    = (wpli != null) ? wpli.WebPartLayoutCodeName : string.Empty;
                            var redirectUrl = ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/WebPartProperties_layout_frameset.aspx") + URLHelper.UpdateParameterInUrl(RequestContext.CurrentQueryString, "layoutcodename", codeName);
                            ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "RefreshHeader", ScriptHelper.GetScript("parent.location ='" + redirectUrl + "'"));

                            // Reload the parent page after save
                            EnsureParentPageRefresh();
                        }
                    }
                    else
                    {
                        if (!isSiteManager)
                        {
                            // Reload the parent page after save
                            EnsureParentPageRefresh();
                        }

                        // If all ok show changes saved
                        RegisterRefreshScript();
                    }
                }
            }

            // Clear warning text
            editMenuElem.MessagesPlaceHolder.WarningText = "";
        }

        if (DialogMode)
        {
            switch (e.ActionName)
            {
            case ComponentEvents.SAVE:
            case ComponentEvents.CHECKOUT:
            case ComponentEvents.UNDO_CHECKOUT:
            case ComponentEvents.CHECKIN:
                ScriptHelper.RegisterStartupScript(Page, typeof(string), "wopenerRefresh", ScriptHelper.GetScript("if (wopener && wopener.refresh) { wopener.refresh(); }"));
                break;
            }
        }

        if (isSiteManager && (e.ActionName != ComponentEvents.CHECKOUT) && EditForm.DisplayNameChanged)
        {
            ScriptHelper.RegisterClientScriptBlock(Page, typeof(String), "RefreshBreadcrumbs", ScriptHelper.GetScript("if (parent.refreshBreadcrumbs != null && parent.document.pageLoaded) {parent.refreshBreadcrumbs('" + ResHelper.LocalizeString(EditForm.EditedObject.Generalized.ObjectDisplayName) + "')}"));
        }
    }
    /// <summary>
    /// Gets and bulk updates web part layouts. Called when the "Get and bulk update layouts" button is pressed.
    /// Expects the CreateWebPartLayout method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWebPartLayouts()
    {
        // Prepare the parameters
        string where = "WebPartLayoutCodeName LIKE N'MyNewLayout%'";

        // Get the data
        DataSet layouts = WebPartLayoutInfoProvider.GetWebPartLayouts().Where(where);
        if (!DataHelper.DataSourceIsEmpty(layouts))
        {
            // Loop through the individual items
            foreach (DataRow layoutDr in layouts.Tables[0].Rows)
            {
                // Create object from DataRow
                WebPartLayoutInfo modifyLayout = new WebPartLayoutInfo(layoutDr);

                // Update the properties
                modifyLayout.WebPartLayoutDisplayName = modifyLayout.WebPartLayoutDisplayName.ToUpper();

                // Save the changes
                WebPartLayoutInfoProvider.SetWebPartLayoutInfo(modifyLayout);
            }

            return true;
        }

        return false;
    }
예제 #36
0
    /// <summary>
    /// Sets check out/in/undo panel
    /// </summary>
    protected void SetCheckPanel(WebPartLayoutInfo mwpli)
    {
        WebPartInfo       wpi  = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
        WebPartLayoutInfo wpli = mwpli;

        if (wpi != null)
        {
            if (wpli == null)
            {
                wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
            }
        }

        if (wpli != null)
        {
            this.pnlCheckOutInfo.Visible = true;

            if (wpli.WebPartLayoutCheckedOutByUserID > 0)
            {
                etaCode.ReadOnly = true;
                etaCSS.ReadOnly  = true;

                string   username = null;
                UserInfo ui       = UserInfoProvider.GetUserInfo(wpli.WebPartLayoutCheckedOutByUserID);
                if (ui != null)
                {
                    username = HTMLHelper.HTMLEncode(ui.FullName);
                }

                plcCheckOut.Visible = false;

                // Checked out by current machine
                if (wpli.WebPartLayoutCheckedOutMachineName.ToLower() == HTTPHelper.MachineName.ToLower())
                {
                    this.plcCheckIn.Visible = true;

                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOut"), Server.MapPath(wpli.WebPartLayoutCheckedOutFilename));
                }
                else
                {
                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckedOutOnAnotherMachine"), wpli.WebPartLayoutCheckedOutMachineName, username);
                }

                if (CMSContext.CurrentUser.IsGlobalAdministrator)
                {
                    this.plcUndoCheckOut.Visible = true;
                }
            }
            else
            {
                wpi = WebPartInfoProvider.GetWebPartInfo(wpli.WebPartLayoutWebPartID);
                if (wpi != null)
                {
                    this.lblCheckOutInfo.Text = String.Format(GetString("WebPartEditLayoutEdit.CheckOutInfo"), Server.MapPath(WebPartLayoutInfoProvider.GetWebPartLayoutUrl(wpi.WebPartName, wpli.WebPartLayoutCodeName, null)));

                    this.plcCheckOut.Visible     = true;
                    this.plcCheckIn.Visible      = false;
                    this.plcUndoCheckOut.Visible = false;
                }
            }
        }
    }
    /// <summary>
    /// Button OK click handler.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Trim text values
        txtWebPartName.Text = txtWebPartName.Text.Trim();
        txtWebPartDisplayName.Text = txtWebPartDisplayName.Text.Trim();
        txtWebPartFileName.Text = txtWebPartFileName.Text.Trim();

        // Validate the text box fields
        string errorMessage = new Validator()
            .NotEmpty(txtWebPartName.Text, rfvWebPartName.ErrorMessage)
            .NotEmpty(txtWebPartDisplayName.Text, rfvWebPartDisplayName.ErrorMessage)
            .IsCodeName(txtWebPartName.Text, GetString("WebPart_Clone.InvalidCodeName"))
            .Result;

        // Validate file name
        if(string.IsNullOrEmpty(errorMessage) && chckCloneWebPartFiles.Checked)
        {
            errorMessage = new Validator()
            .NotEmpty(txtWebPartFileName.Text, rfvWebPartFileName.ErrorMessage)
            .IsFileName(Path.GetFileName(txtWebPartFileName.Text.Trim('~')), GetString("WebPart_Clone.InvalidFileName")).Result;
        }

        // Check if webpart with same name exists
        if (WebPartInfoProvider.GetWebPartInfo(txtWebPartName.Text) != null)
        {
            errorMessage = GetString(String.Format("Development-WebPart_Clone.WebPartExists", txtWebPartName.Text));
        }

        // Check if webpart is not cloned to the root category
        WebPartCategoryInfo wci = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");
        if (wci.CategoryID == ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1))
        {
            errorMessage = GetString("Development-WebPart_Clone.cannotclonetoroot");
        }

        if (errorMessage != "")
        {
            lblError.Text = errorMessage;
            lblError.Visible = true;
            return;
        }

        // get web part info object
        WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPartId);
        if (wi == null)
        {
            lblError.Text = GetString("WebPart_Clone.InvalidWebPartID");
            lblError.Visible = true;
            return;
        }

        // Create new webpart with all properties from source webpart
        WebPartInfo nwpi = new WebPartInfo(wi, false);

        nwpi.WebPartID = 0;
        nwpi.WebPartGUID = Guid.NewGuid();

        // Modify clone info
        nwpi.WebPartName = txtWebPartName.Text;
        nwpi.WebPartDisplayName = txtWebPartDisplayName.Text;
        nwpi.WebPartCategoryID = ValidationHelper.GetInteger(drpWebPartCategories.SelectedValue, -1);

        if (nwpi.WebPartParentID <= 0)
        {
            nwpi.WebPartFileName = txtWebPartFileName.Text;
        }

        string path = String.Empty;
        string filename = String.Empty;
        string inher = String.Empty;

        try
        {
            // Copy file if needed and webpart is not ihnerited
            if (chckCloneWebPartFiles.Checked && (wi.WebPartParentID == 0))
            {
                // Get source file path
                string srcFile = GetWebPartPhysicalPath(wi.WebPartFileName);

                // Get destination file path
                string dstFile = GetWebPartPhysicalPath(nwpi.WebPartFileName);

                // Ensure directory
                DirectoryHelper.EnsureDiskPath(Path.GetDirectoryName(DirectoryHelper.EnsurePathBackSlash(dstFile)), URLHelper.WebApplicationPhysicalPath);

                // Check if source and target file path are different
                if (File.Exists(dstFile))
                {
                    throw new Exception(GetString("general.fileexists"));
                }

                // Get file name
                filename = Path.GetFileName(dstFile);
                // Get path to the partial class name replace
                string wpPath = nwpi.WebPartFileName;

                if (!wpPath.StartsWith("~/"))
                {
                    wpPath = WebPartInfoProvider.WebPartsDirectory + "/" + wpPath.TrimStart('/');
                }
                path = Path.GetDirectoryName(wpPath);

                inher = path.Replace('\\', '_').Replace('/', '_') + "_" + Path.GetFileNameWithoutExtension(filename).Replace('.', '_');
                inher = inher.Trim('~');
                inher = inher.Trim('_');

                // Read .aspx file, replace classname and save as new file
                string text = File.ReadAllText(srcFile);
                File.WriteAllText(dstFile, ReplaceASCX(text, DirectoryHelper.CombinePath(path, filename), inher));

                // Read .aspx file, replace classname and save as new file
                if (File.Exists(srcFile + ".cs"))
                {
                    text = File.ReadAllText(srcFile + ".cs");
                    File.WriteAllText(dstFile + ".cs", ReplaceASCXCS(text, inher));
                }

                if (File.Exists(srcFile + ".vb"))
                {
                    text = File.ReadAllText(srcFile + ".vb");
                    File.WriteAllText(dstFile + ".vb", ReplaceASCXVB(text, inher));
                }

                // Copy web part subfolder
                string srcDirectory = srcFile.Remove(srcFile.Length - Path.GetFileName(srcFile).Length) + Path.GetFileNameWithoutExtension(srcFile) + "_files";
                if (Directory.Exists(srcDirectory))
                {
                    string dstDirectory = dstFile.Remove(dstFile.Length - Path.GetFileName(dstFile).Length) + Path.GetFileNameWithoutExtension(dstFile) + "_files";
                    if (srcDirectory.ToLower() != dstDirectory.ToLower())
                    {
                        DirectoryHelper.EnsureDiskPath(srcDirectory, URLHelper.WebApplicationPhysicalPath);
                        DirectoryHelper.CopyDirectory(srcDirectory, dstDirectory);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
            lblError.Visible = true;
            return;
        }

        // Add new web part to database
        WebPartInfoProvider.SetWebPartInfo(nwpi);

        try
        {
            // Get and duplicate all webpart layouts associated to webpart
            DataSet ds = WebPartLayoutInfoProvider.GetWebPartLayouts(webPartId);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    WebPartLayoutInfo wpli = new WebPartLayoutInfo(dr);
                    wpli.WebPartLayoutID = 0;                          // Create new record
                    wpli.WebPartLayoutWebPartID = nwpi.WebPartID;        // Associate layout to new webpart
                    wpli.WebPartLayoutGUID = Guid.NewGuid();
                    wpli.WebPartLayoutCheckedOutByUserID = 0;
                    wpli.WebPartLayoutCheckedOutFilename = "";
                    wpli.WebPartLayoutCheckedOutMachineName = "";

                    // Replace classname and inherits attribut
                    wpli.WebPartLayoutCode = ReplaceASCX(wpli.WebPartLayoutCode, DirectoryHelper.CombinePath(path, filename), inher);
                    WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);
                }
            }

            // Duplicate associated thumbnail
            MetaFileInfoProvider.CopyMetaFiles(webPartId, nwpi.WebPartID, PortalObjectType.WEBPART, MetaFileInfoProvider.OBJECT_CATEGORY_THUMBNAIL, null);
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
            lblError.Visible = true;
            return;
        }

        // Close clone window
        // Refresh web part tree and select/edit new widget
        string script = String.Empty;
        string refreshLink = URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Tree.aspx?webpartid=" + nwpi.WebPartID + "&reload=true");
        if (QueryHelper.Contains("reloadAll"))
        {
            script += "wopener.parent.parent.frames['webparttree'].location.href ='" + refreshLink + "';";
        }
        else
        {
            script = "wopener.location = '" + refreshLink + "';";
        }
        script += "window.close();";

        ltlScript.Text = ScriptHelper.GetScript(script);
    }
예제 #38
0
    /// <summary>
    /// Sets current layout.
    /// </summary>
    protected void SetCurrentLayout(bool saveToWebPartInstance, bool updateLayout)
    {
        if ((webPart != null) && (LayoutCodeName != "|new|"))
        {
            if (saveToWebPartInstance)
            {
                if (LayoutCodeName == "|default|")
                {
                    webPart.SetValue("WebPartLayout", "");
                }
                else
                {
                    webPart.SetValue("WebPartLayout", LayoutCodeName);
                }

                bool isWebPartVariant = (variantId > 0) || (zoneVariantId > 0) || isNewVariant;
                if (!isWebPartVariant)
                {
                    // Update page template
                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
                else
                {
                    // Save the variant properties
                    if ((webPart != null) &&
                        (webPart.ParentZone != null) &&
                        (webPart.ParentZone.ParentTemplateInstance != null) &&
                        (webPart.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
                    {
                        XmlDocument doc         = new XmlDocument();
                        XmlNode     xmlWebParts = null;

                        if (zoneVariantId > 0)
                        {
                            // This webpart is in a zone variant therefore save the whole variant webparts
                            xmlWebParts = webPart.ParentZone.GetXmlNode(doc);
                            if (webPart.VariantMode == VariantModeEnum.MVT)
                            {
                                ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(zoneVariantId, xmlWebParts);
                            }
                            else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(zoneVariantId, xmlWebParts);
                            }
                        }
                        else if (variantId > 0)
                        {
                            // This webpart is a web part variant
                            xmlWebParts = webPart.GetXmlNode(doc);
                            if (webPart.VariantMode == VariantModeEnum.MVT)
                            {
                                ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(variantId, xmlWebParts);
                            }
                            else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(variantId, xmlWebParts);
                            }
                        }
                    }
                }
            }

            string parameters = this.aliasPath + "/" + this.zoneId + "/" + this.webpartId;
            string cacheName  = "CMSVirtualWebParts|" + parameters.ToLower().TrimStart('/');

            CacheHelper.Remove(cacheName);

            if (updateLayout)
            {
                WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
                if (wpi != null)
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                    if (wpli != null)
                    {
                        if (CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode"))
                        {
                            wpli.WebPartLayoutCode = etaCode.Text;
                        }
                        wpli.WebPartLayoutCSS = etaCSS.Text;

                        WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);
                    }
                }
            }
        }
    }
예제 #39
0
    /// <summary>
    /// Saves webpart properties.
    /// </summary>
    public bool Save()
    {
        // Check MVT/CP security
        if (VariantID > 0)
        {
            // Check OnlineMarketing permissions.
            if (!CheckPermissions("Manage"))
            {
                ShowError(GetString("general.modifynotallowed"));
                return(false);
            }
        }

        // Save the data
        if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(form))
        {
            if (SynchronizationHelper.IsCheckedOutByOtherUser(pti))
            {
                string   userName = null;
                UserInfo ui       = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID);
                if (ui != null)
                {
                    userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite));
                }

                ShowError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.TypeInfo.ObjectType, pti.DisplayName, userName));
                return(false);
            }

            // Add web part if new
            if (IsNewWebPart)
            {
                int webpartId = ValidationHelper.GetInteger(WebPartID, 0);

                // Ensure layout zone flag
                if (QueryHelper.GetBoolean("layoutzone", false))
                {
                    WebPartZoneInstance zone = pti.TemplateInstance.EnsureZone(ZoneID);
                    zone.LayoutZone = true;
                }

                webPartInstance = PortalHelper.AddNewWebPart(webpartId, ZoneID, false, ZoneVariantID, Position, templateInstance);

                // Set default layout
                if (wpi.WebPartParentID > 0)
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetDefaultLayout(wpi.WebPartID);
                    if (wpli != null)
                    {
                        webPartInstance.SetValue("WebPartLayout", wpli.WebPartLayoutCodeName);
                    }
                }
            }

            webPartInstance.XMLVersion = 1;
            if (IsNewVariant)
            {
                webPartInstance             = webPartInstance.Clone();
                webPartInstance.VariantMode = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", String.Empty).ToLowerInvariant());
            }

            // Get basic form's data row and update web part
            SaveFormToWebPart(form);

            // Set new position if set
            if (PositionLeft > 0)
            {
                webPartInstance.SetValue("PositionLeft", PositionLeft);
            }
            if (PositionTop > 0)
            {
                webPartInstance.SetValue("PositionTop", PositionTop);
            }

            bool isWebPartVariant = (VariantID > 0) || (ZoneVariantID > 0) || IsNewVariant;
            if (!isWebPartVariant)
            {
                // Save the changes
                CMSPortalManager.SaveTemplateChanges(pi, templateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree);
            }
            else
            {
                Hashtable varProperties = WindowHelper.GetItem("variantProperties") as Hashtable;
                // Save changes to the web part variant
                VariantHelper.SaveWebPartVariantChanges(webPartInstance, VariantID, ZoneVariantID, VariantMode, varProperties);
            }

            // Reload the form (because of macro values set only by JS)
            form.ReloadData();

            // Clear the cached web part
            CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerInvariant());

            ShowChangesSaved();

            return(true);
        }

        if (webPartInstance?.ParentZone?.ParentTemplateInstance != null)
        {
            // Reload the zone/web part variants when saving of the form fails
            webPartInstance.ParentZone.ParentTemplateInstance.LoadVariants(true, VariantModeEnum.None);
        }

        return(false);
    }
예제 #40
0
    /// <summary>
    /// Save new layout.
    /// </summary>
    protected bool Save()
    {
        if (webPartInfo != null)
        {
            // Remove "." due to virtual path provider replacement
            txtLayoutName.Text = txtLayoutName.Text.Replace(".", "");

            string result = new Validator().NotEmpty(txtLayoutName.Text, GetString("WebPartPropertise.errCodeName")).NotEmpty(txtLayoutDisplayName.Text, GetString("WebPartPropertise.errDisplayName")).IsCodeName(txtLayoutName.Text, GetString("WebPartPropertise.errCodeNameFormat")).Result;

            if (result == "")
            {
                WebPartLayoutInfo tmpLayInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(webPartInfo.WebPartName, txtLayoutName.Text.Trim());
                if (tmpLayInfo == null)
                {
                    WebPartLayoutInfo wpli = new WebPartLayoutInfo();

                    wpli.WebPartLayoutCodeName = txtLayoutName.Text.Trim();

                    wpli.WebPartLayoutDescription = txtDescription.Text;
                    wpli.WebPartLayoutDisplayName = txtLayoutDisplayName.Text;

                    if (CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode"))
                    {
                        wpli.WebPartLayoutCode = etaCode.Text;
                    }
                    else
                    {
                        wpli.WebPartLayoutCode = GetDefaultCode();
                    }

                    wpli.WebPartLayoutCSS       = etaCSS.Text;
                    wpli.WebPartLayoutWebPartID = webPartInfo.WebPartID;

                    WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);

                    LayoutCodeName = wpli.WebPartLayoutCodeName;

                    txtDescription.Text       = "";
                    txtLayoutDisplayName.Text = "";
                    txtLayoutName.Text        = "";

                    plcDescription.Visible = false;
                    plcValues.Visible      = false;
                    etaCode.Rows           = 17;

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

                    pnlMenu.Visible         = true;
                    pnlCheckOutInfo.Visible = true;
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("WebPartPropertise.CodeNameAllreadyExists");
                    etaCode.Rows     = 17;
                    return(false);
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = result;
                etaCode.Rows     = 17;
                return(false);
            }
        }

        return(true);
    }
    /// <summary>
    /// Save layout code.
    /// </summary>
    protected bool SaveData()
    {
        // Remove "." due to virtual path provider replacement
        txtCodeName.Text = txtCodeName.Text.Replace(".", "");

        txtDisplayName.Text = txtDisplayName.Text.Trim();
        txtCodeName.Text = txtCodeName.Text.Trim();

        string errorMessage = new Validator()
            .NotEmpty(txtCodeName.Text, rfvCodeName.ErrorMessage)
            .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage)
            .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")).Result;

        int webPartId = ValidationHelper.GetInteger(Request.QueryString["webpartId"], 0);
        WebPartInfo webPartInfo = WebPartInfoProvider.GetWebPartInfo(webPartId);
        if (webPartInfo == null)
        {
            errorMessage = GetString("WebPartEditLayoutEdit.InvalidWebPartID");
        }

        if (errorMessage != String.Empty)
        {
            lblError.Text = errorMessage;
            lblError.Visible = true;
            return false;
        }

        // Get layout info
        WebPartLayoutInfo webPartLayoutInfo = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(layoutId);

        if (webPartLayoutInfo != null)
        {
            // Get layout info using its code name - layout code name must be unique
            DataSet ds = WebPartLayoutInfoProvider.GetWebPartLayouts("WebPartLayoutCodeName = '" + WebPartLayoutInfoProvider.GetWebPartLayoutFullCodeName(webPartInfo.WebPartName, txtCodeName.Text) + "'", null);

            // Find anything?
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                WebPartLayoutInfo temp = new WebPartLayoutInfo(ds.Tables[0].Rows[0]);
                // Is it the same layout?
                if ((ds.Tables[0].Rows.Count > 1) || (temp.WebPartLayoutID != webPartLayoutInfo.WebPartLayoutID))
                {
                    lblError.Text = String.Format(GetString("WebPartEditLayoutEdit.CodeNameAlreadyExist"), txtCodeName.Text);
                    lblError.Visible = true;
                    return false;
                }
            }

            webPartLayoutInfo.WebPartLayoutCodeName = txtCodeName.Text;
            webPartLayoutInfo.WebPartLayoutDisplayName = txtDisplayName.Text;
            webPartLayoutInfo.WebPartLayoutDescription = txtDescription.Text;

            if (!webPartLayoutInfo.Generalized.IsCheckedOut)
            {
                webPartLayoutInfo.WebPartLayoutCode = etaCode.Text;
                webPartLayoutInfo.WebPartLayoutCSS = tbCSS.Text;
            }

            WebPartLayoutInfoProvider.SetWebPartLayoutInfo(webPartLayoutInfo);

            // Reload header if changes were saved
            if (TabMode)
            {
                ScriptHelper.RefreshTabHeader(Page, null);
            }
        }
        return true;
    }
    /// <summary>
    /// Handles form's after data load event.
    /// </summary>
    protected void EditForm_OnAfterDataLoad(object sender, EventArgs e)
    {
        etaCode.Language = LanguageEnum.HTML;

        cssLayoutEditor.Editor.Language = LanguageEnum.CSS;
        cssLayoutEditor.Editor.ShowBookmarks = true;

        // Do not check changes
        DocumentManager.RegisterSaveChangesScript = false;

        EditForm.OnBeforeSave += EditForm_OnBeforeSave;

        etaCode.Language = LanguageEnum.HTML;

        wpli = UIContext.EditedObject as WebPartLayoutInfo;

        layoutID = QueryHelper.GetInteger("layoutid", 0);

        isSiteManager = ((MembershipContext.AuthenticatedUser.IsGlobalAdministrator && layoutID != 0) || QueryHelper.GetBoolean("sitemanager", false));
        isNew = (LayoutCodeName == "|new|");
        isDefault = (LayoutCodeName == "|default|") || (!isSiteManager && string.IsNullOrEmpty(LayoutCodeName));

        if ((wpli == null) || (wpli.WebPartLayoutID <= 0))
        {
            isNew |= isSiteManager;
            editMenuElem.ObjectManager.ObjectType = WebPartLayoutInfo.OBJECT_TYPE;
        }

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "PreviewHierarchyPerformAction", ScriptHelper.GetScript("function actionPerformed(action) { if (action == 'saveandclose') { document.getElementById('" + hdnClose.ClientID + "').value = '1'; } " + editMenuElem.ObjectManager.GetJSFunction(ComponentEvents.SAVE, null, null) + "; }"));

        currentUser = MembershipContext.AuthenticatedUser;

        // Get web part instance (if edited in CMSDesk)
        if ((webpartId != "") && !isSiteManager)
        {
            // Get page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture);
            if (pi == null)
            {
                ShowInformation(GetString("WebPartProperties.WebPartNotFound"), persistent: false);
            }
            else
            {
                // Get page template
                pti = pi.UsedPageTemplateInfo;
                if ((pti != null) && ((pti.TemplateInstance != null)))
                {
                    webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.TemplateInstance.GetWebPart(webpartId);
                }
            }
        }

        // If the web part is not found, try web part ID
        if (webPart == null)
        {
            wpi = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(webpartId, 0));
            if (wpi == null)
            {
                ShowError(GetString("WebPartProperties.WebPartNotFound"));
                startWithFullScreen = false;
                return;
            }
        }
        else
        {
            // CMS desk
            wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (string.IsNullOrEmpty(LayoutCodeName))
            {
                // Get the current layout name
                LayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }
        }

        if (wpi != null)
        {
            // Load the web part information
            webPartInfo = wpi;
            bool loaded = false;

            if (!RequestHelper.IsPostBack())
            {
                if (wpli != null)
                {
                    editMenuElem.MenuPanel.Visible = true;

                    // Read-only code text area
                    etaCode.Editor.ReadOnly = false;
                    loaded = true;
                }

                if (!loaded)
                {
                    string fileName = webPartInfo.WebPartFileName;

                    if (webPartInfo.WebPartParentID > 0)
                    {
                        WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(webPartInfo.WebPartParentID);
                        if (pwpi != null)
                        {
                            fileName = pwpi.WebPartFileName;
                        }
                    }

                    if (!fileName.StartsWithCSafe("~"))
                    {
                        fileName = "~/CMSWebparts/" + fileName;
                    }

                    // Check if filename exist
                    if (!FileHelper.FileExists(fileName))
                    {
                        ShowError(GetString("WebPartProperties.FileNotExist"));
                        pnlContent.Visible = false;
                        editMenuElem.ObjectEditMenu.Visible = false;
                    }
                    else
                    {
                        // Load default web part layout code
                        etaCode.Text = File.ReadAllText(Server.MapPath(fileName));

                        // Load default web part CSS
                        cssLayoutEditor.Text = wpi.WebPartCSS;
                        startWithFullScreen = false;
                    }
                }
            }
        }

        if (((wpli == null) || (wpli.WebPartLayoutID <= 0)) && isSiteManager)
        {
            editMenuElem.Title.Breadcrumbs.AddBreadcrumb(new BreadcrumbItem
            {
                Text = GetString("WebParts.Layout"),
                RedirectUrl = String.Format("{0}&parentobjectid={1}&displaytitle={2}", UIContextHelper.GetElementUrl("CMS.Design", "WebPart.Layout"), QueryHelper.GetInteger("webpartid", 0), false)
            });

            editMenuElem.Title.Breadcrumbs.AddBreadcrumb(new BreadcrumbItem
            {
                Text = GetString("webparts_layout_newlayout"),
            });
        }

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ApplyButton", ScriptHelper.GetScript(
            "function SetRefresh(refreshpage) { document.getElementById('" + hidRefresh.ClientID + @"').value = refreshpage; }
             function OnApplyButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('save');refreshPreview(); }
             function OnOKButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('saveandclose'); } "));

        InitLayoutForm();
    }
예제 #43
0
    /// <summary>
    /// Init event handler.
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        // Do not check changes
        DocumentManager.RegisterSaveChangesScript = false;

        EditForm.OnBeforeSave += EditForm_OnBeforeSave;

        etaCode.Editor.Language = LanguageEnum.HTML;
        etaCSS.Editor.Language  = LanguageEnum.CSS;

        wpli = CMSContext.EditedObject as WebPartLayoutInfo;

        layoutID = QueryHelper.GetInteger("layoutid", 0);

        isSiteManager = ((CMSContext.CurrentUser.IsGlobalAdministrator && layoutID != 0) || QueryHelper.GetBoolean("sitemanager", false));
        isNew         = (LayoutCodeName == "|new|");
        isDefault     = (LayoutCodeName == "|default|") || (!isSiteManager && string.IsNullOrEmpty(LayoutCodeName));

        if ((wpli == null) && isSiteManager)
        {
            isNew = true;
        }

        if (wpli == null)
        {
            editMenuElem.ObjectManager.ObjectType = PredefinedObjectType.WEBPARTLAYOUT;
        }

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "PreviewHierarchyPerformAction", ScriptHelper.GetScript("function actionPerformed(action) { if (action == 'saveandclose') { document.getElementById('" + hdnClose.ClientID + "').value = '1'; } " + editMenuElem.ObjectManager.GetJSFunction(ComponentEvents.SAVE, null, null) + "; }"));

        RegisterResizeHeaders();

        currentUser = CMSContext.CurrentUser;

        // Get webpart instance (if edited in CMSDesk)
        if ((webpartId != "") && !isSiteManager)
        {
            // Get pageinfo
            pi = CMSWebPartPropertiesPage.GetPageInfo(aliasPath, templateId, culture);
            if (pi == null)
            {
                ShowInformation(GetString("WebPartProperties.WebPartNotFound"), null, false);
            }

            // Get page template
            pti = pi.UsedPageTemplateInfo;
            if ((pti != null) && ((pti.TemplateInstance != null)))
            {
                webPart = pti.TemplateInstance.GetWebPart(instanceGuid, zoneVariantId, variantId) ?? pti.GetWebPart(webpartId);
            }
        }

        // If the web part is not found, try webpart ID
        if (webPart == null)
        {
            // Site manager
            wpi = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(webpartId, 0));
            if (wpi == null)
            {
                ShowError(GetString("WebPartProperties.WebPartNotFound"), null, null);
                startWithFullScreen = false;
                return;
            }
        }
        else
        {
            // CMS desk
            wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
            if (string.IsNullOrEmpty(LayoutCodeName))
            {
                // Get the current layout name
                LayoutCodeName = ValidationHelper.GetString(webPart.GetValue("WebPartLayout"), "");
            }
        }

        if (wpi != null)
        {
            if (CMSObjectHelper.UseCheckinCheckout && (!isNew || isSiteManager))
            {
                pnlFormArea.CssClass = "PreviewDefaultContentLarge";
            }
            else
            {
                pnlFormArea.CssClass = "PreviewDefaultContent";
            }

            // Load the web part information
            webPartInfo = wpi;
            bool loaded = false;

            if (!RequestHelper.IsPostBack())
            {
                if (wpli != null)
                {
                    editMenuElem.MenuPanel.Visible = true;

                    // Read-only code text area
                    etaCode.Editor.ReadOnly = false;
                    loaded = true;
                }

                if (!loaded)
                {
                    string fileName = webPartInfo.WebPartFileName;

                    if (webPartInfo.WebPartParentID > 0)
                    {
                        WebPartInfo pwpi = WebPartInfoProvider.GetWebPartInfo(webPartInfo.WebPartParentID);
                        if (pwpi != null)
                        {
                            fileName = pwpi.WebPartFileName;
                        }
                    }

                    if (!fileName.StartsWithCSafe("~"))
                    {
                        fileName = "~/CMSWebparts/" + fileName;
                    }

                    // Check if filename exist
                    if (!FileHelper.FileExists(fileName))
                    {
                        ShowError(GetString("WebPartProperties.FileNotExist"), null, null);
                        plcContent.Visible = false;
                    }
                    else
                    {
                        // Load default web part layout code
                        etaCode.Text = File.ReadAllText(Server.MapPath(fileName));

                        // Load default web part CSS
                        etaCSS.Text         = wpi.WebPartCSS;
                        startWithFullScreen = false;
                    }
                }
            }
        }

        if ((wpli == null) && isSiteManager)
        {
            pnlFormArea.CssClass += " NewPreviewContent";

            var breadcrumbs = new string[2, 3];
            breadcrumbs[0, 0] = GetString("WebParts.Layout");
            breadcrumbs[0, 1] = ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Edit_Layout.aspx?webpartid=" + QueryHelper.GetInteger("webpartid", 0));
            breadcrumbs[1, 0] = GetString("webparts_layout_newlayout");
            editMenuElem.PageTitleBreadcrumbs = breadcrumbs;
        }

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ApplyButton", ScriptHelper.GetScript(
                                                   "function SetRefresh(refreshpage) { document.getElementById('" + hidRefresh.ClientID + @"').value = refreshpage; }
             function OnApplyButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('save');refreshPreview(); }  
             function OnOKButton(refreshpage) { SetRefresh(refreshpage); actionPerformed('saveandclose'); } "));

        InitLayoutForm();

        plcCssLink.Visible = string.IsNullOrEmpty(etaCSS.Text.Trim());

        base.OnInit(e);
    }
    protected void ObjectManager_OnAfterAction(object sender, SimpleObjectManagerEventArgs e)
    {
        wpli = EditForm.EditedObject as WebPartLayoutInfo;

        if (wpli != null)
        {
            LayoutCodeName = wpli.WebPartLayoutCodeName;
        }

        if (e.ActionName == ComponentEvents.SAVE)
        {
            if (EditForm.ValidateData())
            {
                if (!isSiteManager)
                {
                    SetCurrentLayout(true);
                }

                if (ValidationHelper.GetBoolean(hdnClose.Value, false))
                {
                    // If window to close, register close script
                    CloseDialog();
                }
                else
                {
                    // Redirect parent for new
                    if (isNew)
                    {
                        if (isSiteManager)
                        {
                            URLHelper.Redirect("WebPart_Edit_Layout_Frameset.aspx?layoutID=" + wpli.WebPartLayoutID + "&webpartID=" + webPartInfo.WebPartID);
                        }
                        else
                        {
                            var codeName = (wpli != null) ? wpli.WebPartLayoutCodeName : string.Empty;
                            var redirectUrl = ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/WebPartProperties_layout_frameset.aspx") + URLHelper.UpdateParameterInUrl(URLHelper.Url.Query, "layoutcodename", codeName);
                            ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "RefreshHeader", ScriptHelper.GetScript("parent.location ='" + redirectUrl + "'"));
                        }
                    }
                    else
                    {
                        if (!isSiteManager)
                        {
                            // Reload the parent page after save
                            EnsureParentPageRefresh();
                        }

                        // If all ok show changes saved
                        ShowChangesSaved();
                        RegisterRefreshScript();
                    }
                }
            }

            // Clear warning text
            editMenuElem.MessagesPlaceHolder.WarningText = "";
        }

        if (DialogMode)
        {
            switch (e.ActionName)
            {
                case ComponentEvents.SAVE:
                case ComponentEvents.CHECKOUT:
                case ComponentEvents.UNDO_CHECKOUT:
                case ComponentEvents.CHECKIN:
                    ScriptHelper.RegisterStartupScript(Page, typeof(string), "wopenerRefresh", ScriptHelper.GetScript("if (wopener && wopener.refresh) { wopener.refresh(); }"));
                    break;
            }
        }

        if (isSiteManager && (e.ActionName != ComponentEvents.CHECKOUT))
        {
            ScriptHelper.RefreshTabHeader(Page, null);
        }
    }