-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwoWorkflowUsers.html
More file actions
437 lines (375 loc) · 15.3 KB
/
Copy pathwoWorkflowUsers.html
File metadata and controls
437 lines (375 loc) · 15.3 KB
1
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Workflow Users</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
padding: 4px;
overflow: hidden;
height: 100vh;
}
.container {
display: flex;
flex-direction: column;
height: 100%;
}
.people-container {
flex: 1;
overflow-x: auto;
overflow-y: hidden;
display: flex;
flex-direction: row;
align-items: flex-start;
padding: 2px;
scrollbar-width: none;
-ms-overflow-style: none;
}
.people-container::-webkit-scrollbar {
display: none;
}
.column {
display: flex;
flex-direction: column;
margin-right: 4px;
min-width: 150px;
}
.person-item {
font-size: 12px;
padding: 2px 4px;
margin: 1px 0;
cursor: pointer;
border-radius: 2px;
transition: all 0.2s;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.person-item:hover {
opacity: 0.8;
transform: translateX(2px);
}
.person-item.selected {
font-weight: bold;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.submit-container {
display: flex;
justify-content: flex-end;
align-items: center;
padding: 1px;
background: #ffffff;
}
.submit-btn {
font-size: 12px;
padding: 4px 12px;
background: #007AFF;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.submit-btn:hover {
background: #0056CC;
}
.submit-btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.clear-btn {
font-size: 12px;
padding: 4px 12px;
background: transparent;
color: #666;
border: 1px solid #999;
border-radius: 4px;
cursor: pointer;
margin-right: 8px;
}
.clear-btn:hover {
background: #eee;
color: #333;
}
.clear-btn.hidden {
display: none;
}
</style>
</head>
<body>
<div class="container">
<div class="people-container" id="peopleContainer"></div>
<div class="submit-container">
<button class="clear-btn hidden" id="clearBtn" onclick="clearSelection()">Clear selection</button>
<button class="submit-btn" id="submitBtn" onclick="submitSelection()">Submit</button>
</div>
</div>
<script>
let allPeople = [];
let filteredPeople = [];
let selectedPeople = new Set();
let isShiftPressed = false;
let containerHeight = 0;
// Generate pastel color based on first 3 characters of department name
function getDepartmentColor(dept) {
if (!dept) return '#E8E8E8';
const str = dept.substring(0, 3).toUpperCase();
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
// Generate pastel colors (light, muted tones)
const hue = Math.abs(hash) % 360;
const saturation = 30 + (Math.abs(hash) % 20); // 30-50% saturation for pastel
const lightness = 85 + (Math.abs(hash) % 10); // 85-95% lightness for pastel
return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
}
// Measure actual height of one person-item (including margin)
function measureItemHeight() {
const container = document.getElementById('peopleContainer');
const item = document.createElement('div');
item.className = 'person-item';
item.textContent = 'M';
const col = document.createElement('div');
col.className = 'column';
col.style.visibility = 'hidden';
col.style.position = 'absolute';
col.style.left = '-9999px';
col.appendChild(item);
container.appendChild(col);
const sty = getComputedStyle(item);
const h = item.offsetHeight + parseInt(sty.marginTop, 10) + parseInt(sty.marginBottom, 10);
col.remove();
return h;
}
// Calculate how many items fit in a column based on container height
function calculateItemsPerColumn() {
const container = document.getElementById('peopleContainer');
const availableHeight = container.clientHeight - 8; // padding + buffer so last row bumps over before crop
if (availableHeight <= 0) return 1;
const itemHeight = measureItemHeight();
const n = Math.floor(availableHeight / itemHeight);
return Math.max(1, n);
}
// Render people in columns
function renderPeople() {
const container = document.getElementById('peopleContainer');
container.innerHTML = '';
if (filteredPeople.length === 0) {
return;
}
containerHeight = 0; // force recalculation each render
const itemsPerColumn = calculateItemsPerColumn();
const numColumns = Math.ceil(filteredPeople.length / itemsPerColumn);
for (let col = 0; col < numColumns; col++) {
const column = document.createElement('div');
column.className = 'column';
const startIdx = col * itemsPerColumn;
const endIdx = Math.min(startIdx + itemsPerColumn, filteredPeople.length);
for (let i = startIdx; i < endIdx; i++) {
const person = filteredPeople[i];
const item = document.createElement('div');
item.className = 'person-item';
item.textContent = person.name;
item.style.backgroundColor = getDepartmentColor(person.dept);
item.dataset.id = person.id;
item.dataset.name = person.name;
item.title = person.dept ? person.dept : 'No department';
if (selectedPeople.has(person.id)) {
item.classList.add('selected');
}
item.addEventListener('mousedown', function(e) {
e.preventDefault();
});
item.addEventListener('click', function(e) {
handlePersonClick(person.id, e.shiftKey);
});
column.appendChild(item);
}
container.appendChild(column);
}
}
// Handle person item click
function handlePersonClick(id, shiftKey) {
if (shiftKey) {
// Toggle selection
if (selectedPeople.has(id)) {
selectedPeople.delete(id);
} else {
selectedPeople.add(id);
}
} else {
// Single select (clear others)
selectedPeople.clear();
selectedPeople.add(id);
}
renderPeople();
updateSubmitButton();
}
// Update submit button state and clear button visibility
function updateSubmitButton() {
const submitBtn = document.getElementById('submitBtn');
const clearBtn = document.getElementById('clearBtn');
submitBtn.disabled = selectedPeople.size === 0;
clearBtn.classList.toggle('hidden', selectedPeople.size === 0);
}
// Clear selection (only shown when there is a selection)
function clearSelection() {
selectedPeople.clear();
renderPeople();
updateSubmitButton();
}
// Submit selection to FileMaker
function submitSelection() {
if (selectedPeople.size === 0) return;
// Send IDs back to FileMaker (not names)
const selectedIds = Array.from(selectedPeople).filter(id => id);
// Send to FileMaker
if (typeof FileMaker !== 'undefined' && FileMaker.PerformScript) {
// Create value list format (newline-delimited)
const valueList = selectedIds.join('\n');
FileMaker.PerformScript('woWorkflow.ReceiveSelectedUsers', valueList);
} else {
console.log('Selected IDs:', selectedIds);
console.log('Value list:', selectedIds.join('\n'));
}
}
// Track shift key state
document.addEventListener('keydown', function(e) {
if (e.key === 'Shift') {
isShiftPressed = true;
}
});
document.addEventListener('keyup', function(e) {
if (e.key === 'Shift') {
isShiftPressed = false;
}
});
// Handle window resize to recalculate columns
let resizeTimeout;
window.addEventListener('resize', function() {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(function() {
containerHeight = 0; // Reset to recalculate
renderPeople();
}, 100);
});
// Function called from FileMaker to populate people from CSV string
// CSV format: "id1,name1,dept1\nid2,name2,dept2" (return-delimited from FileMaker)
// or: "id1,name1,dept1|id2,name2,dept2" (pipe-delimited)
function populatePeople(csvData) {
if (!csvData || csvData.trim() === '') {
allPeople = [];
applyFilter();
return;
}
// Clear existing data
allPeople = [];
selectedPeople.clear();
// Normalize line breaks (FileMaker uses \r, but could be \r\n or \n)
csvData = csvData.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
// Determine delimiter (newline or pipe)
const delimiter = csvData.includes('\n') ? '\n' : (csvData.includes('|') ? '|' : ',');
// Split into rows
const rows = csvData.split(delimiter);
// Parse each row
rows.forEach(row => {
row = row.trim();
if (!row) return; // Skip empty rows
// Split by comma - handle cases where name or dept might contain commas
// Since FileMaker CSV format is id,name,dept, we can safely split by comma
const parts = row.split(',');
if (parts.length >= 3) {
// Standard format: id, name, dept
allPeople.push({
id: parts[0].trim(),
name: parts[1].trim(),
dept: parts[2].trim() || ''
});
} else if (parts.length === 2) {
// Handle case where dept is empty (trailing comma)
allPeople.push({
id: parts[0].trim(),
name: parts[1].trim(),
dept: ''
});
} else if (parts.length === 1 && parts[0].trim()) {
// Edge case: only ID provided
allPeople.push({
id: parts[0].trim(),
name: '',
dept: ''
});
}
});
// Apply current filter
applyFilter();
updateSubmitButton();
}
// Function called from FileMaker to filter by departments
function filterDept(depts) {
// depts can be a string (value list) or array
let deptArray = [];
if (typeof depts === 'string') {
// Handle FileMaker value list (could be pipe, return, or comma delimited)
if (depts.includes('|')) {
deptArray = depts.split('|').map(d => d.trim()).filter(d => d);
} else if (depts.includes('\n')) {
deptArray = depts.split('\n').map(d => d.trim()).filter(d => d);
} else if (depts.includes(',')) {
deptArray = depts.split(',').map(d => d.trim()).filter(d => d);
} else if (depts.trim() !== '') {
deptArray = [depts.trim()];
}
} else if (Array.isArray(depts)) {
deptArray = depts;
}
// Store filter and apply
currentFilter = deptArray;
applyFilter();
}
let currentFilter = [];
// Apply current filter to people list
function applyFilter() {
if (currentFilter.length === 0) {
// No filter - show all
filteredPeople = [...allPeople];
} else {
// Filter by departments
filteredPeople = allPeople.filter(person =>
currentFilter.includes(person.dept)
);
}
// Sort by department alphabetically, then by name within department
filteredPeople.sort(function(a, b) {
const deptA = (a.dept || '').toLowerCase();
const deptB = (b.dept || '').toLowerCase();
if (deptA !== deptB) return deptA.localeCompare(deptB);
return (a.name || '').localeCompare(b.name || '');
});
renderPeople();
}
// Prevent text selection in people list (shift-click selects multiple people, not text)
document.getElementById('peopleContainer').addEventListener('selectstart', function(e) {
e.preventDefault();
});
// Initialize
updateSubmitButton();
// Initial render after a short delay to ensure container has height
setTimeout(function() {
containerHeight = 0;
renderPeople();
}, 100);
</script>
</body>
</html>