ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
show_popover_with_dynamic_changing_content.php File Reference

Go to the source code of this file.

Functions

 show_popover_with_dynamic_changing_content ()
 

Function Documentation

◆ show_popover_with_dynamic_changing_content()

show_popover_with_dynamic_changing_content ( )

Definition at line 2 of file show_popover_with_dynamic_changing_content.php.

References $_GET, $_SERVER, $DIC, $factory, $list, $url, and exit.

3 {
4  global $DIC;
5  $factory = $DIC->ui()->factory();
6  $renderer = $DIC->ui()->renderer();
7 
8  // This example shows how to change the content of a popover dynamically with ajax requests.
9  // Each popover offers a signal to replace its content, similar to the show signal which shows the popover.
10  // The replace signal will load the new content via ajax from a given URL and insert it into the popover.
11 
12  // The popover in this example initially shows three buttons. Each button will replace the content
13  // of the popover with a new "page" showing some text. Each page also contains a back button which
14  // again replaces the content of the popover with the overview page.
15 
16  $url = $_SERVER['REQUEST_URI'];
17 
18  // This is an ajax request to render the overview page showing the three buttons
19  if (isset($_GET['page']) && $_GET['page'] == 'overview') {
20  // Note: The ID of the replace signal is sent explicitly as GET parameter. This is a proof of concept
21  // and may be subject to change, as the framework could send such parameters implicitly.
22  $signalId = $_GET['replaceSignal'];
23  $replaceSignal = new \ILIAS\UI\Implementation\Component\ReplaceContentSignal($signalId);
24  $button1 = $factory->button()->standard('Go to page 1', '#')
25  ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=1&replaceSignal=' . $signalId));
26  $button2 = $factory->button()->standard('Go to page 2', '#')
27  ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=2&replaceSignal=' . $signalId));
28  $button3 = $factory->button()->standard('Go to page 3', '#')
29  ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=3&replaceSignal=' . $signalId));
30  $list = $factory->listing()->unordered([$button1, $button2, $button3]);
31  echo $renderer->renderAsync($list);
32  exit();
33  }
34 
35  // This is an ajax request to render a page
36  if (isset($_GET['page'])) {
37  $page = (int) $_GET['page'];
38  $signalId = $_GET['replaceSignal'];
39  $replaceSignal = new \ILIAS\UI\Implementation\Component\ReplaceContentSignal($signalId);
40  $button = $factory->button()->standard('Back to Overview', '#')
41  ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=overview&replaceSignal=' . $signalId));
42  $intro = $factory->legacy("<p>You are viewing page {$page}</p>");
43  echo $renderer->renderAsync([$intro, $button]);
44  exit();
45  }
46 
47  // This is the "normal" request to render the popover. Any content of the popover is rendered async.
48  $popover = $factory->popover()->standard($factory->legacy(''))->withTitle('Pages');
49  $asyncUrl = $url . '&page=overview&replaceSignal=' . $popover->getReplaceContentSignal()->getId();
50  $popover = $popover->withAsyncContentUrl($asyncUrl);
51  $button = $factory->button()->standard('Show Popover', '#')
52  ->withOnClick($popover->getShowSignal());
53  return $renderer->render([$popover, $button]);
54 }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$factory
Definition: metadata.php:43
exit
Definition: backend.php:16
$url