Example #1
0
 private async Task MailTemplates_List_ListPreRender(ComponentListEventArgs e)
 {
     if (wim.IsSaveMode && !await CanSaveAsync())
     {
         wim.IsSaveMode = false;
     }
 }
        private async Task SendTestMail_List_ListSave(ComponentListEventArgs e)
        {
            var idQueryString = Request.Query["item"].ToString();

            int.TryParse(idQueryString, out int id);
            await SendTestMailAsync(id);
        }
        private async Task SendTestMail_List_ListLoad(ComponentListEventArgs e)
        {
            var idQueryString = Request.Query["item"].ToString();

            int.TryParse(idQueryString, out int id);

            var mailTemplate = await _mailTemplateRepository.FetchSingleAsync(id);

            var placeholdersSubject = Logic.PlaceholderLogic.GetPlaceholderTags(mailTemplate.Subject);

            foreach (var placeholder in placeholdersSubject)
            {
                wim.Form.AddElement(this, placeholder, true, true,
                                    new Mediakiwi.Framework.ContentListItem.TextFieldAttribute(placeholder, 4000, true));
            }

            var placeholdersBody = Logic.PlaceholderLogic.GetPlaceholderTags(mailTemplate.Body);

            foreach (var placeholder in placeholdersBody)
            {
                wim.Form.AddElement(this, placeholder, true, true,
                                    new Mediakiwi.Framework.ContentListItem.TextFieldAttribute(placeholder, 4000, true));
            }

            var sections = Logic.PlaceholderLogic.GetSectionTags(mailTemplate.Body);

            foreach (var section in sections)
            {
                wim.Form.AddElement(this, section, true, true,
                                    new Mediakiwi.Framework.ContentListItem.Choice_CheckboxAttribute(section, false));
            }
        }
        private async Task SendTestMail_List_ListPreRender(ComponentListEventArgs e)
        {
            var idQueryString = Request.Query["item"].ToString();

            int.TryParse(idQueryString, out int id);
            var mailTemplate = await _mailTemplateRepository.FetchSingleAsync(id);

            EmailFrom = EmailFrom ?? mailTemplate.DefaultSenderEmail;
            EmailTo   = EmailTo ?? wim.CurrentApplicationUser.Email;

            if (string.IsNullOrWhiteSpace(mailTemplate.Subject))
            {
                wim.Notification.AddError("A subject is mandatory, please supply a subject before sending a test e-mail. E-mail can't be sent.");
            }
        }
Example #5
0
        private async Task MailTemplatesList_ListLoad(ComponentListEventArgs e)
        {
            Implement = await _mailTemplateRepository.FetchSingleAsync(e.SelectedKey);

            if (Implement != null)
            {
                var latestTemplate = await _mailTemplateListRepository.FetchSingleByIdentifierAsync(Implement.Identifier);

                if (latestTemplate != null && Implement.ID != latestTemplate.ID)
                {
                    // someone is using the url to go to an old template, redirect to newest
                    Response.Redirect(wim.GetUrl(new KeyValue[] {
                        new KeyValue {
                            Key = "list", Value = wim.CurrentList.ID
                        },
                        new KeyValue {
                            Key = "item", Value = latestTemplate.ID
                        }
                    }));
                }

                if (e.SelectedKey > 0)
                {
                    ListOfAvailablePlaceholders  = "<b>Subject:</b><br/>";
                    ListOfAvailablePlaceholders += string.Join("<br/>", Logic.PlaceholderLogic.GetPlaceholderTags(Implement.Subject));
                    ListOfAvailablePlaceholders += "<br/><br/><b>Body:</b><br/>";
                    ListOfAvailablePlaceholders += string.Join("<br/>", Logic.PlaceholderLogic.GetPlaceholderTags(Implement.Body));
                }
            }
            else
            {
                Implement = new Data.MailTemplate();
            }

            // only show option to revert if there is a published version, a.k.a. a major version
            wim.SetPropertyVisibility(nameof(BtnRevert), Implement.VersionMinor > 0 && Implement.VersionMajor > 0);
            // only show publish button if current version is not published
            wim.SetPropertyVisibility(nameof(BtnPublish), !(Implement.IsPublished.HasValue && Implement.IsPublished.Value));
            wim.SetPropertyVisibility(nameof(BtnPreview), !wim.IsEditMode);
            wim.SetPropertyVisibility(nameof(BtnSendTestMail), !wim.IsEditMode);
            //wim.SetPropertyVisibility(nameof(BtnDefaultValues), !wim.IsEditMode);
            // not working yet, so invisible
            wim.SetPropertyVisibility(nameof(BtnDefaultValues), false);


            Utility.ReflectProperty(Implement, this);
        }
Example #6
0
        private async Task DefaultValues_List_ListSave(ComponentListEventArgs e)
        {
            if (wim.ChangedSearchGridItem != null)
            {
                var idQueryString = Request.Query["item"].ToString();

                int.TryParse(idQueryString, out int id);

                Data.MailTemplate mailTemplate = null;

                foreach (var item in wim.ChangedSearchGridItem)
                {
                    var defaultValue = item as Data.DefaultValuePlaceholder;
                    if (defaultValue != null)
                    {
                        if (defaultValue.ID < 0 && !string.IsNullOrEmpty(defaultValue.Value))
                        {
                            if (mailTemplate == null)
                            {
                                mailTemplate = await _mailTemplateRepository.FetchSingleAsync(id);
                            }

                            // create
                            defaultValue.ID             = 0;
                            defaultValue.MailTemplateID = mailTemplate.ID;
                            await _defaultValuePlaceholderRepository.SaveAsync(defaultValue);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(defaultValue.Value))
                            {
                                // delete
                                await _defaultValuePlaceholderRepository.DeleteAsync(defaultValue);
                            }
                            else
                            {
                                // edit
                                await _defaultValuePlaceholderRepository.SaveAsync(defaultValue);
                            }
                        }
                    }
                }
            }
        }
        private async Task ShowMailPreview_ListLoad(ComponentListEventArgs e)
        {
            var mailTemplateKey = Context.Request.Query["MailTemplateID"].ToString();

            if (!string.IsNullOrEmpty(mailTemplateKey))
            {
                var mailTemplate = await _mailTemplateRepository.FetchSingleAsync(int.Parse(mailTemplateKey));

                var body = HttpUtility.HtmlDecode(mailTemplate.Body);

                //with the mail charset an  shows instead of &nbsp: http://stackoverflow.com/questions/1461907/html-encoding-issues-%C3%82-character-showing-up-instead-of-nbsp
                body = body?.Replace(@"<meta http-equiv=""Content-Type"" content=""text/html; charset=ISO-8859-1"" />", @"<meta http-equiv=""Content-Type"" content=""text/html;charset=utf-8"" />");

                var subject = mailTemplate.Subject;

                var text = $"<div style='margin-left:10px'><h3 style='margin-left: 50px'>{subject}</h3><p>{body}</p></div>";
                var data = System.Text.Encoding.UTF8.GetBytes(text);
                await Response.Body.WriteAsync(data, 0, data.Length);
            }
        }
Example #8
0
        private async Task MailTemplatesList_ListSave(ComponentListEventArgs e)
        {
            var currentTemplateInDatabase = await _mailTemplateListRepository.FetchSingleAsync(Implement.ID);

            var result = await _mailTemplateListRepository.FetchSingleByIdentifierAsync(Identifier);

            if (result != null && result.ID != Implement.ID)
            {
                await Notification.InsertOneAsync("Wim.Module.MailTemplate", $"Identifier {Identifier} is already in use.");
            }

            var id = await _mailTemplateRepository.SaveAsync(Implement, wim.CurrentApplicationUser.ID, wim.CurrentApplicationUser.Displayname, wim.CurrentApplicationUser.Email);

            Response.Redirect(wim.GetUrl(new KeyValue[] {
                new KeyValue {
                    Key = "list", Value = wim.CurrentList.ID
                },
                new KeyValue {
                    Key = "item", Value = id
                }
            }));
        }