|
1 | 1 | <script setup> |
2 | | -import {onMounted, ref, watch} from 'vue'; |
| 2 | +import {onMounted, ref, watch, computed} from 'vue'; |
3 | 3 | import draggable from 'vuedraggable'; |
4 | 4 |
|
5 | 5 | const props = defineProps({ |
@@ -27,6 +27,12 @@ const ljpccalendarmoduletranslations = window.ljpccalendarmoduletranslations |
27 | 27 | const customFields = ref([]); |
28 | 28 | const drag = ref(false); |
29 | 29 |
|
| 30 | +// Select all toggles for permissions |
| 31 | +const selectAllDashboard = ref(false); |
| 32 | +const selectAllCalendar = ref(false); |
| 33 | +const selectAllCreate = ref(false); |
| 34 | +const selectAllEdit = ref(false); |
| 35 | +
|
30 | 36 | const addCustomField = () => { |
31 | 37 | customFields.value.push({ |
32 | 38 | id: Date.now(), |
@@ -62,6 +68,31 @@ onMounted(() => { |
62 | 68 | } |
63 | 69 | }); |
64 | 70 |
|
| 71 | +// Functions to toggle all permissions |
| 72 | +const toggleAllDashboard = () => { |
| 73 | + Object.keys(permissions.value).forEach(key => { |
| 74 | + permissions.value[key].showInDashboard = selectAllDashboard.value; |
| 75 | + }); |
| 76 | +}; |
| 77 | +
|
| 78 | +const toggleAllCalendar = () => { |
| 79 | + Object.keys(permissions.value).forEach(key => { |
| 80 | + permissions.value[key].showInCalendar = selectAllCalendar.value; |
| 81 | + }); |
| 82 | +}; |
| 83 | +
|
| 84 | +const toggleAllCreate = () => { |
| 85 | + Object.keys(permissions.value).forEach(key => { |
| 86 | + permissions.value[key].createItems = selectAllCreate.value; |
| 87 | + }); |
| 88 | +}; |
| 89 | +
|
| 90 | +const toggleAllEdit = () => { |
| 91 | + Object.keys(permissions.value).forEach(key => { |
| 92 | + permissions.value[key].editItems = selectAllEdit.value; |
| 93 | + }); |
| 94 | +}; |
| 95 | +
|
65 | 96 |
|
66 | 97 | const handleSubmit = async (event) => { |
67 | 98 | event.preventDefault(); |
@@ -182,10 +213,25 @@ onMounted(() => { |
182 | 213 | permissions.value[user.id].userTeam = user.text; |
183 | 214 | } |
184 | 215 | }); |
| 216 | + |
| 217 | + // Initialize select all checkboxes based on existing permissions |
| 218 | + updateSelectAllStates(); |
185 | 219 | }) |
186 | 220 | .catch(error => console.error(error)); |
187 | 221 | }); |
188 | 222 |
|
| 223 | +// Function to update select all states based on current permissions |
| 224 | +const updateSelectAllStates = () => { |
| 225 | + const keys = Object.keys(permissions.value); |
| 226 | + if (keys.length === 0) return; |
| 227 | + |
| 228 | + // Only set select all to true if ALL items have that permission |
| 229 | + selectAllDashboard.value = keys.every(key => permissions.value[key].showInDashboard); |
| 230 | + selectAllCalendar.value = keys.every(key => permissions.value[key].showInCalendar); |
| 231 | + selectAllCreate.value = keys.every(key => permissions.value[key].createItems); |
| 232 | + selectAllEdit.value = keys.every(key => permissions.value[key].editItems); |
| 233 | +}; |
| 234 | +
|
189 | 235 | </script> |
190 | 236 |
|
191 | 237 | <template> |
@@ -335,10 +381,62 @@ onMounted(() => { |
335 | 381 | <thead> |
336 | 382 | <tr> |
337 | 383 | <th>{{ ljpccalendarmoduletranslations.userTeam }}</th> |
338 | | - <th>{{ ljpccalendarmoduletranslations.showInDashboardWidget }}</th> |
339 | | - <th>{{ ljpccalendarmoduletranslations.showInCalendar }}</th> |
340 | | - <th v-if="calendarType !== 'ics'">{{ ljpccalendarmoduletranslations.createEvents }}</th> |
341 | | - <th v-if="calendarType !== 'ics'">{{ ljpccalendarmoduletranslations.editEvents }}</th> |
| 384 | + <th> |
| 385 | + <div class="permission-header"> |
| 386 | + {{ ljpccalendarmoduletranslations.showInDashboardWidget }} |
| 387 | + <div class="select-all"> |
| 388 | + <input |
| 389 | + type="checkbox" |
| 390 | + id="select-all-dashboard" |
| 391 | + v-model="selectAllDashboard" |
| 392 | + @change="toggleAllDashboard" |
| 393 | + > |
| 394 | + <label for="select-all-dashboard">{{ ljpccalendarmoduletranslations.all || 'All' }}</label> |
| 395 | + </div> |
| 396 | + </div> |
| 397 | + </th> |
| 398 | + <th> |
| 399 | + <div class="permission-header"> |
| 400 | + {{ ljpccalendarmoduletranslations.showInCalendar }} |
| 401 | + <div class="select-all"> |
| 402 | + <input |
| 403 | + type="checkbox" |
| 404 | + id="select-all-calendar" |
| 405 | + v-model="selectAllCalendar" |
| 406 | + @change="toggleAllCalendar" |
| 407 | + > |
| 408 | + <label for="select-all-calendar">{{ ljpccalendarmoduletranslations.all || 'All' }}</label> |
| 409 | + </div> |
| 410 | + </div> |
| 411 | + </th> |
| 412 | + <th v-if="calendarType !== 'ics'"> |
| 413 | + <div class="permission-header"> |
| 414 | + {{ ljpccalendarmoduletranslations.createEvents }} |
| 415 | + <div class="select-all"> |
| 416 | + <input |
| 417 | + type="checkbox" |
| 418 | + id="select-all-create" |
| 419 | + v-model="selectAllCreate" |
| 420 | + @change="toggleAllCreate" |
| 421 | + > |
| 422 | + <label for="select-all-create">{{ ljpccalendarmoduletranslations.all || 'All' }}</label> |
| 423 | + </div> |
| 424 | + </div> |
| 425 | + </th> |
| 426 | + <th v-if="calendarType !== 'ics'"> |
| 427 | + <div class="permission-header"> |
| 428 | + {{ ljpccalendarmoduletranslations.editEvents }} |
| 429 | + <div class="select-all"> |
| 430 | + <input |
| 431 | + type="checkbox" |
| 432 | + id="select-all-edit" |
| 433 | + v-model="selectAllEdit" |
| 434 | + @change="toggleAllEdit" |
| 435 | + > |
| 436 | + <label for="select-all-edit">{{ ljpccalendarmoduletranslations.all || 'All' }}</label> |
| 437 | + </div> |
| 438 | + </div> |
| 439 | + </th> |
342 | 440 | </tr> |
343 | 441 | </thead> |
344 | 442 | <tbody> |
@@ -449,4 +547,25 @@ small { |
449 | 547 | .merge-tag:hover { |
450 | 548 | text-decoration: underline; |
451 | 549 | } |
| 550 | +
|
| 551 | +.permission-header { |
| 552 | + display: flex; |
| 553 | + flex-direction: column; |
| 554 | +} |
| 555 | +
|
| 556 | +.select-all { |
| 557 | + font-size: 0.85em; |
| 558 | + display: flex; |
| 559 | + align-items: center; |
| 560 | + margin-top: 3px; |
| 561 | +} |
| 562 | +
|
| 563 | +.select-all input { |
| 564 | + margin-right: 5px; |
| 565 | +} |
| 566 | +
|
| 567 | +.select-all label { |
| 568 | + margin-bottom: 0; |
| 569 | + cursor: pointer; |
| 570 | +} |
452 | 571 | </style> |
0 commit comments