Exemple #1
0
    private void SetDialogMode()
    {
        CurrentMaster.PanelContent.CssClass = "PageContent";

        string containerName = QueryHelper.GetString("name", string.Empty);

        if (!string.IsNullOrEmpty(containerName))
        {
            // Set page title
            CurrentMaster.Title.TitleText     = GetString("Container_Edit.EditContainer");
            CurrentMaster.Title.TitleImage    = GetObjectIconUrl(PortalObjectType.WEBPARTCONTAINER, null);
            CurrentMaster.Title.HelpTopicName = "newedit_container";

            // Get container data
            webPartContainerObj = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerName);
            SetEditedObject(webPartContainerObj, "Container_Edit_Frameset.aspx");
        }

        AddDialogButtons();

        // Disable display and code name editing
        txtContainerDisplayName.ReadOnly = txtContainerName.ReadOnly = true;

        // When in modal dialog, the window scrolls to bottom, so this hack will scroll it back to top
        string scrollScript = "var scrollerDiv = document.getElementById('divContent'); if (scrollerDiv != null) setTimeout(function() { scrollerDiv.scrollTop = 0; }, 500);";

        ScriptHelper.RegisterStartupScript(this, GetType(), "ScrollTop", scrollScript, true);
    }
Exemple #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        InitHeaderActions();

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

        if (mDialogMode)
        {
            SetDialogMode();
        }
        else
        {
            // Get by container ID
            containerId = QueryHelper.GetInteger("containerid", 0);
            if (containerId > 0)
            {
                webPartContainerObj = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerId);
                SetEditedObject(webPartContainerObj, null);
            }
        }

        if (!RequestHelper.IsPostBack())
        {
            LoadData(webPartContainerObj);

            // Show changes saved if specified from querystring
            if (QueryHelper.GetInteger("saved", 0) == 1)
            {
                ShowInformation(GetString("General.ChangesSaved"));
            }
        }

        this.plcCssLink.Visible = String.IsNullOrEmpty(txtContainerCSS.Text);
    }
Exemple #3
0
    protected override void OnPreInit(EventArgs e)
    {
        RequireSite = false;

        dialogMode = (QueryHelper.GetBoolean("dialog", false) || QueryHelper.GetBoolean("isindialog", false));
        tabMode    = QueryHelper.GetBoolean("tabmode", false);

        if (dialogMode)
        {
            if (!QueryHelper.ValidateHash("hash", "objectid"))
            {
                URLHelper.Redirect(AdministrationUrlHelper.GetErrorPageUrl("dialogs.badhashtitle", "dialogs.badhashtext"));
            }
        }
        else
        {
            CheckGlobalAdministrator();
        }

        var containerId = QueryHelper.GetInteger("containerid", 0);

        webPartContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerId);

        if (webPartContainer == null)
        {
            string containerName = QueryHelper.GetString("name", null);
            webPartContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerName);
        }

        SetEditedObject(webPartContainer, null);

        base.OnPreInit(e);
    }
    private bool Save(bool closeOnSave)
    {
        // Validate user input
        string errorMessage = new Validator()
                              .NotEmpty(txtContainerDisplayName.Text, rfvDisplayName.ErrorMessage)
                              .NotEmpty(txtContainerName.Text, rfvCodeName.ErrorMessage)
                              .IsCodeName(txtContainerName.Text, GetString("General.InvalidCodeName"))
                              .Result;

        if (!string.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
            return(false);
        }

        // Parse the container text
        string text  = txtContainerText.Text;
        string after = "";

        int wpIndex = text.IndexOf(WebPartContainerInfoProvider.WP_CHAR);

        if (wpIndex >= 0)
        {
            after = text.Substring(wpIndex + 1).Replace(WebPartContainerInfoProvider.WP_CHAR, "");
            text  = text.Substring(0, wpIndex);
        }

        WebPartContainerInfo webPartContainerObj = new WebPartContainerInfo()
        {
            ContainerTextBefore  = text,
            ContainerTextAfter   = after,
            ContainerCSS         = txtContainerCSS.Text,
            ContainerName        = txtContainerName.Text.Trim(),
            ContainerDisplayName = txtContainerDisplayName.Text.Trim()
        };

        // Check for duplicity
        if (WebPartContainerInfoProvider.GetWebPartContainerInfo(webPartContainerObj.ContainerName) != null)
        {
            ShowError(GetString("Container_Edit.UniqueError"));
            return(false);
        }

        WebPartContainerInfoProvider.SetWebPartContainerInfo(webPartContainerObj);
        CMSContext.EditedObject = webPartContainerObj;
        CMSObjectManager.CheckOutNewObject(Page);

        if (mDialogMode)
        {
            ProcessDialog(webPartContainerObj, closeOnSave);
        }
        else
        {
            ProcessPage(webPartContainerObj);
        }

        return(true);
    }
Exemple #5
0
    /// <summary>
    /// Deletes web part container. Called when the "Delete container" button is pressed.
    /// Expects the CreateWebPartContainer method to be run first.
    /// </summary>
    private bool DeleteWebPartContainer()
    {
        // Get the web part container
        WebPartContainerInfo deleteContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo("MyNewContainer");

        // Delete the web part container
        WebPartContainerInfoProvider.DeleteWebPartContainerInfo(deleteContainer);

        return(deleteContainer != null);
    }
Exemple #6
0
    /// <summary>
    /// Saves the web part container.
    /// </summary>
    /// <returns>true if web part container was saved successfully, otherwise false.</returns>
    private bool Save()
    {
        string errorMessage = new Validator()
                              .NotEmpty(txtContainerDisplayName.Text, rfvDisplayName.ErrorMessage)
                              .NotEmpty(txtContainerName.Text, rfvCodeName.ErrorMessage)
                              .IsCodeName(txtContainerName.Text, GetString("general.invalidcodename"))
                              .Result;

        if (errorMessage != string.Empty)
        {
            ShowError(errorMessage);
            return(false);
        }

        // If webPartContainer doesnt already exist, create new one
        if (webPartContainerObj == null)
        {
            webPartContainerObj = new WebPartContainerInfo();
        }

        webPartContainerObj.ContainerTextBefore  = txtContainerTextBefore.Text;
        webPartContainerObj.ContainerTextAfter   = txtContainerTextAfter.Text;
        webPartContainerObj.ContainerCSS         = txtContainerCSS.Text;
        webPartContainerObj.ContainerName        = txtContainerName.Text.Trim();
        webPartContainerObj.ContainerDisplayName = txtContainerDisplayName.Text.Trim();

        // Check existing name
        if (!mDialogMode)
        {
            WebPartContainerInfo wPcI = WebPartContainerInfoProvider.GetWebPartContainerInfo(webPartContainerObj.ContainerName);
            if ((wPcI != null) && (wPcI.ContainerID != webPartContainerObj.ContainerID))
            {
                ShowError(GetString("Container_Edit.UniqueError"));
                return(false);
            }
        }

        // Save the container
        WebPartContainerInfoProvider.SetWebPartContainerInfo(webPartContainerObj);
        ShowInformation(GetString("General.ChangesSaved"));

        // Reload header if changes were saved
        if (TabMode)
        {
            ScriptHelper.RefreshTabHeader(Page, null);
        }

        return(true);
    }
Exemple #7
0
    /// <summary>
    /// Removes web part container from site. Called when the "Remove container from site" button is pressed.
    /// Expects the AddWebPartContainerToSite method to be run first.
    /// </summary>
    private bool RemoveWebPartContainerFromSite()
    {
        // Get the web part container
        WebPartContainerInfo removeContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo("MyNewContainer");

        if (removeContainer != null)
        {
            int siteId = CMSContext.CurrentSiteID;

            // Delete the binding
            WebPartContainerSiteInfoProvider.RemoveContainerFromSite(removeContainer.ContainerID, siteId);

            return(true);
        }

        return(false);
    }
Exemple #8
0
    /// <summary>
    /// Adds web part container to site. Called when the "Add container to site" button is pressed.
    /// Expects the CreateWebPartContainer method to be run first.
    /// </summary>
    private bool AddWebPartContainerToSite()
    {
        // Get the web part container
        WebPartContainerInfo container = WebPartContainerInfoProvider.GetWebPartContainerInfo("MyNewContainer");

        if (container != null)
        {
            int containerId = container.ContainerID;
            int siteId      = CMSContext.CurrentSiteID;

            // Save the binding
            WebPartContainerSiteInfoProvider.AddContainerToSite(containerId, siteId);

            return(true);
        }

        return(false);
    }
Exemple #9
0
    /// <summary>
    /// Gets and updates web part container. Called when the "Get and update container" button is pressed.
    /// Expects the CreateWebPartContainer method to be run first.
    /// </summary>
    private bool GetAndUpdateWebPartContainer()
    {
        // Get the web part container
        WebPartContainerInfo updateContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo("MyNewContainer");

        if (updateContainer != null)
        {
            // Update the properties
            updateContainer.ContainerDisplayName = updateContainer.ContainerDisplayName.ToLower();

            // Save the changes
            WebPartContainerInfoProvider.SetWebPartContainerInfo(updateContainer);

            return(true);
        }

        return(false);
    }
    private bool Save(bool closeOnSave)
    {
        // Validate user input
        string errorMessage = new Validator()
                              .NotEmpty(txtContainerDisplayName.Text, rfvDisplayName.ErrorMessage)
                              .NotEmpty(txtContainerName.Text, rfvCodeName.ErrorMessage)
                              .IsCodeName(txtContainerName.Text, GetString("General.InvalidCodeName"))
                              .Result;

        if (!string.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
            return(false);
        }

        WebPartContainerInfo webPartContainerObj = new WebPartContainerInfo
        {
            ContainerTextBefore  = txtContainerTextBefore.Text,
            ContainerTextAfter   = txtContainerTextAfter.Text,
            ContainerCSS         = txtContainerCSS.Text,
            ContainerName        = txtContainerName.Text.Trim(),
            ContainerDisplayName = txtContainerDisplayName.Text.Trim()
        };

        // Check for duplicity
        if (WebPartContainerInfoProvider.GetWebPartContainerInfo(webPartContainerObj.ContainerName) != null)
        {
            ShowError(GetString("Container_Edit.UniqueError"));
            return(false);
        }

        WebPartContainerInfoProvider.SetWebPartContainerInfo(webPartContainerObj);

        if (mDialogMode)
        {
            ProcessDialog(webPartContainerObj, closeOnSave);
        }
        else
        {
            ProcessPage(webPartContainerObj);
        }

        return(true);
    }
    private void InitEditeObject()
    {
        if (PersistentEditedObject != null)
        {
            webPartContainer = PersistentEditedObject as WebPartContainerInfo;
            return;
        }

        if (containerId > 0)
        {
            webPartContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerId);
        }
        else
        {
            webPartContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerName);
        }

        PersistentEditedObject = webPartContainer;
    }
Exemple #12
0
    /// <summary>
    /// Retrieves the stylesheets of the web part container from the database.
    /// </summary>
    /// <param name="containerName">Container name</param>
    /// <returns>The stylesheet data (plain version only)</returns>
    private static CMSOutputResource GetContainer(string containerName)
    {
        WebPartContainerInfo containerInfo = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerName);

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

        // Build the result
        CMSOutputResource resource = new CMSOutputResource()
        {
            Data         = HTMLHelper.ResolveCSSUrls(containerInfo.ContainerCSS, URLHelper.ApplicationPath),
            LastModified = containerInfo.ContainerLastModified,
            Etag         = containerInfo.ContainerName
        };

        return(resource);
    }
    protected override void OnPreInit(EventArgs e)
    {
        RequireSite = false;

        dialogMode = QueryHelper.GetBoolean("editonlycode", false);
        tabMode    = QueryHelper.GetBoolean("tabmode", false);

        if (dialogMode)
        {
            // Check hash
            if (!QueryHelper.ValidateHash("hash", "saved;containerid;name;selectorid;tabmode;aliaspath;instanceGUID", true, true, true))
            {
                URLHelper.Redirect(ResolveUrl(string.Format("~/CMSMessages/Error.aspx?title={0}&text={1}", ResHelper.GetString("dialogs.badhashtitle"), ResHelper.GetString("dialogs.badhashtext"))));
            }

            // Check permissions for web part properties UI
            if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", new string[] { "Design", "Design.WebPartProperties", "WebPartProperties.General", "WebPartProperties.EditContainers" }, CMSContext.CurrentSiteName))
            {
                RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "Design.WebPartProperties;WebPartProperties.General;WebPartProperties.EditContainers");
            }
        }
        else
        {
            CheckAccessToSiteManager();
        }

        var containerId = QueryHelper.GetInteger("containerid", 0);

        webPartContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerId);

        if (webPartContainer == null)
        {
            string containerName = QueryHelper.GetString("name", null);
            webPartContainer = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerName);
        }

        string frameSetUrl = dialogMode ? "Container_Edit_Frameset.aspx" : null;

        SetEditedObject(webPartContainer, frameSetUrl);

        base.OnPreInit(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Setup the filesystem browser
        int containerId = QueryHelper.GetInteger("containerid", 0);

        if (containerId > 0)
        {
            WebPartContainerInfo ci = WebPartContainerInfoProvider.GetWebPartContainerInfo(containerId);
            EditedObject = ci;

            if (ci != null)
            {
                // Ensure the theme folder
                themeElem.Path = ci.GetThemePath();
            }
        }
        else
        {
            EditedObject = null;
        }
    }
    private void SaveContainer()
    {
        try
        {
            // Validate user input
            string errorMessage = new Validator()
                                  .NotEmpty(txtContainerDisplayName.Text, rfvDisplayName.ErrorMessage)
                                  .NotEmpty(txtContainerName.Text, rfvCodeName.ErrorMessage)
                                  .IsCodeName(txtContainerName.Text, GetString("General.InvalidCodeName"))
                                  .Result;

            if (!string.IsNullOrEmpty(errorMessage))
            {
                ShowError(errorMessage);
                return;
            }

            // Parse the container text
            string text  = txtContainerText.Text;
            string after = "";

            int wpIndex = text.IndexOf(WebPartContainerInfoProvider.WP_CHAR);
            if (wpIndex >= 0)
            {
                after = text.Substring(wpIndex + 1).Replace(WebPartContainerInfoProvider.WP_CHAR, "");
                text  = text.Substring(0, wpIndex);
            }

            WebPartContainerInfo webPartContainerObj = new WebPartContainerInfo()
            {
                ContainerTextBefore  = text,
                ContainerTextAfter   = after,
                ContainerCSS         = txtContainerCSS.Text,
                ContainerName        = txtContainerName.Text.Trim(),
                ContainerDisplayName = txtContainerDisplayName.Text.Trim()
            };

            // Check for duplicity
            if (WebPartContainerInfoProvider.GetWebPartContainerInfo(webPartContainerObj.ContainerName) != null)
            {
                ShowError(GetString("Container_Edit.UniqueError"));
                return;
            }

            WebPartContainerInfoProvider.SetWebPartContainerInfo(webPartContainerObj);
            UIContext.EditedObject = webPartContainerObj;
            CMSObjectManager.CheckOutNewObject(Page);

            if (mDialogMode)
            {
                ProcessDialog(webPartContainerObj, true);
            }
            else
            {
                ProcessPage(webPartContainerObj);
            }
        }
        catch (SecurityException ex)
        {
            ShowError(!SystemContext.IsFullTrustLevel ? ResHelper.GetStringFormat("general.fulltrustrequired", ex.Message) : ex.Message);
        }
        catch (Exception ex)
        {
            ShowError(ex.Message);
        }
    }