Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ protected function addItemGroupBlock(string $block_id, int $block_pos = 0): void
$item_data["description"]
);
$commands_html = $item_list_gui->getCommandsHTML();
$commands_html .= $item_list_gui->getCustomModalsHTML();

// determine behaviour
$item_group = new ilObjItemGroup($item_data["ref_id"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,11 @@ public function getCommandsHTML(string $title = ''): string
return $this->ui->renderer()->render($this->getCommandsDropdown($title, false));
}

public function getCustomModalsHTML(): string
{
return $this->ui->renderer()->render($this->cust_modals);
}

private function getCommandsDropdown(string $title, bool $for_header = false): StandardDropdown
{
$this->populateCommands($for_header);
Expand Down
67 changes: 42 additions & 25 deletions components/ILIAS/ILIASObject/src/Creation/AddNewItemGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

namespace ILIAS\ILIASObject\Creation;

use ILIAS\UI\Component\Clickable;
use ILIAS\UI\Component\Divider\Horizontal;
use ILIAS\UI\Component\Menu\Sub;
use ILIAS\UI\Component\Modal\RoundTrip;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Renderer as UIRenderer;

Expand All @@ -31,63 +35,66 @@
class AddNewItemGUI
{
private \ilLanguage $lng;
private \ilObjectDefinition $obj_definition;
private \ilSetting $settings;
private \ilAccessHandler $access;
private \ilCtrl $ctrl;
private \ilToolbarGUI $toolbar;
private \ilGlobalTemplateInterface $tpl;

private UIFactory $ui_factory;
private UIRenderer $ui_renderer;
private ?RoundTrip $modal = null;

/**
* @param array<ILIAS\ILIASObject\Creation\AddNewItemElement> $elements
* @param array<AddNewItemElement> $elements
* The Key MUST contain the object type or the
*/
public function __construct(
private array $elements = []
) {
public function __construct(array $elements = [])
{
global $DIC;

$this->lng = $DIC['lng'];
$this->toolbar = $DIC['ilToolbar'];
$this->tpl = $DIC['tpl'];

$this->ui_factory = $DIC['ui.factory'];
$this->ui_renderer = $DIC['ui.renderer'];

$this->createModal($elements);
}

/**
* Add new item selection to current page incl. toolbar (trigger) and overlay
* @param array<AddNewItemElement> $elements
*/
public function render(): void
private function createModal(array $elements): void
{
if ($this->elements === []) {
if ($elements === []) {
return;
}

$modal = $this->ui_factory->modal()->roundtrip(
$this->lng->txt('cntr_add_new_item'),
$this->ui_factory->menu()->drilldown(
$this->lng->txt('object_list'),
$this->buildAddNewItemsMenu($this->elements)
$this->buildAddNewItemsMenu($elements)
)
);
$this->setModal($modal);
}

/**
* Add new item selection to current page incl. toolbar (trigger) and overlay
*/
public function render(): void
{
$modal = $this->getModal();
if (!$modal instanceof RoundTrip) {
return;
}

$this->toolbar->addComponent(
$this->ui_factory->button()->primary(
$this->lng->txt('cntr_add_new_item'),
$modal->getShowSignal()
)
);
$this->tpl->setVariable(
'IL_OBJECT_ADD_NEW_ITEM_MODAL',
$this->ui_renderer->render($modal)
$this->ui_factory->button()->primary($this->lng->txt('cntr_add_new_item'), $modal->getShowSignal())
);
$this->tpl->setVariable('IL_OBJECT_ADD_NEW_ITEM_MODAL', $this->ui_renderer->render($modal));
}

/**
* @return array<Component\Menu\Sub|Component\Clickable|Divider\Horizontal>
* @param array<AddNewItemElement> $elements
* @return ?array<Sub|Clickable|Horizontal>
*/
private function buildAddNewItemsMenu(array $elements): ?array
{
Expand All @@ -99,17 +106,27 @@ private function buildAddNewItemsMenu(array $elements): ?array
$element->getLabel(),
$this->buildAddNewItemsMenu($element->getSubElements())
);
continue;
}
if ($element->getType() === AddNewItemElementTypes::Object) {
$sub_menu[] = $this->ui_factory->link()->bulky(
$element->getIcon(),
$element->getLabel(),
$element->getCreationUri()
);
continue;
}
}

return $sub_menu;
}

public function getModal(): ?RoundTrip
{
return $this->modal;
}

public function setModal(RoundTrip $modal): void
{
$this->modal = $modal;
}
}
62 changes: 45 additions & 17 deletions components/ILIAS/ItemGroup/classes/class.ilObjItemGroupGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
*
*********************************************************************/

use ILIAS\ILIASObject\Creation\AddNewItemGUI;
use ILIAS\ItemGroup\StandardGUIRequest;
use ILIAS\ILIASObject\Properties\Translations\TranslationGUI;
use ILIAS\UI\Component\Modal\RoundTrip;

/**
* User Interface class for item groups
Expand Down Expand Up @@ -223,32 +225,58 @@ protected function afterUpdate(): void
parent::afterUpdate();
}

public function listMaterials(): void
public function listMaterials(bool $open_add_new_object_modal = false): void
{
$tree = $this->tree;
$ilTabs = $this->tabs;
$tpl = $this->tpl;
$this->checkPermission('write');

$this->checkPermission("write");
$this->tabs->activateTab('materials');

$parent_ref_id = $this->tree->getParentId($this->object->getRefId());
$parent_type = ilObject::_lookupType($parent_ref_id, true);
$parent_gui_class = "ilObj{$this->obj_definition->getClassName($parent_type)}GUI";
$this->ctrl->setParameterByClass($parent_gui_class, 'ref_id', $parent_ref_id);

$ilTabs->activateTab("materials");
$elements = $this->buildAddNewItemElements(
$this->getCreatableObjectTypes(),
$parent_gui_class,
$this->object->getRefId()
);
$add_new_item_gui = new AddNewItemGUI($elements);
if ($open_add_new_object_modal && $modal = $add_new_item_gui->getModal()) {
$add_new_item_gui->setModal($modal->withOnLoad($modal->getShowSignal()));
}
$add_new_item_gui->render();

$parent_ref_id = $tree->getParentId($this->object->getRefId());
$this->ctrl->clearParameterByClass($parent_gui_class, 'ref_id');

$tab = new ilItemGroupItemsTableGUI(
$this->gui,
$this,
$open_add_new_object_modal ? 'addNewObject' : 'listMaterials'
);
$this->tpl->setContent($tab->getHTML());
}

public function addNewObject(): void
{
$this->listMaterials(true);
}

public function buildAddNewObjectModal(): ?RoundTrip
{
$parent_ref_id = $this->tree->getParentId($this->object->getRefId());
$parent_type = ilObject::_lookupType($parent_ref_id, true);
$parent_gui_class = 'ilObj' . $this->obj_definition->getClassName($parent_type) . 'GUI';
$parent_gui_class = "ilObj{$this->obj_definition->getClassName($parent_type)}GUI";
$this->ctrl->setParameterByClass($parent_gui_class, 'ref_id', $parent_ref_id);
$gui = new ILIAS\ILIASObject\Creation\AddNewItemGUI(
$this->buildAddNewItemElements(
$this->getCreatableObjectTypes(),
$parent_gui_class,
$this->object->getRefId()
)

$elements = $this->buildAddNewItemElements(
$this->getCreatableObjectTypes(),
$parent_gui_class,
$this->object->getRefId()
);
$gui->render();
$this->ctrl->clearParameterByClass($parent_gui_class, 'ref_id');

$tab = new ilItemGroupItemsTableGUI($this->gui, $this, "listMaterials");
$tpl->setContent($tab->getHTML());
return (new AddNewItemGUI($elements))->getModal();
}

public function getCreatableObjectTypes(): array
Expand Down
21 changes: 21 additions & 0 deletions components/ILIAS/ItemGroup/classes/class.ilObjItemGroupListGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ public function init(): void
$this->commands = ilObjItemGroupAccess::_getCommands();
}

public function initItem(int $ref_id, int $obj_id, string $type, string $title = '', string $description = ''): void
{
parent::initItem($ref_id, $obj_id, $type, $title, $description);

if (!$this->checkCommandAccess('write', '', $ref_id, $type)) {
return;
}

$itgr_gui = new ilObjItemGroupGUI($ref_id);
$modal = $itgr_gui->buildAddNewObjectModal();
if ($modal === null) {
return;
}

$button = $this->ui->factory()->button()->shy(
$this->lng->txt('cntr_add_new_item'),
'#'
)->withOnClick($modal->getShowSignal());
$this->addCustomCommandButton($button, $modal);
}

public function enableSubscribe(bool $status): void
{
$this->subscribe_enabled = false;
Expand Down
Loading