/// <summary>
    /// Handle btnOK's OnClick event.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string errorMessage = "";

        // Get WebPartInfo.
        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(QueryHelper.GetInteger("webpartid", 0));

        if (wpi != null)
        {
            // Update web part CSS
            try
            {
                wpi.WebPartCSS = etaCSS.Text;
                WebPartInfoProvider.SetWebPartInfo(wpi);
                lblInfo.Text    = GetString("General.ChangesSaved");
                lblInfo.Visible = true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            // Show error message
            if (errorMessage != "")
            {
                lblError.Text    = errorMessage;
                lblError.Visible = true;
            }
        }
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void webpartGrid_OnAction(string actionName, object actionArgument)
    {
        int webpartId = Convert.ToInt32(actionArgument);

        switch (actionName)
        {
        case "delete":
            // Check 'Modify' permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.webpart", "Modify"))
            {
                RedirectToAccessDenied("cms.webpart", "Modify");
            }

            // Check if webpart has widgets
            DataSet dsWidgets = WidgetInfoProvider.GetWidgets("WidgetWebPartID = " + webpartId, null, 0, "WidgetWebPartID");
            if (!DataHelper.DataSourceIsEmpty(dsWidgets))
            {
                string delPostback = ControlsHelper.GetPostBackEventReference(Page, webpartId.ToString());
                delPostback    = "if (confirm('" + GetString("webparts.deletewithwidgets") + "')) {\n " + delPostback + ";}\n";
                ltlScript.Text = ScriptHelper.GetScript(delPostback);
            }
            else
            {
                // Delete PageTemplateInfo object from database
                WebPartInfoProvider.DeleteWebPartInfo(webpartId);

                // Refresh tree
                ltlScript.Text = ScriptHelper.GetScript("RefreshAdditionalContent();");
            }
            break;
        }
    }
    /// <summary>
    /// Initializes menu.
    /// </summary>
    protected void InitalizeMenu()
    {
        if (webpartId != "")
        {
            // get pageinfo
            PageInfo pi = GetPageInfo(aliasPath, templateId);
            if (pi == null)
            {
                this.Visible = false;
                return;
            }

            PageTemplateInfo pti = pi.PageTemplateInfo;
            if (pti != null)
            {
                WebPartInfo wi = null;

                // Get web part
                WebPartInstance webPart = pti.GetWebPart(instanceGuid, webpartId);
                if (webPart != null)
                {
                    wi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
                    if (ValidationHelper.GetString(webPart.GetValue("WebPartCode"), "").Trim() != "")
                    {
                        showCodeTab = true;
                    }
                    if (webPart.Bindings.Count > 0)
                    {
                        showBindingTab = true;
                    }
                }
                else
                {
                    wi = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(webpartId, 0));
                }

                if (wi != null)
                {
                    // Generate documentation link
                    Literal ltr = new Literal();
                    PageTitle.RightPlaceHolder.Controls.Add(ltr);

                    string docScript = "NewWindow('" + ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/WebPartDocumentationPage.aspx") + "?webpartid=" + ScriptHelper.GetString(wi.WebPartName, false) + "', 'WebPartPropertiesDocumentation', 800, 800); return false;";

                    ltr.Text  = "<table cellpadding=\"0\" cellspacing=\"0\"><tr><td>";
                    ltr.Text += "<a onclick=\"" + docScript + "\" href=\"#\"><img src=\"" + ResolveUrl(GetImageUrl("CMSModules/CMS_PortalEngine/Documentation.png")) + "\" style=\"border-width: 0px;\"></a>";
                    ltr.Text += "</td>";
                    ltr.Text += "<td>";
                    ltr.Text += "<a onclick=\"" + docScript + "\" href=\"#\">" + GetString("WebPartPropertie.DocumentationLink") + "</a>";
                    ltr.Text += "</td></tr></table>";

                    PageTitle.TitleText = GetString("WebpartProperties.Title") + " (" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(wi.WebPartDisplayName)) + ")";
                }
            }
        }

        CurrentUserInfo currentUser = CMSContext.CurrentUser;

        tabsElem.UrlTarget = "webpartpropertiescontent";
    }
Exemple #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);
    }
Exemple #5
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);
    }
    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());
    }
Exemple #7
0
    /// <summary>
    /// Page load.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "Web part clone";

        LoadResources();

        txtWebPartFileName.ReadOnly = false;
        txtWebPartFileName.Enabled  = true;

        if (!RequestHelper.IsPostBack())
        {
            FillDropDownList(0, 0);
        }

        // Get the webpart ID
        webPartId = ValidationHelper.GetInteger(Request.QueryString["webpartID"], 0);
        if (webPartId > 0)
        {
            // Select webpart category on dropdown list
            WebPartInfo wi = WebPartInfoProvider.GetWebPartInfo(webPartId);

            if (wi != null)
            {
                // Find unique webpart name
                string newWebpartName        = wi.WebPartName;
                string newWebpartDisplayName = wi.WebPartDisplayName;
                while (WebPartInfoProvider.GetWebPartInfo(newWebpartName) != null)
                {
                    newWebpartDisplayName = Increment(newWebpartDisplayName, "(", ")");
                    newWebpartName        = Increment(newWebpartName, "_", "");
                }

                string webPartFileName = wi.WebPartFileName;

                // Careful with inherited web parts
                if (wi.WebPartParentID > 0)
                {
                    WebPartInfo wparent = WebPartInfoProvider.GetWebPartInfo(wi.WebPartParentID);
                    if (wparent != null)
                    {
                        // Cannot copy file of webpart which has not own one
                        plcFile.Visible = false;
                        chckCloneWebPartFiles.Checked = false;

                        txtWebPartFileName.ReadOnly = true;
                        txtWebPartFileName.Enabled  = false;
                        lblWebPartFileName.Text     = GetString("Development-WebPart_Clone.ParentWebPart");
                    }
                }

                if (!RequestHelper.IsPostBack())
                {
                    drpWebPartCategories.SelectedValue = wi.WebPartCategoryID.ToString();
                    txtWebPartDisplayName.Text         = newWebpartDisplayName;
                    txtWebPartName.Text     = newWebpartName;
                    txtWebPartFileName.Text = webPartFileName;
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get web part info
        webPartInfo            = WebPartInfoProvider.GetWebPartInfo(WebPartID);
        UIContext.EditedObject = webPartInfo;

        // Check if info object exists
        if (webPartInfo != null)
        {
            // Set field editor
            if (webPartInfo.WebPartParentID > 0)
            {
                parentWebPartInfo = WebPartInfoProvider.GetWebPartInfo(webPartInfo.WebPartParentID);

                if (parentWebPartInfo != null)
                {
                    fieldEditor.Mode                     = FieldEditorModeEnum.InheritedWebPartProperties;
                    fieldEditor.AllowExtraFields         = true;
                    fieldEditor.OriginalFormDefinition   = parentWebPartInfo.WebPartProperties;
                    fieldEditor.FormDefinition           = FormHelper.MergeFormDefinitions(parentWebPartInfo.WebPartProperties, webPartInfo.WebPartProperties);
                    fieldEditor.OnAfterDefinitionUpdate += fieldEditor_OnAfterDefinitionUpdate;
                }
            }
            else
            {
                fieldEditor.Mode      = FieldEditorModeEnum.WebPartProperties;
                fieldEditor.WebPartId = WebPartID;

                // Check newly created field for widgets update
                fieldEditor.OnFieldCreated   += UpdateWidgetsDefinition;
                fieldEditor.AfterItemDeleted += fieldEditor_AfterItemDeleted;
            }
        }
    }
Exemple #9
0
    /// <summary>
    /// PreInit event handler.
    /// </summary>
    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);

        // Init the page components
        PageManager = manPortal;
        manPortal.SetMainPagePlaceholder(plc);

        int webPartId = QueryHelper.GetInteger("webpartid", 0);

        wpi = WebPartInfoProvider.GetWebPartInfo(webPartId);
        UIContext.EditedObject = wpi;

        // If default configuration not available, do not display content
        configAvailable = wpi.HasDefaultConfiguration();

        var pt = wpi.GetVirtualPageTemplate();

        PageInfo pi = PageInfoProvider.GetVirtualPageInfo(pt);

        pi.DocumentNamePath = "/" + ResHelper.GetString("edittabs.design");

        DocumentContext.CurrentPageInfo = pi;

        // Set the design mode
        PortalContext.SetRequestViewMode(ViewModeEnum.DesignWebPart);

        ManagersContainer    = plcManagers;
        ScriptManagerControl = manScript;
    }
Exemple #10
0
    /// <summary>
    /// Creates web part. Called when the "Create part" button is pressed.
    /// </summary>
    private bool CreateWebPart()
    {
        // Get parent category for web part
        WebPartCategoryInfo category = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("MyNewCategory");

        if (category != null)
        {
            // Create new web part object
            WebPartInfo newWebpart = new WebPartInfo();

            // Set the properties
            newWebpart.WebPartDisplayName = "My new web part";
            newWebpart.WebPartName        = "MyNewWebpart";
            newWebpart.WebPartDescription = "This is my new web part.";
            newWebpart.WebPartFileName    = "whatever";
            newWebpart.WebPartProperties  = "<form></form>";
            newWebpart.WebPartCategoryID  = category.CategoryID;

            // Save the web part
            WebPartInfoProvider.SetWebPartInfo(newWebpart);

            return(true);
        }
        return(false);
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void webpartGrid_OnAction(string actionName, object actionArgument)
    {
        int webpartId = Convert.ToInt32(actionArgument);

        switch (actionName)
        {
        case "delete":
            // Check 'Modify' permission
            if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.webpart", "Modify"))
            {
                RedirectToAccessDenied("cms.webpart", "Modify");
            }

            // Delete PageTemplateInfo object from database
            WebPartInfoProvider.DeleteWebPartInfo(webpartId);

            // Refresh tree
            ltlScript.Text = ScriptHelper.GetScript("RefreshAdditionalContent();");
            break;

        case "clone":
            string scriptDialog = "modalDialog('" + URLHelper.ResolveUrl("~/CMSModules/PortalEngine/UI/WebParts/Development/WebPart_Clone.aspx") + "?webpartid=" + webpartId + "&reloadAll=1','WebPartClone', 500, 250);";
            ltlScript.Text = ScriptHelper.GetScript(scriptDialog);
            break;
        }
    }
Exemple #12
0
    /// <summary>
    /// Loads the web part info
    /// </summary>
    private void EnsureWebPartInfo()
    {
        if (wpi != null)
        {
            return;
        }

        if (NestedWebPartID > 0)
        {
            // Setup the form for data source
            wpi       = WebPartInfoProvider.GetWebPartInfo(NestedWebPartID);
            form.Mode = FormModeEnum.Update;
            return;
        }

        if (!IsNewWebPart)
        {
            // Get web part by code name
            wpi       = WebPartInfoProvider.GetWebPartInfo(webPartInstance.WebPartType);
            form.Mode = FormModeEnum.Update;
        }
        else
        {
            // Web part instance wasn't created yet, get by web part ID
            wpi       = WebPartInfoProvider.GetWebPartInfo(ValidationHelper.GetInteger(WebPartID, 0));
            form.Mode = FormModeEnum.Insert;
        }
    }
Exemple #13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        lblFiles.ToolTip           = GetString("clonning.settings.webpart.files.tooltip");
        lblFileName.ToolTip        = GetString("clonning.settings.webpart.filename.tooltip");
        lblWebPartCategory.ToolTip = GetString("clonning.settings.webpart.category.tooltip");

        if (!RequestHelper.IsPostBack())
        {
            FillDropDownList(0, 0);

            WebPartInfo wpi = InfoToClone as WebPartInfo;
            if (wpi != null)
            {
                if (wpi.WebPartParentID > 0)
                {
                    WebPartInfo wparent = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                    if (wparent != null)
                    {
                        // Hide files box for inherited webparts
                        plcFiles.Visible = false;
                    }
                }

                if (plcFiles.Visible)
                {
                    string absolutePath = WebPartInfoProvider.WebPartsDirectory + "/" + wpi.WebPartFileName.TrimStart('/');
                    txtFileName.Text = FileHelper.GetUniqueFileName(absolutePath).Substring(WebPartInfoProvider.WebPartsDirectory.Length).TrimStart('/');
                }

                drpWebPartCategories.SelectedValue = wpi.WebPartCategoryID.ToString();
            }
        }
    }
Exemple #14
0
    /// <summary>
    /// Creates widget. Called when the "Create widget" button is pressed.
    /// </summary>
    private bool CreateWidget()
    {
        // Get parent webpart and category for widget
        WebPartInfo        webpart  = WebPartInfoProvider.GetWebPartInfo("AbuseReport");
        WidgetCategoryInfo category = WidgetCategoryInfoProvider.GetWidgetCategoryInfo("MyNewCategory");

        // Widget cannot be created from inherited webpart
        if ((webpart != null) && (webpart.WebPartParentID == 0) && (category != null))
        {
            // Create new widget object
            WidgetInfo newWidget = new WidgetInfo();

            // Set the properties from parent webpart
            newWidget.WidgetName        = "MyNewWidget";
            newWidget.WidgetDisplayName = "My new widget";
            newWidget.WidgetDescription = webpart.WebPartDescription;

            newWidget.WidgetProperties = FormHelper.GetFormFieldsWithDefaultValue(webpart.WebPartProperties, "visible", "false");

            newWidget.WidgetWebPartID  = webpart.WebPartID;
            newWidget.WidgetCategoryID = category.WidgetCategoryID;

            // Save new widget
            WidgetInfoProvider.SetWidgetInfo(newWidget);

            return(true);
        }

        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        widgetInfo             = WidgetInfoProvider.GetWidgetInfo(WidgetID);
        UIContext.EditedObject = widgetInfo;

        if (widgetInfo != null)
        {
            webpartInfo           = WebPartInfoProvider.GetWebPartInfo(widgetInfo.WidgetWebPartID);
            fieldEditor.DisplayIn = FormInfo.DISPLAY_CONTEXT_DASHBOARD;

            if (webpartInfo != null)
            {
                // Set original form definition from webpart
                fieldEditor.OriginalFormDefinition = webpartInfo.WebPartProperties;

                // Merge class and alternative form definitions
                string formDef = FormHelper.MergeFormDefinitions(webpartInfo.WebPartProperties, widgetInfo.WidgetProperties);

                // Use alternative form mode for field editor
                fieldEditor.Mode           = FieldEditorModeEnum.Widget;
                fieldEditor.FormDefinition = formDef;

                // Use same control for widgets as for webparts
                fieldEditor.DisplayedControls = FieldEditorControlsEnum.Controls;

                // Handle definition update (move up, move down, delete, OK button)
                fieldEditor.OnAfterDefinitionUpdate += fieldEditor_OnAfterDefinitionUpdate;
            }
        }
        else
        {
            fieldEditor.Visible = false;
            ShowError(GetString("general.invalidid"));
        }
    }
Exemple #16
0
    /// <summary>
    /// Gets and bulk updates web parts. Called when the "Get and bulk update parts" button is pressed.
    /// Expects the CreateWebPart method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWebParts()
    {
        // Prepare the parameters
        string where = "WebPartName LIKE N'MyNewWebpart%'";

        // Get the data
        DataSet webparts = WebPartInfoProvider.GetWebParts(where, null);

        if (!DataHelper.DataSourceIsEmpty(webparts))
        {
            // Loop through the individual items
            foreach (DataRow webpartDr in webparts.Tables[0].Rows)
            {
                // Create object from DataRow
                WebPartInfo modifyWebpart = new WebPartInfo(webpartDr);

                // Update the properties
                modifyWebpart.WebPartDisplayName = modifyWebpart.WebPartDisplayName.ToUpper();

                // Save the changes
                WebPartInfoProvider.SetWebPartInfo(modifyWebpart);
            }

            return(true);
        }

        return(false);
    }
Exemple #17
0
    /// <summary>
    /// Event loaded after ok button clicked.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Event args</param>
    void ucDefaultValueEditor_XMLCreated(object sender, EventArgs e)
    {
        int         webPartId = QueryHelper.GetInteger("webpartid", 0);
        WebPartInfo wpi       = WebPartInfoProvider.GetWebPartInfo(webPartId);

        if (wpi != null)
        {
            if (wpi.WebPartParentID > 0)
            {
                //Remove overloaded default values and replace them with new ones
                string filteredDef = String.Empty;
                //Load parent
                WebPartInfo parentInfo = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                if (parentInfo != null)
                {
                    // Remove properties from collection with same name as in default system xml
                    filteredDef = ucDefaultValueEditor.FitlerDefaultValuesDefinition(wpi.WebPartDefaultValues, parentInfo.WebPartProperties, false);
                }
                // FilteredDef now contains only properties inherited from parent web part
                // Combine with changed default system values
                wpi.WebPartDefaultValues = FormHelper.CombineFormDefinitions(filteredDef, ucDefaultValueEditor.DefaultValueXMLDefinition);
            }
            else
            {
                wpi.WebPartDefaultValues = ucDefaultValueEditor.DefaultValueXMLDefinition;
            }
            WebPartInfoProvider.SetWebPartInfo(wpi);
        }

        string url = URLHelper.RemoveParameterFromUrl(URLRewriter.CurrentURL, "saved");

        url = URLHelper.AddParameterToUrl(url, "saved", "1");
        URLHelper.Redirect(url);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        webpartId = QueryHelper.GetInteger("webpartid", 0);

        Title = "Web part documentation";

        // Resource string
        btnOk.Text = GetString("General.Ok");

        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webpartId);

        EditedObject = wpi;
        if (wpi != null)
        {
            HeaderAction action = new HeaderAction();
            action.Text        = GetString("webparteditdocumentation.view");
            action.RedirectUrl = "~/CMSModules/PortalEngine/UI/WebParts/WebPartDocumentationPage.aspx?webpartid=" + wpi.WebPartName;
            action.Target      = "_blank";
            CurrentMaster.HeaderActions.AddAction(action);
        }

        // HTML editor settings
        htmlText.AutoDetectLanguage = false;
        htmlText.DefaultLanguage    = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
        htmlText.EditorAreaCSS      = "";
        htmlText.ToolbarSet         = "SimpleEdit";

        // Load data
        if (!RequestHelper.IsPostBack() && (wpi != null))
        {
            htmlText.ResolvedValue = wpi.WebPartDocumentation;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        widgetInfo = WidgetInfoProvider.GetWidgetInfo(this.WidgetID);
        if (widgetInfo != null)
        {
            webpartInfo           = WebPartInfoProvider.GetWebPartInfo(widgetInfo.WidgetWebPartID);
            fieldEditor.DisplayIn = FormInfo.DISPLAY_CONTEXT_DASHBOARD;

            if (webpartInfo != null)
            {
                // Merge class and alternative form definitions
                string formDef = FormHelper.MergeFormDefinitions(webpartInfo.WebPartProperties, widgetInfo.WidgetProperties);

                // Use alternative form mode for field editor
                fieldEditor.Mode              = FieldEditorModeEnum.General;
                fieldEditor.FormDefinition    = formDef;
                fieldEditor.IsAlternativeForm = true;

                // Use same control for widgets as for webparts
                fieldEditor.DisplayedControls = FieldEditorControlsEnum.Controls;

                // Handle definition update (move up, move down, delete, OK button)
                fieldEditor.OnAfterDefinitionUpdate += fieldEditor_OnAfterDefinitionUpdate;
            }
        }
        else
        {
            fieldEditor.Visible = false;
            ShowErrorMessage();
        }
    }
Exemple #20
0
    /// <summary>
    /// Handle btnOK's OnClick event.
    /// </summary>
    protected void Save()
    {
        string errorMessage = "";

        if (wpi != null)
        {
            // Update web part CSS
            try
            {
                wpi.WebPartCSS = etaCSS.Text;
                WebPartInfoProvider.SetWebPartInfo(wpi);
                ShowChangesSaved();
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            // Show error message
            if (errorMessage != "")
            {
                ShowError(errorMessage);
            }

            RegisterRefreshScript();
        }
    }
Exemple #21
0
    /// <summary>
    /// Gets the default layout code for the web part
    /// </summary>
    protected string GetDefaultCode()
    {
        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;
        }

        string fileFullPath = Server.MapPath(fileName);

        if (File.Exists(fileFullPath))
        {
            return(File.ReadAllText(fileFullPath));
        }

        return(null);
    }
    /// <summary>
    /// Generates the web part code.
    /// </summary>
    /// <param name="webpartId">Web part ID</param>
    /// <param name="baseControl">Base control nested within the web part</param>
    /// <param name="ascx">Returning ASCX code</param>
    /// <param name="code">Returning code behind</param>
    public static void GenerateWebPartCode(int webpartId, string baseControl, out string ascx, out string code)
    {
        string designer = null;

        WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webpartId);

        GenerateWebPartCode(wpi, baseControl, out ascx, out code, out designer);
    }
Exemple #23
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 void Page_Load(object sender, EventArgs e)
    {
        this.Title = "WebPart Edit - Properties";
        CurrentMaster.BodyClass += " FieldEditorBody";

        // get webpart ID
        webPartId           = QueryHelper.GetInteger("webpartid", 0);
        FieldEditor.Visible = false;

        // If saved is found in query string
        if ((!RequestHelper.IsPostBack()) && (QueryHelper.GetInteger("saved", 0) == 1))
        {
            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");
        }

        if (webPartId > 0)
        {
            // Get web part info
            wi = WebPartInfoProvider.GetWebPartInfo(webPartId);

            // Check if info object exists
            if (wi != null)
            {
                // For inherited webpart display DefaultValue Editor
                if (wi.WebPartParentID > 0)
                {
                    FieldEditor.Visible                 = false;
                    pnlDefaultEditor.Visible            = true;
                    DefaultValueEditor1.Visible         = true;
                    DefaultValueEditor1.ParentWebPartID = wi.WebPartParentID;
                    if (wi.WebPartParentID > 0)
                    {
                        DefaultValueEditor1.DefaultValueXMLDefinition = wi.WebPartDefaultValues;
                    }
                    else
                    {
                        DefaultValueEditor1.DefaultValueXMLDefinition = wi.WebPartProperties;
                    }
                    // Add handler to
                    DefaultValueEditor1.XMLCreated += new EventHandler(DefaultValueEditor1_XMLCreated);
                }
                else
                {
                    // set fieldeditor
                    FieldEditor.WebPartId    = webPartId;
                    FieldEditor.Mode         = FieldEditorModeEnum.WebPartProperties;
                    FieldEditor.Visible      = true;
                    pnlDefaultEditor.Visible = false;

                    // Check newly created field for widgets update
                    FieldEditor.OnFieldCreated += UpdateWidgetsDefinition;
                }
            }
        }
    }
Exemple #25
0
    /// <summary>
    /// Deletes web part. Called when the "Delete part" button is pressed.
    /// Expects the CreateWebPart method to be run first.
    /// </summary>
    private bool DeleteWebPart()
    {
        // Get the web part
        WebPartInfo deleteWebpart = WebPartInfoProvider.GetWebPartInfo("MyNewWebpart");

        // Delete the web part
        WebPartInfoProvider.DeleteWebPartInfo(deleteWebpart);

        return(deleteWebpart != 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);
    }
    void fieldEditor_AfterItemDeleted(object sender, FieldEditorEventArgs e)
    {
        if (e == null)
        {
            return;
        }

        // Remove deleted field or category from inherited web parts
        InfoDataSet <WebPartInfo> webParts = WebPartInfoProvider.GetWebParts()
                                             .WhereEquals("WebPartParentID", WebPartID).TypedResult;

        if (!DataHelper.DataSourceIsEmpty(webParts))
        {
            foreach (WebPartInfo info in webParts)
            {
                switch (e.ItemType)
                {
                case FieldEditorSelectedItemEnum.Field:
                    info.WebPartProperties = FormHelper.RemoveFieldFromAlternativeDefinition(info.WebPartProperties, e.ItemName, e.ItemOrder);
                    break;

                case FieldEditorSelectedItemEnum.Category:
                    info.WebPartProperties = FormHelper.RemoveCategoryFromAlternativeDefinition(info.WebPartProperties, e.ItemName, e.ItemOrder);
                    break;
                }

                // Update web part
                info.Update();
            }
        }

        // Remove deleted field or category from widgets based on this web part
        InfoDataSet <WidgetInfo> widgets = WidgetInfoProvider.GetWidgets()
                                           .WhereEquals("WidgetWebPartID", WebPartID).TypedResult;

        if (!DataHelper.DataSourceIsEmpty(widgets))
        {
            foreach (WidgetInfo info in widgets)
            {
                switch (e.ItemType)
                {
                case FieldEditorSelectedItemEnum.Field:
                    info.WidgetProperties = FormHelper.RemoveFieldFromAlternativeDefinition(info.WidgetProperties, e.ItemName, e.ItemOrder);
                    break;

                case FieldEditorSelectedItemEnum.Category:
                    info.WidgetProperties = FormHelper.RemoveCategoryFromAlternativeDefinition(info.WidgetProperties, e.ItemName, e.ItemOrder);
                    break;
                }

                // Update widget
                info.Update();
            }
        }
    }
    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);
    }
Exemple #29
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        lblFiles.ToolTip           = GetString("clonning.settings.webpart.files.tooltip");
        lblFileName.ToolTip        = GetString("clonning.settings.webpart.filename.tooltip");
        lblWebPartCategory.ToolTip = GetString("clonning.settings.webpart.category.tooltip");

        if (!RequestHelper.IsPostBack())
        {
            var wpi = InfoToClone as WebPartInfo;
            if (wpi != null)
            {
                if (wpi.WebPartParentID > 0)
                {
                    WebPartInfo wparent = WebPartInfoProvider.GetWebPartInfo(wpi.WebPartParentID);
                    if (wparent != null)
                    {
                        // Hide files box for inherited webparts
                        plcFiles.Visible = false;
                    }
                }

                if (plcFiles.Visible)
                {
                    string filePath = wpi.WebPartFileName;
                    bool   isRooted = filePath.StartsWith("~/", StringComparison.Ordinal);
                    if (!isRooted)
                    {
                        // Get the rooted path
                        filePath = WebPartInfoProvider.WebPartsDirectory + "/" + filePath.TrimStart('/');
                    }
                    // Ensure unique file name
                    filePath = FileHelper.GetUniqueFileName(filePath);
                    if (!isRooted)
                    {
                        // Get back the path relative to the web parts directory
                        filePath = filePath.Substring(WebPartInfoProvider.WebPartsDirectory.Length).TrimStart('/');
                    }
                    txtFileName.Text = filePath;
                }

                drpWebPartCategories.Value = wpi.WebPartCategoryID.ToString();

                if (SystemContext.IsPrecompiledWebsite)
                {
                    txtFileName.Text = wpi.WebPartFileName;
                    chkFiles.Checked = false;

                    txtFileName.Enabled = chkFiles.Enabled = false;
                    txtFileName.ToolTip = chkFiles.ToolTip = GetString("general.copyfiles.precompiled");
                }
            }
        }
    }
Exemple #30
0
    /// <summary>
    /// Generates the web part code.
    /// </summary>
    protected void GenerateCode()
    {
        string ascx;
        string code;

        // Generate the code
        WebPartInfoProvider.GenerateWebPartCode(webpartId, txtBaseControl.Text.Trim(), out ascx, out code);

        txtASCX.Text = ascx;
        txtCS.Text   = code;
    }