|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Broadcast email</title> |
| 6 | + <style> |
| 7 | + :root { |
| 8 | + color-scheme: light; |
| 9 | + } |
| 10 | + body { font-family: "Segoe UI", Arial, sans-serif; background-color: #f4f6fb; margin: 0; padding: 32px; } |
| 11 | + .container { max-width: 820px; margin: 0 auto; background: #fff; border-radius: 12px; padding: 32px; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12); } |
| 12 | + h1 { margin-top: 0; color: #111827; } |
| 13 | + .field { margin-bottom: 22px; } |
| 14 | + label { display: block; font-weight: 600; margin-bottom: 6px; color: #111827; } |
| 15 | + input[type="text"], select { width: 100%; padding: 10px 12px; border: 1px solid #cbd5f5; border-radius: 8px; font-size: 14px; } |
| 16 | + select[multiple] { min-height: 220px; } |
| 17 | + .errorlist { margin: 4px 0 0; padding: 0; list-style: none; color: #b91c1c; font-size: 13px; } |
| 18 | + button[type="submit"] { background-color: #2563eb; color: #fff; border: none; padding: 12px 24px; border-radius: 8px; font-weight: 600; cursor: pointer; } |
| 19 | + button:disabled { opacity: 0.6; cursor: not-allowed; } |
| 20 | + a { color: #2563eb; text-decoration: none; } |
| 21 | + .editor-toolbar { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; } |
| 22 | + .editor-toolbar button { background: #e0e7ff; border: 1px solid #c7d2fe; color: #1e1b4b; padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer; } |
| 23 | + .editor-toolbar button:hover { background: #c7d2fe; } |
| 24 | + .rich-editor { border: 1px solid #cbd5f5; border-radius: 10px; padding: 12px; min-height: 200px; line-height: 1.5; font-size: 15px; background: #f8fafc; } |
| 25 | + .rich-editor:focus { outline: 2px solid #6366f1; background: #fff; } |
| 26 | + .rich-editor:empty:before { content: attr(data-placeholder); color: #94a3b8; } |
| 27 | + .search-input { width: 100%; padding: 8px 10px; border: 1px solid #cbd5f5; border-radius: 6px; margin-bottom: 10px; font-size: 14px; } |
| 28 | + small { color: #6b7280; display: block; margin-top: 4px; } |
| 29 | + form .actions { margin-top: 28px; } |
| 30 | + </style> |
| 31 | +</head> |
| 32 | +<body> |
| 33 | + <div class="container"> |
| 34 | + <h1>Broadcast email</h1> |
| 35 | + <p>Pick a template and send it to selected accounts. Only templates explicitly allowed for broadcasting will appear here.</p> |
| 36 | + <p><a href="{% url 'mail_tools:list' %}">← Back to templates</a></p> |
| 37 | + |
| 38 | + <form method="post" id="broadcast-form"> |
| 39 | + {% csrf_token %} |
| 40 | + <div class="field"> |
| 41 | + {{ form.template_slug.label_tag }} |
| 42 | + {{ form.template_slug }} |
| 43 | + {{ form.template_slug.errors }} |
| 44 | + </div> |
| 45 | + |
| 46 | + <div class="field"> |
| 47 | + {{ form.subject.label_tag }} |
| 48 | + {{ form.subject }} |
| 49 | + {{ form.subject.errors }} |
| 50 | + </div> |
| 51 | + |
| 52 | + <div class="field" id="editor-field"> |
| 53 | + <label for="rich-editor">Message body</label> |
| 54 | + <noscript><small>Rich text editing requires JavaScript. Please enable it to compose a message.</small></noscript> |
| 55 | + <div class="editor-toolbar" aria-label="Formatting toolbar"> |
| 56 | + <button type="button" data-command="bold"><strong>B</strong></button> |
| 57 | + <button type="button" data-command="italic"><em>I</em></button> |
| 58 | + <button type="button" data-command="insertUnorderedList">• List</button> |
| 59 | + <button type="button" data-command="createLink">Link</button> |
| 60 | + <button type="button" data-command="removeFormat">Clear</button> |
| 61 | + </div> |
| 62 | + <div id="rich-editor" class="rich-editor" contenteditable="true" data-placeholder="Compose your optional message..."></div> |
| 63 | + {{ form.body_html }} |
| 64 | + {% if form.body_html.help_text %} |
| 65 | + <small>{{ form.body_html.help_text }}</small> |
| 66 | + {% endif %} |
| 67 | + {{ form.body_html.errors }} |
| 68 | + </div> |
| 69 | + |
| 70 | + <div class="field"> |
| 71 | + <label for="recipient-filter">Recipients</label> |
| 72 | + <input type="search" id="recipient-filter" class="search-input" placeholder="Filter recipients by email or username…" autocomplete="off"> |
| 73 | + {{ form.recipients }} |
| 74 | + <small>Hold Ctrl/Cmd to select multiple recipients.</small> |
| 75 | + {{ form.recipients.errors }} |
| 76 | + </div> |
| 77 | + |
| 78 | + {% if form.non_field_errors %} |
| 79 | + <ul class="errorlist"> |
| 80 | + {% for error in form.non_field_errors %} |
| 81 | + <li>{{ error }}</li> |
| 82 | + {% endfor %} |
| 83 | + </ul> |
| 84 | + {% endif %} |
| 85 | + |
| 86 | + <div class="actions"> |
| 87 | + <button type="submit">Send emails</button> |
| 88 | + </div> |
| 89 | + </form> |
| 90 | + </div> |
| 91 | + |
| 92 | + <script> |
| 93 | + (function () { |
| 94 | + const form = document.getElementById("broadcast-form"); |
| 95 | + const editor = document.getElementById("rich-editor"); |
| 96 | + const hiddenInput = document.getElementById("id_body_html"); |
| 97 | + |
| 98 | + const initial = hiddenInput.value || ""; |
| 99 | + if (initial) { |
| 100 | + editor.innerHTML = initial; |
| 101 | + } |
| 102 | + |
| 103 | + const syncHidden = () => { |
| 104 | + hiddenInput.value = editor.innerHTML.trim(); |
| 105 | + }; |
| 106 | + |
| 107 | + editor.addEventListener("input", syncHidden); |
| 108 | + form.addEventListener("submit", syncHidden); |
| 109 | + |
| 110 | + document.querySelector(".editor-toolbar").addEventListener("click", (event) => { |
| 111 | + const button = event.target.closest("button[data-command]"); |
| 112 | + if (!button) { |
| 113 | + return; |
| 114 | + } |
| 115 | + event.preventDefault(); |
| 116 | + const command = button.dataset.command; |
| 117 | + if (command === "createLink") { |
| 118 | + const url = prompt("Enter the URL"); |
| 119 | + if (url) { |
| 120 | + document.execCommand("createLink", false, url); |
| 121 | + } |
| 122 | + } else { |
| 123 | + document.execCommand(command, false, null); |
| 124 | + } |
| 125 | + editor.focus(); |
| 126 | + syncHidden(); |
| 127 | + }); |
| 128 | + |
| 129 | + const filterInput = document.getElementById("recipient-filter"); |
| 130 | + const recipientSelect = document.getElementById("id_recipients"); |
| 131 | + |
| 132 | + filterInput.addEventListener("input", () => { |
| 133 | + const term = filterInput.value.trim().toLowerCase(); |
| 134 | + Array.from(recipientSelect.options).forEach((option) => { |
| 135 | + const text = option.text.toLowerCase(); |
| 136 | + const value = option.value.toLowerCase(); |
| 137 | + option.hidden = term && !text.includes(term) && !value.includes(term); |
| 138 | + }); |
| 139 | + }); |
| 140 | + })(); |
| 141 | + </script> |
| 142 | +</body> |
| 143 | +</html> |
0 commit comments