Esempio n. 1
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());
    }
Esempio n. 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);
    }
Esempio n. 4
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();
    }
Esempio n. 5
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);
    }
Esempio n. 6
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);
    }
Esempio n. 10
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);
    }
Esempio n. 11
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);
    }
Esempio n. 12
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;
        }
    }
Esempio n. 13
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;
        }
    }
Esempio n. 14
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|");
    }
Esempio n. 15
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);
        }
    }
Esempio n. 16
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
        {
        }
    }
Esempio n. 17
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);
    }
Esempio n. 18
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;
                }
            }
        }
    }
Esempio n. 19
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);
                    }
                }
            }
        }
    }
    /// <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);
    }
Esempio n. 21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        StringSafeDictionary <object> decodedProperties = new StringSafeDictionary <object>();

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

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

        string widgetName = ValidationHelper.GetString(mProperties["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
        {
            // Merge widget and it's parent webpart properties
            string properties = FormHelper.MergeFormDefinitions(wpi.WebPartProperties, wi.WidgetProperties);

            // Prepare form
            WidgetZoneTypeEnum zoneType           = WidgetZoneTypeEnum.Editor;
            FormInfo           zoneTypeDefinition = PortalFormHelper.GetPositionFormInfo(zoneType);
            FormInfo           fi = PortalFormHelper.GetWidgetFormInfo(wi.WidgetName, Enum.GetName(typeof(WidgetZoneTypeEnum), zoneType), properties, zoneTypeDefinition, true);

            // Apply changed values
            DataRow dr = PortalHelper.CombineWithDefaultValues(fi, wi);
            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.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();

            // 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 (mProperties.Contains(columnName))
                {
                    FormFieldInfo ffi = fi.GetFormField(columnName);
                    if ((ffi != null) && ffi.Visible && (!ffi.DisplayIn.Contains(FormInfo.DISPLAY_CONTEXT_DASHBOARD)))
                    {
                        value = mProperties[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
                        value = control.ContextResolver.ResolveMacros(value.ToString(), avoidInjection);
                    }
                }

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

            control.PartInstance.IsWidget = true;

            // Load webpart content
            control.OnContentLoaded();

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

        catch (Exception ex)
        {
            AddErrorWebPart("widget.failedtoload", ex);
        }
    }