pm_view.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const { div, h2, p, section, button, form, input, textarea, br, label, pre, span } = require("../server/node_modules/hyperaxe");
  2. const { template, i18n } = require('./main_views');
  3. const { getConfig } = require('../configs/config-manager.js');
  4. exports.pmView = async (initialRecipients = '', initialSubject = '', initialText = '', showPreview = false) => {
  5. const title = i18n.pmSendTitle;
  6. const description = i18n.pmDescription;
  7. const textLen = (initialText || '').length;
  8. const pmVis = getConfig().pmVisibility === 'mutuals' ? 'mutuals' : 'whole';
  9. const pmVisLabel = pmVis === 'mutuals' ? i18n.settingsPmVisibilityMutuals : i18n.settingsPmVisibilityWhole;
  10. return template(
  11. title,
  12. section(
  13. div({ class: "tags-header" },
  14. h2(title),
  15. p(description)
  16. ),
  17. section(
  18. div({ class: "pm-form" },
  19. form({ method: "POST", action: "/pm", id: "pm-form" },
  20. p({ class: "pm-visibility-note" }, span({ class: "accent" }, "* "), pmVisLabel),
  21. label({ for: "recipients" }, i18n.pmRecipients),
  22. br(),
  23. input({
  24. type: "text",
  25. name: "recipients",
  26. placeholder: i18n.pmRecipientsHint,
  27. required: true,
  28. value: initialRecipients
  29. }),
  30. br(),
  31. label({ for: "subject" }, i18n.pmSubject),
  32. br(),
  33. input({ type: "text", name: "subject", placeholder: i18n.pmSubjectHint, value: initialSubject }),
  34. br(),
  35. label({ for: "text" }, i18n.pmText),
  36. br(),
  37. textarea({ name: "text", rows: "6", cols: "50", id: "pm-text", maxlength: "8096" }, initialText),
  38. div({ class: "pm-actions-block" },
  39. div({ class: "pm-actions" },
  40. button({ type: "submit", formaction: "/pm/preview", formmethod: "POST" }, i18n.pmPreview),
  41. button({ type: "submit", class: "btn-compact" }, i18n.pmSend)
  42. )
  43. )
  44. ),
  45. showPreview
  46. ? div({ id: "pm-preview-area", class: "pm-preview" },
  47. h2(i18n.pmPreviewTitle),
  48. p({ id: "pm-preview-count", class: "pm-preview-count" }, `${textLen}/8096`),
  49. div({ id: "pm-preview-content", class: "pm-preview-content" },
  50. pre({ class: "pm-pre" }, initialText || '')
  51. )
  52. )
  53. : null
  54. )
  55. )
  56. )
  57. );
  58. };