Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Initialize HTML editor
        this.txtText.Editor.EnableViewState = false;
        this.txtText.Editor.EditorMode      = EditorModeEnum.Advanced;
        this.txtText.Editor.Language        = LanguageEnum.HTMLMixed;
        this.txtText.Editor.Height          = new Unit("400px");
        this.txtText.Editor.Width           = new Unit("100%");

        // Initialize Plain Text editor
        this.txtPlainText.Editor.EnableViewState = false;
        this.txtPlainText.Editor.EditorMode      = EditorModeEnum.Advanced;
        this.txtPlainText.Editor.Language        = LanguageEnum.Text;
        this.txtPlainText.Editor.Height          = new Unit("400px");
        this.txtPlainText.Editor.Width           = new Unit("100%");

        // Fill the e-mail type enumeration
        if (!RequestHelper.IsPostBack())
        {
            DataHelper.FillWithEnum <EmailTemplateMacros.EmailType>(drpEmailType, "emailtemplate.type.", EmailTemplateMacros.GetEmailTypeString, true);
        }

        // Initialize required field validators
        RequiredFieldValidatorDisplayName.ErrorMessage = GetString("EmailTemplate_Edit.FillDisplayNameField");
        RequiredFieldValidatorCodeName.ErrorMessage    = GetString("EmailTemplate_Edit.FillCodeNameField");

        // Initialize other controls
        AttachmentTitle.TitleText = GetString("general.attachments");

        // Register save button handler
        CMSPage.CurrentPage.CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;

        if (EmailTemplateID > 0)
        {
            // Get email template info of specified 'templateid'
            EmailTemplateInfo templateInfo = EmailTemplateProvider.GetEmailTemplate(EmailTemplateID);
            EditedObject = templateInfo;
            // Get SiteID of the template
            SiteID = templateInfo.TemplateSiteID;

            // Check if user is assigned to web site
            if (!CMSContext.CurrentUser.IsGlobalAdministrator)
            {
                if (!CMSContext.CurrentUser.IsInSite(SiteInfoProvider.GetSiteName(SiteID)))
                {
                    // Disable object for user
                    EditedObject = null;
                }
            }

            // Fill the form
            if (!RequestHelper.IsPostBack())
            {
                // Load data to the form.
                LoadData(templateInfo);
                // Show message that the email template was created or updated successfully.
                if (QueryHelper.GetBoolean("saved", false))
                {
                    lblInfo.Visible = true;

                    // Reload header if changes were saved

                    if ((Page is CMSPage) && ((CMSPage)Page).TabMode)
                    {
                        ScriptHelper.RefreshTabHeader(Page, null);
                    }
                }

                // Show attachment list
                AttachmentList.Visible  = true;
                AttachmentTitle.Visible = true;
            }
        }

        // Get correct MacroResolver
        MacroResolver resolver = EmailTemplateMacros.GetEmailTemplateResolver(EmailTemplateMacros.GetEmailTypeEnum(drpEmailType.SelectedValue));

        txtText.Resolver      = resolver;
        txtPlainText.Resolver = resolver;

        macroSelectorElm.Resolver             = resolver;
        macroSelectorElm.ShowMacroTreeAbove   = true;
        macroSelectorElm.ExtendedTextAreaElem = this.txtText.Editor.EditorID;
        macroSelectorElm.TextAreaID           = this.txtText.Editor.ClientID;

        macroSelectorPlain.Resolver             = resolver;
        macroSelectorPlain.ShowMacroTreeAbove   = true;
        macroSelectorPlain.ExtendedTextAreaElem = this.txtPlainText.Editor.EditorID;
        macroSelectorPlain.TextAreaID           = this.txtPlainText.Editor.ClientID;
    }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Initialize HTML editor
        txtText.Editor.EnableViewState = false;
        txtText.Editor.EditorMode      = EditorModeEnum.Advanced;
        txtText.Editor.Language        = LanguageEnum.HTMLMixed;
        txtText.Editor.Height          = new Unit("400px");
        txtText.Editor.Width           = new Unit("100%");

        // Initialize Plain Text editor
        txtPlainText.Editor.EnableViewState = false;
        txtPlainText.Editor.EditorMode      = EditorModeEnum.Advanced;
        txtPlainText.Editor.Language        = LanguageEnum.Text;
        txtPlainText.Editor.Height          = new Unit("400px");
        txtPlainText.Editor.Width           = new Unit("100%");

        txtPlainText.Editor.FullScreenParentElementID = txtText.Editor.FullScreenParentElementID = "divContent";

        if (TemplateType == null)
        {
            drpEmailType.DropDown.AutoPostBack = true;
        }
        else
        {
            drpEmailType.DropDown.Enabled = false;
            drpEmailType.Value            = EmailTemplateMacros.GetEmailTypeString(TemplateType.Value);
        }

        // Initialize required field validators
        RequiredFieldValidatorDisplayName.ErrorMessage = GetString("EmailTemplate_Edit.FillDisplayNameField");
        RequiredFieldValidatorCodeName.ErrorMessage    = GetString("EmailTemplate_Edit.FillCodeNameField");

        // Register save button handler
        pnlObjectLocking.ObjectManager.OnSaveData    += new EventHandler <SimpleObjectManagerEventArgs>(ObjectManager_OnSaveData);
        pnlObjectLocking.ObjectManager.OnAfterAction += new EventHandler <SimpleObjectManagerEventArgs>(ObjectManager_OnAfterAction);

        if (EmailTemplateID > 0)
        {
            // Get email template info of specified 'templateid'
            templateInfo = EmailTemplateProvider.GetEmailTemplate(EmailTemplateID);
            EditedObject = templateInfo;

            // Get SiteID of the template
            SiteID = templateInfo.TemplateSiteID;

            // Check if user is assigned to web site
            if (!CMSContext.CurrentUser.IsGlobalAdministrator)
            {
                if (!CMSContext.CurrentUser.IsInSite(SiteInfoProvider.GetSiteName(SiteID)))
                {
                    // Disable object for user
                    EditedObject = null;
                }
            }

            // Fill the form
            if (!RequestHelper.IsPostBack())
            {
                // Load data to the form
                LoadData(templateInfo);

                // Show message that the email template was created or updated successfully.
                if (QueryHelper.GetBoolean("saved", false))
                {
                    ShowChangesSaved();

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

            // Register paste attachment script
            RegisterPasteScript();
        }
        else
        {
            pnlObjectLocking.ObjectManager.ObjectType = PredefinedObjectType.EMAILTEMPLATE;
        }

        // Get correct MacroResolver
        ContextResolver resolver = EmailTemplateMacros.GetEmailTemplateResolver(EmailTemplateMacros.GetEmailTypeEnum(ValidationHelper.GetString(drpEmailType.Value, "")));

        txtText.Resolver      = resolver;
        txtPlainText.Resolver = resolver;

        // Disable display name and code name editation when editing item from selector
        txtDisplayName.Enabled = txtCodeName.Enabled = !EditMode || !DialogMode;

        macroSelectorElm.Resolver             = resolver;
        macroSelectorElm.ShowMacroTreeAbove   = true;
        macroSelectorElm.ExtendedTextAreaElem = txtText.Editor.EditorID;
        macroSelectorElm.TextAreaID           = txtText.Editor.ClientID;

        macroSelectorPlain.Resolver             = resolver;
        macroSelectorPlain.ShowMacroTreeAbove   = true;
        macroSelectorPlain.ExtendedTextAreaElem = txtPlainText.Editor.EditorID;
        macroSelectorPlain.TextAreaID           = txtPlainText.Editor.ClientID;

        InitHeaderActions(EmailTemplateID, SiteID);
    }