TextEditService.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Net;
  4. using System.Text;
  5. using System.Web;
  6. namespace FastReport.Web.Services
  7. {
  8. internal sealed class TextEditService : ITextEditService
  9. {
  10. public string GetTemplateTextEditForm(string click, WebReport webReport)
  11. {
  12. if (!click.IsNullOrWhiteSpace())
  13. {
  14. var @params = click.Split(',');
  15. if (@params.Length == 4)
  16. {
  17. if (int.TryParse(@params[1], out var pageN) &&
  18. float.TryParse(@params[2], out var left) &&
  19. float.TryParse(@params[3], out var top))
  20. {
  21. string result = null;
  22. webReport.Report.FindClickedObject<TextObject>(@params[0], pageN, left, top,
  23. (textObject, reportPage, _pageN) =>
  24. {
  25. webReport.Res.Root("Buttons");
  26. string okText = webReport.Res.Get("Ok");
  27. string cancelText = webReport.Res.Get("Cancel");
  28. result = Template_textedit_form(textObject.Text, okText, cancelText);
  29. });
  30. return result;
  31. }
  32. }
  33. }
  34. return null;
  35. }
  36. private static string Template_textedit_form(string text, string okText, string cancelText) => $@"
  37. <!DOCTYPE html>
  38. <html>
  39. <head>
  40. <meta charset=""utf-8"">
  41. <meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">
  42. <title>Text edit</title>
  43. <style>
  44. body {{
  45. margin: 8px;
  46. height: calc(100vh - 16px);
  47. }}
  48. textarea {{
  49. width: 100%;
  50. height: calc(100% - 42px);
  51. box-sizing : border-box;
  52. }}
  53. button {{
  54. float: right;
  55. margin-left: 8px;
  56. margin-top: 8px;
  57. height: 30px;
  58. }}
  59. </style>
  60. </head>
  61. <body>
  62. <textarea autofocus>{HttpUtility.HtmlEncode(text)}</textarea>
  63. <br>
  64. <button onclick=""window.close();"">{HttpUtility.HtmlEncode(cancelText)}</button>
  65. <button onclick=""window.postMessage('submit', '*');"">{HttpUtility.HtmlEncode(okText)}</button>
  66. </body>
  67. </html>
  68. ";
  69. }
  70. }