Skip to content

Commit bb62421

Browse files
committed
Allow to clone mails
1 parent 9395271 commit bb62421

File tree

3 files changed

+107
-7
lines changed

3 files changed

+107
-7
lines changed

assets/js/mails.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,31 @@ function loadMail(id) {
200200
'<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6" style="height: 22px;width: 22px;"><path stroke-linecap="round" stroke-linejoin="round" d="m20.25 7.5-.625 10.632a2.25 2.25 0 0 1-2.247 2.118H6.622a2.25 2.25 0 0 1-2.247-2.118L3.75 7.5m8.25 3v6.75m0 0-3-3m3 3 3-3M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125Z"></path></svg><div class="ml5">Save changes</div>'
201201
]
202202
}),
203-
jsCreateElement('button', {
203+
jsCreateElement('div', {
204204
attrs: {
205-
class: 'mailSend buttonIcon',
206-
style: 'width: fit-content;',
207-
onclick: 'sendMail(' + id + ')'
205+
style: 'display: flex;align-items: center;gap: 10px;'
208206
},
209-
rawHtml: [
210-
'<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"><path stroke-linecap="round" stroke-linejoin="round" d="M21.75 6.75v10.5a2.25 2.25 0 0 1-2.25 2.25h-15a2.25 2.25 0 0 1-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0 0 19.5 4.5h-15a2.25 2.25 0 0 0-2.25 2.25m19.5 0v.243a2.25 2.25 0 0 1-1.07 1.916l-7.5 4.615a2.25 2.25 0 0 1-2.36 0L3.32 8.91a2.25 2.25 0 0 1-1.07-1.916V6.75" /></svg><div class="ml5">Send email</div>'
207+
children: [
208+
jsCreateElement('button', {
209+
attrs: {
210+
class: 'mailSend buttonIcon',
211+
style: 'width: fit-content;',
212+
onclick: 'duplicateMail(' + id + ')',
213+
},
214+
rawHtml: [
215+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" width="24" height="24" stroke-width="2"><path d="M7 7m0 2.667a2.667 2.667 0 0 1 2.667 -2.667h8.666a2.667 2.667 0 0 1 2.667 2.667v8.666a2.667 2.667 0 0 1 -2.667 2.667h-8.666a2.667 2.667 0 0 1 -2.667 -2.667z"></path><path d="M4.012 16.737a2.005 2.005 0 0 1 -1.012 -1.737v-10c0 -1.1 .9 -2 2 -2h10c.75 0 1.158 .385 1.5 1"></path></svg><div class="ml5">Duplicate</div>'
216+
]
217+
}),
218+
jsCreateElement('button', {
219+
attrs: {
220+
class: 'mailSend buttonIcon',
221+
style: 'width: fit-content;',
222+
onclick: 'sendMail(' + id + ')'
223+
},
224+
rawHtml: [
225+
'<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"><path stroke-linecap="round" stroke-linejoin="round" d="M21.75 6.75v10.5a2.25 2.25 0 0 1-2.25 2.25h-15a2.25 2.25 0 0 1-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0 0 19.5 4.5h-15a2.25 2.25 0 0 0-2.25 2.25m19.5 0v.243a2.25 2.25 0 0 1-1.07 1.916l-7.5 4.615a2.25 2.25 0 0 1-2.36 0L3.32 8.91a2.25 2.25 0 0 1-1.07-1.916V6.75" /></svg><div class="ml5">Send email</div>'
226+
]
227+
})
211228
]
212229
})
213230
]
@@ -766,6 +783,18 @@ function saveMail(mailID) {
766783
});
767784
}
768785

786+
async function duplicateMail(mailID) {
787+
let mailData = await fetch("/api/mails/duplicate?mailID=" + mailID, {
788+
method: "POST"
789+
})
790+
.then(manageErrors)
791+
.then(response => response.json())
792+
.then(data => {
793+
window.location.reload();
794+
});
795+
796+
console.log(mailData);
797+
}
769798

770799
async function sendMail(mailID) {
771800
let lists = await fetch("/api/lists/all", {

nimletter.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.4.3"
3+
version = "0.4.4"
44
author = "ThomasTJdev"
55
description = "Newsletter"
66
license = "AGPL v3"

src/routes/routes_mail.nim

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import
44
std/[
55
json,
6+
random,
67
strutils
78
]
89

@@ -24,6 +25,9 @@ import
2425
../utils/validate_data
2526

2627

28+
randomize()
29+
30+
2731
proc formatTags(tags: string): seq[string] =
2832
for tag in tags.split(","):
2933
if tag.strip() != "":
@@ -82,6 +86,73 @@ proc(request: Request) =
8286
)
8387

8488

89+
mailRouter.post("/api/mails/duplicate",
90+
proc(request: Request) =
91+
createTFD()
92+
if not c.loggedIn: resp Http401
93+
94+
let mailID = @"mailID"
95+
96+
if not mailID.isValidInt():
97+
resp Http400, "Invalid UUID"
98+
99+
var mailData: seq[string]
100+
pg.withConnection conn:
101+
mailData = getRow(conn, sqlSelect(
102+
table = "mails",
103+
select = [
104+
"id",
105+
"name",
106+
"contentHTML",
107+
"contentEditor",
108+
"editorType",
109+
"tags",
110+
"category",
111+
"send_once",
112+
"subject",
113+
],
114+
where = [
115+
"id = ?"
116+
]),
117+
mailID)
118+
119+
if mailData.len() == 0 or mailData[0] == "":
120+
resp Http404, "mail not found for UUID " & mailID
121+
122+
var newMailID: string
123+
pg.withConnection conn:
124+
newMailID = $insertID(conn, sqlInsert(
125+
table = "mails",
126+
data = [
127+
"name",
128+
"identifier",
129+
"contentHTML",
130+
"contentEditor",
131+
"editorType",
132+
"tags",
133+
"category",
134+
"send_once",
135+
"subject"
136+
]),
137+
mailData[1], # name
138+
mailData[1].toLowerAscii().replace(" ", "-").subStr(0, 20).strip(chars={'-', '_'}) & "-" & $rand(1000000), # identifier
139+
mailData[2], # contentHTML
140+
mailData[3], # contentEditor
141+
mailData[4], # editorType
142+
mailData[5], # tags
143+
mailData[6], # category
144+
mailData[7], # send_once
145+
mailData[8], # subject
146+
)
147+
148+
resp Http200, (
149+
%* {
150+
"id": newMailID
151+
}
152+
)
153+
)
154+
155+
85156
mailRouter.get("/api/mails/get",
86157
proc(request: Request) =
87158
createTFD()

0 commit comments

Comments
 (0)