| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Windows;
 
- using System.Windows.Controls;
 
- using System.Windows.Media;
 
- using System.Windows.Threading;
 
- using InABox.Clients;
 
- using InABox.Core;
 
- using InABox.Mail;
 
- using InABox.Wpf;
 
- using InABox.WPF;
 
- using Microsoft.Win32;
 
- namespace PRSDesktop
 
- {
 
-     /// <summary>
 
-     ///     Interaction logic for EmailForm.xaml
 
-     /// </summary>
 
-     public partial class EmailForm : ThemableWindow
 
-     {
 
-         private readonly ICoreMailMessage _message;
 
-         private readonly DataModel _model;
 
-         private readonly List<Tuple<string, byte[]>> attachments = new();
 
-         public EmailForm(ICoreMailMessage message, DataModel model = null)
 
-         {
 
-             _message = message;
 
-             _model = model;
 
-             InitializeComponent();
 
-             EmailImage.Source = PRSDesktop.Resources.email.AsBitmapImage(32, 32);
 
-             Subject.Text = _message.Subject;
 
-             Body.Text = _message.Body;
 
-             To.Text = _message.To != null ? string.Join("; ", message.To) : "";
 
-             Body.SetColor(Colors.LightYellow);
 
-             if (_message.Attachments != null)
 
-                 attachments.AddRange(_message.Attachments);
 
-             Attachments.ItemsSource = attachments;
 
-             ApplyTemplate.Visibility = model != null ? Visibility.Visible : Visibility.Collapsed;
 
-             var timer = new DispatcherTimer();
 
-             timer.Interval = TimeSpan.FromMilliseconds(100);
 
-             timer.Tick += (o, e) =>
 
-             {
 
-                 var bEnabled = !string.IsNullOrWhiteSpace(To.Text) && !string.IsNullOrWhiteSpace(Subject.Text) &&
 
-                                !string.IsNullOrWhiteSpace(Body.Text);
 
-                 if (bEnabled != Send.IsEnabled)
 
-                     Send.IsEnabled = bEnabled;
 
-             };
 
-             timer.IsEnabled = true;
 
-         }
 
-         public double Zoom
 
-         {
 
-             get => Body.ZoomFactor;
 
-             set => Body.ZoomFactor = value;
 
-         }
 
-         private void SendClick(object sender, RoutedEventArgs e)
 
-         {
 
-             _message.To = To.Text.Split(new[] { "; " }, StringSplitOptions.RemoveEmptyEntries);
 
-             //_message.CC = CC.Text.Split(new String[] { "; " }, StringSplitOptions.RemoveEmptyEntries);
 
-             //_message.BCC = BCC.Text.Split(new String[] { "; " }, StringSplitOptions.RemoveEmptyEntries);
 
-             _message.Subject = Subject.Text;
 
-             _message.Body = Body.Text;
 
-             _message.Attachments = attachments.ToArray();
 
-             DialogResult = true;
 
-             Close();
 
-         }
 
-         private void AddAttachment_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var dlg = new OpenFileDialog();
 
-             dlg.Title = "Select Attachment";
 
-             dlg.Filter = "All Files (*.*)|*.*";
 
-             if (dlg.ShowDialog() == true)
 
-                 attachments.Add(new Tuple<string, byte[]>(Path.GetFileName(dlg.FileName), File.ReadAllBytes(dlg.FileName)));
 
-             Attachments.ItemsSource = null;
 
-             Attachments.ItemsSource = attachments;
 
-         }
 
-         private void DeleteAttachment_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var attachment = Attachments.SelectedItem as Tuple<string, byte[]>;
 
-             if (attachment != null)
 
-             {
 
-                 attachments.Remove(attachment);
 
-                 Attachments.ItemsSource = null;
 
-                 Attachments.ItemsSource = attachments;
 
-             }
 
-         }
 
-         private void ApplyTemplate_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var templates = new Client<DataModelTemplate>().Query(new Filter<DataModelTemplate>(x => x.Model).IsEqualTo(_model.Name));
 
-             if (templates.Rows.Any())
 
-             {
 
-                 var context = new ContextMenu();
 
-                 foreach (var row in templates.Rows)
 
-                 {
 
-                     var menu = new MenuItem
 
-                     {
 
-                         Header = row.Get<DataModelTemplate, string>(x => x.Name),
 
-                         Tag = row
 
-                     };
 
-                     menu.Click += (o, args) =>
 
-                     {
 
-                         var cur = ((MenuItem)o).Tag as CoreRow;
 
-                         var data = cur.Get<DataModelTemplate, string>(x => x.Template);
 
-                         try
 
-                         {
 
-                             Body.Text = DataModelUtils.ParseTemplate(_model, data);
 
-                         }
 
-                         catch (Exception err)
 
-                         {
 
-                             MessageBox.Show("Unable to Parse Template!\n\n" + err.Message);
 
-                         }
 
-                     };
 
-                     context.Items.Add(menu);
 
-                 }
 
-                 context.Items.Add(new Separator());
 
-                 var item = new MenuItem
 
-                 {
 
-                     Header = "Manage Templates",
 
-                     Tag = null
 
-                 };
 
-                 item.Click += (o, args) =>
 
-                 {
 
-                     var list = new DataModelTemplateForm(_model);
 
-                     list.ShowDialog();
 
-                 };
 
-                 context.Items.Add(item);
 
-                 context.PlacementTarget = ApplyTemplate;
 
-                 context.IsOpen = true;
 
-             }
 
-             else
 
-             {
 
-                 var list = new DataModelTemplateForm(_model);
 
-                 list.ShowDialog();
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |