2024-06-13 00:51:59 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
using Wino.Core.Domain;
|
2024-11-10 23:28:25 +01:00
|
|
|
|
using Wino.Core.Domain.Entities.Mail;
|
2024-06-13 00:51:59 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
namespace Wino.Dialogs;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed partial class SignatureEditorDialog : ContentDialog
|
2024-06-13 00:51:59 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public AccountSignature Result;
|
|
|
|
|
|
|
|
|
|
|
|
public SignatureEditorDialog()
|
2024-06-13 00:51:59 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
InitializeComponent();
|
2024-07-18 20:04:11 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
SignatureNameTextBox.Header = Translator.SignatureEditorDialog_SignatureName_TitleNew;
|
2024-07-18 20:04:11 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
// TODO: Should be added additional logic to enable/disable primary button when webview content changed.
|
|
|
|
|
|
IsPrimaryButtonEnabled = true;
|
|
|
|
|
|
}
|
2024-06-13 00:51:59 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public SignatureEditorDialog(AccountSignature signatureModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
SignatureNameTextBox.Text = signatureModel.Name.Trim();
|
|
|
|
|
|
SignatureNameTextBox.Header = string.Format(Translator.SignatureEditorDialog_SignatureName_TitleEdit, signatureModel.Name);
|
|
|
|
|
|
|
|
|
|
|
|
Result = new AccountSignature
|
2024-06-13 00:51:59 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
Id = signatureModel.Id,
|
|
|
|
|
|
Name = signatureModel.Name,
|
|
|
|
|
|
MailAccountId = signatureModel.MailAccountId,
|
|
|
|
|
|
HtmlBody = signatureModel.HtmlBody
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Should be added additional logic to enable/disable primary button when webview content changed.
|
|
|
|
|
|
IsPrimaryButtonEnabled = true;
|
|
|
|
|
|
}
|
2024-06-13 00:51:59 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
private async void SignatureDialogOpened(ContentDialog sender, ContentDialogOpenedEventArgs args)
|
|
|
|
|
|
{
|
2025-02-22 00:43:39 +01:00
|
|
|
|
await WebViewEditor.RenderHtmlAsync(Result?.HtmlBody ?? string.Empty);
|
2025-02-16 11:54:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DialogClosed(ContentDialog sender, ContentDialogClosedEventArgs args)
|
|
|
|
|
|
{
|
2025-02-22 00:43:39 +01:00
|
|
|
|
WebViewEditor.Dispose();
|
2025-02-16 11:54:23 +01:00
|
|
|
|
}
|
2024-06-13 00:51:59 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
private async void SaveClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
|
|
|
|
|
{
|
2025-02-22 00:43:39 +01:00
|
|
|
|
var newSignature = Regex.Unescape(await WebViewEditor.GetHtmlBodyAsync());
|
2024-06-13 00:51:59 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
if (Result == null)
|
|
|
|
|
|
{
|
2024-06-13 00:51:59 +02:00
|
|
|
|
Result = new AccountSignature
|
|
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
|
Name = SignatureNameTextBox.Text.Trim(),
|
|
|
|
|
|
HtmlBody = newSignature
|
2024-06-13 00:51:59 +02:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-02-16 11:54:23 +01:00
|
|
|
|
else
|
2024-06-13 00:51:59 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
Result.Name = SignatureNameTextBox.Text.Trim();
|
|
|
|
|
|
Result.HtmlBody = newSignature;
|
|
|
|
|
|
}
|
2024-06-13 00:51:59 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
Hide();
|
|
|
|
|
|
}
|
2024-06-13 00:51:59 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
private void CancelClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
Hide();
|
|
|
|
|
|
}
|
2024-06-13 00:51:59 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
private void SignatureNameTextBoxTextChanged(object sender, TextChangedEventArgs e) => IsPrimaryButtonEnabled = !string.IsNullOrWhiteSpace(SignatureNameTextBox.Text);
|
2024-06-13 00:51:59 +02:00
|
|
|
|
}
|