Skip to content

Commit

Permalink
artifact-editor-comment matches mm/dd/yy dates and copies the values …
Browse files Browse the repository at this point in the history
…to Date of release.
  • Loading branch information
bengarrett committed Sep 24, 2024
1 parent 6dc40a6 commit 25295c4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
64 changes: 42 additions & 22 deletions assets/js/editor-artifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,28 +349,6 @@ import { clipValue, getElmById, titleize } from "./helper.mjs";
ca.value = audio;
});

const cmmt = document.getElementById("artifact-editor-comment");
if (cmmt === null) {
throw new Error("The comment input is missing.");
}
cmmt.addEventListener("input", (e) => {
e.target.classList.remove("is-valid");
});
const cmmtReset = document.getElementById("artifact-editor-comment-undo");
if (cmmtReset === null) {
throw new Error("The comment reset is missing.");
}
const cmmtResetter = document.getElementById(
"artifact-editor-comment-resetter"
);
if (cmmtResetter === null) {
throw new Error("The comment resetter is missing.");
}
cmmtReset.addEventListener("click", () => {
cmmt.classList.remove("is-valid");
cmmt.value = cmmtResetter.value;
});

const vt = document.getElementById("artifact-editor-virustotal");
if (vt === null) {
throw new Error("The virustotal input is missing.");
Expand Down Expand Up @@ -433,6 +411,48 @@ import { clipValue, getElmById, titleize } from "./helper.mjs";
day.value = values[2];
});

const cmmt = document.getElementById("artifact-editor-comment");
if (cmmt === null) {
throw new Error("The comment input is missing.");
}
cmmt.addEventListener("input", (e) => {
e.target.classList.remove("is-valid");
const unsetDateOfRelease =
year.value == 0 && month.value == 0 && day.value == 0;
if (unsetDateOfRelease == false) {
return;
}
const mmddyyDatePattern =
/(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/(\d{2})/;
const match = mmddyyDatePattern.exec(e.target.value);
if (match) {
const mm = match[1];
const md = match[2];
const my = match[3];
const val = parseInt(my, 10);
year.value = 2000 + val;
if (val >= 79 && val <= 99) {
year.value = 1900 + val;
}
month.value = mm;
day.value = md;
}
});
const cmmtReset = document.getElementById("artifact-editor-comment-undo");
if (cmmtReset === null) {
throw new Error("The comment reset is missing.");
}
const cmmtResetter = document.getElementById(
"artifact-editor-comment-resetter"
);
if (cmmtResetter === null) {
throw new Error("The comment resetter is missing.");
}
cmmtReset.addEventListener("click", () => {
cmmt.classList.remove("is-valid");
cmmt.value = cmmtResetter.value;
});

const dateLastMod = document.getElementById("artifact-editor-date-lastmod");
if (dateLastMod === null) {
// do nothing as the date last mod input is optional
Expand Down
Loading

0 comments on commit 25295c4

Please sign in to comment.