ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\UI\examples\Modal\Interruptive Namespace Reference

Functions

 base ()
 
 show_modal_on_button_click ()
 
 show_modal_on_button_click_async_rendered ()
 
 with_custom_labels ()
 

Function Documentation

◆ base()

ILIAS\UI\examples\Modal\Interruptive\base ( )

description: > Example for rendering an interruptive modal.

expected output: >

ILIAS shows no example because the modal is not called. This behaviour is expected.

Definition at line 32 of file base.php.

33{
34 global $DIC;
35 $factory = $DIC->ui()->factory();
36 $renderer = $DIC->ui()->renderer();
37 $message = 'Are you sure you want to delete the following items?';
38 $form_action = $DIC->ctrl()->getFormActionByClass('ilsystemstyledocumentationgui');
39 $modal = $factory->modal()->interruptive('My Title', $message, $form_action);
40
41 // Note: This modal is just rendered in the DOM but not displayed
42 // because its show/close signals are not triggered by any components
43 return $renderer->render($modal);
44}
$renderer
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31

References $DIC, $message, and $renderer.

◆ show_modal_on_button_click()

ILIAS\UI\examples\Modal\Interruptive\show_modal_on_button_click ( )

description: > Example for rendering a interruptive modal on a click onto a button.

expected output: > Clicking "Show Modal" opens up a modal with some content. A click onto "Delete" will reload the page and displays a confirmation below the example.

A click onto "Cancel" or Close Glyph will hide the modal.

Definition at line 34 of file show_modal_on_button_click.php.

35{
36 global $DIC;
37 $factory = $DIC->ui()->factory();
38 $renderer = $DIC->ui()->renderer();
39 $refinery = $DIC->refinery();
40 $request_wrapper = $DIC->http()->wrapper()->query();
41 $post_wrapper = $DIC->http()->wrapper()->post();
42 $ctrl = $DIC->ctrl();
43
44 $message = 'Are you sure you want to delete the following items?';
45 $ctrl->setParameterByClass('ilsystemstyledocumentationgui', 'modal_nr', 1);
46 $form_action = $ctrl->getFormActionByClass('ilsystemstyledocumentationgui');
47 $icon = $factory->image()->standard('./assets/images/standard/icon_crs.svg', '');
48
49 $items = [
50 $factory->modal()->interruptiveItem()->standard('10', 'Course 1', $icon, 'Some description text'),
51 $factory->modal()->interruptiveItem()->keyValue('20', 'Item Key', 'item value'),
52 $factory->modal()->interruptiveItem()->standard('30', 'Course 3', $icon, 'Last but not least, a description'),
53 $factory->modal()->interruptiveItem()->keyValue('50', 'Second Item Key', 'another item value'),
54 ];
55 $modal = $factory->modal()->interruptive('My Title', $message, $form_action)->withAffectedItems($items);
56 $button = $factory->button()->standard('Show Modal', '')
57 ->withOnClick($modal->getShowSignal());
58
59 $out = [$button, $modal];
60
61 // Display POST data of affected items in a panel
62 if (
63 $post_wrapper->has('interruptive_items') &&
64 $request_wrapper->retrieve('modal_nr', $refinery->kindlyTo()->string()) === '1'
65 ) {
66 $out[] = $post_wrapper->retrieve('interruptive_items', $refinery->custom()->transformation(
67 function ($item_keys) use ($factory, $post_wrapper) {
68 return $factory->panel()->standard('Items deleted', $factory->legacy("Number of items deleted: ".count($item_keys)));
69 }
70 ));
71 }
72
73 return $renderer->render($out);
74}
$out
Definition: buildRTE.php:24

References $DIC, $message, $out, ILIAS\UI\examples\Layout\Page\Standard\$refinery, $renderer, ILIAS\UI\examples\Layout\Page\Standard\$request_wrapper, and ILIAS\UI\examples\MainControls\Slate\Notification\standard().

+ Here is the call graph for this function:

◆ show_modal_on_button_click_async_rendered()

ILIAS\UI\examples\Modal\Interruptive\show_modal_on_button_click_async_rendered ( )

description: > Example for rendering an interruptive modal by clicking a button. In the background an asynchronous action is running.

expected output: >

ILIAS shows three buttons. A click onto the buttons will open a modal each.

Definition at line 32 of file show_modal_on_button_click_async_rendered.php.

33{
34 global $DIC;
35 $factory = $DIC->ui()->factory();
36 $renderer = $DIC->ui()->renderer();
37 $refinery = $DIC->refinery();
38 $request_wrapper = $DIC->http()->wrapper()->query();
39 $post_wrapper = $DIC->http()->wrapper()->post();
40 $ctrl = $DIC->ctrl();
41
42 $message = 'Are you sure you want to delete the following item?';
43 $ctrl->setParameterByClass('ilsystemstyledocumentationgui', 'modal_nr', "2");
44 $form_action = $ctrl->getFormActionByClass('ilsystemstyledocumentationgui');
45 $items = ['First Item', 'Second Item', 'Third Item'];
46
47 // Check if this is the ajax request to deliver the new modal showing the affected item
48 if ($request_wrapper->has('item')) {
49 $id = $request_wrapper->retrieve('item', $refinery->kindlyTo()->string());
50 $item = $items[$id];
51 $affected_item = $factory->modal()->interruptiveItem()->standard($id, $item);
52 $modal = $factory->modal()->interruptive('Delete Items', $message, $form_action)
53 ->withAffectedItems([$affected_item]);
54 echo $renderer->render($modal);
55 exit();
56 }
57
58 // Create a button per item
59 $out = [];
60 foreach ($items as $i => $item) {
61 $ajax_url = $_SERVER['REQUEST_URI'] . '&item=' . $i;
62 $modal = $factory->modal()->interruptive('', '', '')
63 ->withAsyncRenderUrl($ajax_url);
64 $button = $factory->button()->standard('Delete ' . $item, '#')
65 ->withOnClick($modal->getShowSignal());
66 $out[] = $button;
67 $out[] = $modal;
68 }
69
70 // Display POST data of affected items in a panel
71 if (
72 $post_wrapper->has('interruptive_items') &&
73 $request_wrapper->has('modal_nr') && $request_wrapper->retrieve('modal_nr', $refinery->kindlyTo()->string()) === '2'
74 ) {
75 $out[] = $post_wrapper->retrieve('interruptive_items', $refinery->custom()->transformation(
76 function ($v) use ($factory, $post_wrapper, $items) {
77 return $factory->panel()->standard('Affected Item', $factory->legacy()->content($items[$v[0]]));
78 }
79 ));
80 }
81
82 return $renderer->render($out);
83}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
exit
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26

References $_SERVER, $DIC, $id, $message, $out, ILIAS\UI\examples\Layout\Page\Standard\$refinery, $renderer, ILIAS\UI\examples\Layout\Page\Standard\$request_wrapper, exit, and ILIAS\UI\examples\MainControls\Slate\Notification\standard().

+ Here is the call graph for this function:

◆ with_custom_labels()

ILIAS\UI\examples\Modal\Interruptive\with_custom_labels ( )

description: > An example showing how you can set a custom label for the modals action- and cancel-button.

expected output: > ILIAS shows a button titled "I will interrupt you". Clicking the button opens a modal with some content including

two buttons which labels were customized.

Definition at line 34 of file with_custom_labels.php.

35{
36 global $DIC;
37 $factory = $DIC->ui()->factory();
38 $renderer = $DIC->ui()->renderer();
39
40 $modal = $factory->modal()->interruptive(
41 'Interrupting something',
42 'Am I interrupting you?',
43 '#'
44 )->withActionButtonLabel(
45 'Yeah you do!'
46 )->withCancelButtonLabel(
47 'Nah, not really'
48 );
49
50 $trigger = $factory->button()->standard('I will interrupt you', $modal->getShowSignal());
51
52 return $renderer->render([$modal, $trigger]);
53}

References $DIC, and $renderer.