diff --git a/web/static/js/quotes.js b/web/static/js/quotes.js
index 715ca3c..1fbf0e1 100644
--- a/web/static/js/quotes.js
+++ b/web/static/js/quotes.js
@@ -13,42 +13,6 @@ if (sorting == null) {
sorting = "-datetime";
}
-function datetimeToLocalISO(datetime) {
- var options = {
- year: "numeric",
- month: "2-digit",
- day: "2-digit",
- hour: "2-digit",
- minute: "2-digit",
- second: "2-digit",
- timeZoneName: "longOffset",
- };
-
- var formatter = new Intl.DateTimeFormat("sv-SE", options);
- var date = new Date(datetime);
-
- return formatter
- .formatToParts(date)
- .map(({ type, value }) => {
- if (type === "timeZoneName") {
- return value.slice(3);
- } else {
- return value;
- }
- })
- .join("")
- .replace(" ", "T")
- .replace(" ", "");
-}
-
-function escapedString(str) {
- return str
- .replace("&", "&")
- .replace("<", "<")
- .replace(">", ">")
- .replace("\n", "
");
-}
-
function renderBlockQuote(quote) {
return `
@@ -168,11 +132,7 @@ $(document).on("click", "#btn-add-close", function (e) {
$(document).on("submit", "#quote-create", function (e) {
e.preventDefault();
- formdata = $("#quote-create").serializeArray();
- data = {};
- $(formdata).each(function (index, obj) {
- data[obj.name] = obj.value;
- });
+ data = formToJSON($("#quote-create"));
data.datetime = datetimeToLocalISO(data.datetime);
$.ajax({
url: "/api/quotes",
diff --git a/web/static/js/settings.js b/web/static/js/settings.js
index a4f2b95..8b4c449 100644
--- a/web/static/js/settings.js
+++ b/web/static/js/settings.js
@@ -31,12 +31,7 @@ $(document).on("click", "#btn-logout", function (e) {
$(document).on("submit", "#user-update", function (e) {
e.preventDefault();
- formdata = $("#user-update").serializeArray();
- data = {};
- $(formdata).each(function (index, obj) {
- data[obj.name] = obj.value;
- });
- console.log(data);
+ data = formToJSON($("#user-update"));
$.ajax({
url: "/api/auth",
type: "PATCH",
diff --git a/web/static/js/utils.js b/web/static/js/utils.js
new file mode 100644
index 0000000..42f8923
--- /dev/null
+++ b/web/static/js/utils.js
@@ -0,0 +1,42 @@
+function datetimeToLocalISO(datetime) {
+ var options = {
+ year: "numeric",
+ month: "2-digit",
+ day: "2-digit",
+ hour: "2-digit",
+ minute: "2-digit",
+ second: "2-digit",
+ timeZoneName: "longOffset",
+ };
+ var formatter = new Intl.DateTimeFormat("sv-SE", options);
+ var date = new Date(datetime);
+ return formatter
+ .formatToParts(date)
+ .map(({ type, value }) => {
+ if (type === "timeZoneName") {
+ return value.slice(3);
+ } else {
+ return value;
+ }
+ })
+ .join("")
+ .replace(" ", "T")
+ .replace(" ", "");
+}
+
+function escapedString(str) {
+ return str
+ .replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+ .replace("\n", "
");
+}
+
+function formToJSON(form) {
+ formdata = form.serializeArray();
+ data = {};
+ $(formdata).each(function (index, obj) {
+ data[obj.name] = obj.value;
+ });
+ return data;
+}
diff --git a/web/templates/quotes.html b/web/templates/quotes.html
index 997d39c..46bf819 100644
--- a/web/templates/quotes.html
+++ b/web/templates/quotes.html
@@ -102,6 +102,7 @@
+