Exemple #1
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;
            }
        }