ツール管理へ戻るv3 のソース
<!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: 900px;
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;
}
h2 {
margin: 0 0 14px;
font-size: 1.2rem;
}
.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: 76px;
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,
.notice {
display: none;
margin: 0 0 16px;
padding: 11px 13px;
border-radius: 7px;
}
.error {
color: #9b1c1c;
background: #fff1f1;
border: 1px solid #f0b8b8;
}
.notice {
color: #14532d;
background: #f0fdf4;
border: 1px solid #bbf7d0;
}
.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);
}
button:disabled {
opacity: 0.5;
cursor: not-allowed;
filter: none;
}
.primary {
color: #fff;
background: #2563eb;
}
.secondary {
color: #263548;
background: #e8edf3;
}
.records-section {
margin-top: 30px;
padding-top: 24px;
border-top: 1px solid #dce3ec;
}
.record-count {
margin: 0 0 12px;
color: #526174;
}
.table-wrap {
overflow-x: auto;
border: 1px solid #dce3ec;
border-radius: 8px;
}
table {
width: 100%;
border-collapse: collapse;
min-width: 680px;
}
th,
td {
padding: 9px 10px;
text-align: left;
vertical-align: top;
border-bottom: 1px solid #dce3ec;
overflow-wrap: anywhere;
}
th {
background: #f3f6fa;
white-space: nowrap;
}
tbody tr:last-child td {
border-bottom: 0;
}
.empty-row td {
color: #64748b;
text-align: center;
}
.notice {
margin-top: 16px;
}
.privacy-note {
margin: 18px 0 0;
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">
1件ずつ記録を追加し、最後にすべての記録を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>
<p class="notice" id="noticeMessage" role="status"></p>
<div class="actions">
<button class="primary" type="submit">記録を追加</button>
<button class="secondary" type="reset">入力欄を初期化</button>
</div>
</form>
<section class="records-section" aria-labelledby="recordsHeading">
<h2 id="recordsHeading">記録一覧</h2>
<p class="record-count" id="recordCount" aria-live="polite">記録件数:0件</p>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>待ち時間(分)</th>
<th>相手の区分</th>
<th>依頼内容</th>
<th>作業状況</th>
<th>影響</th>
</tr>
</thead>
<tbody id="recordsBody">
<tr class="empty-row">
<td colspan="5">まだ記録はありません。</td>
</tr>
</tbody>
</table>
</div>
<div class="actions">
<button class="primary" id="downloadButton" type="button" disabled>
全記録をCSVでダウンロード
</button>
<button class="secondary" id="clearRecordsButton" type="button" disabled>
記録一覧を初期化
</button>
</div>
</section>
<p class="privacy-note">
記録はページを開いている間だけブラウザ内に保持されます。
ページを閉じると消去され、外部への送信や自動保存は行いません。
</p>
</main>
<script>
"use strict";
const form = document.getElementById("recordForm");
const errorMessage = document.getElementById("errorMessage");
const noticeMessage = document.getElementById("noticeMessage");
const recordsBody = document.getElementById("recordsBody");
const recordCount = document.getElementById("recordCount");
const downloadButton = document.getElementById("downloadButton");
const clearRecordsButton = document.getElementById("clearRecordsButton");
const records = [];
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 showError(message) {
errorMessage.textContent = message;
errorMessage.style.display = "block";
noticeMessage.textContent = "";
noticeMessage.style.display = "none";
}
function showNotice(message) {
noticeMessage.textContent = message;
noticeMessage.style.display = "block";
errorMessage.textContent = "";
errorMessage.style.display = "none";
}
function clearMessages() {
errorMessage.textContent = "";
errorMessage.style.display = "none";
noticeMessage.textContent = "";
noticeMessage.style.display = "none";
}
function createCell(value) {
const cell = document.createElement("td");
cell.textContent = value;
return cell;
}
function renderRecords() {
recordsBody.replaceChildren();
if (records.length === 0) {
const row = document.createElement("tr");
row.className = "empty-row";
const cell = document.createElement("td");
cell.colSpan = 5;
cell.textContent = "まだ記録はありません。";
row.appendChild(cell);
recordsBody.appendChild(row);
} else {
records.forEach(function (record) {
const row = document.createElement("tr");
row.appendChild(createCell(record.waitMinutes));
row.appendChild(createCell(record.counterparty));
row.appendChild(createCell(record.request));
row.appendChild(createCell(record.workStatus));
row.appendChild(createCell(record.impact));
recordsBody.appendChild(row);
});
}
recordCount.textContent = "記録件数:" + records.length + "件";
downloadButton.disabled = records.length === 0;
clearRecordsButton.disabled = records.length === 0;
}
function escapeCsvCell(value) {
let safeValue = String(value);
if (/^[\s]*[=+\-@]/.test(safeValue)) {
safeValue = "'" + safeValue;
}
return '"' + safeValue.replace(/"/g, '""') + '"';
}
function createCsv() {
const headers = [
"待ち時間(分)",
"相手の区分",
"依頼内容",
"作業状況",
"影響"
];
const lines = [headers.map(escapeCsvCell).join(",")];
records.forEach(function (record) {
const values = [
record.waitMinutes,
record.counterparty,
record.request,
record.workStatus,
record.impact
];
lines.push(values.map(escapeCsvCell).join(","));
});
return lines.join("\r\n");
}
function downloadCsv() {
if (records.length === 0) {
showError("CSVに出力する記録がありません。");
return;
}
const csvText = "\uFEFF" + createCsv();
const blob = new Blob([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);
showNotice(records.length + "件の記録をCSVでダウンロードしました。");
}
function clearRecords() {
if (records.length === 0) {
return;
}
const confirmed = window.confirm(
"記録一覧をすべて消去します。よろしいですか?"
);
if (!confirmed) {
return;
}
records.length = 0;
renderRecords();
clearMessages();
}
form.addEventListener("submit", function (event) {
event.preventDefault();
clearMessages();
const data = getFormData();
const validationError = validateData(data);
if (validationError) {
showError(validationError);
return;
}
records.push(data);
renderRecords();
form.reset();
document.getElementById("waitMinutes").focus();
showNotice("記録を追加しました。続けて入力するか、CSVをダウンロードしてください。");
});
form.addEventListener("reset", function () {
window.setTimeout(clearMessages, 0);
});
downloadButton.addEventListener("click", downloadCsv);
clearRecordsButton.addEventListener("click", clearRecords);
renderRecords();
</script>
</body>
</html>