m1m02530125 commited on
Commit
375fc23
·
1 Parent(s): 9d19f50

feat: スタッフをアーカイブ後は現役一覧に遷移、複数選択での一括アーカイブ/復元/完全削除に対応

Browse files

- アーカイブ実行後のリダイレクト先をアーカイブ一覧から現役一覧に変更
- スタッフ一覧に選択チェックボックス・全選択・一括操作バーを追加
- POST /employees/bulk を追加し、選択した複数スタッフのアーカイブ/復元/完全削除をまとめて実行
- 一括アーカイブ・一括完全削除用の確認モーダルを追加

Files changed (2) hide show
  1. routes/employees.py +29 -1
  2. templates/employees/index.html +138 -0
routes/employees.py CHANGED
@@ -81,7 +81,7 @@ def reorder():
81
  def archive(emp_id):
82
  repo.delete_employee(emp_id)
83
  flash("アーカイブしました", "success")
84
- return redirect(url_for("employees.index") + "?archive=1")
85
 
86
 
87
  @bp.post("/<int:emp_id>/purge")
@@ -100,6 +100,34 @@ def restore(emp_id):
100
  return redirect(url_for("employees.index") + "?archive=1")
101
 
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  def _form_to_employee(emp_id):
104
  f = request.form
105
  patterns = []
 
81
  def archive(emp_id):
82
  repo.delete_employee(emp_id)
83
  flash("アーカイブしました", "success")
84
+ return redirect(url_for("employees.index"))
85
 
86
 
87
  @bp.post("/<int:emp_id>/purge")
 
100
  return redirect(url_for("employees.index") + "?archive=1")
101
 
102
 
103
+ @bp.post("/bulk")
104
+ def bulk_action():
105
+ action = request.form.get("action")
106
+ ids = [int(i) for i in request.form.getlist("ids") if i.isdigit()]
107
+ if not ids:
108
+ flash("スタッフを選択してください", "error")
109
+ return redirect(url_for("employees.index"))
110
+
111
+ if action == "archive":
112
+ for emp_id in ids:
113
+ repo.delete_employee(emp_id)
114
+ flash(f"{len(ids)}名をアーカイブしました", "success")
115
+ return redirect(url_for("employees.index"))
116
+ elif action == "restore":
117
+ for emp_id in ids:
118
+ repo.restore_employee(emp_id)
119
+ flash(f"{len(ids)}名を復元しました", "success")
120
+ return redirect(url_for("employees.index") + "?archive=1")
121
+ elif action == "purge":
122
+ for emp_id in ids:
123
+ repo.purge_employee(emp_id)
124
+ flash(f"{len(ids)}名を完全に削除しました", "success")
125
+ return redirect(url_for("employees.index") + "?archive=1")
126
+
127
+ flash("不正な操作です", "error")
128
+ return redirect(url_for("employees.index"))
129
+
130
+
131
  def _form_to_employee(emp_id):
132
  f = request.form
133
  patterns = []
templates/employees/index.html CHANGED
@@ -26,6 +26,30 @@
26
  </p>
27
  {% endif %}
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  <!-- 従業員一覧 -->
30
  <div id="emp-list">
31
  {% for emp in employees %}
@@ -33,6 +57,10 @@
33
  data-id="{{ emp.id }}">
34
  <div class="card-body py-2 px-3">
35
  <div class="d-flex align-items-center gap-2">
 
 
 
 
36
  <!-- ドラッグハンドル(検索中・アーカイブ中は非表示) -->
37
  {% if not show_archive and not q %}
38
  <span class="drag-handle text-muted" style="cursor:grab;font-size:1.2rem;padding:4px 2px">
@@ -140,6 +168,55 @@
140
  </div>
141
  </div>
142
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  {% endblock %}
144
 
145
  {% block scripts %}
@@ -188,5 +265,66 @@ function openArchiveModal(action, name) {
188
  document.getElementById('archive-form').action = action;
189
  new bootstrap.Modal(document.getElementById('archiveModal')).show();
190
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  </script>
192
  {% endblock %}
 
26
  </p>
27
  {% endif %}
28
 
29
+ {% if employees %}
30
+ <div class="d-flex align-items-center justify-content-between mb-2">
31
+ <div class="form-check m-0">
32
+ <input class="form-check-input" type="checkbox" id="select-all">
33
+ <label class="form-check-label small text-muted" for="select-all">全選択</label>
34
+ </div>
35
+ <div id="bulk-bar" class="d-flex align-items-center gap-2" style="display:none">
36
+ <span class="small text-muted" id="bulk-count"></span>
37
+ {% if not show_archive %}
38
+ <button type="button" class="btn btn-warning btn-sm" onclick="openBulkArchiveModal()">
39
+ <i class="bi bi-archive me-1"></i>アーカイブ
40
+ </button>
41
+ {% else %}
42
+ <button type="button" class="btn btn-outline-success btn-sm" onclick="submitBulk('restore')">
43
+ <i class="bi bi-arrow-counterclockwise me-1"></i>復元
44
+ </button>
45
+ <button type="button" class="btn btn-danger btn-sm" onclick="openBulkPurgeModal()">
46
+ <i class="bi bi-trash me-1"></i>完全削除
47
+ </button>
48
+ {% endif %}
49
+ </div>
50
+ </div>
51
+ {% endif %}
52
+
53
  <!-- 従業員一覧 -->
54
  <div id="emp-list">
55
  {% for emp in employees %}
 
57
  data-id="{{ emp.id }}">
58
  <div class="card-body py-2 px-3">
59
  <div class="d-flex align-items-center gap-2">
60
+ <div class="form-check m-0">
61
+ <input class="form-check-input emp-select" type="checkbox" value="{{ emp.id }}"
62
+ data-name="{{ emp.name }}" aria-label="{{ emp.name }}を選択">
63
+ </div>
64
  <!-- ドラッグハンドル(検索中・アーカイブ中は非表示) -->
65
  {% if not show_archive and not q %}
66
  <span class="drag-handle text-muted" style="cursor:grab;font-size:1.2rem;padding:4px 2px">
 
168
  </div>
169
  </div>
170
  </div>
171
+
172
+ <!-- 一括アーカイブ確認モーダル -->
173
+ <div class="modal fade" id="bulkArchiveModal" tabindex="-1">
174
+ <div class="modal-dialog modal-dialog-centered modal-sm">
175
+ <div class="modal-content">
176
+ <div class="modal-body p-4 text-center">
177
+ <i class="bi bi-archive-fill text-warning d-block mb-2" style="font-size:2.2rem"></i>
178
+ <div class="fw-semibold mb-1"><span id="bulk-archive-count"></span>名をアーカイブ</div>
179
+ <div id="bulk-archive-names" class="text-muted small mb-2" style="max-height:120px;overflow-y:auto"></div>
180
+ <div style="color:var(--text-muted);font-size:.85rem;margin-bottom:1.25rem">
181
+ 後から復元できます。
182
+ </div>
183
+ <div class="d-flex gap-2">
184
+ <button class="btn btn-secondary flex-grow-1" data-bs-dismiss="modal">キャンセル</button>
185
+ <button type="button" class="btn btn-warning flex-grow-1" onclick="submitBulk('archive', this)">
186
+ <i class="bi bi-archive me-1"></i>アーカイブ
187
+ </button>
188
+ </div>
189
+ </div>
190
+ </div>
191
+ </div>
192
+ </div>
193
+
194
+ <!-- 一括完全削除確認モーダル -->
195
+ <div class="modal fade" id="bulkPurgeModal" tabindex="-1">
196
+ <div class="modal-dialog modal-dialog-centered modal-sm">
197
+ <div class="modal-content">
198
+ <div class="modal-body p-4 text-center">
199
+ <i class="bi bi-trash-fill text-danger d-block mb-2" style="font-size:2.2rem"></i>
200
+ <div class="fw-semibold mb-1"><span id="bulk-purge-count"></span>名を完全に削除</div>
201
+ <div id="bulk-purge-names" class="text-muted small mb-2" style="max-height:120px;overflow-y:auto"></div>
202
+ <div style="color:var(--text-muted);font-size:.85rem;margin-bottom:1.25rem">
203
+ <span class="text-danger fw-semibold">この操作は取り消せません。</span>
204
+ </div>
205
+ <div class="d-flex gap-2">
206
+ <button class="btn btn-secondary flex-grow-1" data-bs-dismiss="modal">キャンセル</button>
207
+ <button type="button" class="btn btn-danger flex-grow-1" onclick="submitBulk('purge', this)">
208
+ <i class="bi bi-trash me-1"></i>完全削除
209
+ </button>
210
+ </div>
211
+ </div>
212
+ </div>
213
+ </div>
214
+ </div>
215
+
216
+ <!-- 一括操作送信用フォーム -->
217
+ <form id="bulk-form" method="post" action="{{ url_for('employees.bulk_action') }}" style="display:none">
218
+ <input type="hidden" name="action" id="bulk-action-input">
219
+ </form>
220
  {% endblock %}
221
 
222
  {% block scripts %}
 
265
  document.getElementById('archive-form').action = action;
266
  new bootstrap.Modal(document.getElementById('archiveModal')).show();
267
  }
268
+
269
+ // ── 複数選択(一括操作) ──────────────────────────────────────────
270
+ function getSelectedEmps() {
271
+ return [...document.querySelectorAll('.emp-select:checked')];
272
+ }
273
+
274
+ function updateBulkBar() {
275
+ const all = document.querySelectorAll('.emp-select');
276
+ const selected = getSelectedEmps();
277
+ const bar = document.getElementById('bulk-bar');
278
+ if (bar) {
279
+ bar.style.display = selected.length > 0 ? 'flex' : 'none';
280
+ document.getElementById('bulk-count').textContent = `${selected.length}件選択中`;
281
+ }
282
+ const selectAll = document.getElementById('select-all');
283
+ if (selectAll) {
284
+ selectAll.checked = all.length > 0 && selected.length === all.length;
285
+ selectAll.indeterminate = selected.length > 0 && selected.length < all.length;
286
+ }
287
+ }
288
+
289
+ document.querySelectorAll('.emp-select').forEach(cb => cb.addEventListener('change', updateBulkBar));
290
+
291
+ document.getElementById('select-all')?.addEventListener('change', e => {
292
+ document.querySelectorAll('.emp-select').forEach(cb => cb.checked = e.target.checked);
293
+ updateBulkBar();
294
+ });
295
+
296
+ function submitBulk(action, btn) {
297
+ const selected = getSelectedEmps();
298
+ if (selected.length === 0) return;
299
+ if (btn) {
300
+ btn.disabled = true;
301
+ btn.innerHTML = '<span class="spinner-border spinner-border-sm me-1"></span>処理中…';
302
+ }
303
+ const form = document.getElementById('bulk-form');
304
+ form.querySelectorAll('input[name="ids"]').forEach(el => el.remove());
305
+ selected.forEach(cb => {
306
+ const inp = document.createElement('input');
307
+ inp.type = 'hidden';
308
+ inp.name = 'ids';
309
+ inp.value = cb.value;
310
+ form.appendChild(inp);
311
+ });
312
+ document.getElementById('bulk-action-input').value = action;
313
+ form.submit();
314
+ }
315
+
316
+ function openBulkArchiveModal() {
317
+ const selected = getSelectedEmps();
318
+ document.getElementById('bulk-archive-count').textContent = selected.length;
319
+ document.getElementById('bulk-archive-names').textContent = selected.map(cb => cb.dataset.name).join('、');
320
+ new bootstrap.Modal(document.getElementById('bulkArchiveModal')).show();
321
+ }
322
+
323
+ function openBulkPurgeModal() {
324
+ const selected = getSelectedEmps();
325
+ document.getElementById('bulk-purge-count').textContent = selected.length;
326
+ document.getElementById('bulk-purge-names').textContent = selected.map(cb => cb.dataset.name).join('、');
327
+ new bootstrap.Modal(document.getElementById('bulkPurgeModal')).show();
328
+ }
329
  </script>
330
  {% endblock %}