ツール管理へ戻る

v1 → v2 の差分

--- v1
+++ v2
@@ -1,317 +1,423 @@
-<!doctype html>
-<html lang="ja">
-<head>
-  <meta charset="utf-8">
-  <meta name="viewport" content="width=device-width, initial-scale=1">
-  <title>回答待ち時間の把握</title>
-  <style>
-    :root {
-      color-scheme: light;
-      font-family: system-ui, -apple-system, "Noto Sans JP", sans-serif;
-      color: #1f2937;
-      background: #f3f6fa;
-    }
-
-    * {
-      box-sizing: border-box;
-    }
-
-    body {
-      margin: 0;
-      padding: 32px 16px;
-    }
-
-    main {
-      max-width: 760px;
-      margin: 0 auto;
-      padding: 28px;
-      background: #fff;
-      border: 1px solid #dce3ec;
-      border-radius: 14px;
-      box-shadow: 0 8px 24px rgba(31, 41, 55, 0.07);
-    }
-
-    h1 {
-      margin: 0 0 8px;
-      font-size: 1.6rem;
-    }
-
-    .intro {
-      margin: 0 0 22px;
-      color: #526174;
-      line-height: 1.6;
-    }
-
-    .duration {
-      display: flex;
-      align-items: center;
-      gap: 12px;
-      margin-bottom: 22px;
-      padding: 16px;
-      background: #eef5ff;
-      border-radius: 10px;
-    }
-
-    .duration label {
-      font-weight: 700;
-    }
-
-    .duration input {
-      width: 110px;
-    }
-
-    input,
-    textarea {
-      width: 100%;
-      padding: 10px 12px;
-      border: 1px solid #bcc8d6;
-      border-radius: 7px;
-      font: inherit;
-      background: #fff;
-    }
-
-    input:focus,
-    textarea:focus {
-      outline: 3px solid rgba(37, 99, 235, 0.18);
-      border-color: #2563eb;
-    }
-
-    .unit {
-      color: #526174;
-    }
-
-    .field {
-      margin: 0 0 18px;
-    }
-
-    .field label,
-    fieldset legend {
-      display: block;
-      margin-bottom: 7px;
-      font-weight: 700;
-    }
-
-    textarea {
-      min-height: 82px;
-      resize: vertical;
-    }
-
-    fieldset {
-      margin: 0 0 18px;
-      padding: 14px;
-      border: 1px solid #dce3ec;
-      border-radius: 9px;
-    }
-
-    fieldset legend {
-      padding: 0 5px;
-    }
-
-    .choice {
-      display: inline-flex;
-      align-items: center;
-      gap: 7px;
-      margin: 3px 18px 3px 0;
-      cursor: pointer;
-    }
-
-    .choice input {
-      width: auto;
-      margin: 0;
-    }
-
-    .actions {
-      display: flex;
-      flex-wrap: wrap;
-      gap: 10px;
-      margin-top: 22px;
-    }
-
-    button {
-      padding: 10px 15px;
-      border: 0;
-      border-radius: 7px;
-      font: inherit;
-      font-weight: 700;
-      cursor: pointer;
-    }
-
-    .primary {
-      color: #fff;
-      background: #2563eb;
-    }
-
-    .secondary {
-      color: #263548;
-      background: #e8edf3;
-    }
-
-    button:hover {
-      filter: brightness(0.96);
-    }
-
-    #summary {
-      display: none;
-      margin-top: 24px;
-      padding: 16px;
-      border: 1px solid #cbd9ec;
-      border-radius: 9px;
-      background: #f8fbff;
-    }
-
-    #summary h2 {
-      margin: 0 0 10px;
-      font-size: 1.15rem;
-    }
-
-    #summary p {
-      margin: 6px 0;
-      white-space: pre-wrap;
-      overflow-wrap: anywhere;
-    }
-
-    .notice {
-      margin-top: 18px;
-      color: #64748b;
-      font-size: 0.9rem;
-    }
-
-    @media (max-width: 520px) {
-      body {
-        padding: 16px 10px;
-      }
-
-      main {
-        padding: 20px 16px;
-      }
-
-      .duration {
-        align-items: flex-start;
-        flex-wrap: wrap;
-      }
-    }
-
-    @media print {
-      body {
-        padding: 0;
-        background: #fff;
-      }
-
-      main {
-        max-width: none;
-        border: 0;
-        box-shadow: none;
-      }
-
-      .actions,
-      .notice {
-        display: none;
-      }
-    }
-  </style>
-</head>
-<body>
-  <main>
-    <h1>回答待ち時間の把握</h1>
-    <p class="intro">お客様や部下からの回答を待った時間と、その間の作業への影響を記録します。</p>
-
-    <form id="waitForm">
-      <div class="duration">
-        <label for="waitMinutes">待ち時間</label>
-        <input id="waitMinutes" name="waitMinutes" type="number" min="0" step="1" value="60" inputmode="numeric">
-        <span class="unit">分(約1時間)</span>
-      </div>
-
-      <div class="field">
-        <label for="counterparty">相手の区分</label>
-        <input id="counterparty" name="counterparty" type="text" placeholder="例:お客様、部下">
-      </div>
-
-      <div class="field">
-        <label for="request">依頼内容</label>
-        <textarea id="request" name="request" placeholder="回答を依頼した内容を記入"></textarea>
-      </div>
-
-      <fieldset>
-        <legend>回答待ちの間、作業は止まりましたか?</legend>
-        <label class="choice">
-          <input type="radio" name="workStatus" value="作業が止まった">
-          作業が止まった
-        </label>
-        <label class="choice">
-          <input type="radio" name="workStatus" value="別の仕事をしていた">
-          別の仕事をしていた
-        </label>
-        <label class="choice">
-          <input type="radio" name="workStatus" value="未選択">
-          まだ分からない
-        </label>
-      </fieldset>
-
-      <div class="field">
-        <label for="impact">止まった作業・影響</label>
-        <textarea id="impact" name="impact" placeholder="例:次工程に着手できなかった、別作業へ切り替えた"></textarea>
-      </div>
-
-      <div class="actions">
-        <button class="primary" type="submit">記録を表示</button>
-        <button class="secondary" type="button" id="printButton">印刷</button>
-        <button class="secondary" type="reset">入力を消去</button>
-      </div>
-    </form>
-
-    <section id="summary" aria-live="polite">
-      <h2>記録内容</h2>
-      <p><strong>待ち時間:</strong><span id="outMinutes"></span>分</p>
-      <p><strong>相手の区分:</strong><span id="outCounterparty"></span></p>
-      <p><strong>依頼内容:</strong><span id="outRequest"></span></p>
-      <p><strong>作業状況:</strong><span id="outStatus"></span></p>
-      <p><strong>止まった作業・影響:</strong><span id="outImpact"></span></p>
-    </section>
-
-    <p class="notice">このページはブラウザ内だけで動作します。入力内容の自動保存や外部への送信は行いません。機密情報や個人情報は入力しないでください。</p>
-  </main>
-
-  <script>
-    "use strict";
-
-    const form = document.getElementById("waitForm");
-    const summary = document.getElementById("summary");
-
-    function valueOrPlaceholder(value) {
-      return value.trim() || "未記入";
-    }
-
-    form.addEventListener("submit", function (event) {
-      event.preventDefault();
-
-      const minutes = document.getElementById("waitMinutes").value;
-      const selectedStatus = form.querySelector('input[name="workStatus"]:checked');
-
-      document.getElementById("outMinutes").textContent =
-        minutes === "" ? "未記入" : minutes;
-      document.getElementById("outCounterparty").textContent =
-        valueOrPlaceholder(document.getElementById("counterparty").value);
-      document.getElementById("outRequest").textContent =
-        valueOrPlaceholder(document.getElementById("request").value);
-      document.getElementById("outStatus").textContent =
-        selectedStatus ? selectedStatus.value : "未選択";
-      document.getElementById("outImpact").textContent =
-        valueOrPlaceholder(document.getElementById("impact").value);
-
-      summary.style.display = "block";
-      summary.scrollIntoView({ behavior: "smooth", block: "nearest" });
-    });
-
-    document.getElementById("printButton").addEventListener("click", function () {
-      window.print();
-    });
-
-    form.addEventListener("reset", function () {
-      window.setTimeout(function () {
-        summary.style.display = "none";
-      }, 0);
-    });
-  </script>
-</body>
+<!doctype html>
+<html lang="ja">
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1">
+  <title>回答待ち時間の記録</title>
+  <style>
+    :root {
+      font-family: system-ui, -apple-system, "Noto Sans JP", sans-serif;
+      color: #1f2937;
+      background: #f3f6fa;
+    }
+
+    * {
+      box-sizing: border-box;
+    }
+
+    body {
+      margin: 0;
+      padding: 32px 16px;
+    }
+
+    main {
+      max-width: 760px;
+      margin: 0 auto;
+      padding: 28px;
+      background: #fff;
+      border: 1px solid #dce3ec;
+      border-radius: 14px;
+      box-shadow: 0 8px 24px rgba(31, 41, 55, 0.07);
+    }
+
+    h1 {
+      margin: 0 0 8px;
+      font-size: 1.6rem;
+    }
+
+    .description {
+      margin: 0 0 24px;
+      color: #526174;
+      line-height: 1.6;
+    }
+
+    .field {
+      margin-bottom: 18px;
+    }
+
+    .field label,
+    fieldset legend {
+      display: block;
+      margin-bottom: 7px;
+      font-weight: 700;
+    }
+
+    .example {
+      margin: 5px 0 0;
+      color: #64748b;
+      font-size: 0.9rem;
+    }
+
+    input[type="number"],
+    input[type="text"],
+    textarea {
+      width: 100%;
+      padding: 10px 12px;
+      border: 1px solid #bcc8d6;
+      border-radius: 7px;
+      font: inherit;
+      background: #fff;
+    }
+
+    input:focus,
+    textarea:focus {
+      outline: 3px solid rgba(37, 99, 235, 0.18);
+      border-color: #2563eb;
+    }
+
+    textarea {
+      min-height: 82px;
+      resize: vertical;
+    }
+
+    .minutes-row {
+      display: flex;
+      align-items: center;
+      gap: 10px;
+    }
+
+    .minutes-row input {
+      max-width: 180px;
+    }
+
+    fieldset {
+      margin: 0 0 18px;
+      padding: 14px;
+      border: 1px solid #dce3ec;
+      border-radius: 9px;
+    }
+
+    fieldset legend {
+      padding: 0 5px;
+    }
+
+    .choice {
+      display: inline-flex;
+      align-items: center;
+      gap: 7px;
+      margin: 3px 18px 3px 0;
+      cursor: pointer;
+    }
+
+    .choice input {
+      margin: 0;
+    }
+
+    .error {
+      display: none;
+      margin: 0 0 16px;
+      padding: 11px 13px;
+      color: #9b1c1c;
+      background: #fff1f1;
+      border: 1px solid #f0b8b8;
+      border-radius: 7px;
+    }
+
+    .actions {
+      display: flex;
+      flex-wrap: wrap;
+      gap: 10px;
+      margin-top: 22px;
+    }
+
+    button {
+      padding: 10px 15px;
+      border: 0;
+      border-radius: 7px;
+      font: inherit;
+      font-weight: 700;
+      cursor: pointer;
+    }
+
+    button:hover {
+      filter: brightness(0.96);
+    }
+
+    .primary {
+      color: #fff;
+      background: #2563eb;
+    }
+
+    .secondary {
+      color: #263548;
+      background: #e8edf3;
+    }
+
+    .result {
+      display: none;
+      margin-top: 24px;
+      padding: 16px;
+      border: 1px solid #b9dec4;
+      border-radius: 9px;
+      background: #f2fbf4;
+    }
+
+    .result h2 {
+      margin: 0 0 8px;
+      font-size: 1.1rem;
+    }
+
+    .result p {
+      margin: 0;
+      line-height: 1.6;
+    }
+
+    .notice {
+      margin-top: 18px;
+      color: #64748b;
+      font-size: 0.9rem;
+      line-height: 1.5;
+    }
+
+    @media (max-width: 520px) {
+      body {
+        padding: 16px 10px;
+      }
+
+      main {
+        padding: 20px 16px;
+      }
+    }
+  </style>
+</head>
+<body>
+  <main>
+    <h1>回答待ち時間の記録</h1>
+    <p class="description">
+      入力した内容を、Excelで開けるCSVファイルとしてダウンロードできます。
+    </p>
+
+    <form id="recordForm" novalidate>
+      <div class="field">
+        <label for="waitMinutes">待ち時間(分)</label>
+        <div class="minutes-row">
+          <input
+            id="waitMinutes"
+            name="waitMinutes"
+            type="number"
+            min="0"
+            step="1"
+            placeholder="例:60"
+            inputmode="numeric"
+            required
+          >
+          <span>分</span>
+        </div>
+        <p class="example">入力例:60(約1時間)</p>
+      </div>
+
+      <div class="field">
+        <label for="counterparty">相手の区分</label>
+        <input
+          id="counterparty"
+          name="counterparty"
+          type="text"
+          placeholder="例:お客様、部下"
+          required
+        >
+        <p class="example">個人名などは入力しないでください。</p>
+      </div>
+
+      <div class="field">
+        <label for="request">依頼内容</label>
+        <textarea
+          id="request"
+          name="request"
+          placeholder="例:部品の納期確認"
+          required
+        ></textarea>
+      </div>
+
+      <fieldset>
+        <legend>作業状況</legend>
+        <label class="choice">
+          <input type="radio" name="workStatus" value="作業が止まった">
+          作業が止まった
+        </label>
+        <label class="choice">
+          <input type="radio" name="workStatus" value="別の仕事をしていた">
+          別の仕事をしていた
+        </label>
+        <label class="choice">
+          <input type="radio" name="workStatus" value="影響なし">
+          影響なし
+        </label>
+        <p class="example">いずれかを選択してください。</p>
+      </fieldset>
+
+      <div class="field">
+        <label for="impact">影響</label>
+        <textarea
+          id="impact"
+          name="impact"
+          placeholder="例:次工程の開始が遅れた"
+          required
+        ></textarea>
+      </div>
+
+      <p class="error" id="errorMessage" role="alert"></p>
+
+      <div class="actions">
+        <button class="primary" type="submit">CSVをダウンロード</button>
+        <button class="secondary" type="reset">入力を初期化</button>
+      </div>
+    </form>
+
+    <section class="result" id="resultMessage" aria-live="polite">
+      <h2>CSVを作成しました</h2>
+      <p>入力した5項目を1行にまとめたCSVファイルをダウンロードしました。</p>
+    </section>
+
+    <p class="notice">
+      このページはブラウザ内だけで動作し、入力内容の保存や外部への送信は行いません。
+      ダウンロードしたCSVファイルは、お使いのパソコンで適切に管理してください。
+    </p>
+  </main>
+
+  <script>
+    "use strict";
+
+    const form = document.getElementById("recordForm");
+    const errorMessage = document.getElementById("errorMessage");
+    const resultMessage = document.getElementById("resultMessage");
+
+    function getFormData() {
+      const selectedStatus = form.querySelector('input[name="workStatus"]:checked');
+
+      return {
+        waitMinutes: document.getElementById("waitMinutes").value.trim(),
+        counterparty: document.getElementById("counterparty").value.trim(),
+        request: document.getElementById("request").value.trim(),
+        workStatus: selectedStatus ? selectedStatus.value : "",
+        impact: document.getElementById("impact").value.trim()
+      };
+    }
+
+    function validateData(data) {
+      const minutes = Number(data.waitMinutes);
+
+      if (data.waitMinutes === "") {
+        return "待ち時間を入力してください。";
+      }
+
+      if (!Number.isFinite(minutes) || !Number.isInteger(minutes) || minutes < 0) {
+        return "待ち時間は0以上の整数で入力してください。";
+      }
+
+      if (!data.counterparty) {
+        return "相手の区分を入力してください。";
+      }
+
+      if (!data.request) {
+        return "依頼内容を入力してください。";
+      }
+
+      if (!data.workStatus) {
+        return "作業状況を選択してください。";
+      }
+
+      if (!data.impact) {
+        return "影響を入力してください。";
+      }
+
+      return "";
+    }
+
+    function escapeCsvCell(value) {
+      let safeValue = String(value);
+
+      // Excelで開いた際に、数式として解釈される可能性のある文字を無効化する
+      if (/^[\s]*[=+\-@]/.test(safeValue)) {
+        safeValue = "'" + safeValue;
+      }
+
+      return '"' + safeValue.replace(/"/g, '""') + '"';
+    }
+
+    function createCsv(data) {
+      const headers = [
+        "待ち時間(分)",
+        "相手の区分",
+        "依頼内容",
+        "作業状況",
+        "影響"
+      ];
+
+      const values = [
+        data.waitMinutes,
+        data.counterparty,
+        data.request,
+        data.workStatus,
+        data.impact
+      ];
+
+      return [
+        headers.map(escapeCsvCell).join(","),
+        values.map(escapeCsvCell).join(",")
+      ].join("\r\n");
+    }
+
+    function downloadCsv(csvText) {
+      const bom = "\uFEFF";
+      const blob = new Blob([bom, csvText], {
+        type: "text/csv;charset=utf-8"
+      });
+      const downloadUrl = URL.createObjectURL(blob);
+      const link = document.createElement("a");
+
+      link.href = downloadUrl;
+      link.download = "回答待ち時間の記録.csv";
+      document.body.appendChild(link);
+      link.click();
+      link.remove();
+
+      window.setTimeout(function () {
+        URL.revokeObjectURL(downloadUrl);
+      }, 1000);
+    }
+
+    function showError(message) {
+      errorMessage.textContent = message;
+      errorMessage.style.display = "block";
+      resultMessage.style.display = "none";
+    }
+
+    function clearMessages() {
+      errorMessage.textContent = "";
+      errorMessage.style.display = "none";
+      resultMessage.style.display = "none";
+    }
+
+    form.addEventListener("submit", function (event) {
+      event.preventDefault();
+      clearMessages();
+
+      const data = getFormData();
+      const validationError = validateData(data);
+
+      if (validationError) {
+        showError(validationError);
+        return;
+      }
+
+      const csvText = createCsv(data);
+      downloadCsv(csvText);
+      resultMessage.style.display = "block";
+    });
+
+    form.addEventListener("reset", function () {
+      window.setTimeout(clearMessages, 0);
+    });
+  </script>
+</body>
 </html>