Beispiel #1
0
        /// <summary>
        /// Updates the controls
        /// </summary>
        private void UpdateControls()
        {
            pnlTemplateLogo.Visible = CommunicationTemplateHelper.HasTemplateLogo(ceEmailTemplate.Text);
            imgTemplateLogo.Help    = CommunicationTemplateHelper.GetTemplateLogoHelpText(ceEmailTemplate.Text);

            var lavaFieldsTemplateDictionaryFromControls = hfLavaFieldsState.Value.FromJsonOrNull <Dictionary <string, string> >() ?? new Dictionary <string, string>();

            lavaFieldsTemplateDictionaryFromControls = CommunicationTemplateHelper.UpdateLavaFieldsTemplateDictionaryFromControls(phLavaFieldsControls, lavaFieldsTemplateDictionaryFromControls);

            // dictionary of keys and default values from Lava Fields KeyValueList control
            var lavaFieldsDefaultDictionary = kvlMergeFields.Value.AsDictionary();

            ceEmailTemplate.Text = CommunicationTemplateHelper.GetUpdatedTemplateHtml(ceEmailTemplate.Text, imgTemplateLogo.BinaryFileId, lavaFieldsTemplateDictionaryFromControls, lavaFieldsDefaultDictionary);

            var lavaFieldsTemplateDictionary = CommunicationTemplateHelper.GetLavaFieldsTemplateDictionaryFromTemplateHtml(ceEmailTemplate.Text);

            hfLavaFieldsState.Value          = lavaFieldsTemplateDictionary.ToJson(indentOutput: false);
            btnUpdateTemplatePreview.Visible = lavaFieldsTemplateDictionary.Any();
            CommunicationTemplateHelper.CreateDynamicLavaValueControls(lavaFieldsTemplateDictionary, lavaFieldsDefaultDictionary, phLavaFieldsControls);

            var    mergeFields         = Rock.Lava.LavaHelper.GetCommonMergeFields(RockPage);
            string resolvedPreviewHtml = ceEmailTemplate.Text.ResolveMergeFields(mergeFields);

            if (cbCssInliningEnabled.Checked)
            {
                resolvedPreviewHtml = resolvedPreviewHtml.ConvertHtmlStylesToInlineAttributes();
            }

            ifEmailPreview.Attributes["srcdoc"] = resolvedPreviewHtml;
            pnlEmailPreview.Visible             = true;
            upnlEmailPreview.Update();
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                // Get the CommunicationId if it is specified as a parameter.
                // If not found, check for the legacy parameter "EmailId".
                var communicationIdentifier = PageParameter(PageParameterKey.CommunicationId);

                if (string.IsNullOrEmpty(communicationIdentifier))
                {
                    communicationIdentifier = PageParameter("emailId");
                }

                ShowEdit(communicationIdentifier.AsInteger());
            }
            else
            {
                // Create Controls for LavaFields Values
                var lavaFieldsTemplateDictionary = hfLavaFieldsState.Value.FromJsonOrNull <Dictionary <string, string> >() ?? new Dictionary <string, string>();

                // dictionary of keys and default values from Lava Fields KeyValueList control
                var lavaFieldsDefaultDictionary = kvlMergeFields.Value.AsDictionary();

                CommunicationTemplateHelper.CreateDynamicLavaValueControls(lavaFieldsTemplateDictionary, lavaFieldsDefaultDictionary, phLavaFieldsControls);
                btnUpdateTemplatePreview.Visible = lavaFieldsTemplateDictionary.Any();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Handles the Click event of the lbUpdateLavaFields control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void lbUpdateLavaFields_Click(object sender, EventArgs e)
        {
            // do an UpdateControls to make sure the "lava-fields" tag exists if there are lava fields defined in the UI
            UpdateControls();

            Dictionary <string, string> lavaFieldsTemplateDictionary = CommunicationTemplateHelper.GetLavaFieldsTemplateDictionaryFromTemplateHtml(ceEmailTemplate.Text);

            kvlMergeFields.Value = lavaFieldsTemplateDictionary.Select(a => string.Format("{0}^{1}", a.Key, a.Value)).ToList().AsDelimited("|");
        }
Beispiel #4
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                ShowDetail(PageParameter("TemplateId").AsInteger());
            }
            else
            {
                // Create Controls for LavaFields Values
                var lavaFieldsTemplateDictionary = hfLavaFieldsState.Value.FromJsonOrNull <Dictionary <string, string> >() ?? new Dictionary <string, string>();

                // dictionary of keys and default values from Lava Fields KeyValueList control
                var lavaFieldsDefaultDictionary = kvlMergeFields.Value.AsDictionary();

                CommunicationTemplateHelper.CreateDynamicLavaValueControls(lavaFieldsTemplateDictionary, lavaFieldsDefaultDictionary, phLavaFieldsControls);
                btnUpdateTemplatePreview.Visible = lavaFieldsTemplateDictionary.Any();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="templateId">The template identifier.</param>
        private void ShowDetail(int templateId)
        {
            CommunicationTemplate communicationTemplate = null;
            var newTemplate       = false;
            var pushCommunication = new CommunicationDetails();

            if (!templateId.Equals(0))
            {
                communicationTemplate = new CommunicationTemplateService(new RockContext()).Get(templateId);
                if (communicationTemplate != null)
                {
                    lTitle.Text = communicationTemplate.Name.FormatAsHtmlTitle();
                    pdAuditDetails.SetEntity(communicationTemplate, ResolveRockUrl("~"));
                }

                pushCommunication = new CommunicationDetails
                {
                    PushData = communicationTemplate.PushData,
                    PushImageBinaryFileId = communicationTemplate.PushImageBinaryFileId,
                    PushMessage           = communicationTemplate.PushMessage,
                    PushTitle             = communicationTemplate.PushTitle,
                    PushOpenMessage       = communicationTemplate.PushOpenMessage,
                    PushOpenAction        = communicationTemplate.PushOpenAction
                };
            }

            if (communicationTemplate == null)
            {
                RockPage.PageTitle    = "New Communication Template";
                lTitle.Text           = "New Communication Template".FormatAsHtmlTitle();
                communicationTemplate = new CommunicationTemplate();
                newTemplate           = true;
            }

            LoadDropDowns();

            mfpSMSMessage.MergeFields.Clear();
            mfpSMSMessage.MergeFields.Add("GlobalAttribute");
            mfpSMSMessage.MergeFields.Add("Rock.Model.Person");

            hfCommunicationTemplateId.Value = templateId.ToString();

            tbName.Text        = communicationTemplate.Name;
            cbIsActive.Checked = communicationTemplate.IsActive;
            tbDescription.Text = communicationTemplate.Description;
            cpCategory.SetValue(communicationTemplate.CategoryId);

            imgTemplatePreview.BinaryFileId = communicationTemplate.ImageFileId;
            imgTemplateLogo.BinaryFileId    = communicationTemplate.LogoBinaryFileId;

            // Email Fields
            tbFromName.Text    = communicationTemplate.FromName;
            tbFromAddress.Text = communicationTemplate.FromEmail;

            tbReplyToAddress.Text        = communicationTemplate.ReplyToEmail;
            tbCCList.Text                = communicationTemplate.CCEmails;
            tbBCCList.Text               = communicationTemplate.BCCEmails;
            cbCssInliningEnabled.Checked = communicationTemplate.CssInliningEnabled;
            kvlMergeFields.Value         = communicationTemplate.LavaFields.Select(a => string.Format("{0}^{1}", a.Key, a.Value)).ToList().AsDelimited("|");

            hfShowAdditionalFields.Value = (!string.IsNullOrEmpty(communicationTemplate.ReplyToEmail) || !string.IsNullOrEmpty(communicationTemplate.CCEmails) || !string.IsNullOrEmpty(communicationTemplate.BCCEmails)).ToTrueFalse().ToLower();

            tbEmailSubject.Text = communicationTemplate.Subject;

            nbTemplateHelp.InnerHtml = CommunicationTemplateHelper.GetTemplateHelp(true);
            ceEmailTemplate.Text     = communicationTemplate.Message;

            hfAttachedBinaryFileIds.Value = communicationTemplate.Attachments.Select(a => a.BinaryFileId).ToList().AsDelimited(",");
            UpdateAttachedFiles(false);

            // SMS Fields
            dvpSMSFrom.SetValue(communicationTemplate.SMSFromDefinedValueId);
            tbSMSTextMessage.Text = communicationTemplate.SMSMessage;

            // render UI based on Authorized and IsSystem
            var readOnly       = false;
            var restrictedEdit = false;

            if (!newTemplate && !communicationTemplate.IsAuthorized(Authorization.EDIT, CurrentPerson))
            {
                restrictedEdit            = true;
                readOnly                  = true;
                nbEditModeMessage.Text    = EditModeMessage.NotAuthorizedToEdit(CommunicationTemplate.FriendlyTypeName);
                nbEditModeMessage.Visible = true;
            }

            if (communicationTemplate.IsSystem)
            {
                restrictedEdit            = true;
                nbEditModeMessage.Text    = EditModeMessage.System(CommunicationTemplate.FriendlyTypeName);
                nbEditModeMessage.Visible = true;
            }

            tbName.ReadOnly    = restrictedEdit;
            cbIsActive.Enabled = !restrictedEdit;

            tbFromName.ReadOnly               = restrictedEdit;
            tbName.ReadOnly                   = restrictedEdit;
            tbFromAddress.ReadOnly            = restrictedEdit;
            tbReplyToAddress.ReadOnly         = restrictedEdit;
            tbCCList.ReadOnly                 = restrictedEdit;
            tbBCCList.ReadOnly                = restrictedEdit;
            tbEmailSubject.ReadOnly           = restrictedEdit;
            fupAttachments.Visible            = !restrictedEdit;
            fupAttachments.BinaryFileTypeGuid = this.GetAttributeValue(AttributeKey.AttachmentBinaryFileType).AsGuidOrNull() ?? Rock.SystemGuid.BinaryFiletype.DEFAULT.AsGuid();
            // Allow these to be Editable if they are IsSystem, but not if they don't have EDIT Auth
            tbDescription.ReadOnly     = readOnly;
            imgTemplatePreview.Enabled = !readOnly;
            ceEmailTemplate.ReadOnly   = readOnly;

            mfpSMSMessage.Visible     = !restrictedEdit;
            dvpSMSFrom.Enabled        = !restrictedEdit;
            tbSMSTextMessage.ReadOnly = restrictedEdit;
            ceEmailTemplate.ReadOnly  = restrictedEdit;

            btnSave.Enabled = !readOnly;

            tglPreviewAdvanced.Checked = true;

            var pushNotificationControl = phPushNotification.Controls[0] as PushNotification;

            if (pushNotificationControl != null)
            {
                pushNotificationControl.SetFromCommunication(pushCommunication);
            }

            SetEmailMessagePreviewModeEnabled(tglPreviewAdvanced.Checked);
        }
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="emailTemplateId">The email template id.</param>
        protected void ShowEdit(int emailTemplateId)
        {
            var globalAttributes = GlobalAttributesCache.Get();

            string globalFromName = globalAttributes.GetValue("OrganizationName");

            tbFromName.Help = string.Format("If a From Name value is not entered the 'Organization Name' Global Attribute value of '{0}' will be used when this template is sent. <small><span class='tip tip-lava'></span></small>", globalFromName);

            string globalFrom = globalAttributes.GetValue("OrganizationEmail");

            tbFrom.Help = string.Format("If a From Address value is not entered the 'Organization Email' Global Attribute value of '{0}' will be used when this template is sent. <small><span class='tip tip-lava'></span></small>", globalFrom);

            tbTo.Help = "You can specify multiple email addresses by separating them with a comma.";

            SystemCommunicationService emailTemplateService = new SystemCommunicationService(new RockContext());
            SystemCommunication        emailTemplate        = emailTemplateService.Get(emailTemplateId);

            bool showMessagePreview = false;

            var pushCommunication = new CommunicationDetails();

            if (emailTemplate != null)
            {
                pdAuditDetails.Visible = true;
                pdAuditDetails.SetEntity(emailTemplate, ResolveRockUrl("~"));

                lActionTitle.Text       = ActionTitle.Edit(SystemCommunication.FriendlyTypeName).FormatAsHtmlTitle();
                hfEmailTemplateId.Value = emailTemplate.Id.ToString();

                cbIsActive.Checked = emailTemplate.IsActive.GetValueOrDefault();
                cpCategory.SetValue(emailTemplate.CategoryId);
                tbTitle.Text         = emailTemplate.Title;
                tbFromName.Text      = emailTemplate.FromName;
                tbFrom.Text          = emailTemplate.From;
                tbTo.Text            = emailTemplate.To;
                tbCc.Text            = emailTemplate.Cc;
                tbBcc.Text           = emailTemplate.Bcc;
                tbSubject.Text       = emailTemplate.Subject;
                ceEmailTemplate.Text = emailTemplate.Body;

                pushCommunication = new CommunicationDetails
                {
                    PushData = emailTemplate.PushData,
                    PushImageBinaryFileId = emailTemplate.PushImageBinaryFileId,
                    PushMessage           = emailTemplate.PushMessage,
                    PushTitle             = emailTemplate.PushTitle,
                    PushOpenMessage       = emailTemplate.PushOpenMessage,
                    PushOpenAction        = emailTemplate.PushOpenAction
                };

                nbTemplateHelp.InnerHtml = CommunicationTemplateHelper.GetTemplateHelp(false);

                kvlMergeFields.Value = emailTemplate.LavaFields.Select(a => string.Format("{0}^{1}", a.Key, a.Value)).ToList().AsDelimited("|");

                hfShowAdditionalFields.Value = (!string.IsNullOrEmpty(emailTemplate.Cc) || !string.IsNullOrEmpty(emailTemplate.Bcc)).ToTrueFalse().ToLower();

                cbCssInliningEnabled.Checked = emailTemplate.CssInliningEnabled;

                showMessagePreview = true;
            }
            else
            {
                pdAuditDetails.Visible  = false;
                lActionTitle.Text       = ActionTitle.Add(SystemCommunication.FriendlyTypeName).FormatAsHtmlTitle();
                hfEmailTemplateId.Value = 0.ToString();

                cbIsActive.Checked = true;
                cpCategory.SetValue(( int? )null);
                tbTitle.Text         = string.Empty;
                tbFromName.Text      = string.Empty;
                tbFrom.Text          = string.Empty;
                tbTo.Text            = string.Empty;
                tbCc.Text            = string.Empty;
                tbBcc.Text           = string.Empty;
                tbSubject.Text       = string.Empty;
                ceEmailTemplate.Text = string.Empty;
            }

            var pushNotificationControl = phPushNotification.Controls[0] as PushNotification;

            if (pushNotificationControl != null)
            {
                pushNotificationControl.SetFromCommunication(pushCommunication);
            }

            SetEmailMessagePreviewModeEnabled(showMessagePreview);

            LoadDropDowns();

            // SMS Fields
            mfpSMSMessage.MergeFields.Clear();
            mfpSMSMessage.MergeFields.Add("GlobalAttribute");
            mfpSMSMessage.MergeFields.Add("Rock.Model.Person");

            if (emailTemplate != null)
            {
                dvpSMSFrom.SetValue(emailTemplate.SMSFromDefinedValueId);
                tbSMSTextMessage.Text = emailTemplate.SMSMessage;
            }
        }