ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
show_modal_on_button_click_async_rendered.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
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
$out
Definition: buildRTE.php:24
$renderer
exit
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31