/// <summary>
    /// Handles the UniGrid's external data bound event.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Source name</param>
    /// <param name="parameter">Parameter</param>
    object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "type":
            string type = ValidationHelper.GetString(parameter, string.Empty);
            if (string.IsNullOrEmpty(type))
            {
                type = EmailTemplateMacros.GetEmailTypeString(EmailTemplateMacros.EmailType.General);
            }

            return(HTMLHelper.HTMLEncode(ResHelper.GetString("emailtemplate.type." + type)));
        }

        return(parameter);
    }
    /// <summary>
    /// Page load event.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        usTemplate.WhereCondition = SqlHelperClass.AddWhereCondition(usTemplate.WhereCondition, (SiteId > 0) ? "EmailTemplateSiteID = " + SiteId : "EmailTemplateSiteID IS NULL");

        // Filter type
        if (TemplateType.HasValue)
        {
            usTemplate.WhereCondition = SqlHelperClass.AddWhereCondition(usTemplate.WhereCondition, "EmailTemplateType = '" + SqlHelperClass.GetSafeQueryString(EmailTemplateMacros.GetEmailTypeString(TemplateType.Value)) + "'");
        }

        // Edit button initialization
        if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.EmailTemplates", "Modify"))
        {
            string templateType = null;
            if (TemplateType != null)
            {
                templateType = "&templatetype=" + EmailTemplateMacros.GetEmailTypeString(TemplateType.Value);
            }

            if (!String.IsNullOrEmpty(EditDialogUrl))
            {
                string url = EditDialogUrl + "?name=##ITEMID##&tabmode=1&editonlycode=1" + templateType;
                url = URLHelper.AddParameterToUrl(url, "hash", QueryHelper.GetHash("?editonlycode=1" + templateType));
                usTemplate.EditItemPageUrl = url;
            }

            if (!String.IsNullOrEmpty(NewDialogUrl))
            {
                string url = NewDialogUrl + "?editonlycode=1" + templateType;
                url = URLHelper.AddParameterToUrl(url, "hash", QueryHelper.GetHash("?editonlycode=1" + templateType));
                usTemplate.NewItemPageUrl = url;
            }
        }

        usTemplate.ButtonClear.Visible = false;
        usTemplate.ReturnColumnName    = ReturnColumnName;
        CheckRegularExpression         = true;
    }
예제 #3
0
    private void RedirectOnSave(EmailTemplateInfo templateInfo, bool closeOnSave)
    {
        StringBuilder redirectUrl = new StringBuilder();

        redirectUrl.Append(URLHelper.ResolveUrl(RefreshPageURL), "?saved=1&tabmode=", QueryHelper.GetInteger("tabmode", 0));

        if (GlobalTemplate)
        {
            redirectUrl.Append("&selectedsiteid=0");
        }
        else if (QueryHelper.GetInteger("selectedsiteid", 0) != 0)
        {
            redirectUrl.Append("&selectedsiteid=", QueryHelper.GetInteger("selectedsiteid", 0));
        }
        else if (SiteID > 0)
        {
            redirectUrl.Append("&siteid=" + SiteID);
        }

        // Selector ID in query means dialog mode
        string selector = QueryHelper.GetString("selectorid", string.Empty);

        if (!string.IsNullOrEmpty(selector))
        {
            // Add dialog specific query parameters
            redirectUrl.Append("&editonlycode=1");
            redirectUrl.Append("&name=", templateInfo.TemplateName, "&selectorid=", selector);

            string type = null;
            if (TemplateType != null)
            {
                type = "&templatetype=" + EmailTemplateMacros.GetEmailTypeString(TemplateType.Value);
                redirectUrl.Append(type);
            }
            redirectUrl.Append("&hash=", QueryHelper.GetHash("?editonlycode=1" + type));

            ScriptHelper.RegisterWOpenerScript(Page);

            StringBuilder script = new StringBuilder();
            if (!EditMode)
            {
                // Add selector refresh
                script.Append(@"
if (wopener) {{                        
    wopener.US_SelectNewValue_", selector, "('", templateInfo.TemplateName, @"');
}}");
            }

            if (closeOnSave)
            {
                script.AppendLine("CloseDialog();");
            }
            else
            {
                script.Append(@"
window.name = '", selector, @"';
window.open('", URLHelper.UrlEncodeQueryString(redirectUrl.ToString()), "', window.name);");
            }

            ScriptHelper.RegisterStartupScript(this, GetType(), "UpdateSelector", script.ToString(), true);
        }
        else if (DialogMode)
        {
            if (closeOnSave)
            {
                ScriptHelper.RegisterWOpenerScript(Page);
                ScriptHelper.RegisterStartupScript(this, GetType(), "closeDialog", ScriptHelper.GetScript("CloseDialog();"));
            }
            else
            {
                ShowChangesSaved();
            }
        }
        else
        {
            // Add UI specific query parameters
            redirectUrl.Append("&templateid=", templateInfo.TemplateID);
            URLHelper.Redirect(URLHelper.UrlEncodeQueryString(redirectUrl.ToString()));
        }
    }
예제 #4
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);
    }