From bc5adc19a45c18f9c9ea97f3358e8a2b097f637e Mon Sep 17 00:00:00 2001 From: iszmais <45942348+iszmais@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:55:09 +0100 Subject: [PATCH] refactor dashboard modals for multi manage (#8522) --- .../class.ilDashboardLearningSequenceGUI.php | 21 +- ...class.ilStudyProgrammeDashboardViewGUI.php | 6 +- .../classes/class.ilDashboardBlockGUI.php | 299 +++++------------- .../classes/class.ilMembershipBlockGUI.php | 19 +- .../classes/class.ilSelectedItemsBlockGUI.php | 38 +-- .../Dashboard/Block/js/ReplaceModalContent.js | 40 --- .../Dashboard/Block/js/modal-confirmation.js | 44 +++ .../classes/class.ilFavouritesListGUI.php | 25 +- .../classes/DashboardLayoutProvider.php | 7 + ...class.ilDashboardRecommendedContentGUI.php | 11 +- 10 files changed, 161 insertions(+), 349 deletions(-) delete mode 100644 Services/Dashboard/Block/js/ReplaceModalContent.js create mode 100644 Services/Dashboard/Block/js/modal-confirmation.js diff --git a/Modules/LearningSequence/classes/class.ilDashboardLearningSequenceGUI.php b/Modules/LearningSequence/classes/class.ilDashboardLearningSequenceGUI.php index 39131e510d9a..71a9ca7753b3 100644 --- a/Modules/LearningSequence/classes/class.ilDashboardLearningSequenceGUI.php +++ b/Modules/LearningSequence/classes/class.ilDashboardLearningSequenceGUI.php @@ -21,10 +21,6 @@ use ILIAS\UI\Component\Symbol\Icon\Standard; use ILIAS\Services\Dashboard\Block\BlockDTO; -/** - * @ilCtrl_IsCalledBy ilDashboardLearningSequenceGUI: ilColumnGUI - * @ilCtrl_Calls ilDashboardLearningSequenceGUI: ilCommonActionDispatcherGUI - */ class ilDashboardLearningSequenceGUI extends ilDashboardBlockGUI { protected function getIcon(string $title): Standard @@ -111,23 +107,18 @@ public function getBlockType(): string return 'pdlern'; } - public function confirmedRemoveObject(): void + public function confirmedRemove(array $ids): void { - $refIds = (array) ($this->http->request()->getParsedBody()['ref_id'] ?? []); - if ($refIds === []) { - $this->ctrl->redirect($this, 'manage'); - } - - foreach ($refIds as $ref_id) { - if ($this->access->checkAccess('leave', '', (int) $ref_id)) { - if (ilObject::_lookupType((int) $ref_id, true) === 'lso') { - $lso = ilObjLearningSequence::getInstanceByRefId((int) $ref_id); + foreach ($ids as $ref_id) { + if ($this->access->checkAccess('leave', '', $ref_id)) { + if (ilObject::_lookupType($ref_id, true) === 'lso') { + $lso = ilObjLearningSequence::getInstanceByRefId($ref_id); if ($lso instanceof ilObjLearningSequence) { $lso->getLSRoles()->leave($this->user->getId()); } } - ilForumNotification::checkForumsExistsDelete((int) $ref_id, $this->user->getId()); + ilForumNotification::checkForumsExistsDelete($ref_id, $this->user->getId()); } } diff --git a/Modules/StudyProgramme/classes/class.ilStudyProgrammeDashboardViewGUI.php b/Modules/StudyProgramme/classes/class.ilStudyProgrammeDashboardViewGUI.php index 71fee2b58b14..6eaf128987f8 100644 --- a/Modules/StudyProgramme/classes/class.ilStudyProgrammeDashboardViewGUI.php +++ b/Modules/StudyProgramme/classes/class.ilStudyProgrammeDashboardViewGUI.php @@ -65,7 +65,7 @@ public function initData(): void ) { $properties[$this->lng->txt('prg_dash_label_valid')] = $row->getExpiryDate() ?: $row->getValidity(); - if($cert_link = $this->maybeGetCertificateLink($this->user->getId(), $prg->getId(), $prg->getRefId())) { + if ($cert_link = $this->maybeGetCertificateLink($this->user->getId(), $prg->getId(), $prg->getRefId())) { $properties[$this->lng->txt('certificate')] = $cert_link; } } else { @@ -112,10 +112,6 @@ public function getBlockType(): string return 'pdprg'; } - public function confirmedRemoveObject(): void - { - } - public function removeMultipleEnabled(): bool { return false; diff --git a/Services/Dashboard/Block/classes/class.ilDashboardBlockGUI.php b/Services/Dashboard/Block/classes/class.ilDashboardBlockGUI.php index 5f33d8a0ee8f..c5c78c8d49f8 100644 --- a/Services/Dashboard/Block/classes/class.ilDashboardBlockGUI.php +++ b/Services/Dashboard/Block/classes/class.ilDashboardBlockGUI.php @@ -20,6 +20,7 @@ use ILIAS\HTTP\Services; use ILIAS\Refinery\Factory; +use ILIAS\UI\Component\Modal\RoundTrip; use ILIAS\UI\Implementation\Component\ReplaceSignal; use JetBrains\PhpStorm\NoReturn; use ILIAS\UI\Component\Card\RepositoryObject; @@ -28,10 +29,6 @@ use ILIAS\HTTP\Response\ResponseHeader; use ILIAS\Filesystem\Stream\Streams; -/** - * @ilCtrl_IsCalledBy ilDashboardBlockGUI: ilColumnGUI - * @ilCtrl_Calls ilDashboardBlockGUI: ilCommonActionDispatcherGUI - */ abstract class ilDashboardBlockGUI extends ilBlockGUI implements ilDesktopItemHandling { private string $content; @@ -176,7 +173,6 @@ public function init(): void $this->lng->loadLanguageModule('rep'); $this->lng->loadLanguageModule('pd'); $this->initViewSettings(); - $this->main_tpl->addJavaScript('Services/Dashboard/Block/js/ReplaceModalContent.js'); $this->viewSettings->parse(); $this->requested_item_ref_id = (int) ($this->http->request()->getQueryParams()['item_ref_id'] ?? 0); $this->initData(); @@ -192,15 +188,8 @@ public function init(): void protected function initAndShow(): string { $this->init(); - if ($this->ctrl->isAsynch()) { - $responseStream = Streams::ofString($this->getHTML()); - $response = $this->http->response()->withBody($responseStream); - $this->http->saveResponse($response); - $this->http->sendResponse(); - $this->http->close(); - } if ($this->parent === ilDashboardGUI::class) { - $this->returnToContext(); + $this->ctrl->redirectByClass(ilDashboardGUI::class, 'show'); } return $this->getHTML(); @@ -407,23 +396,73 @@ public function addCommandActions(): void } if ($this->removeMultipleEnabled()) { - $roundtrip_modal = $this->ui->factory()->modal()->roundtrip( - $this->getRemoveMultipleActionText(), - $this->ui->factory()->legacy('PH') - ); - $roundtrip_modal = $roundtrip_modal->withAsyncRenderUrl( - $this->ctrl->getLinkTarget( - $this, - 'removeFromDeskRoundtrip' - ) . '&page=manage&replaceSignal=' . $roundtrip_modal->getReplaceSignal()->getId() - ); $this->addBlockCommand( $this->ctrl->getLinkTarget($this, 'manage'), $this->getRemoveMultipleActionText(), '', - $roundtrip_modal + $this->getRemoveModal() + ); + } + } + + public function getRemoveModal(): RoundTrip + { + $items = $this->getManageFields(); + if ($items !== []) { + if ($this->viewSettings->isSelectedItemsViewActive()) { + $question = $this->lng->txt('dash_info_sure_remove_from_favs'); + } else { + $question = $this->lng->txt('mmbr_info_delete_sure_unsubscribe'); + } + $modal = $this->ui->factory()->modal()->roundtrip( + $this->getRemoveMultipleActionText(), + [ + $this->ui->factory()->messageBox()->confirmation($question), + $this->ui->factory()->messageBox()->info($this->lng->txt('select_one')), + ], + $items, + $this->ctrl->getLinkTargetByClass([ilDashboardGUI::class, $this::class], 'confirmedRemove') + )->withSubmitLabel($this->getRemoveMultipleActionText()); + + $modal = $modal->withOnLoadCode(fn($id) => "il.Dashboard.confirmModal($id)"); + } else { + $modal = $this->ui->factory()->modal()->roundtrip( + $this->getRemoveMultipleActionText(), + $this->ui->factory()->messageBox()->info($this->lng->txt('pd_no_items_to_manage')) ); } + + return $modal; + } + + protected function getManageFields(): array + { + $inputs = []; + foreach ($this->getItemGroups() as $key => $item_group) { + $options = []; + foreach ($item_group as $item) { + $icon = $this->ui->renderer()->render($this->ui->factory()->symbol()->icon()->custom(ilObject::_getIcon($item->getObjId()), '')); + if ($this instanceof ilMembershipBlockGUI) { + if ($this->rbacsystem->checkAccess('leave', $item->getRefId())) { + if ($item->getType() === 'crs' || $item->getType() === 'grp') { + $members_obj = ilParticipants::getInstance($item->getRefId()); + if (!$members_obj->checkLastAdmin([$this->user->getId()])) { + continue; + } + } + $options[$item->getRefId()] = $icon . $item->getTitle(); + } + } else { + $options[$item->getRefId()] = $icon . $item->getTitle(); + } + } + if ($options !== []) { + $inputs[] = $this->ui->factory()->input()->field()->multiSelect((string) $key, $options) + ->withAdditionalTransformation($this->refinery->to()->listOf($this->refinery->kindlyTo()->int())); + } + } + + return $inputs; } public function executeCommand(): string @@ -440,8 +479,15 @@ public function executeCommand(): string break; default: - if (method_exists($this, $cmd . 'Object')) { - return $this->{$cmd . 'Object'}(); + switch ($cmd) { + case 'confirmedRemove': + $form = $this->ui->factory()->input()->container()->form()->standard('', $this->getManageFields())->withRequest($this->http->request()); + $this->confirmedRemove(array_merge(...array_filter($form->getData()))); + // no break + default: + if (method_exists($this, $cmd . 'Object')) { + return $this->{$cmd . 'Object'}(); + } } } return ''; @@ -469,19 +515,6 @@ public function changePDItemPresentationObject(): string return $this->initAndShow(); } - protected function cancel(): void - { - $this->ctrl->returnToParent($this); - } - - protected function returnToContext(): void - { - if ($this->http->request()->getQueryParams()['manage'] ?? false) { - $this->ctrl->redirect($this, 'manage'); - } - $this->ctrl->redirectByClass(ilDashboardGUI::class, 'show'); - } - /** * @return array */ @@ -507,198 +540,26 @@ public function addToDeskObject(): void { $this->favourites_manager->add($this->user->getId(), $this->requested_item_ref_id); $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('rep_added_to_favourites'), true); - $this->returnToContext(); + $this->ctrl->redirectByClass(ilDashboardGUI::class, 'show'); } public function removeFromDeskObject(): void { $this->favourites_manager->remove($this->user->getId(), $this->requested_item_ref_id); $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('rep_removed_from_favourites'), true); - $this->returnToContext(); - } - - #[NoReturn] - public function removeFromDeskRoundtripObject(): void - { - $page = ''; - if ($this->http->wrapper()->query()->has('page')) { - $page = $this->http->wrapper()->query()->retrieve('page', $this->refinery->kindlyTo()->string()); - } - - if ($this->http->wrapper()->query()->has('replaceSignal')) { - $signalId = $this->http->wrapper()->query()->retrieve( - 'replaceSignal', - $this->refinery->kindlyTo()->string() - ); - $replace_signal = new ReplaceSignal($signalId); - } - - switch ($page) { - case 'manage': - $modal = $this->ui->factory()->modal()->roundtrip( - $this->getRemoveMultipleActionText(), - $this->ui->factory()->legacy($this->manage($replace_signal ?? null)) - ); - $content = $modal->withAdditionalOnLoadCode(function ($id) { - return " - $('#$id').attr('data-modal-name', 'remove_modal_view_" . $this->viewSettings->getCurrentView() . "'); - "; - }); - break; - case 'confirm': - default: - if ($this->viewSettings->isSelectedItemsViewActive()) { - $question = $this->lng->txt('dash_info_sure_remove_from_favs'); - } else { - $question = $this->lng->txt('mmbr_info_delete_sure_unsubscribe'); - } - $content = [ - $this->ui->factory()->messageBox()->confirmation($question), - $this->ui->factory()->legacy($this->confirmRemoveObject()) - ]; - } - $responseStream = Streams::ofString($this->ui->renderer()->renderAsync($content)); - $this->http->saveResponse( - $this->http->response() - ->withBody($responseStream) - ->withHeader(ResponseHeader::CONTENT_TYPE, 'application/json') - ); - $this->http->sendResponse(); - $this->http->close(); - } - - public function manage(ReplaceSignal $replace_signal = null): string - { - $page = ''; - if ($this->http->wrapper()->query()->has('page')) { - $page = $this->http->wrapper()->query()->retrieve('page', $this->refinery->kindlyTo()->string()); - } - $top_tb = new ilToolbarGUI(); - $top_tb->setFormAction($this->ctrl->getFormAction($this, 'confirmRemove')); - $top_tb->setFormName('pd_remove_multiple_view_' . $this->viewSettings->getCurrentView()); - $top_tb->setId('pd_remove_multiple_view_' . $this->viewSettings->getCurrentView()); - $top_tb->setLeadingImage(ilUtil::getImagePath('nav/arrow_upright.svg'), $this->lng->txt('actions')); - $this->ctrl->setParameter($this, 'page', 'confirm'); - $url = $this->ctrl->getLinkTarget( - $this, - 'removeFromDeskRoundtrip', - '', - true - ); - $this->ctrl->clearParameters($this); - $button = $this->ui->factory()->button()->standard($this->getRemoveMultipleActionText(), '#') - ->withOnLoadCode(function ($id) use ($url): string { - return " - il.Dashboard.replaceModalContent('$id', " . $this->viewSettings->getCurrentView() . ", '$url'); - "; - }); - - $grouped_items = []; - $item_groups = $this->getItemGroups(); - foreach ($item_groups as $key => $item_group) { - $group = new ilPDSelectedItemsBlockGroup(); - $group->setLabel((string) $key); - $items = []; - foreach ($item_group as $item) { - if ($this->rbacsystem->checkAccess('leave', $item->getRefId())) { - if ($item->getType() === 'crs') { - $members_obj = ilParticipants::getInstance($item->getRefId()); - if (!$members_obj->checkLastAdmin([$this->user->getId()])) { - continue; - } - } - $items[] = $item; - } - } - $group->setItems(array_map(static fn(BlockDTO $item): array => $item->toArray(), $items)); - $grouped_items[] = $group; - } - $top_tb->addStickyItem($button); - - $top_tb->setCloseFormTag(false); - - $bot_tb = new ilToolbarGUI(); - $bot_tb->setLeadingImage(ilUtil::getImagePath('nav/arrow_downright.svg'), $this->lng->txt('actions')); - $bot_tb->addStickyItem($button); - $bot_tb->setOpenFormTag(false); - - $tpl = new ilTemplate('tpl.remove_multiple_modal_id_wrapper.html', true, true, 'Services/Dashboard'); - $manageListHTML = $this->renderManageList($grouped_items); - if ($manageListHTML) { - $tpl->setVariable('CONTENT', $top_tb->getHTML() . $this->renderManageList($grouped_items) . $bot_tb->getHTML()); - } else { - $tpl->setVariable('CONTENT', $this->ui->renderer()->render($this->ui->factory()->messageBox()->info($this->lng->txt('pd_no_items_to_manage')))); - } - $tpl->setVariable('VIEW', $this->viewSettings->getCurrentView()); - - return $tpl->get(); - } - - protected function renderManageList(array $grouped_items): string - { - $this->ctrl->setParameter($this, 'manage', '1'); - $title = ''; - if ( - $this->viewSettings->isSelectedItemsViewActive() || - $this->viewSettings->isRecommendedContentViewActive() || - $this->viewSettings->isMembershipsViewActive() - ) { - $title .= $this->lng->txt('remove'); - } else { - $title .= $this->lng->txt('pd_unsubscribe_memberships'); - } - $title .= ' ' . strtolower($this->lng->txt('from')) . ' ' . - $this->lng->txt('dash_' . $this->viewSettings->getViewName($this->viewSettings->getCurrentView())); - $this->main_tpl->setTitle($title); - - return (new ilDashObjectsTableRenderer($this))->render($grouped_items); - } - - public function confirmRemoveObject(): string - { - $this->ctrl->setParameter($this, 'view', $this->viewSettings->getCurrentView()); - - $refIds = (array) ($this->http->request()->getParsedBody()['id'] ?? []); - if ($refIds === []) { - $message_box = $this->ui->factory()->messageBox()->info($this->lng->txt('select_one')); - return $this->ui->renderer()->render($message_box); - } - - if ($this->viewSettings->isSelectedItemsViewActive()) { - $question = $this->lng->txt('dash_info_sure_remove_from_favs'); - } else { - $question = $this->lng->txt('mmbr_info_delete_sure_unsubscribe'); - } - - $cgui = new ilConfirmationGUI(); - $cgui->setHeaderText($question); - - $cgui->setFormAction($this->ctrl->getFormAction($this)); - $cgui->setCancel($this->lng->txt('cancel'), 'viewDashboard'); - $cgui->setConfirm($this->lng->txt('confirm'), 'confirmedRemove'); - - foreach ($refIds as $ref_id) { - $obj_id = ilObject::_lookupObjectId((int) $ref_id); - $title = ilObject::_lookupTitle($obj_id); - $type = ilObject::_lookupType($obj_id); - - $cgui->addItem( - 'ref_id[]', - $ref_id, - $title, - ilObject::_getIcon($obj_id, 'small', $type), - $this->lng->txt('icon') . ' ' . $this->lng->txt('obj_' . $type) - ); - } - - return $cgui->getHTML(); + $this->ctrl->redirectByClass(ilDashboardGUI::class, 'show'); } abstract public function removeMultipleEnabled(): bool; abstract public function getRemoveMultipleActionText(): string; - abstract public function confirmedRemoveObject(): void; + /** + * @param int[] $ids + */ + public function confirmedRemove(array $ids): void + { + } public function byType(string $a_type): ilObjectListGUI { diff --git a/Services/Dashboard/Block/classes/class.ilMembershipBlockGUI.php b/Services/Dashboard/Block/classes/class.ilMembershipBlockGUI.php index c36bb5c7988e..47249dbcd005 100644 --- a/Services/Dashboard/Block/classes/class.ilMembershipBlockGUI.php +++ b/Services/Dashboard/Block/classes/class.ilMembershipBlockGUI.php @@ -69,18 +69,13 @@ public function getBlockType(): string return 'pdmem'; } - public function confirmedRemoveObject(): void + public function confirmedRemove(array $ids): void { - $refIds = (array) ($this->http->request()->getParsedBody()['ref_id'] ?? []); - if ($refIds === []) { - $this->ctrl->redirect($this, 'manage'); - } - - foreach ($refIds as $ref_id) { - if ($this->access->checkAccess('leave', '', (int) $ref_id)) { - switch (ilObject::_lookupType((int) $ref_id, true)) { + foreach ($ids as $ref_id) { + if ($this->access->checkAccess('leave', '', $ref_id)) { + switch (ilObject::_lookupType($ref_id, true)) { case 'crs': - $members = new ilCourseParticipants(ilObject::_lookupObjId((int) $ref_id)); + $members = new ilCourseParticipants(ilObject::_lookupObjId($ref_id)); $members->delete($this->user->getId()); $members->sendUnsubscribeNotificationToAdmins($this->user->getId()); @@ -91,7 +86,7 @@ public function confirmedRemoveObject(): void break; case 'grp': - $members = new ilGroupParticipants(ilObject::_lookupObjId((int) $ref_id)); + $members = new ilGroupParticipants(ilObject::_lookupObjId($ref_id)); $members->delete($this->user->getId()); $members->sendNotification( @@ -107,7 +102,7 @@ public function confirmedRemoveObject(): void continue 2; } - ilForumNotification::checkForumsExistsDelete((int) $ref_id, $this->user->getId()); + ilForumNotification::checkForumsExistsDelete($ref_id, $this->user->getId()); } } diff --git a/Services/Dashboard/Block/classes/class.ilSelectedItemsBlockGUI.php b/Services/Dashboard/Block/classes/class.ilSelectedItemsBlockGUI.php index 825d272e410e..3124d0d4b738 100644 --- a/Services/Dashboard/Block/classes/class.ilSelectedItemsBlockGUI.php +++ b/Services/Dashboard/Block/classes/class.ilSelectedItemsBlockGUI.php @@ -21,9 +21,6 @@ use ILIAS\Services\Dashboard\Block\BlockDTO; use ILIAS\UI\Component\Modal\RoundTrip; -/** - * @ilCtrl_IsCalledBy ilSelectedItemsBlockGUI: ilColumnGUI - */ class ilSelectedItemsBlockGUI extends ilDashboardBlockGUI { public function initViewSettings(): void @@ -90,15 +87,10 @@ public function getBlockType(): string return 'pditems'; } - public function confirmedRemoveObject(): void + public function confirmedRemove(array $ids): void { - $refIds = (array) ($this->http->request()->getParsedBody()['ref_id'] ?? []); - if ($refIds === []) { - $this->ctrl->redirect($this, 'manage'); - } - - foreach ($refIds as $ref_id) { - $this->favourites_manager->remove($this->user->getId(), (int) $ref_id); + foreach ($ids as $ref_id) { + $this->favourites_manager->remove($this->user->getId(), $ref_id); } $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('pd_remove_multi_confirm'), true); @@ -114,28 +106,4 @@ public function getRemoveMultipleActionText(): string { return $this->lng->txt('pd_remove_multiple'); } - - public function getConfigureModal(): RoundTrip - { - $roundtrip_modal = $this->ui->factory()->modal()->roundtrip( - $this->lng->txt('rep_configure'), - $this->ui->factory()->legacy('PH') - )->withAdditionalOnLoadCode(function ($id) { - return "document.body.appendChild(document.getElementById('$id')); - let configure_modal_script = document.body.appendChild(document.createElement('script')); - configure_modal_script.src = 'Services/Dashboard/Block/js/ReplaceModalContent.js'; - document.body.appendChild(configure_modal_script); - let modal_js_script = document.body.appendChild(document.createElement('script')); - modal_js_script.src = 'src/UI/templates/js/Modal/modal.js'; - document.body.appendChild(modal_js_script); - "; - }); - - return $roundtrip_modal->withAsyncRenderUrl( - $this->ctrl->getLinkTargetByClass( - [ilDashboardGUI::class, ilColumnGUI::class, $this::class], - 'removeFromDeskRoundtrip' - ) . '&page=manage&replaceSignal=' . $roundtrip_modal->getReplaceSignal()->getId() - ); - } } diff --git a/Services/Dashboard/Block/js/ReplaceModalContent.js b/Services/Dashboard/Block/js/ReplaceModalContent.js deleted file mode 100644 index 1347bb629d96..000000000000 --- a/Services/Dashboard/Block/js/ReplaceModalContent.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * This file is part of ILIAS, a powerful learning management system - * published by ILIAS open source e-Learning e.V. - * - * ILIAS is licensed with the GPL-3.0, - * see https://www.gnu.org/licenses/gpl-3.0.en.html - * You should have received a copy of said license along with the - * source code, too. - * - * If this is not the case or you just want to try ILIAS, you'll find - * us at: - * https://www.ilias.de - * https://github.com/ILIAS-eLearning - * - *********************************************************************/ - -il.Dashboard = il.Dashboard || {}; -/** - * @param {string} id - * @param {int} view - * @param {string} url - */ -il.Dashboard.replaceModalContent = function (id, view, url) { - document.getElementById(id).addEventListener('click', function (e) { - const form = document.querySelector('form[name="pd_remove_multiple_view_' + view + '"]'); - const formData = new FormData(form); - let post_data = ''; - for (const [name, value] of formData) { - post_data += 'id[]=' + encodeURIComponent(value) + '&'; - } - const modal = document.querySelector('div[data-modal-name="remove_modal_view_' + view + '"]'); - post_data = post_data.slice(0, -1); - form.addEventListener('submit', function (e) { - e.preventDefault(); - }); - const modalFooter = modal.querySelector('.modal-footer'); - modalFooter.parentNode.removeChild(modalFooter); - il.Util.ajaxReplacePostRequestInner(url, post_data, 'pd_unsubscribe_multiple_view_' + view); - }); -}; diff --git a/Services/Dashboard/Block/js/modal-confirmation.js b/Services/Dashboard/Block/js/modal-confirmation.js new file mode 100644 index 000000000000..ea15db360b07 --- /dev/null +++ b/Services/Dashboard/Block/js/modal-confirmation.js @@ -0,0 +1,44 @@ +/** + * This file is part of ILIAS, a powerful learning management system + * published by ILIAS open source e-Learning e.V. + * + * ILIAS is licensed with the GPL-3.0, + * see https://www.gnu.org/licenses/gpl-3.0.en.html + * You should have received a copy of said license along with the + * source code, too. + * + * If this is not the case or you just want to try ILIAS, you'll find + * us at: + * https://www.ilias.de + * https://github.com/ILIAS-eLearning + * + *********************************************************************/ + +il.Dashboard = il.Dashboard || {}; + +il.Dashboard.confirmModal = function (node) { + node.querySelectorAll('.alert').forEach((e) => { + e.hidden = true; + }); + node.querySelector('button[id]').addEventListener('click', (e) => { + if (node.querySelector('.alert-warning').hidden) { + e.preventDefault(); + e.stopPropagation(); + } + if (node.querySelector('input:checked') !== null) { + node.querySelector('.alert-info').hidden = true; + node.querySelector('.alert-warning').hidden = false; + node.querySelectorAll('input').forEach((input) => { + input.hidden = true; + input.closest('li').hidden = true; + input.closest('ul').parentNode.parentNode.style.display = 'none'; + }); + node.querySelectorAll('input:checked').forEach((input) => { + input.closest('li').hidden = false; + input.closest('ul').parentNode.parentNode.style.display = ''; + }); + } else { + node.querySelector('.alert-info').hidden = false; + } + }, true); +}; diff --git a/Services/Dashboard/Favourites/classes/class.ilFavouritesListGUI.php b/Services/Dashboard/Favourites/classes/class.ilFavouritesListGUI.php index 26d7197c6e97..5025d3b1ac04 100644 --- a/Services/Dashboard/Favourites/classes/class.ilFavouritesListGUI.php +++ b/Services/Dashboard/Favourites/classes/class.ilFavouritesListGUI.php @@ -18,16 +18,12 @@ declare(strict_types=1); -/** - * Favourites UI - * - * @author Alexander Killing - */ -class ilFavouritesListGUI +class ilFavouritesListGUI extends ilSelectedItemsBlockGUI { protected ILIAS\DI\UIServices $ui; protected ilCtrl $ctrl; protected ilLanguage $lng; + protected ilSelectedItemsBlockGUI $favoritesManager; public function __construct(?ilObjUser $user = null) { @@ -42,16 +38,17 @@ public function __construct(?ilObjUser $user = null) $this->ui = $DIC->ui(); $this->ctrl = $DIC->ctrl(); $this->lng = $DIC->language(); + $this->favoritesManager = new ilSelectedItemsBlockGUI(); $this->lng->loadLanguageModule('rep'); + } public function render(): string { - $favoritesManager = new ilSelectedItemsBlockGUI(); $f = $this->ui->factory(); $item_groups = []; $ctrl = $this->ctrl; - foreach ($favoritesManager->getItemGroups() as $key => $group) { + foreach ($this->favoritesManager->getItemGroups() as $key => $group) { $items = []; foreach ($group as $item) { $items[] = $f->item()->standard( @@ -63,15 +60,13 @@ public function render(): string } } if (count($item_groups) > 0) { - $ctrl->setParameterByClass(ilSelectedItemsBlockGUI::class, 'view', '0'); - $ctrl->setParameterByClass(ilSelectedItemsBlockGUI::class, 'col_side', 'center'); - $ctrl->setParameterByClass(ilSelectedItemsBlockGUI::class, 'block_type', 'pditems'); - // see PR discussion at https://github.com/ILIAS-eLearning/ILIAS/pull/5247/files - $configureModal = $favoritesManager->getConfigureModal(); + $configureModal = $this->favoritesManager->getRemoveModal()->withAdditionalOnLoadCode(static fn($id) => " + document.querySelector('#mainspacekeeper').append($id) + "); $config_item = $f->item()->standard( $f->button()->shy( - $this->lng->txt('rep_configure'), + $this->favoritesManager->getRemoveMultipleActionText(), $configureModal->getShowSignal() ) ); @@ -81,6 +76,6 @@ public function render(): string return $this->ui->renderer()->render([$panel, $configureModal]); } - return $favoritesManager->getNoItemFoundContent(); + return $this->favoritesManager->getNoItemFoundContent(); } } diff --git a/Services/Dashboard/GlobalScreen/classes/DashboardLayoutProvider.php b/Services/Dashboard/GlobalScreen/classes/DashboardLayoutProvider.php index 6698fb44c92b..e094a1b17504 100644 --- a/Services/Dashboard/GlobalScreen/classes/DashboardLayoutProvider.php +++ b/Services/Dashboard/GlobalScreen/classes/DashboardLayoutProvider.php @@ -18,6 +18,7 @@ declare(strict_types=1); +use ILIAS\DI\Container; use ILIAS\GlobalScreen\Scope\Layout\Provider\AbstractModificationProvider; use ILIAS\GlobalScreen\Scope\Layout\Provider\ModificationProvider; use ILIAS\GlobalScreen\ScreenContext\Stack\ContextCollection; @@ -30,6 +31,12 @@ class DashboardLayoutProvider extends AbstractModificationProvider implements Mo { protected ?Collection $data_collection; + public function __construct(Container $dic) + { + $dic->ui()->mainTemplate()->addJavaScript('Services/Dashboard/Block/js/modal-confirmation.js'); + parent::__construct($dic); + } + public function isInterestedInContexts(): ContextCollection { return $this->context_collection->desktop(); diff --git a/Services/Repository/RecommendedContent/classes/class.ilDashboardRecommendedContentGUI.php b/Services/Repository/RecommendedContent/classes/class.ilDashboardRecommendedContentGUI.php index 8587bf8f0ea0..c7f936e19760 100644 --- a/Services/Repository/RecommendedContent/classes/class.ilDashboardRecommendedContentGUI.php +++ b/Services/Repository/RecommendedContent/classes/class.ilDashboardRecommendedContentGUI.php @@ -114,16 +114,11 @@ public function addCustomCommandsToActionMenu(ilObjectListGUI $itemListGui, int ); } - public function confirmedRemoveObject(): void + public function confirmedRemoveObject(array $ids): void { $rec_manager = new ilRecommendedContentManager(); - $refIds = (array) ($this->http->request()->getParsedBody()['ref_id'] ?? []); - if ($refIds === []) { - $this->ctrl->redirect($this, 'manage'); - } - - foreach ($refIds as $ref_id) { - $rec_manager->declineObjectRecommendation($this->user->getId(), (int) $ref_id); + foreach ($ids as $ref_id) { + $rec_manager->declineObjectRecommendation($this->user->getId(), $ref_id); } $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('pd_remove_multi_confirm'), true); $this->ctrl->returnToParent($this);