refactor(web): move util js functions into a separate file
This commit is contained in:
parent
eeb4b52192
commit
3bfc54e407
@ -13,42 +13,6 @@ if (sorting == null) {
|
|||||||
sorting = "-datetime";
|
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", "<br>");
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderBlockQuote(quote) {
|
function renderBlockQuote(quote) {
|
||||||
return `
|
return `
|
||||||
<div class="border rounded-lg p-6 hover:shadow-md transition-shadow">
|
<div class="border rounded-lg p-6 hover:shadow-md transition-shadow">
|
||||||
@ -168,11 +132,7 @@ $(document).on("click", "#btn-add-close", function (e) {
|
|||||||
|
|
||||||
$(document).on("submit", "#quote-create", function (e) {
|
$(document).on("submit", "#quote-create", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
formdata = $("#quote-create").serializeArray();
|
data = formToJSON($("#quote-create"));
|
||||||
data = {};
|
|
||||||
$(formdata).each(function (index, obj) {
|
|
||||||
data[obj.name] = obj.value;
|
|
||||||
});
|
|
||||||
data.datetime = datetimeToLocalISO(data.datetime);
|
data.datetime = datetimeToLocalISO(data.datetime);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/api/quotes",
|
url: "/api/quotes",
|
||||||
|
|||||||
@ -31,12 +31,7 @@ $(document).on("click", "#btn-logout", function (e) {
|
|||||||
|
|
||||||
$(document).on("submit", "#user-update", function (e) {
|
$(document).on("submit", "#user-update", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
formdata = $("#user-update").serializeArray();
|
data = formToJSON($("#user-update"));
|
||||||
data = {};
|
|
||||||
$(formdata).each(function (index, obj) {
|
|
||||||
data[obj.name] = obj.value;
|
|
||||||
});
|
|
||||||
console.log(data);
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/api/auth",
|
url: "/api/auth",
|
||||||
type: "PATCH",
|
type: "PATCH",
|
||||||
|
|||||||
42
web/static/js/utils.js
Normal file
42
web/static/js/utils.js
Normal file
@ -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", "<br>");
|
||||||
|
}
|
||||||
|
|
||||||
|
function formToJSON(form) {
|
||||||
|
formdata = form.serializeArray();
|
||||||
|
data = {};
|
||||||
|
$(formdata).each(function (index, obj) {
|
||||||
|
data[obj.name] = obj.value;
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
}
|
||||||
@ -102,6 +102,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="/static/js/utils.js"></script>
|
||||||
<script src="/static/js/quotes.js"></script>
|
<script src="/static/js/quotes.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@ -94,6 +94,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="/static/js/utils.js"></script>
|
||||||
<script src="/static/js/settings.js"></script>
|
<script src="/static/js/settings.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user