| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 | 
							- using Comal.Classes;
 
- using InABox.Core;
 
- using InABox.DynamicGrid;
 
- using InABox.WPF;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Threading.Tasks;
 
- using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
 
- namespace PRSServer.Forms.WebTemplates
 
- {
 
-     public class WebTemplateGrid : DynamicDataGrid<WebTemplate>
 
-     {
 
-         private readonly string defaultTemplate = @"
 
- @{Model.LoadModel(new string[] { ""CompanyInformation"", ""CompanyLogo"", ""User"" });}
 
- <!DOCTYPE html>
 
- <html>
 
-     <head>
 
-         <title>Untitled page</title>
 
-         <meta charset=""utf8"">
 
-         <meta name=""viewport"" content=""width=device-width,initial-scale=1"">
 
-     </head>
 
-     <body>
 
-         <h1>New Page</h1>
 
-         <p>
 
-             This is an empty page.
 
-         </p>
 
-     </body>
 
- </html>";
 
-         public WebTemplateGrid()
 
-         {
 
-             ActionColumns.Add(new DynamicImageColumn(Properties.Resources.html.AsBitmapImage(), EditTemplateAction));
 
-             OnCreateItem += (sender, item) => { (item as WebTemplate).Template = defaultTemplate; };
 
-             OnAfterSave += (sender, items) =>
 
-             {
 
-                 foreach (var item in items.Cast<WebTemplate>()) SaveToLocalFolder(item);
 
-             };
 
-             OnDoubleClick += (sender, args) =>
 
-             {
 
-                 if (SelectedRows.Length == 1) EditWebTemplateScript(SelectedRows[0]);
 
-                 args.Handled = true;
 
-             };
 
-         }
 
-         protected override void DoReconfigure(FluentList<DynamicGridOption> options)
 
-         {
 
-             base.DoReconfigure(options);
 
-             options.AddRange(DynamicGridOption.AddRows, DynamicGridOption.EditRows, DynamicGridOption.DeleteRows);
 
-         }
 
-         private bool EditTemplateAction(CoreRow arg)
 
-         {
 
-             if (arg != null) EditWebTemplateScript(arg);
 
-             return false;
 
-         }
 
-         private static void SaveToLocalFolder(WebTemplate template)
 
-         {
 
-             if (CoreUtils.GetVersion() == "???")
 
-                 File.WriteAllText(
 
-                     string.Format("{0}/WebBackup/Templates/{1}_{2}_{3}.html",
 
-                         Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
 
-                         template.DataModel,
 
-                         template.Slug,
 
-                         template.ID
 
-                     ),
 
-                     template.Template
 
-                 );
 
-         }
 
-         private void EditWebTemplateScript(CoreRow arg)
 
-         {
 
-             var template = LoadItem(arg);
 
-             var editor = new ScriptEditor(template.Template, SyntaxLanguage.HTML, $"Template: {template}");
 
-             editor.OnSave += (e, args) =>
 
-             {
 
-                 template.Template = editor.Script;
 
-                 SaveToLocalFolder(template);
 
-                 SaveItem(template);
 
-             };
 
-             editor.OnCompile += (e, args) =>
 
-             {
 
-                 editor.Save();
 
-                 editor.ClearErrors().AddError("Template Saved").AddError("Compiling Template...");
 
-                 Task.Run(() =>
 
-                 {
 
-                     var errors = new List<string>();
 
-                     try
 
-                     {
 
-                         WebHandler.CompileTemplate(template);
 
-                         errors.Add("Template Compiled Successfully!");
 
-                     }
 
-                     catch (Exception e0)
 
-                     {
 
-                         errors.Add("ERROR: ");
 
-                         errors.AddRange(e0.Message.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries));
 
-                     }
 
-                     Dispatcher.Invoke(() =>
 
-                     {
 
-                         editor.ClearErrors();
 
-                         foreach (var error in errors) editor.AddError(error);
 
-                     });
 
-                 });
 
-             };
 
-             editor.Show();
 
-         }
 
-     }
 
- }
 
 
  |