Spaces:
Running
Running
Update static/process1.js
Browse files- static/process1.js +294 -293
static/process1.js
CHANGED
@@ -1,293 +1,294 @@
|
|
1 |
-
let allUsers = [];
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
}
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
|
|
|
1 |
+
let allUsers = [];
|
2 |
+
let selectedUsers = [];
|
3 |
+
let userToDelete = null;
|
4 |
+
|
5 |
+
// ページ読み込み時にユーザーリストを取得
|
6 |
+
document.addEventListener('DOMContentLoaded', fetchUserList);
|
7 |
+
|
8 |
+
// ユーザーリスト取得 - Flask APIの変更に合わせて修正
|
9 |
+
function fetchUserList() {
|
10 |
+
fetch('/list_base_audio')
|
11 |
+
.then(response => response.json())
|
12 |
+
.then(data => {
|
13 |
+
if (data.status === 'success' && Array.isArray(data.id)) {
|
14 |
+
// APIの変更: data.fileNames → data.id
|
15 |
+
allUsers = data.id;
|
16 |
+
renderUserList(allUsers);
|
17 |
+
} else {
|
18 |
+
showError('メンバーリストの取得に失敗しました');
|
19 |
+
}
|
20 |
+
})
|
21 |
+
.catch(error => {
|
22 |
+
console.error('Error fetching user list:', error);
|
23 |
+
showError('サーバーとの通信中にエラーが発生しました');
|
24 |
+
});
|
25 |
+
}
|
26 |
+
|
27 |
+
// ユーザーリストの表示
|
28 |
+
function renderUserList(users) {
|
29 |
+
const userListElement = document.getElementById('userList');
|
30 |
+
|
31 |
+
if (!users || users.length === 0) {
|
32 |
+
userListElement.innerHTML = `
|
33 |
+
<div class="no-users">
|
34 |
+
<p>登録されているメンバーがいません。</p>
|
35 |
+
<p>「新規登録」から音声を登録してください。</p>
|
36 |
+
</div>
|
37 |
+
`;
|
38 |
+
return;
|
39 |
+
}
|
40 |
+
|
41 |
+
let html = '';
|
42 |
+
users.forEach(user => {
|
43 |
+
const firstLetter = user.substr(0, 1).toUpperCase();
|
44 |
+
html += `
|
45 |
+
<div class="user-item">
|
46 |
+
<input type="checkbox" id="user-${user}" value="${user}" onchange="toggleUserSelection('${user}')">
|
47 |
+
<label for="user-${user}">${user}</label>
|
48 |
+
<div class="user-avatar">${firstLetter}</div>
|
49 |
+
<button class="delete-button" onclick="showDeleteModal('${user}')">
|
50 |
+
<i class="fas fa-trash"></i>
|
51 |
+
</button>
|
52 |
+
</div>
|
53 |
+
`;
|
54 |
+
});
|
55 |
+
|
56 |
+
userListElement.innerHTML = html;
|
57 |
+
|
58 |
+
// 既に選択済みのユーザーがあればチェックを入れる
|
59 |
+
checkStoredSelections();
|
60 |
+
}
|
61 |
+
|
62 |
+
// ユーザー選択の切り替え
|
63 |
+
function toggleUserSelection(username) {
|
64 |
+
const index = selectedUsers.indexOf(username);
|
65 |
+
if (index === -1) {
|
66 |
+
selectedUsers.push(username);
|
67 |
+
} else {
|
68 |
+
selectedUsers.splice(index, 1);
|
69 |
+
}
|
70 |
+
|
71 |
+
updateSelectedCount();
|
72 |
+
updateProceedButton();
|
73 |
+
saveSelections();
|
74 |
+
}
|
75 |
+
|
76 |
+
// すべてのユーザーを選択
|
77 |
+
function selectAllUsers() {
|
78 |
+
selectedUsers = [...allUsers];
|
79 |
+
|
80 |
+
// チェックボックスを更新
|
81 |
+
allUsers.forEach(user => {
|
82 |
+
const checkbox = document.getElementById(`user-${user}`);
|
83 |
+
if (checkbox) checkbox.checked = true;
|
84 |
+
});
|
85 |
+
|
86 |
+
updateSelectedCount();
|
87 |
+
updateProceedButton();
|
88 |
+
saveSelections();
|
89 |
+
}
|
90 |
+
|
91 |
+
// すべての選択を解除
|
92 |
+
function deselectAllUsers() {
|
93 |
+
selectedUsers = [];
|
94 |
+
|
95 |
+
// チェックボックスを更新
|
96 |
+
allUsers.forEach(user => {
|
97 |
+
const checkbox = document.getElementById(`user-${user}`);
|
98 |
+
if (checkbox) checkbox.checked = false;
|
99 |
+
});
|
100 |
+
|
101 |
+
updateSelectedCount();
|
102 |
+
updateProceedButton();
|
103 |
+
saveSelections();
|
104 |
+
}
|
105 |
+
|
106 |
+
// 選択数の表示を更新
|
107 |
+
function updateSelectedCount() {
|
108 |
+
document.getElementById('selectedCount').textContent = `選択中: ${selectedUsers.length}人`;
|
109 |
+
}
|
110 |
+
|
111 |
+
// 進むボタンの有効/無効を更新
|
112 |
+
function updateProceedButton() {
|
113 |
+
document.getElementById('proceedButton').disabled = selectedUsers.length === 0;
|
114 |
+
}
|
115 |
+
|
116 |
+
// 選択を保存
|
117 |
+
function saveSelections() {
|
118 |
+
localStorage.setItem('selectedUsers', JSON.stringify(selectedUsers));
|
119 |
+
}
|
120 |
+
|
121 |
+
// 保存されている選択を読み込み
|
122 |
+
function checkStoredSelections() {
|
123 |
+
const storedSelections = localStorage.getItem('selectedUsers');
|
124 |
+
if (storedSelections) {
|
125 |
+
try {
|
126 |
+
selectedUsers = JSON.parse(storedSelections);
|
127 |
+
selectedUsers = selectedUsers.filter(user => allUsers.includes(user)); // 存在するユーザーのみ選択
|
128 |
+
|
129 |
+
// チェックボックスに反映
|
130 |
+
selectedUsers.forEach(user => {
|
131 |
+
const checkbox = document.getElementById(`user-${user}`);
|
132 |
+
if (checkbox) checkbox.checked = true;
|
133 |
+
});
|
134 |
+
|
135 |
+
updateSelectedCount();
|
136 |
+
updateProceedButton();
|
137 |
+
} catch (e) {
|
138 |
+
console.error('保存された選択の読み込みに失敗しました', e);
|
139 |
+
selectedUsers = [];
|
140 |
+
}
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
// エラー表示
|
145 |
+
function showError(message) {
|
146 |
+
const userListElement = document.getElementById('userList');
|
147 |
+
userListElement.innerHTML = `
|
148 |
+
<div class="no-users">
|
149 |
+
<p>${message}</p>
|
150 |
+
<button class="select-button" onclick="fetchUserList()">再読み込み</button>
|
151 |
+
</div>
|
152 |
+
`;
|
153 |
+
}
|
154 |
+
|
155 |
+
// 選択されたユーザーでサーバーに送信して次のページに進む
|
156 |
+
function proceedWithSelectedUsers() {
|
157 |
+
if (selectedUsers.length === 0) {
|
158 |
+
alert('少なくとも1人のメンバーを選択してください');
|
159 |
+
return;
|
160 |
+
}
|
161 |
+
|
162 |
+
// 選択したユーザーをサーバーに送信
|
163 |
+
fetch('/select_users', {
|
164 |
+
method: 'POST',
|
165 |
+
headers: {
|
166 |
+
'Content-Type': 'application/json',
|
167 |
+
},
|
168 |
+
body: JSON.stringify({
|
169 |
+
users: selectedUsers
|
170 |
+
})
|
171 |
+
})
|
172 |
+
.then(response => response.json())
|
173 |
+
.then(data => {
|
174 |
+
if (data.status === 'success') {
|
175 |
+
// 成功したらインデックスページに進む
|
176 |
+
window.location.href = '/index';
|
177 |
+
} else {
|
178 |
+
alert('エラーが発生しました: ' + (data.error || 'Unknown error'));
|
179 |
+
}
|
180 |
+
})
|
181 |
+
.catch(error => {
|
182 |
+
console.error('Error selecting users:', error);
|
183 |
+
alert('サーバーとの通信中にエラーが発生しました');
|
184 |
+
});
|
185 |
+
}
|
186 |
+
|
187 |
+
// 削除確認モーダルを表示
|
188 |
+
function showDeleteModal(username) {
|
189 |
+
userToDelete = username;
|
190 |
+
document.getElementById('deleteModalText').textContent = `メンバー「${username}」を削除しますか?削除すると元に戻せません。`;
|
191 |
+
document.getElementById('deleteModal').style.display = 'flex';
|
192 |
+
}
|
193 |
+
|
194 |
+
// 削除確認モーダルを非表示
|
195 |
+
function hideDeleteModal() {
|
196 |
+
document.getElementById('deleteModal').style.display = 'none';
|
197 |
+
userToDelete = null;
|
198 |
+
}
|
199 |
+
|
200 |
+
// メンバーの削除を実行
|
201 |
+
function confirmDelete() {
|
202 |
+
if (!userToDelete) return;
|
203 |
+
|
204 |
+
// 削除中の表示
|
205 |
+
document.getElementById('deleteModalText').innerHTML = `
|
206 |
+
<div class="loading">
|
207 |
+
<div class="spinner"></div>
|
208 |
+
<p>メンバー「${userToDelete}」を削除中...</p>
|
209 |
+
</div>
|
210 |
+
`;
|
211 |
+
|
212 |
+
fetch('/reset_member', {
|
213 |
+
method: 'POST',
|
214 |
+
headers: {
|
215 |
+
'Content-Type': 'application/json',
|
216 |
+
},
|
217 |
+
body: JSON.stringify({
|
218 |
+
names: [userToDelete]
|
219 |
+
})
|
220 |
+
})
|
221 |
+
.then(response => response.json())
|
222 |
+
.then(data => {
|
223 |
+
if (data.status === 'success') {
|
224 |
+
// 選択リストからも削除
|
225 |
+
const index = selectedUsers.indexOf(userToDelete);
|
226 |
+
if (index !== -1) {
|
227 |
+
selectedUsers.splice(index, 1);
|
228 |
+
saveSelections();
|
229 |
+
}
|
230 |
+
|
231 |
+
// リストから削除して再表示
|
232 |
+
allUsers = allUsers.filter(user => user !== userToDelete);
|
233 |
+
renderUserList(allUsers);
|
234 |
+
|
235 |
+
// モーダルを閉じる
|
236 |
+
hideDeleteModal();
|
237 |
+
|
238 |
+
// 成功メッセージ表示(オプション)
|
239 |
+
const successMessage = document.createElement('div');
|
240 |
+
successMessage.className = 'success-message';
|
241 |
+
successMessage.innerHTML = `<div style="background: rgba(39, 174, 96, 0.2); color: white; padding: 10px; border-radius: 6px; margin-bottom: 10px; text-align: center;">メンバーを削除しました</div>`;
|
242 |
+
document.querySelector('.container').prepend(successMessage);
|
243 |
+
|
244 |
+
// 数秒後にメッセージを消す
|
245 |
+
setTimeout(() => {
|
246 |
+
successMessage.remove();
|
247 |
+
}, 3000);
|
248 |
+
} else {
|
249 |
+
alert('削除に失敗しました: ' + (data.message || 'Unknown error'));
|
250 |
+
hideDeleteModal();
|
251 |
+
}
|
252 |
+
})
|
253 |
+
.catch(error => {
|
254 |
+
console.error('Error deleting user:', error);
|
255 |
+
alert('サーバーとの通信中にエラーが発生しました');
|
256 |
+
hideDeleteModal();
|
257 |
+
});
|
258 |
+
}
|
259 |
+
|
260 |
+
// ハンバーガーメニュー表示/非表示の切り替え
|
261 |
+
function toggleMenu(event) {
|
262 |
+
event.stopPropagation();
|
263 |
+
const menu = document.getElementById('menu');
|
264 |
+
menu.classList.toggle('open');
|
265 |
+
}
|
266 |
+
|
267 |
+
// メニュー外クリックでメニューを閉じる
|
268 |
+
function closeMenu(event) {
|
269 |
+
const menu = document.getElementById('menu');
|
270 |
+
if (menu.classList.contains('open') && !menu.contains(event.target) && event.target.id !== 'menuButton') {
|
271 |
+
menu.classList.remove('open');
|
272 |
+
}
|
273 |
+
}
|
274 |
+
|
275 |
+
// 各画面へのナビゲーション関数
|
276 |
+
function showUserRegister() {
|
277 |
+
window.location.href = '/userregister';
|
278 |
+
}
|
279 |
+
|
280 |
+
function showIndex() {
|
281 |
+
window.location.href = '/index';
|
282 |
+
}
|
283 |
+
|
284 |
+
function showResults() {
|
285 |
+
window.location.href = '/feedback';
|
286 |
+
}
|
287 |
+
|
288 |
+
function showTalkDetail() {
|
289 |
+
window.location.href = '/talk_detail';
|
290 |
+
}
|
291 |
+
|
292 |
+
function resetAction() {
|
293 |
+
window.location.href = '/reset_html';
|
294 |
+
}
|